Class: WotApi::Wrapper

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/wot_api/wrapper.rb

Constant Summary collapse

REGIONS =
{
  na: 'https://api.worldoftanks.com',
  ru: 'https://api.worldoftanks.ru',
  eu: 'https://api.worldoftanks.eu',
  asia: 'https://api.worldoftanks.asia',
  kr: 'https://api.worldoftanks.kr'
}
REGIONS_WEB =
{
  na: 'http://na.wargaming.net',
  ru: 'http://ru.wargaming.net',
  eu: 'http://eu.wargaming.net',
  asia: 'http://asia.wargaming.net',
  kr: 'http://kr.wargaming.net',
}

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject

Returns the value of attribute configuration.



26
27
28
# File 'lib/wot_api/wrapper.rb', line 26

def configuration
  @configuration
end

.default_regionObject

Returns the value of attribute default_region.



26
27
28
# File 'lib/wot_api/wrapper.rb', line 26

def default_region
  @default_region
end

Class Method Details

.valid_endpoint?(method_sym) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/wot_api/wrapper.rb', line 50

def valid_endpoint?(method_sym)
  !(method_sym.to_s =~ /^([^_]*)_([^_]*)$/).nil?
end

.wot_api_post(method_sym, params) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/wot_api/wrapper.rb', line 28

def wot_api_post(method_sym, params)
  endpoint = method_to_endpoint(method_sym)
  region = params.delete(:region).to_sym rescue get_default_region
  set_base_uri(region)
  begin
    response = merged_post(endpoint, region, params)
  rescue
    raise WotApi::ConnectionError, "Could not connect to WoT endpoint #{endpoint.to_s}"
  end
  return format_response(response)
end

.wot_web_get(endpoint, params = {}) ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'lib/wot_api/wrapper.rb', line 40

def wot_web_get(endpoint, params={})
  region = params.delete(:region).to_sym rescue get_default_region
  set_base_uri(region, true)
  begin
    return self.get(endpoint, params).parsed_response
  rescue Exception => e
    raise WotApi::ConnectionError, "ERROR with WoT web endpoint #{endpoint.to_s}"
  end
end