wot_xbox_api 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c316d361a2ecd2642c46231d0a28b0890d4c21ef
4
+ data.tar.gz: 62602a7ac4f578866c81fb50d37fb74aa0840025
5
+ SHA512:
6
+ metadata.gz: 54399a1c58d0a63c31c4056535a7b12a5c218f3c438202cdfdb7afc40f4b2c8f80c5b95d691827bc66c55c09d753c953ff390c1507e3ba5bb66e90f6c756a18f
7
+ data.tar.gz: e1d7fccb26c838c893534d552906fe137133fd69bbbc19dc35545348f6c9bbcd5cf03e52093870da096384e3868c84c0e190212bbfeb8996fd8012cd0c302e71
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in wot_xbox_api.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # WotXboxApi
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/wot_xbox_api`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'wot_xbox_api'
13
+ ```
14
+
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install wot_xbox_api
23
+
24
+ ## Usage
25
+
26
+ ```ruby
27
+ require 'wot_xbox_api'
28
+ client = WotXboxApi::Client
29
+ leaderboard = client.leaderboard
30
+ player_hashes = leaderboard.player_hashes
31
+ stats = client.player_stats(6060264)
32
+ ```
33
+
34
+ ## Development
35
+
36
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
37
+
38
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
39
+
40
+ ## Contributing
41
+
42
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/wot_xbox_api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
43
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "wot_xbox_api"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,4 @@
1
+ module WotXboxApi
2
+ class CallFailedException < StandardError
3
+ end
4
+ end
@@ -0,0 +1,34 @@
1
+ module WotXboxApi
2
+ class Client
3
+ include HTTParty
4
+ base_uri 'console.worldoftanks.com'
5
+
6
+ def initialize()
7
+
8
+ end
9
+
10
+ #TODO: generalize later
11
+ # def call(url_string, options)
12
+ # self.class.get(url_string, options).body
13
+ # end
14
+
15
+ def self.leaderboard(options={:query => {page: 1}})
16
+ WotXboxApi::Leaderboard.new(JSON.parse(get("/leaderboard/get_ratings", options).body))
17
+ end
18
+
19
+ def self.player_stats(player_id)
20
+ WotXboxApi::PlayerStats.new(player_id, Nokogiri::HTML(get("/stats/players/#{player_id}").body))
21
+ end
22
+
23
+ def self.player_tank_stats(player_id, wot_vehicle_id)
24
+ WotXboxApi::PlayerTankStats.new(wot_vehicle_id, Nokogiri::HTML(
25
+ get("/stats/players/#{player_id}/vehicle_details.html?vehicle_cd=#{wot_vehicle_id}").body
26
+ ))
27
+ end
28
+
29
+ def player_search
30
+ #todo
31
+ end
32
+
33
+ end
34
+ end
@@ -0,0 +1,26 @@
1
+ module WotXboxApi
2
+ class Leaderboard
3
+
4
+ attr_accessor :keys, :values, :player_hashes
5
+
6
+ KNOWN_KEYS=["account_id", "battles_count", "battles_count_daily",
7
+ "battles_count_rank", "battles_count_rank_delta", "damage_avg",
8
+ "damage_dealt", "damage_dealt_rank", "damage_dealt_rank_delta",
9
+ "frags_avg", "frags_count", "frags_count_rank", "frags_count_rank_delta",
10
+ "global_rating", "global_rating_rank", "global_rating_rank_delta",
11
+ "hits_ratio", "hits_ratio_rank", "hits_ratio_rank_delta", "name",
12
+ "survived_ratio", "survived_ratio_rank", "survived_ratio_rank_delta",
13
+ "wins_count", "wins_ratio", "wins_ratio_rank", "wins_ratio_rank_delta",
14
+ "xp_amount", "xp_avg", "xp_avg_rank", "xp_avg_rank_delta", "xp_max",
15
+ "xp_max_rank", "xp_max_rank_delta"]
16
+
17
+ def initialize(data)
18
+ @keys = data['data_rating']['result']['keys']
19
+ raise StandardError.new("Expected keys do not match returned keys!") if @keys != KNOWN_KEYS
20
+ @player_hashes = data['data_rating']['result']['values'].collect do |value|
21
+ Hash[KNOWN_KEYS.zip(value)]
22
+ end
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,91 @@
1
+ module WotXboxApi
2
+ class PlayerStats
3
+
4
+ attr_accessor :wot_vehicle_ids, :battle_counts, :win_percentages, :badge_numbers,
5
+ :player_id, :player_tank_stats, :name
6
+
7
+ def initialize(player_id, document)
8
+ self.player_id = player_id
9
+ validate(document)
10
+ load_name(document)
11
+ load_wot_vehicle_ids(document)
12
+ load_vehicle_battle_counts(document)
13
+ load_vehicle_win_percentages(document)
14
+ load_vehicle_badge_numbers(document)
15
+ add_unknown_vehicles(document) #not necessary where the mapping is known & persisted
16
+ load_player_tank_stats(document)
17
+ end
18
+
19
+ def validate(document)
20
+ #Signs this isn't meant as an API: Wargaming does not return a 404
21
+ if document.xpath("//h3[contains(., 'This profile is unavailable')]").any?
22
+ raise CallFailedException.new("This user's page is marked as unavailable")
23
+ end
24
+ end
25
+
26
+ def load_name(document)
27
+ self.name = document.xpath("//span[@class='heading-main_inner-center']").first.children.last.text.strip
28
+ end
29
+
30
+ #TODO loading code is very copy pasta, needs to be DRY'd out
31
+ def load_wot_vehicle_ids(document)
32
+ self.wot_vehicle_ids = document.xpath('//tr/@data-vehicle-cd').collect do |attribute|
33
+ attribute.value
34
+ end
35
+ end
36
+
37
+ def load_vehicle_battle_counts(document)
38
+ self.battle_counts = document.xpath('//td/@data-battle-count').collect do |attribute|
39
+ attribute.value
40
+ end
41
+ end
42
+
43
+ def load_vehicle_win_percentages(document)
44
+ self.win_percentages = document.xpath('//td/@data-win-percent').collect do |attribute|
45
+ attribute.value
46
+ end
47
+ end
48
+
49
+ def load_vehicle_badge_numbers(document)
50
+ self.badge_numbers = document.xpath('//td/@data-badge-number').collect do |attribute|
51
+ attribute.value
52
+ end
53
+ end
54
+
55
+ def load_player_tank_stats(document)
56
+ self.player_tank_stats = wot_vehicle_ids.each_with_index.collect do |wot_vehicle_id, i|
57
+ Thread.future WotXboxApi.pool do
58
+ player_tank_stat = WotXboxApi::Client.player_tank_stats(player_id, wot_vehicle_id)
59
+ #matching on index like this is fragile, but reduces the number
60
+ #of document searches since we can extract the values with xpath
61
+ player_tank_stat.battle_count = self.battle_counts[i]
62
+ player_tank_stat.win_percentage = self.win_percentages[i]
63
+ player_tank_stat.badge_number = self.badge_numbers[i]
64
+ player_tank_stat
65
+ end
66
+ end.map(&:value)
67
+ end
68
+
69
+ def add_unknown_vehicles(document)
70
+ wot_vehicle_ids.each_with_index do |wot_vehicle_id, i|
71
+ unless Vehicle.known?(wot_vehicle_id) #once hot this is trivial
72
+ vehicle_element = document.xpath("(//tr[@data-vehicle-cd]/td[2])[#{i+1}]").first
73
+ tier = vehicle_element.xpath('@data-veh-level').first.value
74
+ #janky
75
+ linky=vehicle_element.xpath('a/@href').first.value
76
+ country = linky.match(/vehicles\/(.*?)\//)[1]
77
+ name = vehicle_element.text.strip
78
+ #superjanky
79
+ type = vehicle_element.xpath("../..").xpath("preceding-sibling::*[1]").first.text.gsub(/[^a-zA-Z]/,'')
80
+ vehicle_hash = {
81
+ :tier => tier,
82
+ :country => country,
83
+ :name => name,
84
+ :type => type
85
+ }
86
+ Vehicle.add_vehicle(wot_vehicle_id, vehicle_hash)
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,28 @@
1
+ module WotXboxApi
2
+ class PlayerTankStats
3
+
4
+ attr_accessor :vehicle, :achievements, :statistics, :battle_count,
5
+ :win_percentage, :badge_number
6
+
7
+ def initialize(wot_vehicle_id, document)
8
+ self.vehicle = Vehicle.get(wot_vehicle_id)
9
+ load_achievements(document)
10
+ load_statistics(document)
11
+ end
12
+
13
+ def load_achievements(document)
14
+ self.achievements = {}
15
+ document.xpath("//div[@class='achievement ']").each do |el|
16
+ achievements[el.xpath("img").first["alt"]]= el['data-count']
17
+ end
18
+ end
19
+
20
+ def load_statistics(document)
21
+ self.statistics = {}
22
+ document.xpath("//span[@data-vehicle-brief-key]").each do |el|
23
+ statistics[el['data-vehicle-brief-key']]=el.text
24
+ end
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,19 @@
1
+ module WotXboxApi
2
+ class Vehicle
3
+
4
+ MAPPING = {}
5
+
6
+ def self.known?(wot_vehicle_id)
7
+ !MAPPING[wot_vehicle_id].nil?
8
+ end
9
+
10
+ def self.add_vehicle(wot_vehicle_id, hash)
11
+ MAPPING[wot_vehicle_id] = hash
12
+ end
13
+
14
+ def self.get(wot_vehicle_id)
15
+ MAPPING[wot_vehicle_id]
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module WotXboxApi
2
+ VERSION = "0.1.1"
3
+ end
@@ -0,0 +1,19 @@
1
+ require 'httparty'
2
+ require 'nokogiri'
3
+ require 'thread/pool'
4
+ require 'thread/future'
5
+ require "wot_xbox_api/version"
6
+ require "wot_xbox_api/client"
7
+ require "wot_xbox_api/call_failed_exception"
8
+ require 'wot_xbox_api/leaderboard'
9
+ require 'wot_xbox_api/player_stats'
10
+ require 'wot_xbox_api/player_tank_stats'
11
+ require 'wot_xbox_api/vehicle'
12
+
13
+
14
+ module WotXboxApi
15
+
16
+ def self.pool
17
+ @pool ||= Thread.pool(ENV['WOT_API_POOL_SIZE']||25)
18
+ end
19
+ end
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'wot_xbox_api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "wot_xbox_api"
8
+ spec.version = WotXboxApi::VERSION
9
+ spec.authors = ["Jon Calvert"]
10
+ spec.email = ["jonathan.calvert@kitcheck.com"]
11
+
12
+ spec.summary = %q{Gem for retrieving data about World of Tanks on XBOX}
13
+ spec.description = %q{Gem for retrieving data about World of Tanks on XBOX}
14
+ spec.homepage = "http://github.com/jcalvert/wot_xbox_api"
15
+
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "httparty"
23
+ spec.add_dependency "nokogiri"
24
+ spec.add_dependency "json"
25
+ spec.add_dependency "activesupport"
26
+ spec.add_dependency "thread"
27
+ spec.add_development_dependency "bundler", "~> 1.10"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "minitest"
30
+ spec.add_development_dependency 'pry'
31
+ end
metadata ADDED
@@ -0,0 +1,187 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wot_xbox_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Jon Calvert
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-11-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: thread
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.10'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.10'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '10.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '10.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: minitest
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: pry
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: Gem for retrieving data about World of Tanks on XBOX
140
+ email:
141
+ - jonathan.calvert@kitcheck.com
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".gitignore"
147
+ - ".travis.yml"
148
+ - CODE_OF_CONDUCT.md
149
+ - Gemfile
150
+ - README.md
151
+ - Rakefile
152
+ - bin/console
153
+ - bin/setup
154
+ - lib/wot_xbox_api.rb
155
+ - lib/wot_xbox_api/call_failed_exception.rb
156
+ - lib/wot_xbox_api/client.rb
157
+ - lib/wot_xbox_api/leaderboard.rb
158
+ - lib/wot_xbox_api/player_stats.rb
159
+ - lib/wot_xbox_api/player_tank_stats.rb
160
+ - lib/wot_xbox_api/vehicle.rb
161
+ - lib/wot_xbox_api/version.rb
162
+ - wot_xbox_api.gemspec
163
+ homepage: http://github.com/jcalvert/wot_xbox_api
164
+ licenses: []
165
+ metadata: {}
166
+ post_install_message:
167
+ rdoc_options: []
168
+ require_paths:
169
+ - lib
170
+ required_ruby_version: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - ">="
173
+ - !ruby/object:Gem::Version
174
+ version: '0'
175
+ required_rubygems_version: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - ">="
178
+ - !ruby/object:Gem::Version
179
+ version: '0'
180
+ requirements: []
181
+ rubyforge_project:
182
+ rubygems_version: 2.4.5
183
+ signing_key:
184
+ specification_version: 4
185
+ summary: Gem for retrieving data about World of Tanks on XBOX
186
+ test_files: []
187
+ has_rdoc: