Class: WotApi::Base
Constant Summary collapse
- ENDPOINTS =
[ '/wot/account/list/', '/wot/account/info/', '/wot/account/tanks/', '/wot/account/achievements/', '/wot/clan/list/', '/wot/clan/info/', '/wot/clan/top/', '/wot/clan/provinces/', '/wot/clan/membersinfo/', '/wot/globalwar/clans/', '/wot/globalwar/famepoints/', '/wot/globalwar/maps/', '/wot/globalwar/provinces/', '/wot/globalwar/top/', '/wot/globalwar/tournaments/', '/wot/globalwar/alleyoffame/', '/wot/globalwar/battles/', '/wot/globalwar/victorypointshistory/', '/wot/encyclopedia/tanks/', '/wot/encyclopedia/tankinfo/', '/wot/encyclopedia/tankengines/', '/wot/encyclopedia/tankturrets/', '/wot/encyclopedia/tankradios/', '/wot/encyclopedia/tankchassis/', '/wot/encyclopedia/tankguns/', '/wot/encyclopedia/achievements/', '/wot/encyclopedia/info/', '/wot/encyclopedia/arenas/', '/wot/ratings/types/', '/wot/ratings/dates/', '/wot/ratings/accounts/', '/wot/ratings/neighbors/', '/wot/ratings/top/', '/wot/clanratings/types/', '/wot/clanratings/dates/', '/wot/clanratings/clans/', '/wot/clanratings/neighbors/', '/wot/clanratings/top/', '/wot/tanks/stats/', '/wot/tanks/achievements/' ]
- 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' }
Class Attribute Summary collapse
-
.configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
.default_region ⇒ Object
readonly
Returns the value of attribute default_region.
Class Method Summary collapse
- .config(params = {}) ⇒ Object
- .merged_params(params) ⇒ Object
- .merged_post(endpoint, params = {}) ⇒ Object
- .pathname(path) ⇒ Object
Class Attribute Details
.configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
60 61 62 |
# File 'lib/wot_api/base.rb', line 60 def configuration @configuration end |
.default_region ⇒ Object (readonly)
Returns the value of attribute default_region.
61 62 63 |
# File 'lib/wot_api/base.rb', line 61 def default_region @default_region end |
Class Method Details
.config(params = {}) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/wot_api/base.rb', line 63 def config(params={}) @configuration = {} @default_region = nil params.each do |conf| region = conf[0].to_sym application_id = conf[1] if REGIONS[region] && application_id @default_region ||= region @configuration[region] = {base_uri: REGIONS[region], application_id: application_id.to_s} else raise WotApi::InvalidConfigError end end end |
.merged_params(params) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/wot_api/base.rb', line 82 def merged_params(params) raise WotApi::InvalidConfigError unless @configuration.class == Hash if region = params.delete(:region).to_sym rescue nil config = @configuration[region] else config = @configuration[@default_region] end base_uri = config[:base_uri] rescue nil application_id = config[:application_id] rescue nil raise WotApi::InvalidRegionError unless base_uri && application_id self.base_uri base_uri params.merge({application_id: application_id}) end |
.merged_post(endpoint, params = {}) ⇒ Object
96 97 98 |
# File 'lib/wot_api/base.rb', line 96 def merged_post(endpoint, params={}) WotApi::Base.post(endpoint, body: merged_params(params)) end |
.pathname(path) ⇒ Object
78 79 80 |
# File 'lib/wot_api/base.rb', line 78 def pathname(path) path.gsub(/(\/)+$/,'').gsub('/wot/','').gsub('/', '_') end |