Documentation ¶
Index ¶
- Constants
- type GameResult
- type GameResultsPage
- type HLTBClient
- func (h *HLTBClient) SearchGames(query string) (*GameResultsPage, error)
- func (h *HLTBClient) SearchGamesByQuery(q *HLTBQuery) (*GameResultsPage, error)
- func (h *HLTBClient) SearchUsers(query string) (*UserResultsPage, error)
- func (h *HLTBClient) SearchUsersByQuery(q *HLTBQuery) (*UserResultsPage, error)
- type HLTBQuery
- type HTTPClient
- type LengthRange
- type Modifier
- type Pages
- type Platform
- type QueryType
- type SortBy
- type SortDirection
- type UserResult
- type UserResultsPage
- type UserStats
Constants ¶
const ( ThreeDO Platform = "3DO" Amiga Platform = "Amiga" AmstradCPC Platform = "Amstrad CPC" Android Platform = "Android" AppleII Platform = "Apple II" Arcade Platform = "Arcade" Atari2600 Platform = "Atari 2600" Atari5200 Platform = "Atari 5200" Atari7800 Platform = "Atari 7800" Atari8bitFamily Platform = "Atari 8-bit Family" AtariJaguar Platform = "Atari Jaguar" AtariJaguarCD Platform = "Atari Jaguar CD" AtariLynx Platform = "Atari Lynx" AtariST Platform = "Atari ST" BBCMicro Platform = "BBC Micro" Browser Platform = "Browser" ColecoVision Platform = "ColecoVision" Commodore64 Platform = "Commodore 64" Dreamcast Platform = "Dreamcast" Emulated Platform = "Emulated" FMTowns Platform = "FM Towns" GameWatch Platform = "Game & Watch" GameBoy Platform = "Game Boy" GameBoyAdvance Platform = "Game Boy Advance" GameBoyColor Platform = "Game Boy Color" GearVR Platform = "Gear VR" GoogleStadia Platform = "Google Stadia" Intellivision Platform = "Intellivision" InteractiveMovie Platform = "Interactive Movie" Linux Platform = "Linux" Mac Platform = "Mac" Mobile Platform = "Mobile" MSX Platform = "MSX" NGage Platform = "N-Gage" NECPC8800 Platform = "NEC PC-8800" NECPC980121 Platform = "NEC PC-9801/21" NECPCFX Platform = "NEC PC-FX" NeoGeo Platform = "Neo Geo" NeoGeoCD Platform = "Neo Geo CD" NeoGeoPocket Platform = "Neo Geo Pocket" NES Platform = "NES" Nintendo3DS Platform = "Nintendo 3DS" Nintendo64 Platform = "Nintendo 64" NintendoDS Platform = "Nintendo DS" NintendoGameCube Platform = "Nintendo GameCube" NintendoSwitch Platform = "Nintendo Switch" OculusGo Platform = "Oculus Go" OculusQuest Platform = "Oculus Quest" OnLive Platform = "OnLive" Ouya Platform = "Ouya" PC Platform = "PC" PCVR Platform = "PC VR" PhilipsCDi Platform = "Philips CD-i" PhilipsVideopacG7000 Platform = "Philips Videopac G7000" PlayStation Platform = "PlayStation" PlayStation2 Platform = "PlayStation 2" PlayStation3 Platform = "PlayStation 3" PlayStation4 Platform = "PlayStation 4" PlayStation5 Platform = "PlayStation 5" PlayStationMobile Platform = "PlayStation Mobile" PlayStationNow Platform = "PlayStation Now" PlayStationPortable Platform = "PlayStation Portable" PlayStationVita Platform = "PlayStation Vita" PlayStationVR Platform = "PlayStation VR" PlugPlay Platform = "Plug & Play" Sega32X Platform = "Sega 32X" SegaCD Platform = "Sega CD" SegaGameGear Platform = "Sega Game Gear" SegaMasterSystem Platform = "Sega Master System" SegaMegaDriveGenesis Platform = "Sega Mega Drive/Genesis" SegaSaturn Platform = "Sega Saturn" SG1000 Platform = "SG-1000" SharpX68000 Platform = "Sharp X68000" SuperNintendo Platform = "Super Nintendo" TigerHandheld Platform = "Tiger Handheld" TurboGrafx16 Platform = "TurboGrafx-16" TurboGrafxCD Platform = "TurboGrafx-CD" VirtualBoy Platform = "Virtual Boy" Wii Platform = "Wii" WiiU Platform = "Wii U" WindowsPhone Platform = "Windows Phone" WonderSwan Platform = "WonderSwan" Xbox Platform = "Xbox" Xbox360 Platform = "Xbox 360" XboxOne Platform = "Xbox One" XboxSeriesXS Platform = "Xbox Series X/S" ZXSpectrum Platform = "ZX Spectrum" // SortByGameName sorts by game title - default SortByGameName SortBy = "name" // SortByGameMainStory sorts by the main story competion time (shortest to longest) SortByGameMainStory SortBy = "main" // SortByGameMainExtras sorts by the main + extras competion time (shortest to longest) SortByGameMainExtras SortBy = "mainp" // SortByGameCompletionist sorts by the completionist competion time (shortest to longest) SortByGameCompletionist SortBy = "comp" // SortByGameAverageTime sorts by the average competion time (shortest to longest) SortByGameAverageTime SortBy = "averagea" // SortByGameTopRated sorts by games with the highest user rating (highest to lowest) SortByGameTopRated SortBy = "rating" // SortByGameMostPopular sorts by games that have been added by the most number of users SortByGameMostPopular SortBy = "popular" // SortByGameMostBacklogs sorts by the number of users with the game in their backlog SortByGameMostBacklogs SortBy = "backlog" // SortByGameMostSubmissions sorts by the number of user submissions (submitted a time) SortByGameMostSubmissions SortBy = "usersp" // SortByGameMostPlayed sorts by the number of users that have completed the game SortByGameMostPlayed SortBy = "playing" // SortByGameMostSpeedruns sorts by the number of submitted speedruns for a game // (note that these are the speed runs submitted to howlongtobeat.com, not speedrun.com) SortByGameMostSpeedruns SortBy = "speedruns" // SortByGameReleaseDate sorts by the release date of the game (earliest to most recent) SortByGameReleaseDate SortBy = "release" // SortByUserTopPosters will sort by the most active comunity members SortByUserTopPosters SortBy = "postcount" // SortByUserName will sort by user's display name SortByUserName SortBy = "name" // SortByUserGender will sort by user's gender SortByUserGender SortBy = "gender" // SortByUserCompleted will sort by user's number of completed games SortByUserCompleted SortBy = "numcomp" // SortByUserBacklog will sort by user's number of games in their backlog SortByUserBacklog SortBy = "numbacklog" // RangeMainStory will search Main Story completion times RangeMainStory LengthRange = "main" // RangeMainExtras will search Main + Extra completion times RangeMainExtras LengthRange = "mainp" // RangeCompletionist will search Completionist completion times RangeCompletionist LengthRange = "comp" // RangeAverageTime will search average completion times RangeAverageTime LengthRange = "averagea" // NoModifier will use no search modifiers NoModifier Modifier = "" // IncludeDLC will show DLC in responses IncludeDLC Modifier = "show_dlc" // IsolateDLC will only return DCL in responses IsolateDLC Modifier = "only_dlc" // ShowUserStats will include user stats in responses ShowUserStats Modifier = "user_stats" // NormalOrder sorts in the direction specified by the SortBy method NormalOrder SortDirection = "Normal Order" // ReverseOrder sorts in the reverse direction specified by the SortBy method ReverseOrder SortDirection = "Reverse Order" // GameQuery will query against game titles GameQuery QueryType = "games" // UserQuery will query against user names UserQuery QueryType = "users" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GameResult ¶
type GameResult struct { ID string `json:"id"` // ID in howlongtobeat.com's database Title string `json:"title"` // Title of game URL string `json:"url"` // Link to game page BoxArtURL string `json:"box-art-url"` // Link to boxart Main string `json:"main"` // Completion time for Main category MainExtra string `json:"main-extra"` // Completion time for Main + Extra category Completionist string `json:"completionist"` // Completion time for Completionist category Other map[string]string `json:"other,omitempty"` // Times that don't fall under the main 3 time categories UserStats *UserStats `json:"user-stats,omitempty"` // Optional additional user details (only present when requested) }
GameResult are the data object for Games. Games contain the thing that you're probably most interested in, which are the completion times. All of the times that are collected are presented as strings, you will need to handle any kind of conversions if you need them as numbers.
Completion times break down as:
- Main - time to complete the main game
- MainExtra - time to complete the main game and all extras
- Completionist - time to 100% the game
- Other - These are other kinds of times, primarily reserved for multiplayer games
type GameResultsPage ¶
type GameResultsPage struct { Games []*GameResult `json:"games"` // Slice of GameResult TotalPages int `json:"total-pages"` // Total number of pages CurrentPage int `json:"curent-page"` // Current page number NextPage int `json:"next-page"` // Next page number TotalMatches int `json:"matches"` // Total query matches // contains filtered or unexported fields }
GameResultsPage is a page of game responses. It is the data model that will be returned for any Game query. Provides ability to move between pages of Game results.
func (*GameResultsPage) GetNextPage ¶
func (g *GameResultsPage) GetNextPage() (*GameResultsPage, error)
GetNextPage will return the next page, if it exists. Uses the client from the initial request to make additional queries.
func (*GameResultsPage) HasNext ¶
func (g *GameResultsPage) HasNext() bool
HasNext will check to see if there is a next page that can be retrieved
func (*GameResultsPage) JSON ¶
func (g *GameResultsPage) JSON() (string, error)
JSON will convert a game object into a json string
type HLTBClient ¶
type HLTBClient struct {
Client *HTTPClient
}
HLTBClient is the main client used to interact with the APIs. You should be creating a client via one of the two "New" methods, either NewDefaultClient or NewCustomClient. Either will be needed to perform game or user queries.
func NewCustomClient ¶
func NewCustomClient(c *HTTPClient) *HLTBClient
NewCustomClient will create a new HLTBClient with provided HTTPClient. Users are able to pass in an HTTPClient with their desired http.Client.
func NewDefaultClient ¶
func NewDefaultClient() *HLTBClient
NewDefaultClient will create a new HLTBClient with default parameters. This is what you should use to create you client if you don't need to use a specific http.Client/settings
func (*HLTBClient) SearchGames ¶
func (h *HLTBClient) SearchGames(query string) (*GameResultsPage, error)
SearchGames performs a search for the provided game title. Will populate default values for the reamaining query parameters, aside from the provided game title.
Note: A query with an empty query string will query ALL games
func (*HLTBClient) SearchGamesByQuery ¶
func (h *HLTBClient) SearchGamesByQuery(q *HLTBQuery) (*GameResultsPage, error)
SearchGamesByQuery queries using a set of user defined parameters. Used for running more complex queries. Takes in a HLTBQuery object, with parameters tailored to a user query. You may include any of the following:
- Query - user name
- QueryType - UserQuery
- SortBy - one of the various "SortByUser" options
- SortDirection - sort direcion, based on SortBy
- Platform - restrict responses to platform (see constants.go)
- LengthType - Type of length parameter to (optionally) fillter by
- LengthMax - Max value for LengthType
- LengthMin - Min value for LengthType
- Modifier - Optional additional query parameters.
- Random - whether or not to retrieve random value
- Page - page of responses to return
Note: A query with an empty "Query" string will query ALL games.
func (*HLTBClient) SearchUsers ¶
func (h *HLTBClient) SearchUsers(query string) (*UserResultsPage, error)
SearchUsers performs a search for the provided user name. Will populate default values for the remaining query parameters aside from the provided user name.
Note: A query with an empty string will query ALL users.
func (*HLTBClient) SearchUsersByQuery ¶
func (h *HLTBClient) SearchUsersByQuery(q *HLTBQuery) (*UserResultsPage, error)
SearchUsersByQuery queries using a set of user defined parameters. Used for running more complex queries. Takes in a HLTBQuery object, with parameters tailored to a user query. You may include any of the following:
- Query - user name
- QueryType - UserQuery
- SortBy - one of the various "SortByUser" options
- SortDirection - sort direcion, based on SortBy
- Random - whether or not to retrieve random value
- Page - page of responses to return
Note: A query with an empty "Query" string will query ALL users.
type HLTBQuery ¶
type HLTBQuery struct { Query string // String to query by QueryType QueryType // Type of query to perform - games or users SortBy SortBy // Specify how data should be sorted SortDirection SortDirection // Specify direction data should be sorted Platform Platform // Platform to query against (only used with game queries) LengthType LengthRange // Optional filter based on completion times (games only) LengthMin string // Optional min length for LengthType (games only) LengthMax string // Optional max length for LengthType (games only) Modifier Modifier // Toggle additional filter methods (games only) Random bool // Return a single, random, entry based on parameters Page int // Page number to return }
HLTBQuery is a query object used to run user defined queries. Both game and user queries both use the HLTBQuery as their means of query. The library handles any mandatory parameters for you, making all parameters optional when constructing a query.
example: client.SearchGamesByQuery(&HLTBQuery{query: "Mario", random: true})
type HTTPClient ¶
HTTPClient handles the connectivity details for the client. This is handled automatically when using the NewDefaultClient constructor, but can optionally be supplied when creating a NewCustomClient. This allows the user to create their own http.Client and pass it in for use. This can be useful if you want to use something other than the default configuration.
type LengthRange ¶
type LengthRange string
LengthRange allows filtering by the time it takes to complete a game
type Pages ¶
type Pages interface {
// contains filtered or unexported methods
}
Pages are a type of data structure for paged responses.
type Platform ¶
type Platform string
Platform is where the game is played (i.e. console, operating system)
type SortDirection ¶
type SortDirection string
SortDirection specifies the direction the responses will be sorted (baed on SortBy)
type UserResult ¶
type UserResult struct { ID string `json:"id"` // ID in howlongtobeat.com's database Name string `json:"name"` // User's display name URL string `json:"url"` // Link to user's page AvatarURL string `json:"avatar-url"` // Link to avatar Location string `json:"location,omitempty"` // User's location Backlog string `json:"backlog,omitempty"` // Number of games in user's backlog Complete string `json:"complete,omitempty"` // Number of games the user's completed Gender string `json:"gender,omitempty"` // User's gender Posts string `json:"posts,omitempty"` // Number of user's forum posts Age int `json:"age,omitempty"` // User's age Accolades []string `json:"accolades,omitempty"` // User accolades for activity on the site. This is things like years of service. }
UserResult are the data object for Users. They contain information about a user that can be collected from the user query response. Users are the people on howlongtobeat.com that contribute completion times to the site or track their game collections.
type UserResultsPage ¶
type UserResultsPage struct { Users []*UserResult `json:"users"` // Slice of UserResult TotalPages int `json:"total-pages"` // Total number of pages CurrentPage int `json:"curent-page"` // Current page number NextPage int `json:"next-page"` // Next page number TotalMatches int `json:"matches"` // Total query matches // contains filtered or unexported fields }
UserResultsPage is a page of user responses. It is the data model that will be returned for any User query. Provides ability to move between pages of User results.
func (*UserResultsPage) GetNextPage ¶
func (u *UserResultsPage) GetNextPage() (*UserResultsPage, error)
GetNextPage will return the next page, if it exists. Uses the client from the initial request to make additional queries.
func (*UserResultsPage) HasNext ¶
func (u *UserResultsPage) HasNext() bool
HasNext will check to see if there is a next page that can be retrieved
func (*UserResultsPage) JSON ¶
func (u *UserResultsPage) JSON() (string, error)
JSON will convert user object into a json string
type UserStats ¶
type UserStats struct { Completed string `json:"completed,omitempty"` // Number of users that have marked the game as Completed Rating string `json:"rating,omitempty"` // Average User rating Backlog string `json:"backlog,omitempty"` // Number of users that have placed game in their backlog Playing string `json:"playing,omitempty"` // Number of users that are currently playing through a game Retired string `json:"retired,omitempty"` // Number of users that did not finish a game SpeedRuns string `json:"speedruns,omitempty"` // Number of users that have submitted speedruns for the game }
UserStats are additional stats based on user activity on howlongtobeat.com This information is only included when additional user details are requested, by setting the Modifier in HLTBQuery to ShowUserStats