govitia / navitia Goto Github PK
View Code? Open in Web Editor NEWA client library in Go for the Navitia API (navitia.io) (v2 WIP)
License: The Unlicense
A client library in Go for the Navitia API (navitia.io) (v2 WIP)
License: The Unlicense
Most resource endpoints (e.g ../stop_areas/{stop_area}) have sub-endpoints (e.g ../routes) following HATEOS principle. Currently you have to take the resource's ID and call a different method.
We could simplify this these ways:
- Have a `func (r {Results}) Related() map[ID]map[string](func(context.Context,*Session) Results)` method on the results type, we'll have to create an exported interface `Results` for this to work intelligently.
- Have a single function `func Related(r {Results}) map[ID]map[string](func(context.Context, *Session) Results)` much like the method.
- Have each `Results` type that returns only one result implement have an `Explore(ctx context.Context, s *Session, selector string)` method, allowing us easier chaining. (i.e `session.Coords(ctx, coords).Explore(ctx,session,"stop_areas")`).
There may be other ways, I'm open to suggestion !
Currently, when we try to parse a remote error, and its not a valid JSON payload, (such as some undefined
errors and path errors) we return an error that is not a RemoteError, which also means that the specifics (status code & plain-text message) gets lost as well.
Add the ability to RemoteError to note what was the plain-text response in case the unmarshalling fails, such as a Plain []byte
field noting the contents, an ID made on the fly, and correct RemoteError.Error
handling.
Currently, VehicleJourney isn't supported, partly because I couldn't find a description in the official docs, so it is necessary to work up from the given samples and responses.
Currently, the types don't have proper validation, notably just after parsing.
Add a .Check
method to all types, calling included types' .Check
methods.
Currently we implement provider selection through the URL only. However this has the downside that for some providers that restrict some endpoints (like SNCF), we can't stop a request before executing it.
One way we could do this is move the providers info from URLs to a proper Struct, with information about which endpoints are allowed/disallowed, which will be integrated in Session
via a map[string]bool
(has O(1) complexity) allowing us not to waste bandwidth.
This may also allow us to have the SSL fingerprints public in those structs, though that's a question for another issue.
As always, I'm open to suggestions.
Note that types
subpackage already has rudimentary support.
As far as I know (we didn't test much and went to the easier solution on our side), Navitia returns datetimes as "YYYYMMDDTHHMMSS".
As implemented here with the time.Parse function, datetimes are parsed as if they were UTC https://github.com/govitia/navitia/blob/master/types/json.go#L23 instead of the correct local time.
In our fork of the library, we've used time.ParseInLocation to get the correct timezone (but it's hardcoded to our use cases only in France with "Europe/Paris" ;))
The correct way might be to use the "context" given by navitia on every endpoint response (https://doc.navitia.io/#other-objects) with the timezone in it, and then use ParseInLocation with this timezone. But this would probably have quite a big impact on everything related to unmarshalling in the library, as it's returned aside of the types themselves.
What do you think ?
If I execute this request:
res, _ := nc.api.Scope(navitiaRegion).VehicleJourneys(context.Background(), navitia.VehicleJourneyRequest{})
I can't marshall the res
directly due to the definition of the VehiclesJourneysResult
struct.
Implement Traffic Reports [/traffic_reports] (navitia.io doc).
Note that types
package already has partial support.
There's already some of them implemented, and it helped find some corner cases, let's generalise it !
### The problem
Currently, the term type
is used everywhere, which doesn't help clarify that we're talking about resources returned by the remote API.
(Warning extreme API-Break).
Rename every mention of types
in the context of a resource returned by the remote API to resource
, including the subpackage's name itself.
For exemple, Coordinates
struct have two associated files (coordinates.go and coordinates_json.go).
The _json file implement the json.Unmarshaller
. We want to move this implementation to the coordinates.go
file directly.
In struct Route ;
type Route struct {
ID ID `json:"id"` // Identifier of the route, eg: "route:RAT:M6"
Name string `json:"name"` // Name of the route
Frequence bool `json:"is_frequence"` // If the route has frequency or not. Can only be “False”, but may be “True” in the future
Line Line `json:"line"` // Line is the line it is connected to
Direction Container `json:"direction"` // Direction is the direction of the route (Place or POI)
PhysicalModes []PhysicalMode `json:"physical_modes"` // PhysicalModes of the line
GeoJSON GeoJSON `json:"geo_json"`
}
According to the following JSON struct:
type jsonRoute struct {
ID *ID `json:"id"`
Name *string `json:"name"`
Line *Line `json:"line"`
Direction *Container `json:"direction"`
// Value to process
Frequence string `json:"is_frequence"`
}
PhysicalModes
and GeoJSON
of Route struct seems to be ignored when unmarshalling process ?!
CO2Emissions values in journeys requests are not unmarshalled.
I'll propose a pull request on this next week.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.