Documentation
¶
Overview ¶
Package modio is a client for the mod.io REST API v1, read-only: search, sorts, mod details, files with their MD5 digests, dependencies and tags, signed with a user's OAuth access token.
Index ¶
- Constants
- Variables
- func Denied(err error) bool
- func UserURL(userID int) string
- type Client
- func (c *Client) Dependencies(ctx context.Context, gameID, modID int, recursive bool) ([]Mod, error)
- func (c *Client) Files(ctx context.Context, gameID, modID int) ([]File, error)
- func (c *Client) Me(ctx context.Context) (User, error)
- func (c *Client) Mod(ctx context.Context, gameID, modID int) (Mod, error)
- func (c *Client) Search(ctx context.Context, q SearchQuery) (ModList, error)
- func (c *Client) Tags(ctx context.Context, gameID int) ([]string, error)
- type Config
- type File
- type Mod
- type ModList
- type SearchQuery
- type User
Constants ¶
const ( // BaseURL is the API root for calls that need no per-user host. BaseURL = "https://api.mod.io/v1" // MaxPageSize is the API's largest _limit. MaxPageSize = 100 )
const ( SortPopular = "-popular" SortDownloads = "-downloads_total" SortRating = "-rating" SortUpdated = "-date_updated" SortNewest = "-date_live" SortName = "name" )
Sort is a value for SearchQuery.Sort; a leading minus sorts descending.
const MaturityExplicit = 8
MaturityExplicit is the Mod.MaturityOption bit for explicit content.
Variables ¶
var ( // ErrNoToken means the Client has no access token; nothing is sent. ErrNoToken = errors.New("modio: no access token") // ErrNoFile means a mod has no downloadable file. ErrNoFile = errors.New("modio: mod has no file to download") )
Functions ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client calls the mod.io API. It holds no state beyond its configuration, so it is safe for concurrent use and cheap to build again when the token changes.
func (*Client) Dependencies ¶
func (c *Client) Dependencies(ctx context.Context, gameID, modID int, recursive bool) ([]Mod, error)
Dependencies lists the mods a mod depends on, all levels down when recursive. Creators also list soft credit links here, so a caller offers them and installs none unasked.
type Config ¶
type Config struct {
// Token is a read-only OAuth access token, sent as a bearer token. Empty makes every call fail with ErrNoToken.
Token string
// UserID, when set, sends calls to the token's own host (UserURL) instead of BaseURL.
UserID int
// Platform is sent as X-Modio-Platform ("windows", "linux", ...) and picks which build of a mod's files the API
// returns; empty sends none.
Platform string
// HTTP sends every request; nil means http.DefaultClient. Redirects to another origin are refused so the token
// stays with the API.
HTTP *http.Client
// BaseURL replaces the API root; it wins over UserID.
BaseURL string
// UserAgent is sent with every request when set.
UserAgent string
}
Config is what a Client is built from.
type File ¶
type File struct {
ID int `json:"id"`
Filesize int64 `json:"filesize"`
Filename string `json:"filename"`
Version string `json:"version"`
Changelog string `json:"changelog"`
Filehash struct {
MD5 string `json:"md5"`
} `json:"filehash"`
Download struct {
// BinaryURL can expire: read the file again right before downloading.
BinaryURL string `json:"binary_url"`
} `json:"download"`
}
File is one uploaded build of a mod.
func (File) Downloadable ¶
Downloadable reports whether the file carries an address.
func (File) VersionName ¶
VersionName is the file's own version, or its id when the author left it blank.
type Mod ¶
type Mod struct {
ID int `json:"id"`
Name string `json:"name"`
Summary string `json:"summary"`
Description string `json:"description"`
ProfileURL string `json:"profile_url"`
DateUpdated int64 `json:"date_updated"`
MaturityOption int `json:"maturity_option"`
SubmittedBy struct {
Username string `json:"username"`
} `json:"submitted_by"`
Logo struct {
Thumb string `json:"thumb_320x180"`
} `json:"logo"`
Stats struct {
Downloads int `json:"downloads_total"`
RatingsPositive int `json:"ratings_positive"`
} `json:"stats"`
Tags []struct {
Name string `json:"name"`
} `json:"tags"`
// Modfile is the current file.
Modfile File `json:"modfile"`
}
Mod is one mod listing.
type SearchQuery ¶
type SearchQuery struct {
GameID int
// Text matches names and summaries.
Text string
// Sort is one of the Sort constants; empty keeps the API's order.
Sort string
// TagsIn keeps mods carrying any listed tag; TagsNotIn drops mods carrying any.
TagsIn, TagsNotIn []string
// IDs keeps only these mods.
IDs []int
// Offset is the first mod's position and Limit the page length, at most MaxPageSize; zero Limit is MaxPageSize.
Offset, Limit int
}
SearchQuery is one mods listing. Zero fields are not sent.