vainglory

package module
v0.0.0-...-54d7e84 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2018 License: MIT Imports: 11 Imported by: 0

README

go-vainglory

Vainglory API Wrapper

documentation

Documentation can be found at here.

testing

In order to run the tests locally you will need to add a conf.json file in the root folder

In the file you will need to add the following:

{ "key" : "[API key]", }

dependencies

Though this client only has one dependency the project uses the new go module system. More information on go modules can be found here.

Documentation

Index

Constants

View Source
const (

	// China Mobile China region
	China = "cn"
	// NorthAmerica Mobile North America region
	NorthAmerica = "na"
	// Europe Mobile Europe region
	Europe = "eu"
	// SouthAmerica Mobile South America region
	SouthAmerica = "sa"
	// EastAsia Mobile East Asia region
	EastAsia = "ea"
	// SoutheastAsia Mobile SEA region
	SoutheastAsia = "sg"
	// NATournament North America Tournament region
	NATournament = "tournament-na"
	// EUTournament Europe Tournament region
	EUTournament = "tournament-eu"
	// EATournament East Asia Tournament region
	EATournament = "tournament-ea"
	// SEATournament North America Tournament region
	SEATournament = "tournament-sg"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Base

type Base struct {
	Timestamp time.Time `json:"time"`
	Type      string    `json:"type"`
}

Base is the base of all telemetery event types. This information will always be returned.

func (Base) GetTimestamp

func (b Base) GetTimestamp() time.Time

GetTimestamp returns the event timestamp.

func (Base) GetType

func (b Base) GetType() string

GetType returns the event type.

type BuyItemEvent

type BuyItemEvent struct {
	Base
	Payload struct {
		Team          string    `json:"Team"`
		Actor         string    `json:"Actor"`
		Item          string    `json:"Item"`
		Cost          int       `json:"Cost"`
		RemainingGold int       `json:"RemainingGold"`
		Position      []float64 `json:"Position"`
	} `json:"payload"`
}

type Client

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

Client is the main struct for vainglory

func New

func New(key string, httpClient *http.Client) (*Client, error)

New returns a new defaulted Session struct.

func (*Client) GetMatch

func (c *Client) GetMatch(matchID string, shardID string) (*MatchResponse, error)

GetMatch retrieves the match data for a specified match id and passes back a MatchResponse.

func (*Client) GetMatches

func (c *Client) GetMatches(options GetMatchesRequestOptions, shardID string) (*MatchesResponse, error)

GetMatches retrieves a list of match data and passes back a MatchesResponse.

func (*Client) GetPlayer

func (c *Client) GetPlayer(id string, shardID string) (*PlayerResponse, error)

GetPlayer retrieves player data for a specified player id and passes back a PlayerResponse.

func (*Client) GetPlayers

func (c *Client) GetPlayers(options GetPlayersRequestOptions, shardID string) (*PlayersResponse, error)

GetPlayers retrieves a list of player data and passes back a PlayersResponse.

func (*Client) GetStatus

func (c *Client) GetStatus() (*StatusResponse, error)

GetStatus retrieves status data from the PUBG servers and passes back a StatusResponse.

func (*Client) GetTelemetry

func (c *Client) GetTelemetry(url string) (*TelemetryResponse, error)

GetTelemetry retrieves the telemetry data at a specified url and passes back a TelemetryResponse.

type DealDamageEvent

type DealDamageEvent struct {
	Base
	Payload struct {
		Team         string `json:"Team"`
		Actor        string `json:"Actor"`
		Target       string `json:"Target"`
		Source       string `json:"Source"`
		Damage       int    `json:"Damage"`
		Dealt        int    `json:"Dealt"`
		IsHero       int    `json:"IsHero"`
		TargetIsHero int    `json:"TargetIsHero"`
	} `json:"payload"`
}

type EarnXPEvent

type EarnXPEvent struct {
	Base
	Payload struct {
		Team       string `json:"Team"`
		Actor      string `json:"Actor"`
		Source     string `json:"Source"`
		Amount     int    `json:"Amount"`
		SharedWith int    `json:"SharedWith"`
	} `json:"payload"`
}

type GetMatchesRequestOptions

type GetMatchesRequestOptions struct {
	// PageOffset Allows paging over results
	PageOffset int `url:"page[offset],omitempty"`
	// PageLimit The default (and maximum) is 5. Values less than 5 and greater than 1 are supported.
	PageLimit int `url:"page[limit],omitempty"`
	// Sort By default, Matches are sorted by creation time ascending.
	Sort string `url:"sort,omitempty"`
	// StartCreationFilter Must occur before end time. Format is iso8601 Usage: filter[createdAt-start]=2017-01-01T08:25:30Z
	StartCreationFilter time.Time `url:"filter[createdAt-start],omitempty"`
	// EndCreationFilter Queries search the last 3 hrs. Format is iso8601 i.e.filter[createdAt-end]=2017-01-01T13:25:30Z
	EndCreationFilter time.Time `url:"filter[createdAt-end],omitempty"`
	// PlayerNamesFilter Filters by player name. Usage: filter[playerNames]=player1,player2,…
	PlayerNamesFilter []string `url:"filter[playerNames],comma,omitempty"`
	// PlayerIDsFilter Filters by player Id. Usage:filter[playerIds]=playerId,playerId,…
	PlayerIDsFilter []string `url:"filter[playerIds],comma,omitempty"`
	// TeamNamesFilter Filters by team names. Team names are the same as the in game team tags. Usage: filter[teamNames]=TSM,team2,…
	TeamNamesFilter []string `url:"filter[teamNames],comma,omitempty"`
	// GameModeFilter Filter by gameMode Usage: filter[gameMode]=casual,ranked,…
	GameModeFilter []string `url:"filter[gameMode],comma,omitempty"`
	// PatchVersionFilter Filter by Vainglory patch version. Usage: filter[patchVersion]=2.10,2.11,…
	PatchVersionFilter []string `url:"filter[patchVersion],comma,omitempty"`
}

GetMatchesRequestOptions Various paging, sorting, and filter options for the get matches endpoint

type GetPlayersRequestOptions

type GetPlayersRequestOptions struct {
	// PlayerNamesFilter Filters by player name. Usage: filter[playerNames]=player1,player2,…
	PlayerNamesFilter []string `url:"filter[playerNames],comma,omitempty"`
	// PlayerIDsFilter Filters by player Id. Usage:filter[playerIds]=playerId,playerId,…
	PlayerIDsFilter []string `url:"filter[playerIds],comma,omitempty"`
}

GetPlayersRequestOptions Filter options for the get players endpoint

type GoldFromTowerKillEvent

type GoldFromTowerKillEvent struct {
	Base
	Payload struct {
		Team   string `json:"Team"`
		Actor  string `json:"Actor"`
		Amount int    `json:"Amount"`
	} `json:"payload"`
}

type HealTargetEvent

type HealTargetEvent struct {
	Base
	Payload struct {
		Team         string `json:"Team"`
		Actor        string `json:"Actor"`
		TargetActor  string `json:"TargetActor"`
		TargetTeam   string `json:"TargetTeam"`
		Source       string `json:"Source"`
		Heal         int    `json:"Heal"`
		Healed       int    `json:"Healed"`
		IsHero       int    `json:"IsHero"`
		TargetIsHero int    `json:"TargetIsHero"`
	} `json:"payload"`
}

type HeroBanEvent

type HeroBanEvent struct {
	Base
	Payload struct {
		Hero string `json:"Hero"`
		Team string `json:"Team"`
	} `json:"payload"`
}

type HeroSelectEvent

type HeroSelectEvent struct {
	Base
	Payload struct {
		Hero   string `json:"Hero"`
		Team   string `json:"Team"`
		Player string `json:"Player"`
		Handle string `json:"Handle"`
	} `json:"payload"`
}

type HeroSkinSelectEvent

type HeroSkinSelectEvent struct {
	Base
	Payload struct {
		Hero string `json:"Hero"`
		Skin string `json:"Skin"`
	} `json:"payload"`
}

type KillActorEvent

type KillActorEvent struct {
	Base
	Payload struct {
		Team         string    `json:"Team"`
		Actor        string    `json:"Actor"`
		Killed       string    `json:"Killed"`
		KilledTeam   string    `json:"KilledTeam"`
		Gold         string    `json:"Gold"`
		IsHero       int       `json:"IsHero"`
		TargetIsHero int       `json:"TargetIsHero"`
		Position     []float64 `json:"Position"`
	} `json:"payload"`
}

type LearnAbilityEvent

type LearnAbilityEvent struct {
	Base
	Payload struct {
		Team    string `json:"Team"`
		Actor   string `json:"Actor"`
		Ability string `json:"Ability"`
		Level   int    `json:"Level"`
	} `json:"payload"`
}

type LevelUpEvent

type LevelUpEvent struct {
	Base
	Payload struct {
		Team         string `json:"Team"`
		Actor        string `json:"Actor"`
		Level        int    `json:"Level"`
		LifetimeGold int    `json:"LifetimeGold"`
	} `json:"payload"`
}

type MatchAsset

type MatchAsset struct {
	Attributes struct {
		URL         string    `json:"URL"`
		CreatedAt   time.Time `json:"createdAt"`
		Description string    `json:"description"`
		Name        string    `json:"name"`
	} `json:"attributes"`
	// contains filtered or unexported fields
}

type MatchAttributes

type MatchAttributes struct {
	CreatedAt    time.Time  `json:"createdAt"`
	Duration     int        `json:"duration"`
	GameMode     string     `json:"gameMode"`
	PatchVersion string     `json:"patchVersion"`
	ShardID      string     `json:"shardId"`
	Stats        MatchStats `json:"stats"`
	TitleID      string     `json:"titleId"`
}

type MatchData

type MatchData struct {
	Attributes    MatchAttributes    `json:"attributes"`
	Relationships MatchRelationships `json:"relationships"`
	Links         struct {
		Schema string `json:"schema"`
		Self   string `json:"self"`
	} `json:"links"`
	// contains filtered or unexported fields
}

type MatchDataRelationship

type MatchDataRelationship struct {
	Data struct {
		// contains filtered or unexported fields
	} `json:"data"`
}

type MatchDataRelationships

type MatchDataRelationships struct {
	Data []typeIDPair `json:"data"`
}

type MatchParticipant

type MatchParticipant struct {
	Attributes struct {
		Actor   string           `json:"actor"`
		ShardID string           `json:"shardId"`
		Stats   ParticipantStats `json:"stats"`
	} `json:"attributes"`
	Relationships struct {
		Player MatchDataRelationship `json:"player"`
	} `json:"relationships"`
	// contains filtered or unexported fields
}

type MatchPlayer

type MatchPlayer struct {
	Attributes struct {
		Name         string      `json:"name"`
		PatchVersion string      `json:"patchVersion"`
		ShardID      string      `json:"shardId"`
		Stats        PlayerStats `json:"stats"`
		TitleID      string      `json:"titleId"`
	} `json:"attributes"`
	Relationships struct {
		Assets MatchDataRelationships `json:"assets"`
	} `json:"relationships"`
	Links struct {
		Schema string `json:"schema"`
		Self   string `json:"self"`
	} `json:"links"`
	// contains filtered or unexported fields
}

type MatchRelationships

type MatchRelationships struct {
	Assets     MatchDataRelationships `json:"assets"`
	Rosters    MatchDataRelationships `json:"rosters"`
	Rounds     MatchDataRelationships `json:"rounds"`
	Spectators MatchDataRelationships `json:"spectators"`
}

type MatchResponse

type MatchResponse struct {
	Data         MatchData         `json:"data"`
	Included     []json.RawMessage `json:"included"`
	Participants []MatchParticipant
	Rosters      []MatchRoster
	Assets       []MatchAsset
	Players      []MatchPlayer
	Links        struct {
		Self string `json:"self"`
	} `json:"links"`
	Meta struct{} `json:"meta"`
}

func (*MatchResponse) GetMatchID

func (mr *MatchResponse) GetMatchID() (id string)

GetMatchID Pull match id from a given match response

func (*MatchResponse) GetStatsByName

func (mr *MatchResponse) GetStatsByName() (s map[string]*PlayerStats)

GetStatsByName is a helper function to retrieve player MatchStats from a MatchResponse. A map is more performant than a slice in larger data sets so it is recommended to use this map instead of iterating through the MatchResponse data looking for players

type MatchRoster

type MatchRoster struct {
	Attributes struct {
		ShardID string      `json:"shardId"`
		Stats   RosterStats `json:"stats"`
		Won     string      `json:"won"`
	} `json:"attributes"`
	Relationships struct {
		Participants MatchDataRelationships `json:"participants"`
	} `json:"relationships"`
	// contains filtered or unexported fields
}

type MatchStats

type MatchStats struct {
	EndGameReason string `json:"endGameReason"`
	Queue         string `json:"queue"`
}

type MatchesResponse

type MatchesResponse struct {
	Data         []MatchData       `json:"data"`
	Included     []json.RawMessage `json:"included"`
	Participants []MatchParticipant
	Rosters      []MatchRoster
	Assets       []MatchAsset
	Players      []MatchPlayer
	Links        struct {
		Schema string `json:"schema"`
		Self   string `json:"self"`
	} `json:"links"`
	Meta struct{} `json:"meta"`
}

type NPCkillNPCEvent

type NPCkillNPCEvent struct {
	Base
	Payload struct {
		Team         string    `json:"Team"`
		Actor        string    `json:"Actor"`
		Killed       string    `json:"Killed"`
		KilledTeam   string    `json:"KilledTeam"`
		Gold         string    `json:"Gold"`
		IsHero       int       `json:"IsHero"`
		TargetIsHero int       `json:"TargetIsHero"`
		Position     []float64 `json:"Position"`
	} `json:"payload"`
}

type ParticipantStats

type ParticipantStats struct {
	Assists              int            `json:"assists"`
	CrystalMineCaptures  int            `json:"crystalMineCaptures"`
	Deaths               int            `json:"deaths"`
	Farm                 int            `json:"farm"`
	FirstAfkTime         float64        `json:"firstAfkTime"`
	Gold                 float64        `json:"gold"`
	GoldMineCaptures     int            `json:"goldMineCaptures"`
	ItemGrants           map[string]int `json:"itemGrants"`
	ItemSells            map[string]int `json:"itemSells"`
	ItemUses             map[string]int `json:"itemUses"`
	Items                []string       `json:"items"`
	JungleKills          int            `json:"jungleKills"`
	KarmaLevel           int            `json:"karmaLevel"`
	Kills                int            `json:"kills"`
	KrakenCaptures       int            `json:"krakenCaptures"`
	Level                int            `json:"level"`
	MinionKills          int            `json:"minionKills"`
	NonJungleMinionKills int            `json:"nonJungleMinionKills"`
	SkillTier            int            `json:"skillTier"`
	SkinKey              string         `json:"skinKey"`
	TurretCaptures       int            `json:"turretCaptures"`
	WentAfk              bool           `json:"wentAfk"`
	Winner               bool           `json:"winner"`
}

type PlayerAttributes

type PlayerAttributes struct {
	Name         string      `json:"name"`
	PatchVersion string      `json:"patchVersion"`
	ShardID      string      `json:"shardId"`
	Stats        PlayerStats `json:"stats"`
	TitleID      string      `json:"titleID"`
}

type PlayerData

type PlayerData struct {
	Attributes PlayerAttributes `json:"attributes"`
	// contains filtered or unexported fields
}

type PlayerFirstSpawnEvent

type PlayerFirstSpawnEvent struct {
	Base
	Payload struct {
		Team  string `json:"Team"`
		Actor string `json:"Actor"`
	} `json:"payload"`
}

type PlayerResponse

type PlayerResponse struct {
	Data PlayerData `json:"data"`
}

type PlayerStats

type PlayerStats struct {
	EloEarnedSeason4 int `json:"elo_earned_season_4"`
	EloEarnedSeason5 int `json:"elo_earned_season_5"`
	EloEarnedSeason6 int `json:"elo_earned_season_6"`
	EloEarnedSeason7 int `json:"elo_earned_season_7"`
	EloEarnedSeason8 int `json:"elo_earned_season_8"`
	EloEarnedSeason9 int `json:"elo_earned_season_9"`
	GamesPlayed      struct {
		Aral        int `json:"aral"`
		Blitz       int `json:"blitz"`
		BlitzRounds int `json:"blitz_rounds"`
		Casual      int `json:"casual"`
		Casual5V5   int `json:"casual_5v5"`
		Ranked      int `json:"ranked"`
		Ranked5V5   int `json:"ranked_5v5"`
	} `json:"gamesPlayed"`
	GuildTag     string `json:"guildTag"`
	KarmaLevel   int    `json:"karmaLevel"`
	Level        int    `json:"level"`
	LifetimeGold int    `json:"lifetimeGold"`
	LossStreak   int    `json:"lossStreak"`
	Played       int    `json:"played"`
	PlayedAral   int    `json:"played_aral"`
	PlayedBlitz  int    `json:"played_blitz"`
	PlayedCasual int    `json:"played_casual"`
	PlayedRanked int    `json:"played_ranked"`
	RankPoints   struct {
		Blitz     float64 `json:"blitz"`
		Ranked    float64 `json:"ranked"`
		Ranked5V5 float64 `json:"ranked_5v5"`
	} `json:"rankPoints"`
	SkillTier int `json:"skillTier"`
	WinStreak int `json:"winStreak"`
	Wins      int `json:"wins"`
	Xp        int `json:"xp"`
}

type PlayersResponse

type PlayersResponse struct {
	Data  []PlayerData
	Links struct {
		Self string `json:"self"`
	} `json:"links"`
}

type RESTError

type RESTError struct {
	Request      *http.Request
	Response     *http.Response
	ResponseBody []byte
}

RESTError stores error information about a request with a bad response code. Message is not always present, there are cases where api calls can fail without returning a json message.

func (RESTError) Error

func (r RESTError) Error() string

type RosterStats

type RosterStats struct {
	AcesEarned       int    `json:"acesEarned"`
	Gold             int    `json:"gold"`
	HeroKills        int    `json:"heroKills"`
	KrakenCaptures   int    `json:"krakenCaptures"`
	Side             string `json:"side"`
	TurretKills      int    `json:"turretKills"`
	TurretsRemaining int    `json:"turretsRemaining"`
}

type SellItemEvent

type SellItemEvent struct {
	Base
	Payload struct {
		Team  string `json:"Team"`
		Actor string `json:"Actor"`
		Item  string `json:"Item"`
		Cost  int    `json:"Cost"`
	} `json:"payload"`
}

type StatusAttributes

type StatusAttributes struct {
	Released string `json:"releasedAt"`
	Version  string `json:"version"`
}

StatusAttributes contains all of the attributes returned in the StatusResponse

type StatusResponse

type StatusResponse struct {
	Data StatusResponseData `json:"data"`
}

StatusResponse is the response payload for the status end point

type StatusResponseData

type StatusResponseData struct {
	Attributes StatusAttributes `json:"attributes"`
	// contains filtered or unexported fields
}

StatusResponseData contains all of the data returned in the StatusResponse

type TelemetryEvent

type TelemetryEvent interface {
	GetType() string         // returns the event type.
	GetTimestamp() time.Time // returns the Timestamp of the event.
}

TelemetryEvent is an interface for TelemetryEvent's.

type TelemetryResponse

type TelemetryResponse struct {
	Events                  []TelemetryEvent
	HeroBanEvents           []*HeroBanEvent
	HeroSelectEvents        []*HeroSelectEvent
	HeroSkinSelectEvents    []*HeroSkinSelectEvent
	PlayerFirstSpawnEvents  []*PlayerFirstSpawnEvent
	LevelUpEvents           []*LevelUpEvent
	BuyItemEvents           []*BuyItemEvent
	LearnAbilityEvents      []*LearnAbilityEvent
	UseAbilityEvents        []*UseAbilityEvent
	UseItemAbilityEvents    []*UseItemAbilityEvent
	DealDamageEvents        []*DealDamageEvent
	HealTargetEvents        []*HealTargetEvent
	EarnXPEvents            []*EarnXPEvent
	KillActorEvents         []*KillActorEvent
	VampirismEvents         []*VampirismEvent
	GoldFromTowerKillEvents []*GoldFromTowerKillEvent
	SellItemEvents          []*SellItemEvent
	NPCkillNPCEvents        []*NPCkillNPCEvent
}

TelemetryResponse is the response payload for the telemetry end point

func ParseTelemetry

func ParseTelemetry(b []byte) (*TelemetryResponse, error)

ParseTelemetry reads the telemetry event type from the json and passes it to the unmarshaller

func ReadTelemetryFromFile

func ReadTelemetryFromFile(path string) (tr *TelemetryResponse, err error)

ReadTelemetryFromFile parses json telemetry data from a given file and returns a TelemetryResponse struct. It is more performant to cache telemetry data for future use.

func (*TelemetryResponse) ToFile

func (tr *TelemetryResponse) ToFile(path string) (err error)

ToFile will save a TelemetryResponse to the file at a specified location. These data are always static and so it makes sense to cache/save this somewhere locally to prevent from having to request the large file multiple times

type UseAbilityEvent

type UseAbilityEvent struct {
	Base
	Payload struct {
		Team           string    `json:"Team"`
		Actor          string    `json:"Actor"`
		Ability        string    `json:"Ability"`
		Position       []float64 `json:"Position"`
		TargetActor    string    `json:"TargetActor"`
		TargetPosition []float64 `json:"TargetPosition"`
	} `json:"payload"`
}

type UseItemAbilityEvent

type UseItemAbilityEvent struct {
	Base
	Payload struct {
		Team           string    `json:"Team"`
		Actor          string    `json:"Actor"`
		Ability        string    `json:"Ability"`
		Position       []float64 `json:"Position"`
		TargetActor    string    `json:"TargetActor"`
		TargetPosition []float64 `json:"TargetPosition"`
	} `json:"payload"`
}

type VampirismEvent

type VampirismEvent struct {
	Base
	Payload struct {
		Actor        string `json:"Actor"`
		Team         string `json:"Team"`
		TargetActor  string `json:"TargetActor"`
		TargetTeam   string `json:"TargetTeam"`
		Source       string `json:"Source"`
		Vamp         string `json:"Vamp"`
		IsHero       int    `json:"IsHero"`
		TargetIsHero int    `json:"TargetIsHero"`
	} `json:"payload"`
}

Jump to

Keyboard shortcuts

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