tankpreise

package module
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 23, 2019 License: Apache-2.0 Imports: 6 Imported by: 0

README

tankpreise

Go Report Card codebeat badge Maintainability

Query prices of gas

Developed using go-modules

Library use

livingit.de/code/tankpreise is a library wrapper for https://creativecommons.tankerkoenig.de/

Example usage

gp, err := tankpreise.NewGasPrices()
gp.SetLicense("get one")
p, err := gp.PriceQuery(tankpreise.PricesRequest{
    IDs: stations,
})

stations is a string array of station ids, the license number presented here is the demo license from the provided and will return only example data

CLI

livingit.de/code/tankpreise/cmd/tankpreise is a command line utility to query the api.

Search for gas stations
tankpreise search --latitude 52.521 --longitude 13.438 --radius 10 --sort dist --gas-type all 

will return gas stations in a radius with 10 around provided locations sorted by distance regardless of gas type:

ID                                     Open    Name                                      Street                           ZipCode   City
474e5046-deaf-4f9b-9a32-9797b778f047   true    TOTAL BERLIN                              MARGARETE-SOMMER-STR. 2          10407     BERLIN
4429a7d9-fb2d-4c29-8cfe-2ca90323f9f8   true    TOTAL BERLIN                              HOLZMARKTSTR. 36-42              10243     BERLIN
278130b1-e062-4a0f-80cc-19e486b4c024   true    Aral Tankstelle                           Holzmarktstraße 12/14            10179     Berlin
1c4f126b-1f3c-4b38-9692-05c400ea8e61   true    Sprint Berlin Kniprodestr.                Kniprodestr. 25                  10407     Berlin
...

ID must be used in calls that provide details or price comparisons

Price comparison
tankpreise price --station-id 474e5046-deaf-4f9b-9a32-9797b778f047 --station-id 4429a7d9-fb2d-4c29-8cfe-2ca90323f9f8

will return list of prices for provided stations

ID                                     Status   E5         E10        Diesel
474e5046-deaf-4f9b-9a32-9797b778f047   open     1.234000   1.234000   1.234000
4429a7d9-fb2d-4c29-8cfe-2ca90323f9f8   open     1.234000   1.234000   1.234000
Details on station
tankpreise detail --station-id 474e5046-deaf-4f9b-9a32-9797b778f047

will return details on the station

ID              474e5046-deaf-4f9b-9a32-9797b778f047
Name            TOTAL BERLIN
Street          MARGARETE-SOMMER-STR. 2
City            10407 BERLIN
State
Brand           TOTAL
Opening times
Is open         true

History

Version Description
0.2.1 some code cleanup
0.2.0 version with removed confidential info
0.1.0 initial version

Documentation

Index

Constants

View Source
const DefaultBaseUrl = "https://creativecommons.tankerkoenig.de/json/"

DefaultBaseUrl is the URL where the api is hosted

View Source
const DemoAPIKey = "00000000-0000-0000-0000-000000000002"

DemoAPIKey is a key when used will return only dample data and no real data

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseResponse

type BaseResponse struct {
	OK      bool   // OK denotes success of api call
	Message string // potential error message
}

BaseResponse contains all properties returned by every API call

type DetailRequest

type DetailRequest struct {
	ID string `url:"id"`
}

DetailRequest is used to get details about a gas station

type DetailResponse

type DetailResponse struct {
	BaseResponse
	License string  `json:"license"`
	Data    string  `json:"data"`
	Status  string  `json:"status"`
	Station Station `json:"station"`
}

DetailResponse contains data returned for a detail request

type GasPrices

type GasPrices struct {
	// contains filtered or unexported fields
}

GasPrices is the main entrypoint of the library

func NewGasPrices

func NewGasPrices() (*GasPrices, error)

NewGasPrices returns a new instance

func (*GasPrices) Detail

func (gp *GasPrices) Detail(query DetailRequest) (*DetailResponse, error)

