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) GetGame(ctx context.Context, gameID string) ([]GameDeal, error)
- func (c *Client) ListDeals(ctx context.Context, storeID, sortBy string, 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 GameDeal
- type GameResult
- type Store
Constants ¶
const DefaultUserAgent = "cheapshark-cli/0.1 (tamnd87@gmail.com)"
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 rawURL and returns the response body. It paces and retries according to the client's settings.
func (*Client) GetGame ¶ added in v0.1.1
GetGame returns all deals for a single game by its CheapShark game ID.
func (*Client) ListDeals ¶
ListDeals returns deals sorted and filtered per the given parameters. storeID "" omits the storeID filter. sortBy defaults to "Recent".
func (*Client) ListStores ¶
ListStores returns all stores known to CheapShark. Active-only filtering is done by the caller.
func (*Client) SearchGames ¶
SearchGames searches games by title. The CheapShark API returns an array of game stubs.
type Config ¶
type Config struct {
BaseURL string
Rate time.Duration
Retries int
Timeout time.Duration
UserAgent string
}
Config holds the tunables for a Client.
type Deal ¶
type Deal struct {
Title string `kit:"id" json:"title"`
Store string `json:"store"`
Sale string `json:"sale_price"`
Normal string `json:"normal_price"`
Savings string `json:"savings_pct"`
Rating string `json:"rating"`
DealID string `json:"deal_id"`
}
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 GameDeal ¶ added in v0.1.1
type GameDeal struct {
Title string `kit:"id" json:"title"`
Store string `json:"store"`
Price string `json:"price"`
Retail string `json:"retail"`
Savings string `json:"savings_pct"`
DealID string `json:"deal_id"`
}
GameDeal is one deal from a game's detail page.
type GameResult ¶
type GameResult struct {
GameID string `kit:"id" json:"game_id"`
Title string `json:"title"`
Cheapest string `json:"cheapest"`
}
GameResult is one entry from the CheapShark /games search endpoint.