rawg

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2020 License: MIT Imports: 10 Imported by: 2

README

RAWG Video Games Database Golang client

Build Status codecov Go Report Card License Mentioned in Awesome Go

This is unofficial RAWG SDK GO. This library contains methods for interacting with RAWG API.

Installation

go get github.com/dimuska139/rawg-sdk-go

Usage

package main

import (
    "fmt"
    "net/http"
    "strings"
    "github.com/dimuska139/rawg-sdk-go"
)

func main() {
    config := rawg.Config{
        ApiKey:  "yourapikey", // Your personal API key (see https://rawg.io/apidocs)
        Language: "ru",
        Rps:      5,
    }
    client := rawg.NewClient(http.DefaultClient, &config)
    
    filter := rawg.NewGamesFilter().
        SetSearch("Gta5").
        SetPage(1).
        SetPageSize(10).
        ExcludeCollection(1).
        WithoutParents()
    
    data, total, err := client.GetGames(filter)

    ...
}

The tests should be considered a part of the documentation. Also you can read official docs.

API limitations

Only 5 requests per second allowed from one IP. The "Rps" parameter in configuration performs this limitation. So you don't worry about it.

License

RAWG SDK GO is released under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Achievement

type Achievement struct {
	ID          int     `json:"id"`
	Name        string  `json:"name"`
	Description string  `json:"description"`
	Image       string  `json:"image"`
	Percent     float32 `json:"percent,string"`
}