Detail returns details about a gas station

func (*GasPrices) PriceQuery

func (gp *GasPrices) PriceQuery(query PricesRequest) (*PricesResponse, error)

PriceQuery returns prices found

func (*GasPrices) Search

func (gp *GasPrices) Search(query SearchRequest) (*SearchResponse, error)

Search returns a list of stations

func (*GasPrices) SetBaseUrl

func (gp *GasPrices) SetBaseUrl(url string)

SetBaseUrl can be used to override default api base

func (*GasPrices) SetLicense

func (gp *GasPrices) SetLicense(apiKey string)

SetLicense allows to set an api key

type PricesRequest

type PricesRequest struct {
	IDs []string
}

PricesRequest request to get prices for stations listed by id

func (*PricesRequest) String

func (pr *PricesRequest) String() string

String method is used to print values passed as an operand to any format that accepts a string or to an unformatted printer such as Print.

type PricesResponse

type PricesResponse struct {
	BaseResponse
	License string                  `json:"license"`
	Data    string                  `json:"data"`
	Prices  map[string]StationPrice `json:"prices"`
}

PricesResponse returns prices for gas stations

type SearchRequest

type SearchRequest struct {
	Latitude  float64 `url:"lat"`  // geographic width of location
	Longitude float64 `url:"lng"`  // geographic height of location
	Radius    float64 `url:"rad"`  // Radius to search within
	GasType   string  `url:"type"` // GasType denotes which type of gas to lopok for (one of e5, e10, diesel or all)
	Sort      string  `url:"sort"` // Sort allows to specify whether to search by dist or price, no effect when GasType == all
}

SearchRequest lets you provide all parameters for a radius search

type SearchResponse

type SearchResponse struct {
	BaseResponse
	License  string    `json:"license"`
	Data     string    `json:"data"`
	Status   string    `json:"status"`
	Stations []Station `json:"stations"`
}

SearchResponse contains all data returned by a radius search

type Station

type Station struct {
	ID           string `json:"id"`
	Name         string `json:"name"`
	Brand        string `json:"brand"`
	Street       string `json:"street"`
	HouseNumber  string `json:"houseNumber"`
	PostCode     int    `json:"postCode"`
	Place        string `json:"place"`
	OpeningTimes []struct {
		Text  string `json:"text"`
		Start string `json:"start"`
		End   string `json:"end"`
	} `json:"openingTimes"`
	Overrides []string `json:"overrides"`
	WholeDay  bool     `json:"wholeDay"`
	IsOpen    bool     `json:"isOpen"`
	E5        float64  `json:"e5"`
	E10       float64  `json:"e10"`
	Diesel    float64  `json:"diesel"`
	Lat       float64  `json:"lat"`
	Lng       float64  `json:"lng"`
	Dist      float64  `json:"dist"`
	State     string   `json:"state"`
}

Station describes a gas station

type StationPrice

type StationPrice struct {
	Status string      `json:"status"`
	E5     interface{} `json:"e5"`
	E10    interface{} `json:"e10"`
	Diesel interface{} `json:"diesel"`
}

StationPrice contains prices for gas types

func (*StationPrice) GetDiesel

func (sp *StationPrice) GetDiesel() (float64, error)

GetDiesel returns the price for diesel

func (*StationPrice) GetE10

func (sp *StationPrice) GetE10() (float64, error)

GetE10 returns the price for E10

func (*StationPrice) GetE5

func (sp *StationPrice) GetE5() (float64, error)

GetE5 returns the price for E5

func (*StationPrice) HasDiesel

func (sp *StationPrice) HasDiesel() bool

HasDiesel returns true if the station has type diesel

func (*StationPrice) HasE10

func (sp *StationPrice) HasE10() bool

HasE1 returns true if the station has type E5

func (*StationPrice) HasE5

func (sp *StationPrice) HasE5() bool

HasE5 returns true if the station has type E5

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL