Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckResponse ¶
CheckResponse checks the API response for errors, and returns them if present. A response is considered an error if it has a status code outside the 200 range. API error responses are expected to have either no response body, or a JSON response body that maps to ErrorResponse. Any other response body will be silently ignored.
Types ¶
type Client ¶
type Client struct {
// Base URL for API requests
BaseURL *url.URL
// APIKey used for authentication with the API
APIKey string
// User agent for client
UserAgent string
// Services used for communicating with the API
Station StationService
Prices PricesService
// contains filtered or unexported fields
}
Client communicates with Tankerkönig-API.
func (*Client) Do ¶
Do sends an API request and returns the API response. The API response is JSON decoded and stored in the value pointed to by v, or returned as an error if an API error has occurred. If v implements the io.Writer interface, the raw response will be written to v, without attempting to decode it.
func (*Client) NewRequest ¶
func (c *Client) NewRequest(method, urlStr string, query url.Values, body interface{}) (*http.Request, error)
NewRequest creates an API request. A relative URL can be provided in urlStr, which will be resolved to the BaseURL of the Client. Relative URLs should always be specified without a preceding slash. If specified, the value pointed to by body is JSON encoded and included in as the request body.
type ErrorResponse ¶
type ErrorResponse struct {
// HTTP response that caused this error
Response *http.Response
Ok bool `json:"ok"`
Message string `json:"message"`
}
An ErrorResponse reports the error caused by an API request.
func (*ErrorResponse) Error ¶
func (r *ErrorResponse) Error() string
type Price ¶
type Price struct {
Status string `json:"status"` // Open-status
Diesel interface{} `json:"diesel"` // Price for diesel fuel type
E5 interface{} `json:"e5"` // Price for E5 fuel type
E10 interface{} `json:"e10"` // Price for E10 fuel type
}
Price represents a price data structure.
type PricesService ¶
type PricesService interface {
// Get returns a map of Price items for one or multiple station IDs.
Get(ids ...string) (map[string]Price, *Response, error)
}
PricesService is an interface to query price information from the Tankerkönig-API.
type PricesServiceOp ¶
type PricesServiceOp struct {
// contains filtered or unexported fields
}
PricesServiceOp handles communication with the price related methods of the Tankerkönig-API.
type Response ¶
Response is a Tankerkönig-API response. This wraps the standard http.Response returned from Tankerkönig-API.
type Station ¶
type Station struct {
Brand string `json:"brand"` // Brand
Dist float64 `json:"dist"` // Distance (air line) from the search point to the gas station
HouseNumber string `json:"houseNumber"` // House number
Id string `json:"id"` // ID
IsOpen bool `json:"isOpen"` // Open-status
Lat float64 `json:"lat"` // Latitude
Lng float64 `json:"Lng"` // Longitude
Name string `json:"name"` // Name
Place string `json:"place"` // Place
PostCode int `json:"postCode"` // Post code
Diesel interface{} `json:"diesel"` // Price for diesel fuel type
E5 interface{} `json:"e5"` // Price for E5 fuel type
E10 interface{} `json:"e10"` // Price for E10 fuel type
Street string `json:"street"` // Street
Overrides []string `json:"overrides"`
WholeDay bool `json:"wholeDay"`
State string `json:"state"`
OpeningTimes []openingTime `json:"openingTimes"`
}
Station represents a gas station.
type StationService ¶
type StationService interface {
// Detail returns the station for the given ID
Detail(id string) (Station, *Response, error)
// List returns all stations within a radius of a location.
List(lat float64, lng float64, rad int) ([]Station, *Response, error)
}
StationService is an interface to query station information from the Tankerkönig-API.
type StationServiceOp ¶
type StationServiceOp struct {
// contains filtered or unexported fields
}
StationServiceOp handles communication with the station related methods of the Tankerkönig-API.