wot-api 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 46f3fadbec32ee6f93706530f8d5d6f482a7db7d
4
+ data.tar.gz: 6933ec75824d47eccd7d5e1d6cf0a7a61e15704d
5
+ SHA512:
6
+ metadata.gz: fd0416077c7f48d64cabad729c965260a9ce9ff2ae28ac4db348101fe787580a1aa5730ae8ecbc1ba11fbc2c860b5a9bc9cc856dbac980c900d0d7709a283de4
7
+ data.tar.gz: afeffb8f3b93d810f84a17224544569e1340cdaaceeeea7526c9884452394621dc5475674daae3636933e0b4124959fde0f1c5ef8e494799af6f06c485bf908e
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in wot-api.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Groza Sergiu
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,55 @@
1
+ wot-api
2
+ ========
3
+
4
+ A simple library that allows to interface with World of Tanks API v2.0!
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'wot-api'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install wot-api
19
+
20
+ ## Usage
21
+
22
+ ```ruby
23
+ require 'wot-api'
24
+
25
+ # create a new instance of api
26
+ api = Wot::Api.new("EU")
27
+
28
+ # search players by nickname
29
+ players = api.search("my-nickname")
30
+
31
+ # iterate found players and get detailed info
32
+ players.each do |player|
33
+ puts player.id
34
+
35
+ # get player's detailed information
36
+ info = player.info
37
+
38
+ # get player's tanks
39
+ tanks = player.tanks
40
+
41
+ # get player's statistics
42
+ statistics = player.statistics
43
+
44
+ # get player's achievements
45
+ achievements = player.achievements
46
+ end
47
+ ```
48
+
49
+ ## Contributing
50
+
51
+ 1. Fork it ( https://github.com/serioja90/wot-api/fork )
52
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
53
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
54
+ 4. Push to the branch (`git push origin my-new-feature`)
55
+ 5. Create a new Pull Request
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
@@ -0,0 +1,97 @@
1
+
2
+ require 'json'
3
+ require 'rest-client'
4
+ require 'active_support/core_ext/hash/indifferent_access'
5
+
6
+ module Wot
7
+ autoload :Player, 'wot-api/player'
8
+
9
+ class Api
10
+
11
+ def initialize(region, language = 'en')
12
+ cluster = Wot::cluster(region)
13
+ @app_id = cluster[:application_id]
14
+ @base_url = cluster[:base_url]
15
+ @language = language
16
+ end
17
+
18
+ def search(username, options = {})
19
+ return Wot::Player.search self, username, options
20
+ end
21
+
22
+ def find(account_ids, options = {})
23
+ return Wot::Player.find self, account_ids, options
24
+ end
25
+
26
+ def players_info(account_ids)
27
+ ids = (account_ids.class == Array ? account_ids : [account_ids])
28
+ return make_request "account/info/", {:account_id => ids.join(",")}
29
+ end
30
+
31
+ def player_tanks(account_id)
32
+ return make_request "account/tanks/", {:account_id => account_id}
33
+ end
34
+
35
+ def player_achievements(account_id)
36
+ return make_request "account/achievements/", {:account_id => account_id}
37
+ end
38
+
39
+ def player_stats(account_id,hours_ago)
40
+ return make_request "stats/accountbytime/", {:account_id => account_id, :hours_ago => hours_ago}
41
+ end
42
+
43
+ def player_raitings(account_id)
44
+ return make_request "account/raitings/", {:account_id => account_id}
45
+ end
46
+
47
+ def tanks_list()
48
+ return make_request "encyclopedia/tanks/", {}
49
+ end
50
+
51
+ def tank_info(tank_id)
52
+ return make_request "encyclopedia/tankinfo/", {:tank_id => tank_id}
53
+ end
54
+
55
+ def achievements_list()
56
+ unless @achievements
57
+ response = make_request "encyclopedia/achievements/", {}
58
+ @achievements = Wot::Parser.get_achievements_list(response[:data])
59
+ end
60
+ return @achievements
61
+ end
62
+
63
+ def engines_list()
64
+ raise NotImplementedError
65
+ end
66
+
67
+ def guns_list()
68
+ raise NotImplementedError
69
+ end
70
+
71
+ def radios_list()
72
+ raise NotImplementedError
73
+ end
74
+
75
+ def suspensions_list()
76
+ raise NotImplementedError
77
+ end
78
+
79
+ def turrets_list
80
+ raise NotImplementedError
81
+ end
82
+
83
+ def make_request(suffix,parameters)
84
+ params = {:params => parameters.dup}
85
+ params[:params][:application_id] = @app_id
86
+ params[:params][:language] = @language
87
+ response = JSON.parse(RestClient.get("#{@base_url}/2.0/#{suffix}", params))
88
+ response = response.nested_under_indifferent_access
89
+ raise Wot::Error.new(response[:error]) if response[:status].downcase == "error"
90
+ return response
91
+ end
92
+ end
93
+ end
94
+
95
+ require 'wot-api/clusters'
96
+ require 'wot-api/error'
97
+ require 'wot-api/version'
@@ -0,0 +1,33 @@
1
+
2
+ module Wot
3
+ CLUSTERS = {
4
+ "RU" => {
5
+ :base_url => "http://api.worldoftanks.ru",
6
+ :application_id => "171745d21f7f98fd8878771da1000a31"
7
+ },
8
+ "EU" => {
9
+ :base_url => "api.worldoftanks.eu",
10
+ :application_id => "d0a293dc77667c9328783d489c8cef73"
11
+ },
12
+ "NA" => {
13
+ :base_url => "http://api.worldoftanks.com",
14
+ :application_id => "16924c431c705523aae25b6f638c54dd"
15
+ },
16
+ "ASIA" => {
17
+ :base_url => "http://api.worldoftanks.asia",
18
+ :application_id => "39b4939f5f2460b3285bfa708e4b252c"
19
+ },
20
+ "KR" => {
21
+ :base_url => "http://api.worldoftanks.kr",
22
+ :application_id => "ffea0f1c3c5f770db09357d94fe6abfb"
23
+ }
24
+ }
25
+
26
+ module_function
27
+
28
+ def cluster(region)
29
+ cluster = Wot::CLUSTERS[region.to_s]
30
+ raise "Region '#{region}' not found!" if cluster.nil?
31
+ return cluster
32
+ end
33
+ end
@@ -0,0 +1,13 @@
1
+
2
+ module Wot
3
+ class Error < StandardError
4
+ attr_accessor :field, :message, :code, :value
5
+ def initialize(options)
6
+ super options[:message]
7
+ @field = options[:field]
8
+ @message = options[:message]
9
+ @code = options[:code]
10
+ @value = options[:value]
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,66 @@
1
+
2
+ module Wot
3
+ class Player
4
+ autoload :Info, 'wot-api/player/info'
5
+ autoload :Tank, 'wot-api/player/tank'
6
+ autoload :Achievement, 'wot-api/player/achievement'
7
+ autoload :Statistics, 'wot-api/player/statistics'
8
+ autoload :ExtendedStatistics, 'wot-api/player/extended_statistics'
9
+
10
+ attr_accessor :id, :account_id, :nickname, :api
11
+
12
+ def self.search(api, nickname, options = {})
13
+ parameters = {search: nickname}
14
+ parameters = parameters.merge options
15
+ response = api.make_request 'account/list/', parameters
16
+ return create_players_from_data response[:data], api
17
+ end
18
+
19
+ def self.find(api, account_ids, options = {})
20
+ parameters = {
21
+ account_id: (account_ids.class == Array ? account_ids : [account_ids]),
22
+ fields: 'account_id,nickname'
23
+ }
24
+ parameters = parameters.merge options
25
+ response = api.make_request 'account/info/', parameters
26
+ return create_players_from_data response[:data].values, api
27
+ end
28
+
29
+ def self.create_players_from_data(data,api)
30
+ players = []
31
+ data.each do |item|
32
+ players << Wot::Player.new(item, api)
33
+ end
34
+ return players
35
+ end
36
+
37
+ def initialize(options, api)
38
+ @api = api
39
+ @id = options[:account_id]
40
+ @account_id = @id
41
+ @nickname = options[:nickname]
42
+ end
43
+
44
+ def tanks
45
+ @tanks ||= Wot::Player::Tank.get_tanks(self,@api)
46
+ return @tanks
47
+ end
48
+
49
+ def achievements
50
+ @achievements ||= Wot::Player::Achievement.get_achievements(self,@api)
51
+ return @achievements
52
+ end
53
+
54
+ def info
55
+ @info ||= Wot::Player::Info.new(self, @api)
56
+ return @info
57
+ end
58
+
59
+ private
60
+
61
+ def method_missing(method_name, *args, &block)
62
+ info
63
+ return @info.send method_name
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,26 @@
1
+
2
+ module Wot
3
+ class Player
4
+ class Achievement
5
+
6
+ attr_accessor :name, :current, :max
7
+
8
+ def self.get_achievements(player,api)
9
+ achievements = []
10
+ response = api.player_achievements(player.id)
11
+ data = response[:data][player.id.to_s]
12
+ names = data[:achievements].keys + data[:max_series].keys
13
+ names.each do |name|
14
+ achievements << Wot::Player::Achievement.new(name,data[:achievements][name],data[:max_series][name])
15
+ end
16
+ return achievements
17
+ end
18
+
19
+ def initialize(name, current, max = nil)
20
+ @name = name
21
+ @current = current
22
+ @max = max
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,25 @@
1
+
2
+ module Wot
3
+ class Player
4
+ class ExtendedStatistics
5
+ attr_accessor :data
6
+
7
+ def initialize(data)
8
+ @data = data
9
+ @data.each do |key,_|
10
+ self.send key
11
+ end
12
+ end
13
+
14
+ private
15
+
16
+ def method_missing(method_name, *args, &block)
17
+ self.class.instance_eval do
18
+ define_method method_name do
19
+ return @data[method_name]
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,33 @@
1
+
2
+ module Wot
3
+ class Player
4
+ class Info
5
+ attr_accessor :player, :data, :api
6
+
7
+ def initialize(player, api)
8
+ @player = player
9
+ @api = api
10
+ response = api.players_info(player.id)
11
+ @data = response[:data][player.id.to_s]
12
+ @data.each do |key,_|
13
+ self.send key
14
+ end
15
+ end
16
+
17
+ def statistics
18
+ @statistics ||= Wot::Player::Statistics.new(@data[:statistics])
19
+ return @statistics
20
+ end
21
+
22
+ protected
23
+
24
+ def method_missing(method_name, *args, &block)
25
+ self.class.instance_eval do
26
+ define_method method_name do
27
+ return @data[method_name]
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,18 @@
1
+
2
+ module Wot
3
+ class Player
4
+ class Statistics
5
+ attr_accessor :data, :max_damage, :max_xp, :all, :clan, :company, :historical
6
+
7
+ def initialize(data)
8
+ @data = data
9
+ @max_damage = data[:max_damage]
10
+ @max_xp = data[:max_xp]
11
+ @all = Wot::Player::ExtendedStatistics.new(@data[:all])
12
+ @clan = Wot::Player::ExtendedStatistics.new(@data[:clan])
13
+ @company = Wot::Player::ExtendedStatistics.new(@data[:company])
14
+ @historical = Wot::Player::ExtendedStatistics.new(@data[:historical])
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,26 @@
1
+
2
+ module Wot
3
+ class Player
4
+ class Tank
5
+
6
+ attr_accessor :data, :id, :mark_of_mastery, :battles, :wins
7
+
8
+ def self.get_tanks(player,api)
9
+ tanks = []
10
+ response = api.player_tanks(player.id)
11
+ response[:data][player.id.to_s].each do |item|
12
+ tanks << Wot::Player::Tank.new(item)
13
+ end
14
+ return tanks
15
+ end
16
+
17
+ def initialize(data)
18
+ @data = data
19
+ @id = @data[:tank_id]
20
+ @mark_of_mastery = @data[:mark_of_mastery]
21
+ @battles = @data[:statistics][:battles]
22
+ @wins = @data[:statistics][:wins]
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,10 @@
1
+
2
+ module Wot
3
+ class Api
4
+ VERSION = "1.0.0"
5
+
6
+ def self.version
7
+ return VERSION
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ require "wot/api/version"
2
+
3
+ module Wot
4
+ module Api
5
+ # Your code goes here...
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module Wot
2
+ module Api
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'wot/api'
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Wot::Api do
4
+ it 'has a version number' do
5
+ expect(Wot::Api::VERSION).not_to be nil
6
+ end
7
+
8
+ it 'does something useful' do
9
+ expect(false).to eq(true)
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/ruby
2
+ # @Author: Groza Sergiu
3
+ # @Date: 2014-07-10 02:28:29
4
+ # @Last Modified by: Groza Sergiu
5
+ # @Last Modified time: 2014-07-10 02:50:43
6
+ require "minitest/autorun"
7
+
8
+ class WotApiTest < Minitest::Test
9
+ def test_initialize
10
+ end
11
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'wot-api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "wot-api"
8
+ spec.version = Wot::Api::VERSION
9
+ spec.authors = ["Groza Sergiu"]
10
+ spec.email = ["info@code-panic.com"]
11
+ spec.summary = %q{Ruby World of Tanks API v2.0}
12
+ spec.description = %q{A simple ruby library that allows to interface with World of Tanks API v2.0!}
13
+ spec.homepage = "http://wot.code-panic.com"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake", "~> 10.3"
23
+ spec.add_development_dependency "rspec", "~> 3.1"
24
+ spec.add_development_dependency "json","~> 1.8"
25
+ spec.add_development_dependency "rest-client","~> 1.7"
26
+ end
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wot-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Groza Sergiu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: json
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.8'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.8'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rest-client
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.7'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.7'
83
+ description: A simple ruby library that allows to interface with World of Tanks API
84
+ v2.0!
85
+ email:
86
+ - info@code-panic.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - lib/wot-api.rb
99
+ - lib/wot-api/clusters.rb
100
+ - lib/wot-api/error.rb
101
+ - lib/wot-api/player.rb
102
+ - lib/wot-api/player/achievement.rb
103
+ - lib/wot-api/player/extended_statistics.rb
104
+ - lib/wot-api/player/info.rb
105
+ - lib/wot-api/player/statistics.rb
106
+ - lib/wot-api/player/tank.rb
107
+ - lib/wot-api/version.rb
108
+ - lib/wot/api.rb
109
+ - lib/wot/api/version.rb
110
+ - spec/spec_helper.rb
111
+ - spec/wot/api_spec.rb
112
+ - test/wot_api_test.rb
113
+ - wot-api.gemspec
114
+ homepage: http://wot.code-panic.com
115
+ licenses:
116
+ - MIT
117
+ metadata: {}
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ requirements: []
133
+ rubyforge_project:
134
+ rubygems_version: 2.2.2
135
+ signing_key:
136
+ specification_version: 4
137
+ summary: Ruby World of Tanks API v2.0
138
+ test_files:
139
+ - spec/spec_helper.rb
140
+ - spec/wot/api_spec.rb
141
+ - test/wot_api_test.rb