ptv

package module
v0.0.0-...-c466710 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 1, 2016 License: MIT Imports: 12 Imported by: 0

README

Go API for Public Transport Victoria

Installation

go get github.com/Checksum/go-ptv-api

Usage

import "github.com/Checksum/go-ptv-api"

func main() {
    client := ptv.NewClient("developerID", "secretKey")
    healthCheck, resp, err := client.HealthCheck.Get()
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FloatToString

func FloatToString(num float64) string

FloatToString converts a float64 number to string

Types

type Client

type Client struct {

	// Base URL for requests
	BaseURL *url.URL

	// Services
	HealthCheck HealthCheckService
	StopsNearMe StopService
	// contains filtered or unexported fields
}

Client manages the communication with the API Modeled after https://github.com/digitalocean/godo/blob/master/godo.go

func NewClient

func NewClient(developerID, securityKey string) *Client

NewClient returns a new PTV API client

func (*Client) Do

func (c *Client) Do(req *http.Request, v interface{}) (*http.Response, error)

Do actually sends the API request. It calculates the signature using the request url, appends it to the request and returns the API response. The API response is JSON decoded and stored as "v" or returns an error. If "v" implements the io.Writer interface, the raw response is written to it, instead of decoding

func (*Client) GenerateSignature

func (c *Client) GenerateSignature(urlStr string) string

GenerateSignature returns the HMAC-SHA1 of the complete request string

func (*Client) NewRequest

func (c *Client) NewRequest(method, urlStr string, body interface{}) (*http.Request, error)

NewRequest creates an API request. A relative URL can be provided in urlStr, which will be resolved to the BaseURL of the Client. Relative URLS should always be specified without a preceding slash. If specified, the value pointed to by body is JSON encoded and included in as the request body.

type HealthCheck

type HealthCheck struct {
	SecurityTokenOK bool `json:"securityTokenOK,omitempty"`
	ClientClockOK   bool `json:"clientClockOK,omitempty"`
	MemcacheOK      bool `json:"memcacheOK,omitempty"`
	DatabaseOK      bool `json:"databaseOK,omitempty"`
}

HealthCheck response

type HealthCheckService

type HealthCheckService interface {
	Get() (*HealthCheck, *http.Response, error)
}

HealthCheckService interfaces with the /healthcheck endpoint

type HealthCheckServiceOp

type HealthCheckServiceOp struct {
	// contains filtered or unexported fields
}

HealthCheckServiceOp handles communication

func (*HealthCheckServiceOp) Get

Get healthcheck info

type NearmeResponse

type NearmeResponse []struct {
	Result Stop   `json:"result"`
	Type   string `json:"type"`
}

NearmeResponse represents the result from the API

type RequestCompletedCallback

type RequestCompletedCallback func(*http.Request, *http.Response)

RequestCompletedCallback defines the type of request callback function

type RouteType

type RouteType int

RouteType represents the type of route. Ex: train, tram, bus

const (
	Train RouteType = iota
	Tram
	Bus
	VLine
	NightBus
)

Types of stops

func (RouteType) String

func (i RouteType) String() string

type Stop

type Stop struct {
	Distance      float64   `json:"distance"`
	Suburb        string    `json:"suburb"`
	TransportType string    `json:"transport_type"`
	RouteType     RouteType `json:"route_type"`
	StopID        int       `json:"stop_id"`
	LocationName  string    `json:"location_name"`
	Latitude      float64   `json:"lat"`
	Longitude     float64   `json:"lon"`
}

Stop represents a single transport stop

type StopService

type StopService interface {
	Get(lat, lon float64) (NearmeResponse, *http.Response, error)
}

StopService interfaces with the /nearme endpoint

type StopServiceOp

type StopServiceOp struct {
	// contains filtered or unexported fields
}

StopServiceOp handles communication

func (*StopServiceOp) Get

func (s *StopServiceOp) Get(lat, lon float64) (NearmeResponse, *http.Response, error)

Get stops nearme

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL