Class: Rito::Base Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/rito/base.rb

Overview

This class is abstract.

Base class for all Rito api classes.

Direct Known Subclasses

MatchHistoryOld, StatsOld

Class Method Summary collapse

Class Method Details

.all_regionsArray

Provides all region codes.

Returns:

  • (Array)

    list of all region codes


41
42
43
# File 'lib/rito/base.rb', line 41

def all_regions
	['br', 'eune', 'euw', 'kr', 'lan', 'las', 'na', 'oce', 'ru', 'tr']
end

.base_url(region:) ⇒ String

Generates the api endpoint based on the given region.

Parameters:

  • region (String)

    the region code

Returns:

  • (String)

    the endpoint base url


18
19
20
# File 'lib/rito/base.rb', line 18

def base_url(region:)
	"https://#{region}.api.pvp.net"
end

.default_queryHash

Provides the api key for every query.

Returns:

  • (Hash)

    api key from ENV


10
11
12
# File 'lib/rito/base.rb', line 10

def default_query
	{'api_key' => ENV['RIOT_API_KEY']}
end

.default_regionString

Provides the region set in ENV. If none is set then returns 'na'.

Returns:

  • (String)

    the region code


34
35
36
# File 'lib/rito/base.rb', line 34

def default_region
	ENV["REGION"] || 'na'
end

.latest_versionObject


45
46
47
# File 'lib/rito/base.rb', line 45

def latest_version
	versions.last
end

.parameterize(query:) ⇒ String

Converts a query hash into a url parameter string.

Parameters:

  • query (Hash)

    the parameters and their values

Returns:

  • (String)

    the url parameters


26
27
28
# File 'lib/rito/base.rb', line 26

def parameterize(query:)
	"?" + query.map{|e| e.join('=')}.join('&')
end