Achievement (a meta-goal defined outside a game's parameters)

type AddedByStatus

type AddedByStatus struct {
	Yet     int `json:"yet"`
	Owned   int `json:"owned"`
	Beaten  int `json:"beaten"`
	Toplay  int `json:"toplay"`
	Dropped int `json:"dropped"`
	Playing int `json:"playing"`
}

AddedByStatus represents number of games added by status

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client to interract with RAWG API

func NewClient

func NewClient(client *http.Client, config *Config) *Client

NewClient creates new Client to interract with RAWG API

func (*Client) GetCreator

func (api *Client) GetCreator(id int) (*CreatorDetailed, error)

GetCreator returns details of the creator

func (*Client) GetCreatorRoles

func (api *Client) GetCreatorRoles(page int, pageSize int) ([]*Role, int, error)

GetCreatorRoles returns a list of creator positions (jobs)

func (*Client) GetCreators

func (api *Client) GetCreators(page int, pageSize int) ([]*Creator, int, error)

GetCreators returns a list of game creators

func (*Client) GetDeveloper

func (api *Client) GetDeveloper(id int) (*DeveloperDetailed, error)

GetDeveloper returns details of the developer

func (*Client) GetDevelopers

func (api *Client) GetDevelopers(page int, pageSize int) ([]*Developer, int, error)

GetDevelopers returns a list of game developers

func (*Client) GetGame

func (api *Client) GetGame(id int) (*GameDetailed, error)

GetGame returns details of the game

func (*Client) GetGameAchievements

func (api *Client) GetGameAchievements(id int) ([]*Achievement, error)

GetGameAchievements returns a list of game achievements

func (*Client) GetGameAdditions

func (api *Client) GetGameAdditions(gameID int, page int, pageSize int) ([]*Game, int, error)

GetGameAdditions returns a list of DLC's for the game, GOTY and other editions, companion apps, etc

func (*Client) GetGameDevelopmentTeam

func (api *Client) GetGameDevelopmentTeam(gameID int, page int, pageSize int, ordering string) ([]*GameDeveloper, int, error)

GetGameDevelopmentTeam returns a list of individual creators that were part of the development team

func (*Client) GetGameMovies

func (api *Client) GetGameMovies(id int) ([]*Movie, error)

GetGameMovies returns a list of game trailers

func (*Client) GetGameReddit

func (api *Client) GetGameReddit(id int) ([]*Reddit, error)

GetGameReddit returns a list of most recent posts from the game's subreddit

func (*Client) GetGameScreenshots

func (api *Client) GetGameScreenshots(gameID int, page int, pageSize int) ([]*Screenshot, int, error)

GetGameScreenshots returns a screenshots list for the game

func (*Client) GetGameSeries

func (api *Client) GetGameSeries(gameID int, page int, pageSize int) ([]*Game, int, error)

GetGameSeries returns a list of games that are part of same series

func (*Client) GetGameStores

func (api *Client) GetGameStores(gameID int, page int, pageSize int) ([]*GameStore, int, error)

GetGameStores returns links to the stores that sell the game

func (*Client) GetGameSuggested

func (api *Client) GetGameSuggested(id int) ([]*Game, error)

GetGameSuggested returns a list of visually similar games

func (*Client) GetGameTwitch

func (api *Client) GetGameTwitch(id int) ([]*Twitch, error)

GetGameTwitch returns streams on Twitch associated with the game

func (*Client) GetGameYoutube

func (api *Client) GetGameYoutube(id int) ([]*Youtube, error)

GetGameYoutube returns videos from YouTube associated with the game

func (*Client) GetGames

func (api *Client) GetGames(filter *GamesFilter) ([]*Game, int, error)

GetGames returns a list of games

func (*Client) GetGenre

func (api *Client) GetGenre(id int) (*GenreDetailed, error)

GetGenre returns details of the genre

func (*Client) GetGenres

func (api *Client) GetGenres(page int, pageSize int, ordering string) ([]*Genre, int, error)

GetGenres returns a list of video game genres

func (*Client) GetParentGames

func (api *Client) GetParentGames(gameID int, page int, pageSize int) ([]*Game, int, error)

GetParentGames returns a list of parent games for DLC's and editions

func (*Client) GetParentsPlatforms

func (api *Client) GetParentsPlatforms(page int, pageSize int, ordering string) ([]*Platform, int, error)

GetParentsPlatforms returns a list of parent platforms

func (*Client) GetPlatform

func (api *Client) GetPlatform(id int) (*PlatformDetailed, error)

GetPlatform returns details of the platform

func (*Client) GetPlatforms

func (api *Client) GetPlatforms(page int, pageSize int, ordering string) ([]*Platform, int, error)

GetPlatforms returns a list of video game platforms

func (*Client) GetPublisher

func (api *Client) GetPublisher(id int) (*PublisherDetailed, error)

GetPublisher returns details of the publisher

func (*Client) GetPublishers

func (api *Client) GetPublishers(page int, pageSize int) ([]*Publisher, int, error)

GetPublishers returns a list of video game publishers

func (*Client) GetStore

func (api *Client) GetStore(id int) (*StoreDetailed, error)

GetStore returns details of the store

func (*Client) GetStores

func (api *Client) GetStores(page int, pageSize int, ordering string) ([]*Store, int, error)

GetStores returns a list of video game storefronts

func (*Client) GetTag

func (api *Client) GetTag(id int) (*TagDetailed, error)

GetTag returns details of the tag

func (*Client) GetTags

func (api *Client) GetTags(page int, pageSize int) ([]*Tag, int, error)

GetTags returns a list of tags

type Clip

type Clip struct {
	Clip    string            `json:"clip"`
	Clips   map[string]string `json:"clips"`
	Video   string            `json:"video"`
	Preview string            `json:"preview"`
}

Clip (Trailer) of the game

type Config

type Config struct {
	ApiKey   string // Your personal API key
	Language string // Language name (ISO 639-1)
	Rps      int    // Max allowed count of requests per second (default: 5)
}

Config represents a configuration of RAWG client

type Creator

type Creator struct {
	ID              int    `json:"id"`
	Name            string `json:"name"`
	Slug            string `json:"slug"`
	Image           string `json:"results"`
	ImageBackground string `json:"image_background"`
	GamesCount      int    `json:"games_count"`
}

Creator represents main information about creator

type CreatorDetailed

type CreatorDetailed struct {
	Creator
	Description  string   `json:"description"`
	ReviewsCount int      `json:"reviews_count"`
	Rating       string   `json:"rating"`
	RatingTop    int      `json:"rating_top"`
	Updated      DateTime `json:"updated"`
}

CreatorDetailed represents detailed information about creator

type DateRange

type DateRange struct {
	From time.Time
	To   time.Time
}

DateRange - two dates: from and to

type DateTime

type DateTime struct {
	time.Time
}

DateTime is a special type to unmarshal dates from any formats

func (*DateTime) UnmarshalJSON

func (d *DateTime) UnmarshalJSON(b []byte) error

UnmarshalJSON converts json to time.Time

type Developer

type Developer struct {
	ID              int    `json:"id"`
	Name            string `json:"name"`
	Slug            string `json:"slug"`
	GamesCount      int    `json:"games_count"`
	ImageBackground string `json:"image_background"`
}

Developer represents main information about video game developer

type DeveloperDetailed

type DeveloperDetailed struct {
	Developer
	Description string `json:"description"`
}

DeveloperDetailed represents detailed information about video game developer

type EsrbRating

type EsrbRating struct {
	ID   int    `json:"id"`
	Slug string `json:"slug"`
	Name string `json:"name"`
}

EsrbRating is an Entertainment Software Rating Board

type Game

type Game struct {
	ID               int            `json:"id"`
	Slug             string         `json:"slug"`
	Name             string         `json:"name"`
	Released         DateTime       `json:"released"`
	Tba              bool           `json:"tba"`
	ImageBackground  string         `json:"background_image"`
	Rating           float32        `json:"rating"`
	RatingTop        int            `json:"rating_top"`
	Ratings          []*Rating      `json:"ratings"`
	RatingsCount     int            `json:"ratings_count"`
	ReviewsTextCount int            `json:"reviews_text_count"`
	Added            int            `json:"added"`
	AddedByStatus    *AddedByStatus `json:"added_by_status"`
	Metacritic       int            `json:"metacritic"`
	Playtime         int            `json:"playtime"`
	SuggestionsCount int            `json:"suggestions_count"`
	ReviewsCount     int            `json:"reviews_count"`
	SaturatedColor   string         `json:"saturated_color"`
	DominantColor    string         `json:"dominant_color"`
	Platforms        []*struct {
		Platform       *Platform    `json:"platform"`
		ReleasedAt     DateTime     `json:"released_at"`
		RequirementsEn *Requirement `json:"requirements_en"`
		RequirementsRu *Requirement `json:"requirements_ru"`
	} `json:"platforms"`
	ParentPlatforms []*struct {
		Platform struct {
			ID   int    `json:"id"`
			Slug string `json:"slug"`
			Name string `json:"name"`
		}
	} `json:"parent_platforms"`
	Genres []*Genre `json:"genres"`
	Stores []*struct {
		ID    int    `json:"id"`
		Store *Store `json:"store"`
		UrlEn string `json:"url_en"`
		UrlRu string `json:"url_ru"`
	} `json:"stores"`
	Clip             *Clip  `json:"clip"`
	Tags             []*Tag `json:"tags"`
	ShortScreenshots []*struct {
		ID   int    `json:"id"`
		Name string `json:"name"`
	} `json:"short_screenshots"`
}

Game represents main information of the game

type GameDetailed

type GameDetailed struct {
	ID                        int                   `json:"id"`
	Slug                      string                `json:"slug"`
	Name                      string                `json:"name"`
	NameOriginal              string                `json:"name_original"`
	Description               string                `json:"description"`
	Metacritic                int                   `json:"metacritic"`
	MetacriticPlatforms       []*MetacriticPlatform `json:"metacritic_platforms"`
	Released                  DateTime              `json:"released"`
	Tba                       bool                  `json:"tba"`
	Updated                   DateTime              `json:"updated"`
	ImageBackground           string                `json:"background_image"`
	ImageBackgroundAdditional string                `json:"background_image_additional"`
	Website                   string                `json:"website"`
	Rating                    float32               `json:"rating"`
	RatingTop                 int                   `json:"rating_top"`
	Ratings                   []*Rating             `json:"ratings"`
	Reactions                 map[string]int        `json:"reactions"`
	Added                     int                   `json:"added"`
	AddedByStatus             *AddedByStatus        `json:"added_by_status"`
	Playtime                  int                   `json:"playtime"`
	ScreenshotsCount          int                   `json:"screenshots_count"`
	MoviesCount               int                   `json:"movies_count"`
	CreatorsCount             int                   `json:"creators_count"`
	AchievementsCount         int                   `json:"achievements_count"`
	ParentAchievementsCount   int                   `json:"parent_achievements_count"`
	RedditUrl                 string                `json:"reddit_url"`
	RedditName                string                `json:"reddit_name"`
	RedditDescription         string                `json:"reddit_description"`
	RedditCount               int                   `json:"reddit_count"`
	TwitchCount               int                   `json:"twitch_count"`
	YoutubeCount              int                   `json:"youtube_count"`
	ReviewsTextCount          int                   `json:"reviews_text_count"`
	RatingsCount              int                   `json:"ratings_count"`
	SuggestionsCount          int                   `json:"suggestions_count"`
	AlternativeNames          []string              `json:"alternative_names"`
	MetacriticUrl             string                `json:"metacritic_url"`
	ParentsCount              int                   `json:"parents_count"`
	AdditionsCount            int                   `json:"additions_count"`
	GameSeriesCountCount      int                   `json:"game_series_count"`
	ReviewsCount              int                   `json:"reviews_count"`
	SaturatedColor            string                `json:"saturated_color"`
	DominantColor             string                `json:"dominant_color"`
	ParentPlatforms           []*struct {
		Platform struct {
			ID   int    `json:"id"`
			Slug string `json:"slug"`
			Name string `json:"name"`
		}
	} `json:"parent_platforms"`
	Platforms []*struct {
		Platform     *Platform    `json:"platform"`
		ReleasedAt   DateTime     `json:"released_at"`
		Requirements *Requirement `json:"requirements"`
	} `json:"platforms"`
	Stores []*struct {
		ID    int    `json:"id"`
		Url   string `json:"url"`
		Store *Store `json:"store"`
	} `json:"stores"`
	Developers     []*Developer `json:"developers"`
	Genres         []*Genre     `json:"genres"`
	Tags           []*Tag       `json:"tags"`
	Publishers     []*Publisher `json:"publishers"`
	EsrbRating     *EsrbRating  `json:"esrb_rating"`
	Clip           *Clip        `json:"clip"`
	DescriptionRaw string       `json:"description_raw"`
}

GameDetailed represents detailed information of the game

type GameDeveloper

type GameDeveloper struct {
	ID              int         `json:"id"`
	Name            string      `json:"name"`
	Slug            string      `json:"slug"`
	Image           string      `json:"image"`
	ImageBackground string      `json:"image_background"`
	GamesCount      int         `json:"games_count"`
	Games           []*Game     `json:"games"`
	Positions       []*Position `json:"positions"`
}

GameDeveloper represents detailed information of game developer (with games list)

type GameStore

type GameStore struct {
	ID      int    `json:"id"`
	GameID  int    `json:"game_id"`
	StoreID int    `json:"store_id"`
	Url     string `json:"url"`
}

GameStore represents "Video game - storefront" relation

type GamesFilter

type GamesFilter struct {
	// contains filtered or unexported fields
}

GamesFilter is a filter to search games in RAWG

func NewGamesFilter

func NewGamesFilter() *GamesFilter

NewGamesFilter creates filter

func (*GamesFilter) ExcludeCollection

func (filter *GamesFilter) ExcludeCollection(collection int) *GamesFilter

ExcludeCollection sets "exclude_collection" parameter

func (*GamesFilter) GetParams

func (filter *GamesFilter) GetParams() map[string]interface{}

GetParams returns filter parameters as Map

func (*GamesFilter) SetCreators

func (filter *GamesFilter) SetCreators(creators ...interface{}) *GamesFilter

SetCreators sets "creators" parameter

func (*GamesFilter) SetDates

func (filter *GamesFilter) SetDates(ranges ...*DateRange) *GamesFilter

SetDates sets "dates" parameter

func (*GamesFilter) SetDevelopers

func (filter *GamesFilter) SetDevelopers(developers ...interface{}) *GamesFilter

SetDevelopers sets "developers" parameter

func (*GamesFilter) SetGenres

func (filter *GamesFilter) SetGenres(genres ...interface{}) *GamesFilter

SetGenres sets "genres" parameter

func (*GamesFilter) SetOrdering

func (filter *GamesFilter) SetOrdering(ordering string) *GamesFilter

SetOrdering sets results ordering

func (*GamesFilter) SetPage

func (filter *GamesFilter) SetPage(page int) *GamesFilter

SetPage sets "page" parameter

func (*GamesFilter) SetPageSize

func (filter *GamesFilter) SetPageSize(pageSize int) *GamesFilter

SetPageSize sets "page_size" parameter

func (*GamesFilter) SetParentPlatforms

func (filter *GamesFilter) SetParentPlatforms(parentPlatforms ...int) *GamesFilter

SetParentPlatforms sets "parent_platforms" parameter

func (*GamesFilter) SetPlatforms

func (filter *GamesFilter) SetPlatforms(platforms ...int) *GamesFilter

SetPlatforms sets "platforms" parameter

func (*GamesFilter) SetPlatformsCount

func (filter *GamesFilter) SetPlatformsCount(count int) *GamesFilter

SetPlatformsCount sets "platforms_count" parameter

func (*GamesFilter) SetPublishers

func (filter *GamesFilter) SetPublishers(publishers ...interface{}) *GamesFilter

SetPublishers sets "publishers" parameter

func (*GamesFilter) SetSearch

func (filter *GamesFilter) SetSearch(search string) *GamesFilter

SetSearch sets "search" parameter

func (*GamesFilter) SetStores

func (filter *GamesFilter) SetStores(stores ...int) *GamesFilter

SetStores sets "stores" parameter

func (*GamesFilter) SetTags

func (filter *GamesFilter) SetTags(tags ...interface{}) *GamesFilter

SetTags sets "tags" parameter

func (*GamesFilter) WithoutAdditions

func (filter *GamesFilter) WithoutAdditions() *GamesFilter

WithoutAdditions sets "exclude_additions" parameter

func (*GamesFilter) WithoutGameSeries

func (filter *GamesFilter) WithoutGameSeries() *GamesFilter

WithoutGameSeries sets "exclude_game_series" parameter

func (*GamesFilter) WithoutParents

func (filter *GamesFilter) WithoutParents() *GamesFilter

WithoutParents sets "exclude_parents" parameter

type Genre

type Genre struct {
	ID              int    `json:"id"`
	Name            string `json:"name"`
	Slug            string `json:"slug"`
	GamesCount      int    `json:"games_count"`
	ImageBackground string `json:"image_background"`
}

Genre represents game genre

type GenreDetailed

type GenreDetailed struct {
	Genre
	Description string `json:"description"`
}

GenreDetailed represents detailed information of video game genre

type MetacriticPlatform

type MetacriticPlatform struct {
	Metascore int    `json:"metascore"`
	Url       string `json:"url"`
	Platform  *struct {
		Platform int    `json:"platform"`
		Name     string `json:"name"`
		Slug     string `json:"slug"`
	} `json:"platform"`
}

MetacriticPlatform represents metascore - metacritic rating of the game

type Movie

type Movie struct {
	ID      int               `json:"id"`
	Name    string            `json:"name"`
	Preview string            `json:"preview"`
	Data    map[string]string `json:"data"`
}

Movie of the game

type ParentPlatform

type ParentPlatform struct {
	Platform struct {
		ID   int    `json:"id"`
		Name string `json:"name"`
		Slug string `json:"slug"`
	} `json:"platform"`
}

ParentPlatform is a parent video game platform. For instance, for PS2 and PS4 the “parent platform” is PlayStation.

type Platform

type Platform struct {
	ID              int    `json:"id"`
	Name            string `json:"name"`
	Slug            string `json:"slug"`
	GamesCount      int    `json:"games_count"`
	ImageBackground string `json:"image_background"`
	Image           string `json:"image"`
	YearStart       int    `json:"year_start"`
	YearEnd         int    `json:"year_end"`
}

Platform represents game platform

type PlatformDetailed

type PlatformDetailed struct {
	Platform
	Description string `json:"description"`
}

PlatformDetailed represents detailed information of video game platform

type Position

type Position struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
	Slug string `json:"slug"`
}

