Documentation
¶
Overview ¶
Package cheapshark is the library behind the cheapshark command line: the HTTP client, request shaping, and the typed data models for the CheapShark PC game deal price aggregator API.
The Client here is the spine every command shares. It sets a real User-Agent, paces requests, and retries transient failures (429 and 5xx).
Index ¶
- Constants
- type Client
- func (c *Client) Get(ctx context.Context, rawURL string) ([]byte, error)
- func (c *Client) ListDeals(ctx context.Context, storeID string, maxPrice float64, limit int) ([]Deal, error)
- func (c *Client) ListStores(ctx context.Context) ([]Store, error)
- func (c *Client) SearchGames(ctx context.Context, title string, limit int) ([]GameResult, error)
- type Config
- type Deal
- type Domain
- type GameResult
- type Store
Constants ¶
const DefaultUserAgent = "cheapshark-cli/dev (+https://github.com/tamnd/cheapshark-cli)"
DefaultUserAgent identifies the client to CheapShark.
const Host = "cheapshark.com"
Host is the site this client talks to.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
HTTP *http.Client
UserAgent string
BaseURL string
// Rate is the minimum gap between requests. Zero means no pacing.
Rate time.Duration
Retries int
// contains filtered or unexported fields
}
Client talks to the CheapShark API over HTTP.
func (*Client) Get ¶
Get fetches url and returns the response body. It paces and retries according to the client's settings.
func (*Client) ListDeals ¶
func (c *Client) ListDeals(ctx context.Context, storeID string, maxPrice float64, limit int) ([]Deal, error)
ListDeals returns deals from the given store filtered by maxPrice (0 = no filter). storeID "1" is Steam.
func (*Client) ListStores ¶
ListStores returns all stores known to CheapShark.
func (*Client) SearchGames ¶
SearchGames searches games by title. The CheapShark API returns either an array or a map depending on the query; we handle both formats.
type Deal ¶
type Deal struct {
Title string `kit:"id" json:"title"`
StoreID string `json:"store_id"`
SalePrice string `json:"sale_price"`
NormalPrice string `json:"normal_price"`
Savings string `json:"savings"`
DealID string `json:"deal_id"`
GameID string `json:"game_id"`
SteamAppID string `json:"steam_app_id"`
Metacritic string `json:"metacritic"`
DealRating string `json:"deal_rating"`
}
Deal is a single game deal from the CheapShark /deals endpoint.
type Domain ¶
type Domain struct{}
Domain is the cheapshark driver.
func (Domain) Classify ¶
Classify turns any accepted input into (type, id) for URI resolution. All-digit inputs are treated as gameIDs; anything else is a query.
func (Domain) Info ¶
func (Domain) Info() kit.DomainInfo
Info describes the scheme, the hostnames a pasted link is matched against, and the identity reused for the binary's help and version.
type GameResult ¶
type GameResult struct {
GameID string `kit:"id" json:"game_id"`
SteamAppID string `json:"steam_app_id"`
Cheapest string `json:"cheapest"`
}
GameResult is one entry from the CheapShark /games search endpoint.