Documentation ¶
Index ¶
- Constants
- Variables
- func ComputeHmac256(message []byte, secret string) string
- type Client
- func (c *Client) DepartureList(r *HVVDepartureListRequest) (*HVVDepartureListResponse, error)
- func (c *Client) DistanceMatrix(r *DistanceMatrixRequest) (*DistanceMatrixResponse, error)
- func (c *Client) GoogleCalender(r *GoogleCalenderRequest) (*GoogleCalenderResponse, error)
- func (c *Client) HVVGetRoute(r *HVVGetRouteRequest) (*HVVGetRouteResponse, error)
- func (c *Client) Numbers() (string, error)
- func (c *Client) OpenForecast(r *OpenWeatherRequest) (*ForecastResponse, error)
- func (c *Client) OpenWeather(r *OpenWeatherRequest) (*WeatherResponse, error)
- func (c *Client) Tankerkoenig(r *TankerkoenigRequest) (*FuelPriceResponse, error)
- type Coords
- type Credentials
- type DateTime
- type DistanceMatrixCommonResponse
- type DistanceMatrixElement
- type DistanceMatrixElementsRow
- type DistanceMatrixRequest
- type DistanceMatrixResponse
- type ErrorMessage
- type ForecastResponse
- type FuelPriceResponse
- type GasTyp
- type GoogleCalenderRequest
- type GoogleCalenderResponse
- type HVVCommonResponse
- type HVVDepartureListRequest
- type HVVDepartureListResponse
- type HVVGetRouteRequest
- type HVVGetRouteResponse
- type Key
- type Language
- type Mode
- type OpenWeatherCommonResponse
- type OpenWeatherRequest
- type Station
- type Status
- type TankerkoenigCommonResponse
- type TankerkoenigRequest
- type Time
- type Traffic
- type Units
- type WeatherResponse
Constants ¶
const ( TravelModeDriving = Mode("driving") TravelModeWalking = Mode("walking") TravelModeBicycling = Mode("bicycling") TravelModeTransit = Mode("transit") AvoidTolls = "tolls" AvoidHighways = "highways" AvoidFerries = "ferries" AvoidIndoor = "indoor" )
--------------------------------------------------Google API---------------------------------------------------------- Travel mode preferences.
const ( // See, edit, share, and permanently delete all the calendars you can // access using Google Calendar CalendarScope = "https://www.googleapis.com/auth/calendar" // View and edit events on all your calendars CalendarEventsScope = "https://www.googleapis.com/auth/calendar.events" // View events on all your calendars CalendarEventsReadonlyScope = "https://www.googleapis.com/auth/calendar.events.readonly" // View your calendars CalendarReadonlyScope = "https://www.googleapis.com/auth/calendar.readonly" // View your Calendar settings CalendarSettingsReadonlyScope = "https://www.googleapis.com/auth/calendar.settings.readonly" )
const ( UnitsMetric = Units("metric") UnitsImperial = Units("imperial") GERMAN = Language("de") ENGLISH = Language("en") SPANISH = Language("sp") Latitude = Coords("53.460210") Longitude = Coords("9.951299") )
--------------------------------------------------------------------------------------------------------------------- Units to use on request.
const ( Radius = 2.0 GasTypAll = GasTyp("all") GasTypE5 = GasTyp("e5") GasTypE10 = GasTyp("e10") GasTypDiesel = GasTyp("diesel") SortbyDistance = "dist" SortbyPrice = "price" )
--------------------------------------------Tankerkoenig Api----------------------------------------------------------
const (
REALTIMEON = "REALTIME"
)
Variables ¶
var ( ApiKeyOpenWeather = apiKey("YOUR_APIKEY") ApikeyDistanceMatrix = apiKey("YOUR_APIKEY") ApiKeyTankerkoenig = apiKey("YOUR_APIKEY") ApiKeyHvv = apiKey("YOUR_APIKEY") ApiKeyHvvUSER = "YOUR_USERNAME" )
var NumbersApi = &apiConfig{
"http://numbersapi.com/",
"",
}
var Urls = map[string]string{
"Dammtor": "https://geofox.hvv.de/jsf/home.seam?clear=true&onefield=true&language=de&start=Moorburger%20Ring&startCity=Hamburg&startType=STATION&destination=Dammtor%20(Messe%2FCCH)&destinationCity=Hamburg&destType=STATION&execute=true",
"Informatikum": "https://geofox.hvv.de/jsf/home.seam?execute=true&date=29.03.2019&time=23:18&language=de&start=Moorburger%20Ring&startCity=Hamburg&startType=STATION&destination=Informatikum&destinationCity=Hamburg&destinationType=STATION&timeIsDeparture=1&wayBy=train",
"Gym-S": "https://geofox.hvv.de/jsf/home.seam?execute=true&date=29.03.2019&time=23:18&language=de&start=Moorburger%20Ring&startCity=Hamburg&startType=STATION&destination=Francoper%20Straße&destinationCity=Hamburg&destinationType=STATION&timeIsDeparture=1&wayBy=train",
}
Functions ¶
func ComputeHmac256 ¶
Generates the Signature for the Header
Types ¶
type Client ¶
type Client struct { Apikey Key // contains filtered or unexported fields }
func NewClient ¶
func NewClient() *Client
@Todo add optional aruguments like below func NewClient(optional... Optional) (*Client, error)
func NewClientWithTestUrl ¶
func (*Client) DepartureList ¶
func (c *Client) DepartureList(r *HVVDepartureListRequest) (*HVVDepartureListResponse, error)
@todo not implemented yet
func (*Client) DistanceMatrix ¶
func (c *Client) DistanceMatrix(r *DistanceMatrixRequest) (*DistanceMatrixResponse, error)
func (*Client) GoogleCalender ¶
func (c *Client) GoogleCalender(r *GoogleCalenderRequest) (*GoogleCalenderResponse, error)
@todo use client.get() do make a request
func (*Client) HVVGetRoute ¶
func (c *Client) HVVGetRoute(r *HVVGetRouteRequest) (*HVVGetRouteResponse, error)
func (*Client) OpenForecast ¶
func (c *Client) OpenForecast(r *OpenWeatherRequest) (*ForecastResponse, error)
Returns weather forecast for 5 days with data every hours of given Lon and Lat
func (*Client) OpenWeather ¶
func (c *Client) OpenWeather(r *OpenWeatherRequest) (*WeatherResponse, error)
Returns the current Weather of given Lon and Lat
func (*Client) Tankerkoenig ¶
func (c *Client) Tankerkoenig(r *TankerkoenigRequest) (*FuelPriceResponse, error)
type Credentials ¶
type Credentials struct { Installed struct { // ClientID is the application's ID. ClientID string `json:"client_id"` // ClientSecret is the application's secret. ClientSecret string `json:"client_secret"` // Endpoint contains the resource server's token endpoint // URLs. These are constants specific to each server and are // often available via site-specific packages, such as // google.Endpoint or github.Endpoint. AuthURL string `json:"auth_uri"` TokenURL string `json:"token_uri"` // RedirectURL is the URL to redirect users going through // the OAuth flow, after the resource owner's URLs. RedirectURL []string `json:"redirect_uris"` // Scope specifies optional requested permissions. Scopes []string // AuthStyle optionally specifies how the endpoint wants the // client ID & client secret sent. The zero value means to // auto-detect. AuthStyle int } `json:"installed"` }
func (*Credentials) AuthCodeURL ¶
func (c *Credentials) AuthCodeURL(state, accessType string) string
AuthCodeURL returns a URL to OAuth 2.0 provider's consent page that asks for permissions for the required scopes explicitly.
State is a token to protect the user from CSRF attacks. You must always provide a non-empty string and validate that it matches the the state query parameter on your redirect callback. See http://tools.ietf.org/html/rfc6749#section-10.12 for more info.
Opts may include AccessTypeOnline or AccessTypeOffline, as well as ApprovalForce. It can also be used to pass the PKCE challenge. See https://www.oauth.com/oauth2-servers/pkce/ for more info.
type DistanceMatrixCommonResponse ¶
type DistanceMatrixCommonResponse struct { //ErrorMessage1 for Google DistanceMatrix Status Status `json:"status,omitempty"` ErrorMessage ErrorMessage `json:"error_message,omitempty"` }
func (*DistanceMatrixCommonResponse) StatusError ¶
func (c *DistanceMatrixCommonResponse) StatusError() error
StatusError returns an error if this object has a Status different
type DistanceMatrixElement ¶
type DistanceMatrixElement struct { Distance Time `json:"distance"` Duration Time `json:"duration"` Status string `json:"status"` }
DistanceMatrixElement is the travel distance and time for a pair of origin and destination.
type DistanceMatrixElementsRow ¶
type DistanceMatrixElementsRow struct {
Elements []DistanceMatrixElement `json:"elements"`
}
DistanceMatrixElementsRow is a row of distance elements.
type DistanceMatrixRequest ¶
type DistanceMatrixRequest struct { // Origins is a list of addresses and/or textual latitude/longitude values // from which to calculate distance and time. // Required. Origins string // Destinations is a list of addresses and/or textual latitude/longitude values // to which to calculate distance and time. // Required. Destinations []string // Mode specifies the mode of transport to use when calculating distance. // Valid values are `ModeDriving`, `ModeWalking`, `ModeBicycling` and `ModeTransit`. // Default is `Modedriving // Optional. // @Todo implement Mode Mode Mode // Language in which to return results. // Optional. Language Language // Units Specifies the unit system to use when expressing distance as text. // Valid values are `UnitsMetric` and `UnitsImperial`. // Optional. Units Units //Restrictions are indicated by use of the avoid parameter, and an argument to that parameter indicating the restriction to avoid. // Valid values are `AvoidTolls`, 'AvoidHighways`, 'AvoidFerries` and `AvoidIndoor` //Optional Avoid string // apiKey from google.developers. // Required ApiKey apiKey }
DistanceMatrixRequest is the request struct for Distance Matrix APi
type DistanceMatrixResponse ¶
type DistanceMatrixResponse struct { DestinationAddresses []string `json:"destination_addresses"` OriginAddresses []string `json:"origin_addresses"` Rows []DistanceMatrixElementsRow `json:"rows"` }
Expected Response from google API
type ErrorMessage ¶
type ErrorMessage interface{}
type ForecastResponse ¶
type ForecastResponse struct { List []struct { Time int `json:"dt"` //time of date forecasted, unix, UTC Main struct { Temp float32 `json:"temp"` TempMin float32 `json:"temp_min"` TempMax float32 `json:"temp_max"` Humidity int `json:"humidity"` // in % } `json:"main"` Weather []struct { ID int `json:"id"` Main string `json:"main"` Description string `json:"description"` Icon string `json:"icon"` } `json:"weather"` Clouds struct { All int `json:"all"` //cloudiness in % } `json:"clouds"` } `json:"list"` }
----------------------------------------------Response------------------------------------------ @Todo combine Forecast and Weather in one struct and make code simpler Expected Response from OpenWeather API
type FuelPriceResponse ¶
type FuelPriceResponse struct { Stations []struct { Brand string `json:"brand"` Street string `json:"street,omitempty"` HouseNumber string `json:"houseNumber"` Price float64 `json:"price,omitempty"` Diesel float64 `json:"diesel"` E5 float64 `json:"e5"` E10 float64 `json:"e10"` IsOpen bool `json:"isOpen"` } `json:"stations"` }
Expected Response from Tankerkoenig API
type GoogleCalenderRequest ¶
type GoogleCalenderResponse ¶
type HVVCommonResponse ¶
type HVVCommonResponse struct { Status Status `json:"returnCode"` ErrorMessage ErrorMessage `json:"errorDevInfo,omitempty"` ErrorText string `json:"errorText,omitempty"` }
func (*HVVCommonResponse) StatusError ¶
func (c *HVVCommonResponse) StatusError() error
StatusError returns an error if this object has a Status different
type HVVDepartureListRequest ¶
type HVVDepartureListRequest struct { // Origins is a list of addresses and/or textual values. (example = Station{Name: "MyStation"}) // Required. Origin Station `json:"start"` // Destinations is a list of addresses and/or textual values.(example = Station{Name: "MyDestionation"}) // to which to calculate distance and time. // Required. Destinations Station `json:"dest"` //Date and Time of the Request. (example = DateTime{Date: "11.06.2019", Time: "14:00"}) //Required. DateTime DateTime `json:"time"` MaxList int `json:"maxList"` ServiceTypes []string `json:"serviceTypes"` // Language in which to return results. // Optional. (default is english) Language Language `json:"language"` // Provides you with Realtime data RealTime string `json:"realtime"` // apiKey from HBT // Required MaxTimeOffset int `json:"maxTimeOffset"` ApiKey apiKey `json:"-"` Username string `json:"-"` }
HVVDepartureListRequest is the request struct for HVV departureList APi
Example of Request Body ....
type HVVDepartureListResponse ¶
type HVVDepartureListResponse struct { Time struct { Date string `json:"date"` Time string `json:"time"` } `json:"time"` Departures []struct { Line struct { Name string `json:"name"` Direction string `json:"direction"` Origin string `json:"origin"` Type struct { SimpleType string `json:"simpleType"` ShortInfo string `json:"shortInfo"` } `json:"type"` } `json:"line"` TimeOffset int `json:"timeOffset"` } `json:"departures"` }
Expected Response for DepatureList from HBT API
type HVVGetRouteRequest ¶
type HVVGetRouteRequest struct { // Origins is a list of addresses and/or textual values. (example = Station{Name: "MyStation"}) // Required. Origin Station `json:"start"` // Destinations is a list of addresses and/or textual values.(example = Station{Name: "MyDestionation"}) // to which to calculate distance and time. // Required. Destinations Station `json:"dest"` //Date and Time of the Request. (example = DateTime{Date: "11.06.2019", Time: "14:00"}) //Required. DateTime DateTime `json:"time"` // Language in which to return results. // Optional. (default is english) Language Language `json:"language"` // Amount of routes to return. // Required Amount int `json:"schedulesAfter"` // apiKey from HBT // Required Apikey apiKey `json:"-"` // Username from HBT. //Required Username string `json:"-"` }
HVVGetRouteRequest is the request struct for HVV GetRoute APi
Example of Request Body {"start":{"name":"START"},"dest":{"name":"DESTINATION"},"time":{"date":"12.06.2019","time":"14:00"},"language":"de","schedulesAfter":3,"timeIsDeparture":true,"schedulesBefore":0,"realtime":"REALTIME"}
func (*HVVGetRouteRequest) MarshalJSON ¶
func (r *HVVGetRouteRequest) MarshalJSON() ([]byte, error)
Implements the Json Interface and adds additional information to the body when called with json.Marshal(r)
type HVVGetRouteResponse ¶
type HVVGetRouteResponse struct { RealtimeSchedules []struct { Start Station `json:"start"` Dest Station `json:"dest"` Time float64 `json:"time"` FootpathTime float64 `json:"footpathTime"` ScheduleElements []struct { From struct { Name string `json:"name"` DepTime DateTime `json:"depTime"` } `json:"from,omitempty"` To struct { Name string `json:"name"` ArrTime DateTime `json:"arrTime"` } `json:"to,omitempty"` Line struct { BusLine string `json:"name"` Direction string `json:"direction"` Origin string `json:"origin"` Type struct { SimpleType string `json:"simpleType"` ShortInfo string `json:"shortInfo"` } `json:"type"` } `json:"line,omitempty"` } `json:"scheduleElements"` } `json:"realtimeSchedules"` }
Expected Response from HBT API
type OpenWeatherCommonResponse ¶
type OpenWeatherCommonResponse struct { Status Status `json:"cod"` // ErrorMessage ErrorMessage `json:"message,omitempty"` }
func (*OpenWeatherCommonResponse) StatusError ¶
func (c *OpenWeatherCommonResponse) StatusError() error
StatusError returns an error if this object has a Status different
type OpenWeatherRequest ¶
type OpenWeatherRequest struct { // Longitude of City // Required. Lon Coords // Latitude of City // Required. Lat Coords // Units Specifies the unit system to use when expressing distance as text. // Valid values are `Metric` for Celsius and `Imperial` for Fahrenheit. // Optional. (default is Kelvin) Units Units // apiKey for OpenWeather API. // Required ApiKey apiKey }
OpenWeatherRequest is the request struct for OpenWeather APi
type TankerkoenigCommonResponse ¶
type TankerkoenigCommonResponse struct { Status Status `json:"status,omitempty"` ErrorMessage ErrorMessage `json:"message,omitempty"` }
func (*TankerkoenigCommonResponse) StatusError ¶
func (c *TankerkoenigCommonResponse) StatusError() error
StatusError returns an error if this object has a Status different
type TankerkoenigRequest ¶
type TankerkoenigRequest struct { // Longitude of City // Required. Lon Coords // Latitude of City // Required. Lat Coords // Radius Specifies the radius to search. // Required Radius float64 // Sorts the response by given form // Valid values are `SortbyDistance` and `SortbyPrice`. // Optional. Sortby string // Specifiys the Gastyp to search, // Valid values are 'GasTypAll', 'GasTypE10', 'GasTypE5' and 'GasTypDiesel' // Required GasTyp GasTyp // apiKey for Tankerkoenig API. // Required ApiKey apiKey }
TankerkoenigRequest is the request struct for Tankerkoenig API
type Traffic ¶
type Traffic struct { Start string Arrive string Traffic []string Duration string Destination string }
---------------------------------------------OLD AND NOT USED---------------------------------------------------------
type WeatherResponse ¶
type WeatherResponse struct { Name string `json:"name"` Time int `json:"dt"` //time of date, unix, UTC Weather []struct { ID int `json:"id"` Main string `json:"main"` Description string `json:"description"` Icon string `json:"icon"` } `json:"weather"` Main struct { Temp float32 `json:"temp,int"` TempMin float32 `json:"temp_min"` TempMax float32 `json:"temp_max"` Humidity int `json:"humidity"` //in % } `json:"main"` Clouds struct { All int `json:"all"` //cloudiness in % } `json:"clouds"` Sys struct { Sunrise int `json:"sunrise"` Sunset int `json:"sunset"` } `json:"sys"` }