astiopendata

package
v0.0.0-...-4ce532d Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2017 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	RetryMax   = flag.Int("ratp-client-retry-max", 0, "the RATP client max retry")
	RetrySleep = flag.Duration("ratp-client-retry-sleep", 0, "the RATP client max sleep")
)

Flags

View Source
var (
	ErrNotFound = errors.New("Not found")
)

Vars

View Source
var Send = func(req *http.Request, httpClient *http.Client) (*http.Response, error) {
	return httpClient.Do(req)
}

Send allows testing functions using it

Functions

This section is empty.

Types

type Client

type Client struct {
	Client               *http.Client
	Logger               xlog.Logger
	MaxRequestsPerSecond int
	RetryMax             int
	RetrySleep           time.Duration
}

Client represents an entity capable of interacting with the Open Data RATP API

func New

func New(c Configuration) *Client

New creates a new Client

func (*Client) GeoPoint

func (c *Client) GeoPoint(id string) (g GeoPoint, err error)

GeoPoint returns the station geo point of a specific ID

func (*Client) Lines

func (c *Client) Lines() (l []Line, err error)

Lines returns the lines

func (*Client) Missions

func (c *Client) Missions() (m []Mission, err error)

TODO Missions returns the missions

func (*Client) Send

func (c *Client) Send(action string, e Envelope) (resp *http.Response, err error)

Send sends a request to the Open Data RATP API

func (*Client) SendWithMaxRetries

func (c *Client) SendWithMaxRetries(action string, e Envelope) (o Envelope, err error)

SendWithMaxRetries tries sending a request to the Open Data RATP API and retries in case of specific conditions

func (*Client) Stations

func (c *Client) Stations() (s []Station, err error)

Stations returns the stations

func (*Client) Version

func (c *Client) Version() (v Version, err error)

Version returns the version

type Configuration

type Configuration struct {
	RetryMax   int           `toml:"retry_max"`
	RetrySleep time.Duration `toml:"retry_sleep"`
}

Configuration represents the RATP configuration

func FlagConfig

func FlagConfig() Configuration

FlagConfig generates a Configuration based on flags

type Direction

type Direction struct {
	Name              string
	Line              Line
	EndOfLineStations []Station
	Way               DirectionWay
}

Direction represents a direction

type DirectionWay

type DirectionWay string

DirectionWay represents a direction way

const (
	DirectionWayOneWay     DirectionWay = "one way"
	DirectionWayReturnTrip DirectionWay = "return trip"
)

Direction ways

func (*DirectionWay) UnmarshalText

func (w *DirectionWay) UnmarshalText(b []byte) error

UnmarshalText allows DirectionWay to implement the TextUnmarshaler interface

type Envelope

type Envelope struct {
	Body    *EnvelopeBody `xml:"http://www.w3.org/2003/05/soap-envelope Body"`
	XMLName xml.Name      `xml:"http://www.w3.org/2003/05/soap-envelope Envelope"`
}

Envelope represents the envelope of the SOAP API

type EnvelopeBody

type EnvelopeBody struct {
	GetGeoPointsRequest  *GetGeoPointsRequest  `xml:"http://wsiv.ratp.fr getGeoPoints"`
	GetGeoPointsResponse *GetGeoPointsResponse `xml:"http://wsiv.ratp.fr getGeoPointsResponse"`
	GetLinesRequest      *GetLinesRequest      `xml:"http://wsiv.ratp.fr getLines"`
	GetLinesResponse     *GetLinesResponse     `xml:"http://wsiv.ratp.fr getLinesResponse"`
	GetStationsRequest   *GetStationsRequest   `xml:"http://wsiv.ratp.fr getStations"`
	GetStationsResponse  *GetStationsResponse  `xml:"http://wsiv.ratp.fr getStationsResponse"`
	GetVersionRequest    *GetVersionRequest    `xml:"http://wsiv.ratp.fr getVersion"`
	GetVersionResponse   *GetVersionResponse   `xml:"http://wsiv.ratp.fr getVersionResponse"`
}

EnvelopeBody represents the envelope body

type GeoPoint

type GeoPoint struct {
	ID         string       `xml:"id"`
	Name       string       `xml:"name"`
	NameSuffix string       `xml:"nameSuffix"`
	Type       GeoPointType `xml:"type"`
	X          float64      `xml:"x"`
	Y          float64      `xml:"y"`
}

GeoPoint represents a geographical point

type GeoPointRequestFilter

type GeoPointRequestFilter struct {
	ID   string       `xml:"http://wsiv.ratp.fr/xsd id"`
	Type GeoPointType `xml:"http://wsiv.ratp.fr/xsd type"`
}

GeoPointRequestFilter represents the gp filter

type GeoPointType

type GeoPointType string

GeoPointType represents a geo point type

const (
	GeoPointTypeAddress GeoPointType = "address"
	GeoPointTypeSpot    GeoPointType = "spot"
	GeoPointTypeStation GeoPointType = "station"
)

GeoPoint types

func (*GeoPointType) UnmarshalText

func (t *GeoPointType) UnmarshalText(b []byte) error

UnmarshalText allows DirectionWay to implement the TextUnmarshaler interface

type GetGeoPointsRequest

type GetGeoPointsRequest struct {
	GeoPoint GeoPointRequestFilter `xml:"http://wsiv.ratp.fr gp"`
	Limit    int                   `xml:"http://wsiv.ratp.fr limit"`
}

GetGeoPointsRequest represents the getGeoPoints request

type GetGeoPointsResponse

type GetGeoPointsResponse struct {
	GeoPoints []GeoPoint `xml:"http://wsiv.ratp.fr return"`
	XMLName   xml.Name   `xml:"http://wsiv.ratp.fr getGeoPointsResponse"`
}

GetGeoPointsResponse represents the getGeoPoints response

type GetLinesRequest

type GetLinesRequest struct{}

GetLinesRequest represents the getLines request

type GetLinesResponse

type GetLinesResponse struct {
	Lines   []Line   `xml:"http://wsiv.ratp.fr return"`
	XMLName xml.Name `xml:"http://wsiv.ratp.fr getLinesResponse"`
}

GetLinesResponse represents getLines response

type GetStationsRequest

type GetStationsRequest struct {
	Limit int `xml:"http://wsiv.ratp.fr limit"`
}

GetStationsRequest represents the getStations request

type GetStationsResponse

type GetStationsResponse struct {
	Result  ResultStation `xml:"http://wsiv.ratp.fr return"`
	XMLName xml.Name      `xml:"http://wsiv.ratp.fr getStationsResponse"`
}

GetStationsResponse represents the getStations response

type GetVersionRequest

type GetVersionRequest struct{}

GetVersionRequest represents the getVersion request

type GetVersionResponse

type GetVersionResponse struct {
	Version Version  `xml:"http://wsiv.ratp.fr return"`
	XMLName xml.Name `xml:"http://wsiv.ratp.fr getVersionResponse"`
}

GetVersionResponse represents getVersion response

type Line

type Line struct {
	Code     string    `xml:"http://wsiv.ratp.fr/xsd code"`
	CodeSTIF string    `xml:"http://wsiv.ratp.fr/xsd codeStif"`
	ID       string    `xml:"http://wsiv.ratp.fr/xsd id"`
	Image    string    `xml:"http://wsiv.ratp.fr/xsd image"`
	Name     string    `xml:"http://wsiv.ratp.fr/xsd name"`
	Network  Network   `xml:"http://wsiv.ratp.fr/xsd reseau"`
	Realm    LineRealm `xml:"http://wsiv.ratp.fr/xsd realm"`
}

Line represents a line

type LineRealm

type LineRealm string

LineRealm represents a line realm

const (
	LineRealmRealTime    LineRealm = "real time"
	LineRealmTheoretical LineRealm = "theoretical"
)

Line realms

func (*LineRealm) UnmarshalText

func (r *LineRealm) UnmarshalText(b []byte) error

UnmarshalText allows LineRealm to implement the TextUnmarshaler interface

type Mission

type Mission struct {
	Code             string
	Direction        Direction
	ID               string
	Line             Line
	EndOfLineStation Station
	Perturbations    []string // TODO Parse message
	Stations         []MissionStation
}

Mission represents a mission

type MissionStation

type MissionStation struct {
	Date     time.Time
	Message  string // TODO Parse message
	Platform string
	Station  Station
	Stop     bool
}

MissionStation represents a mission station

type Network

type Network struct {
	Code  NetworkCode `xml:"code"`
	ID    string      `xml:"id"`
	Image string      `xml:"image"`
	Name  string      `xml:"name"`
}

Network represents a network

type NetworkCode

type NetworkCode string

NetworkCode represents a network code

const (
	NetworkCodeMetro          NetworkCode = "Metro"
	NetworkCodeOptile         NetworkCode = "Optile"
	NetworkCodeOtherBuses     NetworkCode = "Other buses"
	NetworkCodeRATPBus        NetworkCode = "RATP Bus"
	NetworkCodeRATPNoctilien  NetworkCode = "RATP Noctilien"
	NetworkCodeRER            NetworkCode = "RER"
	NetworkCodeSNCFNoctilien  NetworkCode = "SNCF Noctilien"
	NetworkCodeSNCFTransilien NetworkCode = "SNCF Transilien"
	NetworkCodeTramway        NetworkCode = "Tramway"
)

Network codes

func NetworkCodeFromString

func NetworkCodeFromString(i string) (c NetworkCode, err error)

NetworkCodeFromString returns a network code from a string

func (*NetworkCode) UnmarshalText

func (c *NetworkCode) UnmarshalText(b []byte) (err error)

UnmarshalText allows NetworkCode to implement the TextUnmarshaler interface

type ResponseMissions

type ResponseMissions struct {
	Missions []Mission `xml:"http://wsiv.ratp.fr return"`
	XMLName  xml.Name  `xml:"http://wsiv.ratp.fr getMissionResponse"`
}

ResponseMissions represents response of the getMission action

type ResultStation

type ResultStation struct {
	Stations []Station `xml:"http://wsiv.ratp.fr/xsd stations"`
}

ResultStation represents the result of the response of the getStations action

type Station

type Station struct {
	ID                 string      `xml:"id"`
	GeoPointOneWay     GeoPoint    `xml:"geoPointA"`
	GeoPointReturnTrip GeoPoint    `xml:"geoPointR"`
	Line               Line        `xml:"line"`
	Name               string      `xml:"name"`
	StationArea        StationArea `xml:"stationArea"`
}

Station represents a station

type StationArea

type StationArea struct {
	ID string `xml:"id"`
}

StationArea represents a station area

type Version

type Version string

Version represents the version

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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