open_dota_api 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/open_dota_api.rb +4 -0
- data/lib/open_dota_api/client.rb +24 -16
- data/lib/open_dota_api/pro_player.rb +2 -2
- data/lib/open_dota_api/version.rb +1 -1
- data/spec/lib/open_dota_api/client_spec.rb +29 -18
- data/spec/lib/open_dota_api/explorer_spec.rb +4 -0
- data/spec/lib/open_dota_api/pro_player_spec.rb +2 -2
- metadata +49 -50
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 808512136e0502bf89c7a10c8922302f70917042d7a866cf10ff3e8a441ee299
|
4
|
+
data.tar.gz: 0d8487e5a03d1d4c7020c1a739938ecacd52edc60a55801918d3a693310215b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 795eac8e9764bca6fe5cba16bcf29965cc3e4efef6ec6d41dc89303f1d0be0f46d62332c40d2b3928648de259a05f5ccda7158b057aed9e8cc8d6d1a1f341392
|
7
|
+
data.tar.gz: d2844e9bd2e35298cfce1f4b0664ae188ede5b2d5a912b0978e497aab99cd77056655d4069bb01c25c4b87100d090c625ab5cc2907d01a362acf6e7e4b36bd15
|
data/lib/open_dota_api.rb
CHANGED
data/lib/open_dota_api/client.rb
CHANGED
@@ -10,39 +10,45 @@ module OpenDotaApi
|
|
10
10
|
class Client
|
11
11
|
INTERFACE = 'api'.freeze
|
12
12
|
|
13
|
-
def leagues
|
14
|
-
leagues_data = request(League::ENDPOINT)
|
13
|
+
def leagues(attributes = {})
|
14
|
+
leagues_data = request(League::ENDPOINT, query_params: { api_key: attributes.delete(:api_key) }.compact)
|
15
15
|
return {} unless leagues_data.success?
|
16
|
+
|
16
17
|
League.instantiate(leagues_data)
|
17
18
|
end
|
18
19
|
|
19
|
-
def teams
|
20
|
-
teams_data = request(Team::ENDPOINT)
|
20
|
+
def teams(attributes = {})
|
21
|
+
teams_data = request(Team::ENDPOINT, query_params: { api_key: attributes.delete(:api_key) }.compact)
|
21
22
|
return {} unless teams_data.success?
|
23
|
+
|
22
24
|
Team.instantiate(teams_data)
|
23
25
|
end
|
24
26
|
|
25
|
-
def matches(match_id = nil)
|
26
|
-
match_data = request(Match::ENDPOINT, match_id)
|
27
|
+
def matches(match_id = nil, attributes = {})
|
28
|
+
match_data = request(Match::ENDPOINT, match_id, query_params: { api_key: attributes.delete(:api_key) }.compact)
|
27
29
|
return {} unless match_data.success?
|
30
|
+
|
28
31
|
Match.new(match_data)
|
29
32
|
end
|
30
33
|
|
31
|
-
def heroes
|
32
|
-
heroes_data = request(Hero::ENDPOINT)
|
34
|
+
def heroes(attributes = {})
|
35
|
+
heroes_data = request(Hero::ENDPOINT, query_params: { api_key: attributes.delete(:api_key) }.compact)
|
33
36
|
return {} unless heroes_data.success?
|
37
|
+
|
34
38
|
Hero.instantiate(heroes_data)
|
35
39
|
end
|
36
40
|
|
37
|
-
def pro_players
|
38
|
-
pro_players_data = request(ProPlayer::ENDPOINT)
|
41
|
+
def pro_players(attributes = {})
|
42
|
+
pro_players_data = request(ProPlayer::ENDPOINT, query_params: { api_key: attributes.delete(:api_key) }.compact)
|
39
43
|
return {} unless pro_players_data
|
44
|
+
|
40
45
|
ProPlayer.instantiate(pro_players_data)
|
41
46
|
end
|
42
47
|
|
43
|
-
def explorer(league_id = nil)
|
44
|
-
explorer_data = request(Explorer::ENDPOINT, query_params: Explorer.query_params(league_id))
|
48
|
+
def explorer(league_id = nil, attributes = {})
|
49
|
+
explorer_data = request(Explorer::ENDPOINT, query_params: { api_key: attributes.delete(:api_key) }.merge(Explorer.query_params(league_id)).compact)
|
45
50
|
return {} unless explorer_data.success?
|
51
|
+
|
46
52
|
Explorer.new(explorer_data)
|
47
53
|
end
|
48
54
|
|
@@ -52,10 +58,12 @@ module OpenDotaApi
|
|
52
58
|
@connection ||= Connection.new
|
53
59
|
end
|
54
60
|
|
55
|
-
def request(method, argument = nil, query_params:
|
56
|
-
|
57
|
-
|
58
|
-
|
61
|
+
def request(method, argument = nil, query_params: {})
|
62
|
+
params = query_params.merge({ api_key: OpenDotaApi.api_key }.compact)
|
63
|
+
argument = argument ? "/#{argument}" : nil
|
64
|
+
pathname = "/#{INTERFACE}/#{method}#{argument}"
|
65
|
+
|
66
|
+
connection.get(pathname, query: params)
|
59
67
|
end
|
60
68
|
end
|
61
69
|
end
|
@@ -1,10 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe OpenDotaApi::Client do
|
4
|
-
|
5
4
|
let(:client) { described_class.new }
|
6
5
|
let(:endpoint) {}
|
7
|
-
let(:match_id) {
|
6
|
+
let(:match_id) { 3_149_215_336 }
|
8
7
|
let(:league_id) { 5401 }
|
9
8
|
let(:leagues_file) { File.read('spec/data/leagues.json') }
|
10
9
|
let(:teams_file) { File.read('spec/data/teams.json') }
|
@@ -15,7 +14,7 @@ describe OpenDotaApi::Client do
|
|
15
14
|
let(:data_file) {}
|
16
15
|
let(:headers) do
|
17
16
|
{
|
18
|
-
|
17
|
+
'content-type' => ['application/json; charset=utf-8']
|
19
18
|
}
|
20
19
|
end
|
21
20
|
|
@@ -26,12 +25,14 @@ describe OpenDotaApi::Client do
|
|
26
25
|
let(:expected_heroes) { OpenDotaApi::Hero.instantiate(response_json) }
|
27
26
|
let(:expected_pro_players) { OpenDotaApi::ProPlayers.instantiate(response_json) }
|
28
27
|
|
29
|
-
let(:
|
28
|
+
let(:api_key) { 'random-value' }
|
29
|
+
let(:params) { "" }
|
30
|
+
let(:api_url) { "http://api.opendota.com/api/#{endpoint}#{params}" }
|
30
31
|
|
31
32
|
before do
|
32
|
-
stub_request(:get, api_url)
|
33
|
-
|
34
|
-
|
33
|
+
stub_request(:get, api_url)
|
34
|
+
.with(headers: { 'Accept': '*/*', 'Accept-Encoding': 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent': 'Ruby' })
|
35
|
+
.to_return(status: 200, body: data_file, headers: headers)
|
35
36
|
end
|
36
37
|
|
37
38
|
it 'returns interface' do
|
@@ -44,7 +45,7 @@ describe OpenDotaApi::Client do
|
|
44
45
|
let(:data_file) { leagues_file }
|
45
46
|
|
46
47
|
it 'returns array of objects' do
|
47
|
-
expect(client.leagues.all? { |league| league.
|
48
|
+
expect(client.leagues.all? { |league| league.is_a? OpenDotaApi::League }).to be_truthy
|
48
49
|
end
|
49
50
|
|
50
51
|
it 'returns list' do
|
@@ -57,7 +58,7 @@ describe OpenDotaApi::Client do
|
|
57
58
|
let(:data_file) { teams_file }
|
58
59
|
|
59
60
|
it 'returns array of objects' do
|
60
|
-
expect(client.teams.all? { |team| team.
|
61
|
+
expect(client.teams.all? { |team| team.is_a? OpenDotaApi::Team }).to be_truthy
|
61
62
|
end
|
62
63
|
|
63
64
|
it 'returns list' do
|
@@ -70,7 +71,7 @@ describe OpenDotaApi::Client do
|
|
70
71
|
let(:data_file) { match_file }
|
71
72
|
|
72
73
|
it 'returns object' do
|
73
|
-
expect(client.matches(match_id).
|
74
|
+
expect(client.matches(match_id).is_a?(OpenDotaApi::Match)).to be_truthy
|
74
75
|
end
|
75
76
|
|
76
77
|
it 'returns match' do
|
@@ -78,13 +79,12 @@ describe OpenDotaApi::Client do
|
|
78
79
|
end
|
79
80
|
end
|
80
81
|
|
81
|
-
|
82
82
|
describe '#heroes' do
|
83
|
-
let(:endpoint) {
|
83
|
+
let(:endpoint) { OpenDotaApi::Hero::ENDPOINT }
|
84
84
|
let(:data_file) { heroes_file }
|
85
85
|
|
86
86
|
it 'returns array of objects' do
|
87
|
-
expect(client.heroes.all? { |hero| hero.
|
87
|
+
expect(client.heroes.all? { |hero| hero.is_a? OpenDotaApi::Hero }).to be_truthy
|
88
88
|
end
|
89
89
|
|
90
90
|
it 'returns list' do
|
@@ -93,11 +93,11 @@ describe OpenDotaApi::Client do
|
|
93
93
|
end
|
94
94
|
|
95
95
|
describe '#pro_players' do
|
96
|
-
let(:endpoint) {
|
96
|
+
let(:endpoint) { OpenDotaApi::ProPlayer::ENDPOINT }
|
97
97
|
let(:data_file) { pro_players_file }
|
98
98
|
|
99
99
|
it 'returns array of objects' do
|
100
|
-
expect(client.pro_players.all? { |hero| hero.
|
100
|
+
expect(client.pro_players.all? { |hero| hero.is_a? OpenDotaApi::ProPlayer }).to be_truthy
|
101
101
|
end
|
102
102
|
|
103
103
|
it 'returns list' do
|
@@ -107,12 +107,23 @@ describe OpenDotaApi::Client do
|
|
107
107
|
|
108
108
|
describe '#explorer' do
|
109
109
|
let(:query) { OpenDotaApi::Explorer.query_params(league_id) }
|
110
|
-
let(:endpoint) { "#{OpenDotaApi::Explorer::ENDPOINT}
|
110
|
+
let(:endpoint) { "#{OpenDotaApi::Explorer::ENDPOINT}" }
|
111
|
+
let(:params) { "?#{query.keys[0]}=#{query.values[0]}" }
|
111
112
|
let(:data_file) { explorer_file }
|
112
|
-
let(:api_url) {"http://api.opendota.com/api/#{endpoint}"}
|
113
113
|
|
114
114
|
it 'returns array of match ids' do
|
115
|
-
expect(client.explorer(league_id).league_matches_ids.
|
115
|
+
expect(client.explorer(league_id).league_matches_ids.is_a?(Array)).to be_truthy
|
116
|
+
end
|
117
|
+
|
118
|
+
context 'API_KEY' do
|
119
|
+
let(:params) { "?api_key=#{api_key}&#{query.keys[0]}=#{query.values[0]}" }
|
120
|
+
before do
|
121
|
+
OpenDotaApi.api_key = api_key
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'returns array of match ids' do
|
125
|
+
expect(client.explorer(league_id).league_matches_ids.is_a?(Array)).to be_truthy
|
126
|
+
end
|
116
127
|
end
|
117
128
|
end
|
118
129
|
end
|
@@ -19,6 +19,10 @@ describe OpenDotaApi::Explorer do
|
|
19
19
|
expect(explorer).to be_a OpenDotaApi::Entity
|
20
20
|
end
|
21
21
|
|
22
|
+
it 'is not instantiable' do
|
23
|
+
expect { described_class.instantiate }.to raise_error NotImplementedError
|
24
|
+
end
|
25
|
+
|
22
26
|
describe 'default attributes' do
|
23
27
|
it "returns league's matches ids" do
|
24
28
|
expect(explorer.league_matches_ids).to match_array(match_ids)
|
@@ -119,11 +119,11 @@ describe OpenDotaApi::ProPlayer do
|
|
119
119
|
end
|
120
120
|
|
121
121
|
it 'returns if it is locked' do
|
122
|
-
expect(pro_player.
|
122
|
+
expect(pro_player.locked?).to eq is_locked
|
123
123
|
end
|
124
124
|
|
125
125
|
it 'returns if it is pro' do
|
126
|
-
expect(pro_player.
|
126
|
+
expect(pro_player.pro?).to eq is_pro
|
127
127
|
end
|
128
128
|
|
129
129
|
it 'returns locked until' do
|
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: open_dota_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- YaroslavO
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-09-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: hashable
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.1.2
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
26
|
+
version: 0.1.2
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: httparty
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.1
|
33
|
+
version: 0.17.1
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.1
|
40
|
+
version: 0.17.1
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: listen
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -59,83 +59,83 @@ dependencies:
|
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: 3.1.5
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
|
-
name:
|
62
|
+
name: rake
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
64
64
|
requirements:
|
65
|
-
- - "~>"
|
66
|
-
- !ruby/object:Gem::Version
|
67
|
-
version: '3.6'
|
68
65
|
- - ">="
|
69
66
|
- !ruby/object:Gem::Version
|
70
|
-
version:
|
67
|
+
version: 13.0.0
|
68
|
+
- - "~>"
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '13.0'
|
71
71
|
type: :development
|
72
72
|
prerelease: false
|
73
73
|
version_requirements: !ruby/object:Gem::Requirement
|
74
74
|
requirements:
|
75
|
-
- - "~>"
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
version: '3.6'
|
78
75
|
- - ">="
|
79
76
|
- !ruby/object:Gem::Version
|
80
|
-
version:
|
77
|
+
version: 13.0.0
|
78
|
+
- - "~>"
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '13.0'
|
81
81
|
- !ruby/object:Gem::Dependency
|
82
|
-
name:
|
82
|
+
name: rspec
|
83
83
|
requirement: !ruby/object:Gem::Requirement
|
84
84
|
requirements:
|
85
|
-
- - "~>"
|
86
|
-
- !ruby/object:Gem::Version
|
87
|
-
version: '3.0'
|
88
85
|
- - ">="
|
89
86
|
- !ruby/object:Gem::Version
|
90
|
-
version: 3.0
|
87
|
+
version: 3.8.0
|
88
|
+
- - "~>"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '3.8'
|
91
91
|
type: :development
|
92
92
|
prerelease: false
|
93
93
|
version_requirements: !ruby/object:Gem::Requirement
|
94
94
|
requirements:
|
95
|
-
- - "~>"
|
96
|
-
- !ruby/object:Gem::Version
|
97
|
-
version: '3.0'
|
98
95
|
- - ">="
|
99
96
|
- !ruby/object:Gem::Version
|
100
|
-
version: 3.0
|
97
|
+
version: 3.8.0
|
98
|
+
- - "~>"
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '3.8'
|
101
101
|
- !ruby/object:Gem::Dependency
|
102
102
|
name: simplecov
|
103
103
|
requirement: !ruby/object:Gem::Requirement
|
104
104
|
requirements:
|
105
105
|
- - "~>"
|
106
106
|
- !ruby/object:Gem::Version
|
107
|
-
version: 0.
|
107
|
+
version: 0.17.1
|
108
108
|
type: :development
|
109
109
|
prerelease: false
|
110
110
|
version_requirements: !ruby/object:Gem::Requirement
|
111
111
|
requirements:
|
112
112
|
- - "~>"
|
113
113
|
- !ruby/object:Gem::Version
|
114
|
-
version: 0.
|
114
|
+
version: 0.17.1
|
115
115
|
- !ruby/object:Gem::Dependency
|
116
|
-
name:
|
116
|
+
name: webmock
|
117
117
|
requirement: !ruby/object:Gem::Requirement
|
118
118
|
requirements:
|
119
119
|
- - "~>"
|
120
120
|
- !ruby/object:Gem::Version
|
121
|
-
version: '
|
121
|
+
version: '3.7'
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version:
|
124
|
+
version: 3.7.5
|
125
125
|
type: :development
|
126
126
|
prerelease: false
|
127
127
|
version_requirements: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
129
|
- - "~>"
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
version: '
|
131
|
+
version: '3.7'
|
132
132
|
- - ">="
|
133
133
|
- !ruby/object:Gem::Version
|
134
|
-
version:
|
134
|
+
version: 3.7.5
|
135
135
|
description: Unofficial Ruby Library for OpenDotaAPI. This API provides Dota 2 related
|
136
136
|
data.
|
137
137
|
email:
|
138
|
-
- osyaroslav@gmail.com
|
138
|
+
- osyaroslav@gmail.com
|
139
139
|
executables: []
|
140
140
|
extensions: []
|
141
141
|
extra_rdoc_files: []
|
@@ -192,27 +192,26 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
192
192
|
- !ruby/object:Gem::Version
|
193
193
|
version: '0'
|
194
194
|
requirements: []
|
195
|
-
|
196
|
-
rubygems_version: 2.6.12
|
195
|
+
rubygems_version: 3.0.1
|
197
196
|
signing_key:
|
198
197
|
specification_version: 4
|
199
198
|
summary: Ruby wrapper for Open Dota API
|
200
199
|
test_files:
|
201
|
-
- spec/
|
202
|
-
- spec/
|
203
|
-
- spec/data/leagues.json
|
204
|
-
- spec/data/match.json
|
205
|
-
- spec/data/pro_players.json
|
206
|
-
- spec/data/teams.json
|
207
|
-
- spec/data/unofficial_match.json
|
208
|
-
- spec/lib/open_dota_api/client_spec.rb
|
209
|
-
- spec/lib/open_dota_api/connection_spec.rb
|
210
|
-
- spec/lib/open_dota_api/explorer_spec.rb
|
211
|
-
- spec/lib/open_dota_api/hero_spec.rb
|
200
|
+
- spec/spec_helper.rb
|
201
|
+
- spec/lib/open_dota_api/team_spec.rb
|
212
202
|
- spec/lib/open_dota_api/league_spec.rb
|
203
|
+
- spec/lib/open_dota_api/client_spec.rb
|
213
204
|
- spec/lib/open_dota_api/match_spec.rb
|
205
|
+
- spec/lib/open_dota_api/explorer_spec.rb
|
214
206
|
- spec/lib/open_dota_api/matches/player_spec.rb
|
207
|
+
- spec/lib/open_dota_api/hero_spec.rb
|
208
|
+
- spec/lib/open_dota_api/connection_spec.rb
|
215
209
|
- spec/lib/open_dota_api/pro_player_spec.rb
|
216
|
-
- spec/lib/open_dota_api/team_spec.rb
|
217
210
|
- spec/lib/open_dota_api_spec.rb
|
218
|
-
- spec/
|
211
|
+
- spec/data/heroes.json
|
212
|
+
- spec/data/match.json
|
213
|
+
- spec/data/teams.json
|
214
|
+
- spec/data/pro_players.json
|
215
|
+
- spec/data/unofficial_match.json
|
216
|
+
- spec/data/explorer.json
|
217
|
+
- spec/data/leagues.json
|