Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidURL = errors.New("invalid URL")
var ErrTooManyRetries = errors.New("too many retries")
Functions ¶
func LocationFromURL ¶
Types ¶
type Currency ¶
type Currency int
Currency represents the currency of an entity price.
func CurrencyFromLocation ¶
CurrencyFromLocation returns the currency of the given location.
type Entity ¶
type Entity struct { ID int64 `json:"id"` GeizhalsID int64 UpdatedAt time.Time Prices []EntityPrice `gorm:"foreignkey:EntityID;constraint:OnDelete:CASCADE;"` Name string `json:"name"` URL string `json:"url"` Type EntityType `json:"type"` }
func DownloadEntity ¶
DownloadEntity retrieves the metadata (name, price) for a given entity hosted on Geizhals.
func (Entity) FullURL ¶
FullURL returns the URL to download the HTML of the entity for the given location.
func (Entity) GetPrice ¶
func (e Entity) GetPrice(location string) EntityPrice
GetPrice returns the price (EntityPrice) of the entity for the given location. If no price is found for the given location, an empty EntityPrice is returned.
type EntityPrice ¶
type EntityPrice struct { ID int64 EntityID int64 `gorm:"not null;"` Location string `gorm:"not null;"` UpdatedAt time.Time Price float64 `gorm:"not null;default:0"` Currency Currency `gorm:"not null;default:1"` }
EntityPrice represents a price for a specific Entity for a given location.
func UpdateEntityPrice ¶
func UpdateEntityPrice(entity Entity, location string) (EntityPrice, error)
UpdateEntityPrice returns an updated EntityPrice struct from a given input Entity
func (EntityPrice) String ¶
func (e EntityPrice) String() string
type PriceEntry ¶
type PriceEntry struct { Price float64 `json:"price"` Timestamp time.Time `json:"ts"` Valid bool `json:"valid"` }
func (*PriceEntry) UnmarshalJSON ¶
func (entry *PriceEntry) UnmarshalJSON(p []byte) error
UnmarshalJSON implements a custom unmarshaller for the price history response. The API response is an array of length 3, containing the timestamp, price and validity.
type PriceHistory ¶
type PriceHistory struct { Meta PriceHistoryMeta `json:"meta"` Response []PriceEntry `json:"response"` Location string `json:"location"` }
func DownloadPriceHistory ¶
func DownloadPriceHistory(entityIDs, amounts []int64, location string) (PriceHistory, error)
func GetPriceHistory ¶
func GetPriceHistory(entity Entity, location string) (PriceHistory, error)
GetPriceHistory returns the price history for the given entity either from cache or by downloading it.