tpggo

package module
Version: v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2018 License: MIT Imports: 9 Imported by: 0

README

tpggo

An http client for the TPG Open Data.

For more explanation: TPG Open Data

Installation

go get github.com/gophersch/tpggo

Usage

package main

import (
	"fmt"

	"github.com/gophersch/tpggo"
)

const (
	apiKey = "MY_KEY"
)

func main() {

	client := tpggo.NewClient(apiKey)

	// Get all the stops
	if resp, err := client.GetStops(); err != nil {
		panic(err)
	} else {
		for _, stop := range resp.Stops {
			fmt.Printf("Stop Name: %s | Code: %s \n", stop.Code, stop.Name)
		}
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIClient

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

APIClient is an HTTP client for the TPG API.

func NewClient

func NewClient(key string) *APIClient

NewClient create a new APIClient instance with the provided key as API key.

func NewClientWithClient

func NewClientWithClient(key string, client *http.Client) *APIClient

NewClientWithClient offer the possibility to provide a custom http client to use.

func (*APIClient) GetAllNextDepartures

func (c *APIClient) GetAllNextDepartures(stopCode, lineCode, destinationCode string) (GetAllNextDeparturesResponse, error)

GetAllNextDepartures returns the next departures.

func (*APIClient) GetDisruptions

func (c *APIClient) GetDisruptions() (GetDisruptionsResponse, error)

GetDisruptions returns the list of the disruptions on the network.

func (*APIClient) GetLinesColor

func (c *APIClient) GetLinesColor() (GetLinesResponse, error)

GetLinesColor returns visual informations about the lines

func (*APIClient) GetNextDeparturesForLines

func (c *APIClient) GetNextDeparturesForLines(linesCodes, destinationsCodes []string) (GetNextDeparturesResponse, error)

GetNextDeparturesForLines returns the list of departures corresponding to the provided lines and destinations codes.

func (*APIClient) GetNextDeparturesForStop

func (c *APIClient) GetNextDeparturesForStop(stopCode, departureCode string) (GetNextDeparturesResponse, error)

GetNextDeparturesForStop returns the list of departures for the providedstop. If departure code is an empty value, all the next departure corresponding to the stop code will be returned.

func (*APIClient) GetPhysicalStopsByName

func (c *APIClient) GetPhysicalStopsByName(name string) (GetPhysicalStopsResponse, error)

GetPhysicalStopsByName returns the list of physical stops whose stopCode is contained in the `codes` list. Results are send by ascending order regarding the stop code.

func (*APIClient) GetPhysicalStopsFromCodes

func (c *APIClient) GetPhysicalStopsFromCodes(codes []string) (GetPhysicalStopsResponse, error)

GetPhysicalStopsFromCodes returns the list of physicalstops whose stopCode is contained in the `codes` list. Results are send by ascending order regarding the stop code.

func (*APIClient) GetStops

func (c *APIClient) GetStops() (GetStopResponse, error)

GetStops returns the list of all the stops. Results are send by ascending order regarding the stop code.

func (*APIClient) GetStopsByLine

func (c *APIClient) GetStopsByLine(name string) (GetStopResponse, error)

GetStopsByLine returns the list of stops on the provided line. Results are send by ascending order regarding the stop code.

func (*APIClient) GetStopsByName

func (c *APIClient) GetStopsByName(name string) (GetStopResponse, error)

GetStopsByName returns the list of stops whose name include the substring `name`. Results are send by ascending order regarding the stop code.

func (*APIClient) GetStopsClosedToLatLng

func (c *APIClient) GetStopsClosedToLatLng(pos LatLng) (GetStopResponse, error)

GetStopsClosedToLatLng returns all the stops located inside a 500 meter range from the provided position. Results are send by descending distance from the provided position.

func (*APIClient) GetStopsFromCodes

func (c *APIClient) GetStopsFromCodes(codes []string) (GetStopResponse, error)

GetStopsFromCodes returns the list of stops whose stopCode is contained in the `codes` list. Results are send by ascending order regarding the stop code.

func (*APIClient) GetThermometer

func (c *APIClient) GetThermometer(departureCode string) (GetThermometerResponse, error)

GetThermometer returns the list of stops with the disruptions and deviations.

func (*APIClient) GetThermometerPhysicalStops

func (c *APIClient) GetThermometerPhysicalStops(departureCode string) (GetThermometerResponse, error)

GetThermometerPhysicalStops returns the list of stops with the disruptions and deviations.

type APIError

type APIError struct {
	Timestamp    APITime `json:"timestamp"`
	ErrorCode    int     `json:"errorCode"`
	ErrorMessage string  `json:"errorMessage"`
}

APIError returns the information about the failing request

type APITime

type APITime struct {
	time.Time
}

APITime wraps time.Time for handle custom formatting

func (APITime) Equal

func (t APITime) Equal(o time.Time) bool

func (APITime) String

func (t APITime) String() string

func (*APITime) UnmarshalJSON

func (t *APITime) UnmarshalJSON(b []byte) error

type Connection

type Connection struct {
	DestinationCode string `json:"destinationCode"`
	DestinationName string `json:"destinationName"`
	LineCode        string `json:"lineCode"`
}

type Coordinates

type Coordinates struct {
	Latitude    float64 `json:"latitude"`
	Longitude   float64 `json:"longitude"`
	Referential string  `json:"referential"`
}

type Departure

type Departure struct {
	DepartureCode     int64      `json:"departureCode"`
	Line              Connection `json:"line"`
	Reliability       string     `json:"reliability"`
	Timestamp         string     `json:"timestamp"`
	WaitingTime       string     `json:"waitingTime"`
	WaitingTimeMillis int64      `json:"waitingTimeMillis"`
}

type Deviation

type Deviation struct {
	DeviationCode string `json:"deviationCode"`
}

type Disruption

type Disruption struct {
	Code        string  `json:"disruptionCode"`
	Timestamp   APITime `json:"timestamp"`
	Place       string  `json:"place"`
	Consequence string  `json:"consequence"`
	Nature      string  `json:"nature"`
	LineCode    string  `json:"lineCode"`
	StopName    string  `json:"stopName"`
}

type GetAllNextDeparturesResponse

type GetAllNextDeparturesResponse struct {
	Departures []Departure `json:"departures"`
	Stop       Stop        `json:"stop"`
	Timestamp  APITime     `json:"timestamp"`
}

type GetDisruptionsResponse

type GetDisruptionsResponse struct {
	Disruptions []Disruption `json:"disruptions"`
	Timestamp   APITime      `json:"timestamp"`
}

type GetLinesResponse

type GetLinesResponse struct {
	Timestamp APITime     `json:"timestamp"`
	Colors    []LineColor `json:"colors"`
}

GetLinesResponse is the response to a get lines response.

type GetNextDeparturesResponse

type GetNextDeparturesResponse struct {
	Departures []NextDeparture `json:"departures"`
	Stop       Stop            `json:"stop"`
	Timestamp  APITime         `json:"timestamp"`
}

type GetPhysicalStopsResponse

type GetPhysicalStopsResponse struct {
	Stops     []PhysicalStopInfos `json:"stops"`
	Timestamp APITime             `json:"timestamp"`
}

type GetStopResponse

type GetStopResponse struct {
	Stops     []Stop  `json:"stops"`
	Timestamp APITime `json:"timestamp"`
}

GetStopResponse contains the response of the API for any GetStops methods.

type GetThermometerResponse

type GetThermometerResponse struct {
	DestinationCode string      `json:"destinationCode"`
	DestinationName string      `json:"destinationName"`
	LineCode        string      `json:"lineCode"`
	Steps           []Step      `json:"steps"`
	Stop            Stop        `json:"stop"`
	Timestamp       APITime     `json:"timestamp"`
	Disruption      Disruption  `json:"disruptions"`
	Deviations      []Deviation `json:"deviations"`
}

type LatLng

type LatLng struct {
	Lat float64
	Lng float64
}

LatLng represents a WGS84 projection of a point

type LineColor

type LineColor struct {
	LineCode   string `json:"lineCode"`
	Hexa       string `json:"hexa"`
	Background string `json:"background"`
	Text       string `json:"text"`
}

LineColor contains the visual information about a line.

type NextDeparture

type NextDeparture struct {
	Departure
	Characteristics       string       `json:"characteristics"`
	Disruptions           []Disruption `json:"disruptions"`
	VehiculeNo            int64        `json:"vehiculeNo"`
	VehiculeType          string       `json:"vehiculeType"`
	Deviation             Deviation    `json:"deviation,omitempty"`
	ConnectionWaitingTime int          `json:"connectionWaitingTime,omitempty"`
}

type PhysicalStop

type PhysicalStop struct {
	Connections      []Connection `json:"connections"`
	Coordinates      Coordinates  `json:"coordinates"`
	PhysicalStopCode string       `json:"physicalStopCode"`
	StopName         string       `json:"stopName"`
}

type PhysicalStopInfos

type PhysicalStopInfos struct {
	PhysicalStops []PhysicalStop `json:"physicalStops"`
	StopCode      string         `json:"stopCode"`
	StopName      string         `json:"stopName"`
}

type Step

type Step struct {
	DepartureCode int64  `json:"departureCode,omitempty"`
	Deviation     bool   `json:"deviation"`
	DeviationCode string `json:"deviationCode"`
	Reliability   string `json:"reliability,omitempty"`
	Stop          Stop   `json:"stop"`
	Timestamp     string `json:"timestamp"`
	Visible       bool   `json:"visible"`
}

type Stop

type Stop struct {
	Connections []Connection `json:"connections"`
	Code        string       `json:"stopCode"`
	Name        string       `json:"stopName"`
	Distance    int          `json:"distance"`
}

type UnknownResponseError

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

UnknownResponseError represents an unknown server error

func (UnknownResponseError) Error

func (e UnknownResponseError) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL