Class: Wot::Api

Inherits:
Object
  • Object
show all
Defined in:
lib/wot/api.rb,
lib/wot/api/error.rb,
lib/wot/api/version.rb,
lib/wot/api/clusters.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

VERSION =
"1.1.0"
CLUSTERS =
{
  "RU" => {
    :base_url => "http://api.worldoftanks.ru",
    :application_id => "171745d21f7f98fd8878771da1000a31"
  },
  "EU" => {
    :base_url => "api.worldoftanks.eu",
    :application_id => "d0a293dc77667c9328783d489c8cef73"
  },
  "NA" => {
    :base_url => "http://api.worldoftanks.com",
    :application_id => "16924c431c705523aae25b6f638c54dd"
  },
  "ASIA" => {
    :base_url => "http://api.worldoftanks.asia",
    :application_id => "39b4939f5f2460b3285bfa708e4b252c"
  },
  "KR" => {
    :base_url => "http://api.worldoftanks.kr",
    :application_id => "ffea0f1c3c5f770db09357d94fe6abfb"
  }
}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(region, language = 'en') ⇒ Api

Returns a new instance of Api.



12
13
14
15
16
17
# File 'lib/wot/api.rb', line 12

def initialize(region, language = 'en')
  cluster = Wot::Api.cluster(region)
  @app_id = cluster[:application_id]
  @base_url = cluster[:base_url]
  @language = language
end

Class Method Details

.cluster(region) ⇒ Object



26
27
28
29
30
# File 'lib/wot/api/clusters.rb', line 26

def self.cluster(region)
  cluster = CLUSTERS[region.to_s]
  fail "Region '#{region}' not found!" if cluster.nil?
  return cluster
end

.versionObject



5
6
7
# File 'lib/wot/api/version.rb', line 5

def self.version
  return VERSION
end

Instance Method Details

#achievements_listObject

Raises:

  • (NotImplementedError)


56
57
58
# File 'lib/wot/api.rb', line 56

def achievements_list()
  raise NotImplementedError
end

#engines_listObject

Raises:

  • (NotImplementedError)


60
61
62
# File 'lib/wot/api.rb', line 60

def engines_list()
  raise NotImplementedError
end

#find(account_ids, options = {}) ⇒ Object



23
24
25
# File 'lib/wot/api.rb', line 23

def find(, options = {})
  return Wot::Player.find self, , options
end

#guns_listObject

Raises:

  • (NotImplementedError)


64
65
66
# File 'lib/wot/api.rb', line 64

def guns_list()
  raise NotImplementedError
end

#make_request(suffix, parameters) ⇒ Object

Raises:



80
81
82
83
84
85
86
87
88
# File 'lib/wot/api.rb', line 80

def make_request(suffix,parameters)
  params = {:params => parameters.dup}
  params[:params][:application_id] = @app_id
  params[:params][:language] = @language
  response = JSON.parse(RestClient.get("#{@base_url}/2.0/#{suffix}", params))
  response = response.nested_under_indifferent_access
  raise Wot::Api::Error.new(response[:error]) if response[:status].downcase == "error"
  return response
end

#player_achievements(account_id) ⇒ Object



36
37
38
# File 'lib/wot/api.rb', line 36

def player_achievements()
  return make_request "account/achievements/", {:account_id => }
end

#player_raitings(account_id) ⇒ Object



44
45
46
# File 'lib/wot/api.rb', line 44

def player_raitings()
  return make_request "account/raitings/", {:account_id => }
end

#player_stats(account_id, hours_ago) ⇒ Object



40
41
42
# File 'lib/wot/api.rb', line 40

def player_stats(,hours_ago)
  return make_request "stats/accountbytime/", {:account_id => , :hours_ago => hours_ago}
end

#player_tanks(account_id) ⇒ Object



32
33
34
# File 'lib/wot/api.rb', line 32

def player_tanks()
  return make_request "account/tanks/", {:account_id => }
end

#players_info(account_ids) ⇒ Object



27
28
29
30
# File 'lib/wot/api.rb', line 27

def players_info()
  ids = (.class == Array ?  : [])
  return make_request "account/info/", {:account_id => ids.join(",")}
end

#radios_listObject

Raises:

  • (NotImplementedError)


68
69
70
# File 'lib/wot/api.rb', line 68

def radios_list()
  raise NotImplementedError
end

#search(username, options = {}) ⇒ Object



19
20
21
# File 'lib/wot/api.rb', line 19

def search(username, options = {})
  return Wot::Player.search self, username, options
end

#suspensions_listObject

Raises:

  • (NotImplementedError)


72
73
74
# File 'lib/wot/api.rb', line 72

def suspensions_list()
  raise NotImplementedError
end

#tank_info(tank_id) ⇒ Object



52
53
54
# File 'lib/wot/api.rb', line 52

def tank_info(tank_id)
  return make_request "encyclopedia/tankinfo/", {:tank_id => tank_id}
end

#tanks_listObject



48
49
50
# File 'lib/wot/api.rb', line 48

def tanks_list()
  return make_request "encyclopedia/tanks/", {}
end

#turrets_listObject

Raises:

  • (NotImplementedError)


76
77
78
# File 'lib/wot/api.rb', line 76

def turrets_list
  raise NotImplementedError
end