Position (job)

type Publisher

type Publisher struct {
	ID              int    `json:"id"`
	Name            string `json:"name"`
	Slug            string `json:"slug"`
	GamesCount      int    `json:"games_count"`
	ImageBackground string `json:"image_background"`
}

Publisher represents main information about video game publisher

type PublisherDetailed

type PublisherDetailed struct {
	Publisher
	Description string `json:"description"`
}

PublisherDetailed represents detailed information about video game developer

type Rating

type Rating struct {
	ID      int     `json:"id"`
	Title   string  `json:"title"`
	Count   int     `json:"count"`
	Percent float32 `json:"percent"`
}

Rating of the game

type RawgError

type RawgError struct {
	HttpCode int    // HTTP status code (https://en.wikipedia.org/wiki/List_of_HTTP_status_codes)
	Url      string // URL of RAWG endpoint associated with callable function
	Body     string // Raw body of response
	Message  string // Any comment
}

RawgError represents information about errors

func (*RawgError) Error

func (e *RawgError) Error() string

Error() converts error to string

type Reddit

type Reddit struct {
	ID          int      `json:"id"`
	Name        string   `json:"name"`
	Text        string   `json:"text"`
	Image       string   `json:"image"`
	Url         string   `json:"url"`
	Username    string   `json:"username"`
	UsernameUrl string   `json:"username_url"`
	Created     DateTime `json:"created"`
}

