77 lines
2.2 KiB
Go
77 lines
2.2 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
)
|
|
|
|
type EnergyRating struct {
|
|
Value string `json:"value,omitempty"`
|
|
Min string `json:"min,omitempty"`
|
|
Max string `json:"max,omitempty"`
|
|
}
|
|
|
|
type PriceTuple struct {
|
|
IncVat int `json:"inc"`
|
|
ExVat int `json:"exl"`
|
|
}
|
|
|
|
type OutletItem struct {
|
|
ArticleNumber string `json:"sku,omitempty"`
|
|
Price PriceTuple `json:"price,omitempty"`
|
|
Title string `json:"title"`
|
|
}
|
|
|
|
type ItemProp struct {
|
|
Url string `json:"url"`
|
|
Disclaimer string `json:"disclaimer,omitempty"`
|
|
ReleaseDate string `json:"releaseDate,omitempty"`
|
|
SaleStatus string `json:"saleStatus"`
|
|
MarginPercent float64 `json:"mp,omitempty"`
|
|
PresaleDate string `json:"presaleDate,omitempty"`
|
|
Restock string `json:"restock,omitempty"`
|
|
AdvertisingText string `json:"advertisingText,omitempty"`
|
|
Img string `json:"img,omitempty"`
|
|
BadgeUrl string `json:"badgeUrl,omitempty"`
|
|
EnergyRating *EnergyRating `json:"energyRating,omitempty"`
|
|
BulletPoints string `json:"bp,omitempty"`
|
|
LastUpdate int64 `json:"lastUpdate,omitempty"`
|
|
Created int64 `json:"created,omitempty"`
|
|
Buyable bool `json:"buyable"`
|
|
Description string `json:"description,omitempty"`
|
|
BuyableInStore bool `json:"buyableInStore"`
|
|
BoxSize string `json:"boxSize,omitempty"`
|
|
CheapestBItem *OutletItem `json:"bItem,omitempty"`
|
|
AItem *OutletItem `json:"aItem,omitempty"`
|
|
}
|
|
|
|
type BaseItem struct {
|
|
ItemProp
|
|
StockLevel string `json:"stockLevel,omitempty"`
|
|
Stock LocationStock `json:"stock"`
|
|
Id uint `json:"id"`
|
|
Sku string `json:"sku"`
|
|
Title string `json:"title"`
|
|
}
|
|
|
|
type DataItem struct {
|
|
*BaseItem
|
|
Fields map[uint]interface{} `json:"values"`
|
|
}
|
|
|
|
type LocationStock []struct {
|
|
Id string `json:"id"`
|
|
Level string `json:"level"`
|
|
}
|
|
|
|
func FetchItem(sku string) (*DataItem, error) {
|
|
res, err := http.Get("https://slask-finder.tornberg.me/api/get/" + sku)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer res.Body.Close()
|
|
var item DataItem
|
|
err = json.NewDecoder(res.Body).Decode(&item)
|
|
return &item, err
|
|
}
|