Documentation ¶
Index ¶
- Constants
- type Client
- type ClientBuilder
- func (b *ClientBuilder) Build() (*Client, error)
- func (b *ClientBuilder) WithCaller(caller http.Caller) *ClientBuilder
- func (b *ClientBuilder) WithIDFilter(ids []string) *ClientBuilder
- func (b *ClientBuilder) WithInterval(interval int) *ClientBuilder
- func (b *ClientBuilder) WithOutputDirectory(dir string) *ClientBuilder
- func (b *ClientBuilder) WithServiceURL(url string) *ClientBuilder
- func (b *ClientBuilder) WithTimeProvider(provider TimeProvider) *ClientBuilder
- type RealTime
- type TimeProvider
Constants ¶
const ( DefaultInterval = 60 // in seconds DefaultServiceURL = "https://gbfs.citibikenyc.com" ErrEmptyResponse = "empty response" GoogleMapsQuery = "https://www.google.com/maps/?q=%f,%f" StationInformationPath = "/gbfs/en/station_information.json" StationStatusPath = "/gbfs/en/station_status.json" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) ParseStationData ¶
func (c *Client) ParseStationData() (types.NormalizedStationData, error)
ParseStationData fetches station status information from the Citi Bike API and combines it with pre-fetched station information to create a set of normalized data.
The normalized data consists of details such as station ID, name, status, capacity, and the number of available bikes, e-bikes, docks, and scooters, as well as operational status flags.
The function returns a NormalizedStationData instance containing the collected information, or an error if fetching or processing the data fails. Note that the function only includes stations which have corresponding entries in the pre-fetched station information data.
func (*Client) PrintStationDataCSV ¶ added in v1.1.0
PrintStationDataCSV gathers station data periodically according to the client's interval and prints it to the standard output (stdout) in CSV format. The CSV data includes a header row, and each subsequent row represents the current state of a station. The fields are StationID, Name, Longitude, Latitude, Location, Status, BikesAvailable, EBikesAvailable, BikesDisabled, DocksAvailable, DocksDisabled, IsReturning, IsRenting, IsInstalled, and TimeStamp. In case of an error while gathering data, the function continues with the next iteration after the sleep interval. If writing to the CSV writer fails, the function logs the error and exits. The function runs indefinitely, and each iteration is separated by a sleep interval defined by the client.
func (*Client) PrintStationDataJSONL ¶ added in v1.1.0
func (c *Client) PrintStationDataJSONL()
PrintStationDataJSONL fetches station status information from the Citi Bike API and combines it with pre-fetched station information to create a set of normalized data. The normalized data is printed to stdout in the JSONL format.
The function runs indefinitely, fetching new data every minute. To stop the function, you must interrupt the program manually.
type ClientBuilder ¶
type ClientBuilder struct {
// contains filtered or unexported fields
}
func NewClientBuilder ¶
func NewClientBuilder() *ClientBuilder
func (*ClientBuilder) Build ¶
func (b *ClientBuilder) Build() (*Client, error)
Build creates the Client instance
func (*ClientBuilder) WithCaller ¶ added in v1.1.0
func (b *ClientBuilder) WithCaller(caller http.Caller) *ClientBuilder
WithCaller overwrites the default http caller
func (*ClientBuilder) WithIDFilter ¶
func (b *ClientBuilder) WithIDFilter(ids []string) *ClientBuilder
WithIDFilter adds a filter to only look for specific station IDs
func (*ClientBuilder) WithInterval ¶ added in v1.1.0
func (b *ClientBuilder) WithInterval(interval int) *ClientBuilder
WithInterval overwrites the default interval
func (*ClientBuilder) WithOutputDirectory ¶ added in v1.1.0
func (b *ClientBuilder) WithOutputDirectory(dir string) *ClientBuilder
WithOutputDirectory specifies the directory to which CSV files should be written
func (*ClientBuilder) WithServiceURL ¶
func (b *ClientBuilder) WithServiceURL(url string) *ClientBuilder
WithServiceURL overwrites the default service URL
func (*ClientBuilder) WithTimeProvider ¶ added in v1.1.0
func (b *ClientBuilder) WithTimeProvider(provider TimeProvider) *ClientBuilder
WithTimeProvider overwrites the default time provider