Reddit comment

type Requirement

type Requirement struct {
	Minimum     string `json:"minimum"`
	Recommended string `json:"recommended"`
}

Requirement represents game requirements

type Role

type Role struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
	Slug string `json:"slug"`
}

Role is a position (job) of the video game creator

type Screenshot

type Screenshot struct {
	ID        int    `json:"id"`
	Image     string `json:"image"`
	Width     int    `json:"width"`
	Height    int    `json:"height"`
	IsDeleted bool   `json:"is_deleted"`
}

Screenshot of the game

type Store

type Store struct {
	ID              int    `json:"id"`
	Name            string `json:"name"`
	Domain          string `json:"domain"`
	Slug            string `json:"slug"`
	GamesCount      int    `json:"games_count"`
	ImageBackground string `json:"image_background"`
}

Store is a video game storefront

type StoreDetailed

type StoreDetailed struct {
	Store
	Description string `json:"description"`
}

StoreDetailed represents video game storefront (detailed information)

type Tag

type Tag struct {
	ID              int    `json:"id"`
	Name            string `json:"name"`
	Slug            string `json:"slug"`
	GamesCount      int    `json:"games_count"`
	ImageBackground string `json:"image_background"`
	Language        string `json:"language"`
}

Tag of the video game

type TagDetailed

