open_dota_api 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/open_dota_api.rb +1 -1
- data/lib/open_dota_api/client.rb +36 -29
- data/lib/open_dota_api/health.rb +5 -0
- data/lib/open_dota_api/version.rb +1 -1
- data/spec/lib/open_dota_api/client_spec.rb +70 -15
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 41e0de50f5999f18334dd3bc4feb1504de64fb93123e104d738601b6128254c8
|
4
|
+
data.tar.gz: f5cc9056ef69f00d95ad1f534d1e3d870be1e51fa6f6195eaea5a3e4db8a5644
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0fae16428f8cf5aef6be3f2f85248ddc055e873d3c8b0dd9ca60b63421313a41f775ec78b3661ee83835cf551e5cb5af6f157d872e430be1f6dbd415582a3c49
|
7
|
+
data.tar.gz: bd954371cd4a6ad867be36f184830efe93816088b6fb46984c1d749f39fc12b327d2b311a7b4c54b5b10685589bab4af4c6fec24a51f96ca58c9ba3301120531
|
data/lib/open_dota_api.rb
CHANGED
@@ -3,7 +3,7 @@ require 'open_dota_api/version'
|
|
3
3
|
|
4
4
|
module OpenDotaApi
|
5
5
|
extend SingleForwardable
|
6
|
-
def_delegators :client, :leagues, :teams, :matches, :heroes, :pro_players, :explorer
|
6
|
+
def_delegators :client, :limits, :leagues, :teams, :matches, :heroes, :pro_players, :explorer
|
7
7
|
|
8
8
|
def self.client
|
9
9
|
@client ||= Client.new
|
data/lib/open_dota_api/client.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'open_dota_api/connection'
|
2
|
+
require 'open_dota_api/health'
|
2
3
|
require 'open_dota_api/league'
|
3
4
|
require 'open_dota_api/team'
|
4
5
|
require 'open_dota_api/match'
|
@@ -10,46 +11,41 @@ module OpenDotaApi
|
|
10
11
|
class Client
|
11
12
|
INTERFACE = 'api'.freeze
|
12
13
|
|
13
|
-
def
|
14
|
-
|
15
|
-
return {} unless leagues_data.success?
|
14
|
+
def limits(attributes = {})
|
15
|
+
return @limits unless @limits.nil?
|
16
16
|
|
17
|
-
|
17
|
+
request(Health::ENDPOINT, params: attributes)
|
18
|
+
@limits
|
18
19
|
end
|
19
20
|
|
20
|
-
def
|
21
|
-
|
22
|
-
|
21
|
+
def leagues(attributes = {})
|
22
|
+
data = request(League::ENDPOINT, params: attributes)
|
23
|
+
League.instantiate(data)
|
24
|
+
end
|
23
25
|
|
24
|
-
|
26
|
+
def teams(attributes = {})
|
27
|
+
data = request(Team::ENDPOINT, params: attributes)
|
28
|
+
Team.instantiate(data)
|
25
29
|
end
|
26
30
|
|
27
31
|
def matches(match_id = nil, attributes = {})
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
Match.new(match_data)
|
32
|
+
data = request(Match::ENDPOINT, match_id, params: attributes)
|
33
|
+
Match.new(data)
|
32
34
|
end
|
33
35
|
|
34
36
|
def heroes(attributes = {})
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
Hero.instantiate(heroes_data)
|
37
|
+
data = request(Hero::ENDPOINT, params: attributes)
|
38
|
+
Hero.instantiate(data)
|
39
39
|
end
|
40
40
|
|
41
41
|
def pro_players(attributes = {})
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
ProPlayer.instantiate(pro_players_data)
|
42
|
+
data = request(ProPlayer::ENDPOINT, params: attributes)
|
43
|
+
ProPlayer.instantiate(data)
|
46
44
|
end
|
47
45
|
|
48
46
|
def explorer(league_id = nil, attributes = {})
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
Explorer.new(explorer_data)
|
47
|
+
data = request(Explorer::ENDPOINT, params: Explorer.query_params(league_id).merge(attributes))
|
48
|
+
Explorer.new(data)
|
53
49
|
end
|
54
50
|
|
55
51
|
private
|
@@ -58,12 +54,23 @@ module OpenDotaApi
|
|
58
54
|
@connection ||= Connection.new
|
59
55
|
end
|
60
56
|
|
61
|
-
def request(method, argument = nil,
|
62
|
-
|
63
|
-
|
64
|
-
|
57
|
+
def request(method, argument = nil, params: {})
|
58
|
+
pathname = "/#{INTERFACE}/#{method}#{("/#{argument}" if argument)}"
|
59
|
+
|
60
|
+
global_api_key = { api_key: OpenDotaApi.api_key }.compact
|
61
|
+
|
62
|
+
data = connection.get(pathname, query: global_api_key.merge(params.compact))
|
63
|
+
return {} unless data.success?
|
64
|
+
|
65
|
+
limits_fixation(data)
|
66
|
+
data
|
67
|
+
end
|
65
68
|
|
66
|
-
|
69
|
+
def limits_fixation(data)
|
70
|
+
@limits = {
|
71
|
+
per_min: data.headers['x-rate-limit-remaining-minute'],
|
72
|
+
per_month: data.headers['x-rate-limit-remaining-month']
|
73
|
+
}
|
67
74
|
end
|
68
75
|
end
|
69
76
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe OpenDotaApi::Client do
|
4
|
-
let(:client) { described_class.new }
|
5
4
|
let(:endpoint) {}
|
6
5
|
let(:match_id) { 3_149_215_336 }
|
7
6
|
let(:league_id) { 5401 }
|
@@ -14,7 +13,9 @@ describe OpenDotaApi::Client do
|
|
14
13
|
let(:data_file) {}
|
15
14
|
let(:headers) do
|
16
15
|
{
|
17
|
-
'content-type' => ['application/json; charset=utf-8']
|
16
|
+
'content-type' => ['application/json; charset=utf-8'],
|
17
|
+
'x-rate-limit-remaining-minute' => rand(60),
|
18
|
+
'x-rate-limit-remaining-month' => rand(50000)
|
18
19
|
}
|
19
20
|
end
|
20
21
|
|
@@ -33,6 +34,14 @@ describe OpenDotaApi::Client do
|
|
33
34
|
stub_request(:get, api_url)
|
34
35
|
.with(headers: { 'Accept': '*/*', 'Accept-Encoding': 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent': 'Ruby' })
|
35
36
|
.to_return(status: 200, body: data_file, headers: headers)
|
37
|
+
|
38
|
+
stub_request(:get, "http://api.opendota.com/api/health").
|
39
|
+
with(headers: { 'Accept': '*/*', 'Accept-Encoding': 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent': 'Ruby' }).
|
40
|
+
to_return(status: 200, body: "", headers: headers)
|
41
|
+
|
42
|
+
stub_request(:get, "http://api.opendota.com/api/health?api_key=random-value").
|
43
|
+
with(headers: { 'Accept': '*/*', 'Accept-Encoding': 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent': 'Ruby' }).
|
44
|
+
to_return(status: 200, body: "", headers: {})
|
36
45
|
end
|
37
46
|
|
38
47
|
it 'returns interface' do
|
@@ -40,16 +49,38 @@ describe OpenDotaApi::Client do
|
|
40
49
|
end
|
41
50
|
|
42
51
|
describe 'default attributes' do
|
52
|
+
describe '#limits' do
|
53
|
+
let(:endpoint) { OpenDotaApi::Health::ENDPOINT }
|
54
|
+
|
55
|
+
it 'updates limits' do
|
56
|
+
expect{ subject.limits }.to change{ subject.instance_variable_get(:@limits) }.from(nil).to(Hash)
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'check limit after it was set' do
|
60
|
+
before do
|
61
|
+
subject.limits
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'reads limits' do
|
65
|
+
expect{subject.limits}.to_not change(subject, :limits)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
43
70
|
describe '#leagues' do
|
44
71
|
let(:endpoint) { OpenDotaApi::League::ENDPOINT }
|
45
72
|
let(:data_file) { leagues_file }
|
46
73
|
|
47
74
|
it 'returns array of objects' do
|
48
|
-
expect(
|
75
|
+
expect(subject.leagues.all? { |league| league.is_a? OpenDotaApi::League }).to be_truthy
|
49
76
|
end
|
50
77
|
|
51
78
|
it 'returns list' do
|
52
|
-
expect(
|
79
|
+
expect(subject.leagues.to_deep_hash).to eq expected_leagues.to_deep_hash
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'updates limits' do
|
83
|
+
expect{subject.leagues}.to change{ subject.instance_variable_get(:@limits) }.from(nil).to(Hash)
|
53
84
|
end
|
54
85
|
end
|
55
86
|
|
@@ -58,11 +89,15 @@ describe OpenDotaApi::Client do
|
|
58
89
|
let(:data_file) { teams_file }
|
59
90
|
|
60
91
|
it 'returns array of objects' do
|
61
|
-
expect(
|
92
|
+
expect(subject.teams.all? { |team| team.is_a? OpenDotaApi::Team }).to be_truthy
|
62
93
|
end
|
63
94
|
|
64
95
|
it 'returns list' do
|
65
|
-
expect(
|
96
|
+
expect(subject.teams.to_deep_hash).to eq expected_teams.to_deep_hash
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'updates limits' do
|
100
|
+
expect{subject.teams}.to change{ subject.instance_variable_get(:@limits) }.from(nil).to(Hash)
|
66
101
|
end
|
67
102
|
end
|
68
103
|
|
@@ -71,11 +106,15 @@ describe OpenDotaApi::Client do
|
|
71
106
|
let(:data_file) { match_file }
|
72
107
|
|
73
108
|
it 'returns object' do
|
74
|
-
expect(
|
109
|
+
expect(subject.matches(match_id).is_a?(OpenDotaApi::Match)).to be_truthy
|
75
110
|
end
|
76
111
|
|
77
112
|
it 'returns match' do
|
78
|
-
expect(
|
113
|
+
expect(subject.matches(match_id).to_deep_hash).to eq expected_match.to_deep_hash
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'updates limits' do
|
117
|
+
expect{subject.matches(match_id)}.to change{ subject.instance_variable_get(:@limits) }.from(nil).to(Hash)
|
79
118
|
end
|
80
119
|
end
|
81
120
|
|
@@ -84,11 +123,15 @@ describe OpenDotaApi::Client do
|
|
84
123
|
let(:data_file) { heroes_file }
|
85
124
|
|
86
125
|
it 'returns array of objects' do
|
87
|
-
expect(
|
126
|
+
expect(subject.heroes.all? { |hero| hero.is_a? OpenDotaApi::Hero }).to be_truthy
|
88
127
|
end
|
89
128
|
|
90
129
|
it 'returns list' do
|
91
|
-
expect(
|
130
|
+
expect(subject.heroes.to_deep_hash).to eq expected_heroes.to_deep_hash
|
131
|
+
end
|
132
|
+
|
133
|
+
it 'updates limits' do
|
134
|
+
expect{subject.heroes}.to change{ subject.instance_variable_get(:@limits) }.from(nil).to(Hash)
|
92
135
|
end
|
93
136
|
end
|
94
137
|
|
@@ -97,22 +140,30 @@ describe OpenDotaApi::Client do
|
|
97
140
|
let(:data_file) { pro_players_file }
|
98
141
|
|
99
142
|
it 'returns array of objects' do
|
100
|
-
expect(
|
143
|
+
expect(subject.pro_players.all? { |hero| hero.is_a? OpenDotaApi::ProPlayer }).to be_truthy
|
101
144
|
end
|
102
145
|
|
103
146
|
it 'returns list' do
|
104
|
-
expect(
|
147
|
+
expect(subject.pro_players.to_deep_hash).to eq expected_heroes.to_deep_hash
|
148
|
+
end
|
149
|
+
|
150
|
+
it 'updates limits' do
|
151
|
+
expect{subject.pro_players}.to change{ subject.instance_variable_get(:@limits) }.from(nil).to(Hash)
|
105
152
|
end
|
106
153
|
end
|
107
154
|
|
108
155
|
describe '#explorer' do
|
109
156
|
let(:query) { OpenDotaApi::Explorer.query_params(league_id) }
|
110
|
-
let(:endpoint) {
|
157
|
+
let(:endpoint) { OpenDotaApi::Explorer::ENDPOINT }
|
111
158
|
let(:params) { "?#{query.keys[0]}=#{query.values[0]}" }
|
112
159
|
let(:data_file) { explorer_file }
|
113
160
|
|
114
161
|
it 'returns array of match ids' do
|
115
|
-
expect(
|
162
|
+
expect(subject.explorer(league_id).league_matches_ids.is_a?(Array)).to be_truthy
|
163
|
+
end
|
164
|
+
|
165
|
+
it 'updates limits' do
|
166
|
+
expect{subject.explorer(league_id)}.to change{ subject.instance_variable_get(:@limits) }.from(nil).to(Hash)
|
116
167
|
end
|
117
168
|
|
118
169
|
context 'API_KEY' do
|
@@ -122,7 +173,11 @@ describe OpenDotaApi::Client do
|
|
122
173
|
end
|
123
174
|
|
124
175
|
it 'returns array of match ids' do
|
125
|
-
expect(
|
176
|
+
expect(subject.explorer(league_id).league_matches_ids.is_a?(Array)).to be_truthy
|
177
|
+
end
|
178
|
+
|
179
|
+
it 'updates limits' do
|
180
|
+
expect{subject.explorer(league_id)}.to change{ subject.instance_variable_get(:@limits) }.from(nil).to(Hash)
|
126
181
|
end
|
127
182
|
end
|
128
183
|
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.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- YaroslavO
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hashable
|
@@ -148,6 +148,7 @@ files:
|
|
148
148
|
- lib/open_dota_api/entities/instantiable.rb
|
149
149
|
- lib/open_dota_api/entity.rb
|
150
150
|
- lib/open_dota_api/explorer.rb
|
151
|
+
- lib/open_dota_api/health.rb
|
151
152
|
- lib/open_dota_api/hero.rb
|
152
153
|
- lib/open_dota_api/league.rb
|
153
154
|
- lib/open_dota_api/match.rb
|