Class: VaingloryAPI::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/vainglory_api/client.rb

Overview

Used to interface with the official Vainglory API

Constant Summary

BASE_URL =

The base URL used for most requests

'https://api.dc01.gamelockerapp.com'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(api_key, region_identifier = 'na') ⇒ Client

Note:

Requires a valid region short name.

A new instance of Client.

Examples:

Initialize a new client

client = VaingloryAPI::Client.new('API_KEY', 'na')

Parameters:

  • api_key (String)

    your Vainglory API key

  • region_identifier (String) (defaults to: 'na')

    the name or short name for your specified Region shard

See Also:



26
27
28
29
# File 'lib/vainglory_api/client.rb', line 26

def initialize(api_key, region_identifier = 'na')
  @api_key = api_key
  @region = Region.find(region_identifier)
end

Instance Method Details

Checks to see if a link object exists for a given code

Raises:

  • (NotImplementedError)

    this endpoint is not yet available

See Also:



158
159
160
# File 'lib/vainglory_api/client.rb', line 158

def link(_link_id)
  raise(NotImplementedError, 'Coming soon!')
end

#match(match_id) ⇒ OpenStruct

Gets data for a single match

Examples:

Get a single match

client = VaingloryAPI::Client.new('API_KEY', 'na')
client.match('MATCH_ID')

Parameters:

  • match_id (String)

    the ID of the requested match

Returns:

  • (OpenStruct)

    the response and metadata

See Also:



88
89
90
# File 'lib/vainglory_api/client.rb', line 88

def match(match_id)
  get_request(shard_endpoint_uri("matches/#{match_id}"))
end

#matches(filter_params = {}) ⇒ OpenStruct

Gets data from matches (multiple)

Examples:

Get matches

client = VaingloryAPI::Client.new('API_KEY', 'na')
client.matches

Get matches with a filter

client = VaingloryAPI::Client.new('API_KEY', 'na')
client.matches('filter[playerNames]' => 'player_name')

Parameters:

  • filter_params (Hash) (defaults to: {})

    the parameters used to filter results

Options Hash (filter_params):

  • 'page[offset]' (String) — default: 0

    Allows paging over results

  • 'page[limit]' (String) — default: 50

    Values less than 50 and great than 2 are supported.

  • 'sort' (String) — default: createdAt

    By default, Matches are sorted by creation time ascending.

  • 'filter[createdAt-start]' (String) — default: 3hrs ago

    Must occur before end time. Format is iso8601

  • 'filter[createdAt-end]' (String) — default: Now

    Queries search the last 3 hrs. Format is iso8601

  • 'filter[playerNames]' (String)

    Filters by player name, separated by commas.

  • 'filter[playerIds]' (String)

    Filters by player Id, separated by commas.

  • 'filter[teamNames]' (String)

    Filters by team names. Team names are the same as the in game team tags.

  • 'filter[gameMode]' (String)

    Filters by Game Mode

Returns:

  • (OpenStruct)

    the response and metadata

See Also:



74
75
76
# File 'lib/vainglory_api/client.rb', line 74

def matches(filter_params = {})
  get_request(shard_endpoint_uri('matches', filter_params))
end

#player(player_id) ⇒ OpenStruct

Gets data for a single player

Examples:

Get a single player

client = VaingloryAPI::Client.new('API_KEY', 'na')
client.match('PLAYER_ID')

Parameters:

  • player_id (String)

    the ID of the requested player

Returns:

  • (OpenStruct)

    the response and metadata

See Also:



119
120
121
# File 'lib/vainglory_api/client.rb', line 119

def player(player_id)
  get_request(shard_endpoint_uri("players/#{player_id}"))
end

#players(player_name, *additional_player_names) ⇒ OpenStruct

Gets data about players (one or more)

Examples:

Search for a player

client = VaingloryAPI::Client.new('API_KEY', 'na')
client.players('player_name')

Search for multiple players

client = VaingloryAPI::Client.new('API_KEY', 'na')
client.players('player_name', 'player_name2')

Parameters:

  • player_name (String)

    the in-game name (IGN) of a player

  • additional_player_names (String)

    additional IGNs for search for

Returns:

  • (OpenStruct)

    the response and metadata

See Also:



104
105
106
107
108
109
# File 'lib/vainglory_api/client.rb', line 104

def players(player_name, *additional_player_names)
  player_names  = [player_name].concat(additional_player_names)
  filter_params = { 'filter[playerNames]' => player_names.join(',') }

  get_request(shard_endpoint_uri('players', filter_params))
end

#samples(filter_params = {}) ⇒ OpenStruct

Gets batches of random match data

Examples:

Get samples

client = VaingloryAPI::Client.new('API_KEY', 'na')
client.samples

Parameters:

  • filter_params (Hash) (defaults to: {})

    the parameters used to filter results

Options Hash (filter_params):

  • 'page[offset]' (String) — default: 0

    Allows paging over results

  • 'page[limit]' (String) — default: 50

    Values less than 50 and great than 2 are supported.

  • 'sort' (String) — default: createdAt

    By default, Matches are sorted by creation time ascending.

  • 'filter[createdAt-start]' (String) — default: 3hrs ago

    Must occur before end time. Format is iso8601

  • 'filter[createdAt-end]' (String) — default: Now

    Queries search the last 3 hrs. Format is iso8601

Returns:

  • (OpenStruct)

    the response and metadata

See Also:



46
47
48
# File 'lib/vainglory_api/client.rb', line 46

def samples(filter_params = {})
  get_request(shard_endpoint_uri('samples', filter_params))
end

#statusOpenStruct

Gets current API version and release date

Examples:

Get the API's status information

client = VaingloryAPI::Client.new('API_KEY', 'na')
client.status

Returns:

  • (OpenStruct)

    the response and metadata

See Also:



169
170
171
# File 'lib/vainglory_api/client.rb', line 169

def status
  get_request_without_headers(endpoint_uri('status'))
end

#team(_team_id) ⇒ Object

Gets aggregated lifetime information about a single team

Raises:

  • (NotImplementedError)

    this endpoint is not yet available

See Also:



150
151
152
# File 'lib/vainglory_api/client.rb', line 150

def team(_team_id)
  raise(NotImplementedError, 'Coming soon!')
end

#teams(_filter_params = {}) ⇒ Object

Gets aggregated lifetime information about teams (multiple)

Parameters:

  • _filter_params (Hash) (defaults to: {})

    the parameters used to filter results

Options Hash (_filter_params):

  • 'filter[teamNames]' (String)

    Filters by team name

  • 'filter[teamIds]' (String)

    Filters by team ID

Raises:

  • (NotImplementedError)

    this endpoint is not yet available

See Also:



142
143
144
# File 'lib/vainglory_api/client.rb', line 142

def teams(_filter_params = {})
  raise(NotImplementedError, 'Coming soon!')
end

#telemetry(url) ⇒ OpenStruct

Gets telemtry data from a specified URL

Examples:

Get telemetry data

client = VaingloryAPI::Client.new('API_KEY', 'na')
client.telemetry('TELEMETRY_URL')

Parameters:

  • url (String)

    the URL of the requested Telemetry data

Returns:

  • (OpenStruct)

    the response and metadata

See Also:



131
132
133
# File 'lib/vainglory_api/client.rb', line 131

def telemetry(url)
  get_request(URI(url), true, false)
end