open_dota_api 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 41e0de50f5999f18334dd3bc4feb1504de64fb93123e104d738601b6128254c8
4
- data.tar.gz: f5cc9056ef69f00d95ad1f534d1e3d870be1e51fa6f6195eaea5a3e4db8a5644
3
+ metadata.gz: 77eb8d8ed7ee19d5fe47307f6aeab5a2ec4efe7c080ebde0236be76d9514d632
4
+ data.tar.gz: 483158128fc2a61c8e6adc0e270edbccbd4071c3fbaa2eaf65cf24cd1104b5b0
5
5
  SHA512:
6
- metadata.gz: 0fae16428f8cf5aef6be3f2f85248ddc055e873d3c8b0dd9ca60b63421313a41f775ec78b3661ee83835cf551e5cb5af6f157d872e430be1f6dbd415582a3c49
7
- data.tar.gz: bd954371cd4a6ad867be36f184830efe93816088b6fb46984c1d749f39fc12b327d2b311a7b4c54b5b10685589bab4af4c6fec24a51f96ca58c9ba3301120531
6
+ metadata.gz: 292ac0e05f9878954050d2305c3610017554f6b2e4f1a782e3a88bbbad4613d9bcd8a432420701a0743e54d2c8cb42fccb639ed68befbb5de4f7931978fac981
7
+ data.tar.gz: 42d9c3239d9dd40d85f6527377330babf4df4f07d2f20f07d67e62523d5e52989e34db159182e9d3239d41cc2ce855807b31f8d28cba7511f2fcbe86e1489b7b
@@ -3,7 +3,7 @@ require 'open_dota_api/version'
3
3
 
4
4
  module OpenDotaApi
5
5
  extend SingleForwardable
6
- def_delegators :client, :limits, :leagues, :teams, :matches, :heroes, :pro_players, :explorer
6
+ def_delegators :client, :limits, :leagues, :teams, :matches, :heroes, :pro_players, :players, :explorer
7
7
 
8
8
  def self.client
9
9
  @client ||= Client.new
@@ -5,6 +5,7 @@ require 'open_dota_api/team'
5
5
  require 'open_dota_api/match'
6
6
  require 'open_dota_api/hero'
7
7
  require 'open_dota_api/pro_player'
8
+ require 'open_dota_api/player'
8
9
  require 'open_dota_api/explorer'
9
10
 
10
11
  module OpenDotaApi
@@ -43,6 +44,11 @@ module OpenDotaApi
43
44
  ProPlayer.instantiate(data)
44
45
  end
45
46
 
47
+ def players(account_id = nil, attributes = {})
48
+ data = request(Player::ENDPOINT, account_id, params: attributes)
49
+ Player.new(data)
50
+ end
51
+
46
52
  def explorer(league_id = nil, attributes = {})
47
53
  data = request(Explorer::ENDPOINT, params: Explorer.query_params(league_id).merge(attributes))
48
54
  Explorer.new(data)
@@ -0,0 +1,70 @@
1
+ require 'open_dota_api/entity'
2
+
3
+ module OpenDotaApi
4
+ class Player < Entity
5
+ ENDPOINT = 'players'.freeze
6
+
7
+ define_adder(%w[tracked_until rank_tier competitive_rank solo_competitive_rank leaderboard_rank])
8
+
9
+ def self.instantiate(_ = nil)
10
+ raise NotImplementedError
11
+ end
12
+
13
+ def mmr_estimate
14
+ data&.dig('mmr_estimate', 'estimate')
15
+ end
16
+
17
+ # profile section
18
+ def persona_name
19
+ data&.dig('profile', 'personaname')
20
+ end
21
+
22
+ def account_id
23
+ data&.dig('profile', 'account_id')
24
+ end
25
+
26
+ def name
27
+ data&.dig('profile', 'name')
28
+ end
29
+
30
+ def plus
31
+ data&.dig('profile', 'plus')
32
+ end
33
+
34
+ def cheese
35
+ data&.dig('profile', 'cheese')
36
+ end
37
+
38
+ def avatar
39
+ data&.dig('profile', 'avatar')
40
+ end
41
+
42
+ def contributor?
43
+ data&.dig('profile', 'is_contributor')
44
+ end
45
+
46
+ def steam_id
47
+ data&.dig('profile', 'steamid')
48
+ end
49
+
50
+ def avatar_medium
51
+ data&.dig('profile', 'avatarmedium')
52
+ end
53
+
54
+ def avatar_full
55
+ data&.dig('profile', 'avatarfull')
56
+ end
57
+
58
+ def profile_url
59
+ data&.dig('profile', 'profileurl')
60
+ end
61
+
62
+ def last_login
63
+ Time.parse(data&.dig('profile', 'last_login'))
64
+ end
65
+
66
+ def loc_country_code
67
+ data&.dig('profile', 'loccountrycode')
68
+ end
69
+ end
70
+ end
@@ -1,3 +1,3 @@
1
1
  module OpenDotaApi
