Documentation
¶
Overview ¶
Package itchio is a client for the itch.io server-side API and its game page addresses.
Index ¶
- Constants
- Variables
- func PageURL(id string) string
- func ParsePageURL(text string) (string, bool)
- func ValidPage(id string) bool
- type Client
- func (c *Client) DownloadURL(ctx context.Context, uploadID string) (string, error)
- func (c *Client) Me(ctx context.Context) (User, error)
- func (c *Client) SearchGames(ctx context.Context, query string, page int) ([]Game, error)
- func (c *Client) Uploads(ctx context.Context, gameID string) ([]Upload, error)
- type Config
- type Game
- type Upload
- type User
Constants ¶
const ( // BaseURL is the server-side API root (itch.io/docs/api/serverside). Only this host reads the key from the // Authorization header; itch.io/api/1 wants it in the address, where an error quoting the address would leak it. BaseURL = "https://api.itch.io" )
Variables ¶
var ( // ErrNeedsKey means the Client has no API key; nothing is sent. ErrNeedsKey = errors.New("needs an itch.io API key") // ErrBadKey means itch.io rejected the key: it is mistyped or revoked. ErrBadKey = errors.New("itch.io rejected the API key") )
Functions ¶
func ParsePageURL ¶
ParsePageURL reads a pasted game page address: https only, host <user>.itch.io with no user name or port, and a path of the one game slug. It returns "user/game"; the address that opens is always rebuilt from it, so a query, fragment or look-alike host never reaches the browser.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client calls the itch.io API. It holds no state beyond its configuration, so it is safe for concurrent use and cheap to build again when the key changes.
func (*Client) DownloadURL ¶
DownloadURL asks for an upload's file and returns the short-lived signed address itch.io answers with. The API sends that address as a redirect rather than as JSON, so the redirect is read and not followed: the key never travels to the file host.
func (*Client) SearchGames ¶
SearchGames lists the games matching query. itch.io answers every hit on the first page and ignores a page number, so a later page is empty and asks for nothing.
type Config ¶
type Config struct {
// Key is the user's own itch.io API key, sent as a bearer token. Empty makes every call that needs one fail with
// ErrNeedsKey.
Key string
// BaseURL replaces the API root.
BaseURL string
// HTTP sends every request; nil means a client with a default timeout. A redirect to another origin is refused
// so the key stays with the API.
HTTP *http.Client
// UserAgent is sent with every request when set.
UserAgent string
}
Config is what a Client is built from.
type Game ¶
type Game struct {
ID int `json:"id"`
Title string `json:"title"`
// ShortText is the one-line summary the game's page opens with.
ShortText string `json:"short_text"`
URL string `json:"url"`
CoverURL string `json:"cover_url"`
// PublishedAt is the API's own timestamp, unparsed.
PublishedAt string `json:"published_at"`
// User is the account that published the game.
User User `json:"user"`
}
Game is one search hit.
type Upload ¶
type Upload struct {
ID int `json:"id"`
Filename string `json:"filename"`
Size int64 `json:"size"`
// Type is the upload's kind; a soundtrack is not a mod.
Type string `json:"type"`
// Demo marks a demo build, which is not a mod either.
Demo bool `json:"demo"`
// UpdatedAt is the API's own timestamp, unparsed.
UpdatedAt string `json:"updated_at"`
}
Upload is one file attached to a game.