cheapshark

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

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

View Source
const DefaultUserAgent = "cheapshark-cli/0.1 (tamnd87@gmail.com)"

DefaultUserAgent identifies the client to CheapShark.

View Source
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 NewClient

func NewClient() *Client

NewClient returns a Client with DefaultConfig values.

func (*Client) Get

func (c *Client) Get(ctx context.Context, rawURL string) ([]byte, error)

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

func (c *Client) GetGame(ctx context.Context, gameID string) ([]GameDeal, error)

GetGame returns all deals for a single game by its CheapShark game ID.

func (*Client) ListDeals

func (c *Client) ListDeals(ctx context.Context, storeID, sortBy string, limit int) ([]Deal, error)

ListDeals returns deals sorted and filtered per the given parameters. storeID "" omits the storeID filter. sortBy defaults to "Recent".

func (*Client) ListStores

func (c *Client) ListStores(ctx context.Context) ([]Store, error)

ListStores returns all stores known to CheapShark. Active-only filtering is done by the caller.

func (*Client) SearchGames

func (c *Client) SearchGames(ctx context.Context, title string, limit int) ([]GameResult, error)

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.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns sensible defaults.

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

func (Domain) Classify(input string) (uriType, id string, err error)

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.

func (Domain) Locate

func (Domain) Locate(uriType, id string) (string, error)

Locate returns the live https URL for a (type, id).

func (Domain) Register

func (Domain) Register(app *kit.App)

Register installs the client factory and every operation onto app.

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.

type Store

type Store struct {
	ID     string `kit:"id" json:"id"`
	Name   string `json:"name"`
	Active bool   `json:"active"`
}

Store is one store from the CheapShark /stores endpoint.

Jump to

Keyboard shortcuts

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