2
- VERSION = '0.4.1'.freeze
2
+ VERSION = '0.4.2'.freeze
3
3
  end
@@ -0,0 +1,25 @@
1
+ {
2
+ "tracked_until": "1573909596",
3
+ "profile": {
4
+ "account_id": 65366604,
5
+ "personaname": "Misaka 10032",
6
+ "name": null,
7
+ "plus": false,
8
+ "cheese": 0,
9
+ "steamid": "76561198025632332",
10
+ "avatar": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/40/4097bbe60170972397ee8cbe5694632ec339a9cc.jpg",
11
+ "avatarmedium": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/40/4097bbe60170972397ee8cbe5694632ec339a9cc_medium.jpg",
12
+ "avatarfull": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/40/4097bbe60170972397ee8cbe5694632ec339a9cc_full.jpg",
13
+ "profileurl": "https://steamcommunity.com/id/HopeYouDie/",
14
+ "last_login": "2019-09-23T08:55:01.422Z",
15
+ "loccountrycode": "PL",
16
+ "is_contributor": false
17
+ },
18
+ "leaderboard_rank": null,
19
+ "solo_competitive_rank": null,
20
+ "competitive_rank": null,
21
+ "rank_tier": 41,
22
+ "mmr_estimate": {
23
+ "estimate": 2696
24
+ }
25
+ }
@@ -3,10 +3,12 @@ require 'spec_helper'
3
3
  describe OpenDotaApi::Client do
4
4
  let(:endpoint) {}
5
5
  let(:match_id) { 3_149_215_336 }
6
+ let(:steam_32_id) { 65366604 }
6
7
  let(:league_id) { 5401 }
7
8
  let(:leagues_file) { File.read('spec/data/leagues.json') }
8
9
  let(:teams_file) { File.read('spec/data/teams.json') }
9
10
  let(:match_file) { File.read('spec/data/match.json') }
11
+ let(:player_file) { File.read('spec/data/player.json') }
10
12
  let(:heroes_file) { File.read('spec/data/heroes.json') }
11
13
  let(:pro_players_file) { File.read('spec/data/pro_players.json') }
12
14
  let(:explorer_file) { File.read('spec/data/explorer.json') }
@@ -23,6 +25,7 @@ describe OpenDotaApi::Client do
23
25
  let(:expected_leagues) { OpenDotaApi::League.instantiate(response_json) }
24
26
  let(:expected_teams) { OpenDotaApi::Team.instantiate(response_json) }
25
27
  let(:expected_match) { OpenDotaApi::Match.new(response_json) }
28
+ let(:expected_player) { OpenDotaApi::Match.new(response_json) }
26
29
  let(:expected_heroes) { OpenDotaApi::Hero.instantiate(response_json) }
27
30
  let(:expected_pro_players) { OpenDotaApi::ProPlayers.instantiate(response_json) }
28
31
 
@@ -135,6 +138,23 @@ describe OpenDotaApi::Client do
135
138
  end
136
139
  end
137
140
 
141
+ describe '#players' do
142
+ let(:endpoint) { "#{OpenDotaApi::Player::ENDPOINT}/#{steam_32_id}" }
143
+ let(:data_file) { player_file }
144
+
145
+ it 'returns object' do
146
+ expect(subject.players(steam_32_id).is_a?(OpenDotaApi::Player)).to be_truthy
147
+ end
148
+
149
+ it 'returns match' do
150
+ expect(subject.players(steam_32_id).to_deep_hash).to eq expected_player.to_deep_hash
151
+ end
152
+
153
+ it 'updates limits' do
154
+ expect{subject.players(steam_32_id)}.to change{ subject.instance_variable_get(:@limits) }.from(nil).to(Hash)
155
+ end
156
+ end
157
+
138
158
  describe '#pro_players' do
139
159
  let(:endpoint) { OpenDotaApi::ProPlayer::ENDPOINT }
140
160
  let(:data_file) { pro_players_file }