type TagDetailed struct {
	Tag
	Description string `json:"description"`
}

TagDetailed represents detailed information about tag of the video game

type Twitch

type Twitch struct {
	ID          int      `json:"id"`
	ExternalID  int      `json:"external_id"`
	Name        string   `json:"name"`
	Description string   `json:"description"`
	Created     DateTime `json:"created"`
	Published   DateTime `json:"published"`
	Thumbnail   string   `json:"thumbnail"`
	ViewCount   int      `json:"view_count"`
	Language    string   `json:"language"`
}

Twitch stream

type Youtube

type Youtube struct {
	ID            int      `json:"id"`
	ExternalID    string   `json:"external_id"`
	ChannelID     string   `json:"channel_id"`
	Name          string   `json:"name"`
	Description   string   `json:"description"`
	Created       DateTime `json:"created"`
	ViewCount     int      `json:"view_count"`
	CommentsCount int      `json:"comments_count"`
	LikeCount     int      `json:"like_count"`
	DislikeCount  int      `json:"dislike_count"`
	FavoriteCount int      `json:"favorite_count"`
	Thumbnails    *struct {
		High          *YoutubeThumbnail
		Medium        *YoutubeThumbnail
		Default       *YoutubeThumbnail
		SdDefault     *YoutubeThumbnail
		MaxResDefault *YoutubeThumbnail
	}
}

Youtube video associated with the game

type YoutubeThumbnail

type YoutubeThumbnail struct {
	Url    string `json:"url"`
	Width  int    `json:"width"`
	Height int    `json:"height"`
}

YoutubeThumbnail represents thumbnail of the youtube video

Jump to

Keyboard shortcuts

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