Documentation
¶
Index ¶
- Constants
- type Connection
- type ConnectionsRequest
- type ConnectionsResults
- type JourneyRequest
- type JourneyResults
- type Logging
- type Paging
- type PlacesRequest
- type PlacesResults
- type RegionRequest
- type RegionResults
- type RemoteError
- type RemoteErrorID
- type Scope
- func (scope *Scope) ArrivalsSA(ctx context.Context, req ConnectionsRequest, resource types.ID) (*ConnectionsResults, error)
- func (scope *Scope) ArrivalsSP(ctx context.Context, req ConnectionsRequest, resource types.ID) (*ConnectionsResults, error)
- func (scope *Scope) DeparturesSA(ctx context.Context, req ConnectionsRequest, resource types.ID) (*ConnectionsResults, error)
- func (scope *Scope) DeparturesSP(ctx context.Context, req ConnectionsRequest, resource types.ID) (*ConnectionsResults, error)
- func (scope *Scope) Journeys(ctx context.Context, req JourneyRequest) (*JourneyResults, error)
- func (scope *Scope) Places(ctx context.Context, params PlacesRequest) (*PlacesResults, error)
- type Session
- func (s *Session) ArrivalsC(ctx context.Context, req ConnectionsRequest, coords types.Coordinates) (*ConnectionsResults, error)
- func (s *Session) DeparturesC(ctx context.Context, req ConnectionsRequest, coords types.Coordinates) (*ConnectionsResults, error)
- func (s *Session) Journeys(ctx context.Context, req JourneyRequest) (*JourneyResults, error)
- func (s *Session) Places(ctx context.Context, params PlacesRequest) (*PlacesResults, error)
- func (s *Session) RegionByID(ctx context.Context, req RegionRequest, id types.ID) (*RegionResults, error)
- func (s *Session) RegionByPos(ctx context.Context, req RegionRequest, coords types.Coordinates) (*RegionResults, error)
- func (s *Session) Regions(ctx context.Context, req RegionRequest) (*RegionResults, error)
- func (s *Session) Scope(region types.ID) *Scope
Constants ¶
const ( // DefaultAPIProtocol is the protocol to be used DefaultAPIProtocol = "https" // DefaultAPIHostname is the known Navitia API hostname DefaultAPIHostname = "api.navitia.io" // DefaultAPIVersion is the used API Version DefaultAPIVersion = "v1" )
const ( RemoteErrDateOutOfBounds RemoteErrorID = "date_out_of_bounds" // When the given date is out of bounds of the production dates of the region RemoteErrNoOrigin = "no_origin" // Couldn’t find an origin for the journeys RemoteErrNoDestination = "no_destination" // Couldn’t find an destination for the journeys RemoteErrNoOriginNoDestination = "nor_origin_nor_destination" // Couldn’t find an origin nor a destination for the journeys RemoteErrUnknownObject = "unknown_object" // Unknown Object RemoteErrBadFilter = "bad_filter" // Bad filter (with custom filter) RemoteErrUnableToParse = "unable_to_parse" // Unable to parse mal-formed custom filter" )
RemoteErrXXX are the known error ids that can be returned by the navitia server
const Version = "v0.2"
Version is the version of this package
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Connection ¶
A Connection is either a Departure or an Arrival
type ConnectionsRequest ¶
type ConnectionsRequest struct { // From what time on do you want to see the results ? From time.Time // Maximum duration between From and the retrieved results. // // Default value is 24 hours Duration time.Duration // The maximum amount of results // // Default value is 10 results Count uint // ForbiddenURIs Forbidden []types.ID // Freshness of the data Freshness types.DataFreshness // Enables GeoJSON data in the reply. GeoJSON objects can be VERY large ! >1MB. Geo bool }
ConnectionsRequest contains the optional parameters for a Departures request.
type ConnectionsResults ¶
type ConnectionsResults struct { Connections []Connection Paging Paging `json:"links"` Logging `json:"-"` }
ConnectionsResults holds the results of a departures or arrivals request.
func (*ConnectionsResults) UnmarshalJSON ¶
func (cr *ConnectionsResults) UnmarshalJSON(b []byte) error
UnmarshalJSON implements unmarshalling for ConnectionsResults.
type JourneyRequest ¶
type JourneyRequest struct { // There must be at least one From or To parameter defined // When used with just one of them, the resulting Journey won't have a populated Sections field. From types.ID To types.ID // When do you want to depart ? Or is DateIsArrival when do you want to arrive at your destination. Date time.Time DateIsArrival bool // The traveller's type Traveler types.TravelerType // Define the freshness of data to use to compute journeys Freshness types.DataFreshness // Forbidden public transport objects Forbidden []types.ID // Allowed public transport objects // Note: This counstraint intersects with Forbidden Allowed []types.ID // Force the first section mode if it isn't a public transport mode // Note: The parameter is inclusive, not exclusive. As such if you want to forbid a mode you have to include all modes except that one. FirstSectionModes []string // Same, but for the last section LastSectionModes []string // MaxDurationToPT is the maximum allowed duration to reach the public transport. // Use this to limit the walking/biking part. MaxDurationToPT time.Duration // These four following parameters set the speed of each mode (Walking, Bike, BSS & car) // In meters per second WalkingSpeed float64 BikeSpeed float64 CarSpeed float64 // Minimum and maximum amounts of journeys suggested MinJourneys uint MaxJourneys uint // Count fixes the amount of journeys to be returned, overriding minimum & maximum amount // Note: if Count=0 then it isn't taken into account Count uint // Maximum number of transfers in each journey MaxTransfers uint // Maximum duration of a trip MaxDuration time.Duration // To seconds // Wheelchair restricts the answer to accessible public transports Wheelchair bool }
JourneyRequest contain the parameters needed to make a Journey request
type JourneyResults ¶
type JourneyResults struct { Journeys []types.Journey `json:"journeys"` Paging Paging `json:"links"` Logging `json:"-"` // contains filtered or unexported fields }
JourneyResults contains the results of a Journey request
Warning: types.Journey.From / types.Journey.To aren't guaranteed to be filled. Based on very basic inspection, it seems they aren't filled when there are sections...
func (*JourneyResults) Count ¶
func (jr *JourneyResults) Count() int
Count returns the number of results available in a JourneyResults
type Paging ¶
type Paging struct { // Next results Next func(ctx context.Context, s *Session, res results) error // Previous results Previous func(ctx context.Context, s *Session, res results) error }
Paging holds potential Previous / Next functions
func (*Paging) UnmarshalJSON ¶
UnmarshalJSON unmarshals a Paging type from a Links data structure
type PlacesRequest ¶
type PlacesRequest struct { Query string // The search item // Types are the type of objects to query // It can either be a stop_area, an address, a poi or an administrative_region Types []string // If given it will filter the search by specific admin uris AdminURI []string // Enables GeoJSON data in the reply. GeoJSON objects can be VERY large ! >1MB. Geo bool // If given, it will prioritise objects around these coordinates Around types.Coordinates // Maximum amount of results Count uint }
PlacesRequest is the query you need to build before passing it to Places
type PlacesResults ¶
type PlacesResults struct { Places []types.Container `json:"places"` Logging `json:"-"` // contains filtered or unexported fields }
PlacesResults doesn't have pagination, as the remote API doesn't support it.
PlacesResults can be sorted, it implements sort.Interface.
func (*PlacesResults) Len ¶
func (pr *PlacesResults) Len() int
Len is the number of Places in the results.
func (*PlacesResults) Less ¶
func (pr *PlacesResults) Less(i, j int) bool
Less reports if the quality of the Place with the index i is less than that of the Place with the index j
Note: In most use cases, that's the opposite of the desired behaviour, so simply use sort.Reverse and ta-da !
func (*PlacesResults) Swap ¶
func (pr *PlacesResults) Swap(i, j int)
Swap swaps the Place of index i and the Place of index j
type RegionRequest ¶
type RegionRequest struct { // Count is the number of items to return, if count=0, then it will return the default number // BUG: Count doesn't work, server-side. Count uint // Enables Geo data (in MKT format) in the reply. Geo objects can be large and slower to parse. Geo bool }
RegionRequest contains the parameters needed to make a Coverage request
type RegionResults ¶
type RegionResults struct { // The list of regions retrieved Regions []types.Region `json:"Regions"` // Timing information Logging // contains filtered or unexported fields }
A RegionResults holds results for a coverage query
This Results doesn't support paging :(
type RemoteError ¶
type RemoteError struct { StatusCode int ID RemoteErrorID `json:"id"` Message string `json:"message"` }
A RemoteError represents an error sent by the server
func (RemoteError) Error ¶
func (err RemoteError) Error() string
Error formats the error in a human-readable format Also allows it to satisfy the error interface
type Scope ¶
type Scope struct {
// contains filtered or unexported fields
}
A Scope is a coverage-scoped question, allowing you to query information about a specific region.
It is needed for every non-global request you wish to make, and helps have better results with some global request too!
func (*Scope) ArrivalsSA ¶
func (scope *Scope) ArrivalsSA(ctx context.Context, req ConnectionsRequest, resource types.ID) (*ConnectionsResults, error)
ArrivalsSA requests the arrivals for a given StopArea in a given region.
func (*Scope) ArrivalsSP ¶
func (scope *Scope) ArrivalsSP(ctx context.Context, req ConnectionsRequest, resource types.ID) (*ConnectionsResults, error)
ArrivalsSP requests the arrivals for a given StopPoint in a given region.
func (*Scope) DeparturesSA ¶
func (scope *Scope) DeparturesSA(ctx context.Context, req ConnectionsRequest, resource types.ID) (*ConnectionsResults, error)
DeparturesSA requests the departures for a given StopArea
func (*Scope) DeparturesSP ¶
func (scope *Scope) DeparturesSP(ctx context.Context, req ConnectionsRequest, resource types.ID) (*ConnectionsResults, error)
DeparturesSP requests the departures for a given StopPoint
func (*Scope) Journeys ¶
func (scope *Scope) Journeys(ctx context.Context, req JourneyRequest) (*JourneyResults, error)
Journeys computes a list of journeys according to the parameters given in a specific scope
func (*Scope) Places ¶
func (scope *Scope) Places(ctx context.Context, params PlacesRequest) (*PlacesResults, error)
Places searches in all geographical objects within a coverage using their names, returning a list of places.
It is context aware.
type Session ¶
Session holds a current session, it is thread-safe
func New ¶
New creates a new session given an API Key. It acts as a convenience wrapper to NewCustom.
Warning: No Timeout is indicated in the default http client, and as such, it is strongly advised to use NewCustom with a custom *http.Client !
func NewCustom ¶
NewCustom creates a custom new session given an API key, URL to api base & http client
func (*Session) ArrivalsC ¶
func (s *Session) ArrivalsC(ctx context.Context, req ConnectionsRequest, coords types.Coordinates) (*ConnectionsResults, error)
ArrivalsC requests the arrivals from a point described by coordinates.
func (*Session) DeparturesC ¶
func (s *Session) DeparturesC(ctx context.Context, req ConnectionsRequest, coords types.Coordinates) (*ConnectionsResults, error)
DeparturesC requests the departures from a point described by coordinates.
func (*Session) Journeys ¶
func (s *Session) Journeys(ctx context.Context, req JourneyRequest) (*JourneyResults, error)
Journeys computes a list of journeys according to the parameters given
func (*Session) Places ¶
func (s *Session) Places(ctx context.Context, params PlacesRequest) (*PlacesResults, error)
Places searches in all geographical objects using their names, returning a list of corresponding places.
It is context aware.
func (*Session) RegionByID ¶
func (s *Session) RegionByID(ctx context.Context, req RegionRequest, id types.ID) (*RegionResults, error)
RegionByID provides information about a specific region.
If the ID provided isn't an ID of a region, this WILL fail.
It is context aware.
func (*Session) RegionByPos ¶
func (s *Session) RegionByPos(ctx context.Context, req RegionRequest, coords types.Coordinates) (*RegionResults, error)
RegionByPos provides information about the region englobing the specific position.
It is context aware.
func (*Session) Regions ¶
func (s *Session) Regions(ctx context.Context, req RegionRequest) (*RegionResults, error)
Regions lists the areas covered by the Navitia API. i.e it returns the coverage of the API.
It is context aware.
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
Package types implements support for the types used in the Navitia API (see doc.navitia.io), simplified and modified for idiomatic Go use.
|
Package types implements support for the types used in the Navitia API (see doc.navitia.io), simplified and modified for idiomatic Go use. |