@@ -0,0 +1,92 @@
1
+ require 'spec_helper'
2
+
3
+ describe OpenDotaApi::Player do
4
+ let(:account_id) { 65366604 }
5
+ let(:steam_id) { '76561198025632332' }
6
+ let(:avatar) { "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/40/4097bbe60170972397ee8cbe5694632ec339a9cc.jpg" }
7
+ let(:avatar_medium) { "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/40/4097bbe60170972397ee8cbe5694632ec339a9cc_medium.jpg" }
8
+ let(:avatar_full) { "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/40/4097bbe60170972397ee8cbe5694632ec339a9cc_full.jpg" }
9
+ let(:profile_url) { "https://steamcommunity.com/id/HopeYouDie/" }
10
+ let(:persona_name) { "Misaka 10032" }
11
+ let(:name) { nil }
12
+ let(:last_login) { Time.parse('2019-09-23 08:55:01.422000000 +0000').utc }
13
+ let(:cheese) { 0 }
14
+ let(:mmr_estimate) { 2696 }
15
+ let(:plus) { false }
16
+ let(:loc_country_code) { 'PL' }
17
+ let(:is_contributor) { false }
18
+
19
+ let(:player_file) { File.read('spec/data/player.json') }
20
+ let(:response_json) { JSON.parse(player_file) }
21
+ let(:player) { OpenDotaApi::Player.new(response_json) }
22
+
23
+ it 'returns endpoint' do
24
+ expect(described_class::ENDPOINT).to eq 'players'
25
+ end
26
+
27
+ it 'inherits entity object' do
28
+ expect(player).to be_a OpenDotaApi::Entity
29
+ end
30
+
31
+ it 'is not instantiable' do
32
+ expect { described_class.instantiate }.to raise_error NotImplementedError
33
+ end
34
+
35
+ describe 'default attributes' do
36
+ it 'returns account id' do
37
+ expect(player.account_id).to eq account_id
38
+ end
39
+
40
+ it 'returns mmr estimate' do
41
+ expect(player.mmr_estimate).to eq mmr_estimate
42
+ end
43
+
44
+ it 'returns plus' do
45
+ expect(player.plus).to eq plus
46
+ end
47
+
48
+ it 'returns is contributor' do
49
+ expect(player.contributor?).to eq is_contributor
50
+ end
51
+
52
+ it 'returns steam id' do
53
+ expect(player.steam_id).to eq steam_id
54
+ end
55
+
56
+ it 'returns avatar' do
57
+ expect(player.avatar).to eq avatar
58
+ end
59
+
60
+ it 'returns avatar medium' do
61
+ expect(player.avatar_medium).to eq avatar_medium
62
+ end
63
+
64
+ it 'returns avatar full' do
65
+ expect(player.avatar_full).to eq avatar_full
66
+ end
67
+
68
+ it 'returns profile url' do
69
+ expect(player.profile_url).to eq profile_url
70
+ end
71
+
72
+ it 'returns persona name' do
73
+ expect(player.persona_name).to eq persona_name
74
+ end
75
+
76
+ it 'returns last login' do
77
+ expect(player.last_login).to eq last_login
78
+ end
79
+
80
+ it 'returns cheese' do
81
+ expect(player.cheese).to eq cheese
82
+ end
83
+
84
+ it 'returns location country code' do
85
+ expect(player.loc_country_code).to eq loc_country_code
86
+ end
87
+
88
+ it 'returns name' do
89
+ expect(player.name).to eq name
90
+ end
91
+ end
92
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: open_dota_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - YaroslavO
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-01 00:00:00.000000000 Z
11
+ date: 2020-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashable
@@ -153,6 +153,7 @@ files:
153
153
  - lib/open_dota_api/league.rb
154
154
  - lib/open_dota_api/match.rb
155
155
  - lib/open_dota_api/matches/player.rb
156
+ - lib/open_dota_api/player.rb
156
157
  - lib/open_dota_api/pro_player.rb
157
158
  - lib/open_dota_api/team.rb
158
159
  - lib/open_dota_api/version.rb
@@ -160,6 +161,7 @@ files:
160
161
  - spec/data/heroes.json
161
162
  - spec/data/leagues.json
162
163
  - spec/data/match.json
164
+ - spec/data/player.json
163
165
  - spec/data/pro_players.json
164
166
  - spec/data/teams.json
165
167
  - spec/data/unofficial_match.json
@@ -170,6 +172,7 @@ files:
170
172
  - spec/lib/open_dota_api/league_spec.rb
171
173
  - spec/lib/open_dota_api/match_spec.rb
172
174
  - spec/lib/open_dota_api/matches/player_spec.rb
175
+ - spec/lib/open_dota_api/player_spec.rb
173
176
  - spec/lib/open_dota_api/pro_player_spec.rb
174
177
  - spec/lib/open_dota_api/team_spec.rb
175
178
  - spec/lib/open_dota_api_spec.rb
@@ -193,7 +196,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
193
196
  - !ruby/object:Gem::Version
194
197
  version: '0'
195
198
  requirements: []
196
- rubygems_version: 3.0.1
199
+ rubygems_version: 3.0.6
197
200
  signing_key:
198
201
  specification_version: 4
199
202
  summary: Ruby wrapper for Open Dota API
@@ -205,12 +208,14 @@ test_files:
205
208
  - spec/lib/open_dota_api/match_spec.rb
206
209
  - spec/lib/open_dota_api/explorer_spec.rb
207
210
  - spec/lib/open_dota_api/matches/player_spec.rb
211
+ - spec/lib/open_dota_api/player_spec.rb
208
212
  - spec/lib/open_dota_api/hero_spec.rb
209
213
  - spec/lib/open_dota_api/connection_spec.rb
210
214
  - spec/lib/open_dota_api/pro_player_spec.rb
211
215
  - spec/lib/open_dota_api_spec.rb
212
216
  - spec/data/heroes.json
213
217
  - spec/data/match.json
218
+ - spec/data/player.json
214
219
  - spec/data/teams.json
215
220
  - spec/data/pro_players.json
216
221
  - spec/data/unofficial_match.json