open_dota_api 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +22 -0
- data/lib/open_dota_api.rb +10 -0
- data/lib/open_dota_api/client.rb +47 -0
- data/lib/open_dota_api/connection.rb +12 -0
- data/lib/open_dota_api/entities/instantiable.rb +15 -0
- data/lib/open_dota_api/entity.rb +16 -0
- data/lib/open_dota_api/hero.rb +37 -0
- data/lib/open_dota_api/league.rb +29 -0
- data/lib/open_dota_api/match.rb +70 -0
- data/lib/open_dota_api/matches/player.rb +92 -0
- data/lib/open_dota_api/team.rb +37 -0
- data/lib/open_dota_api/version.rb +3 -0
- data/spec/data/heroes.json +1580 -0
- data/spec/data/leagues.json +11559 -0
- data/spec/data/match.json +16857 -0
- data/spec/data/teams.json +55298 -0
- data/spec/lib/open_dota_api/client_spec.rb +89 -0
- data/spec/lib/open_dota_api/connection_spec.rb +23 -0
- data/spec/lib/open_dota_api/hero_spec.rb +58 -0
- data/spec/lib/open_dota_api/league_spec.rb +48 -0
- data/spec/lib/open_dota_api/match_spec.rb +99 -0
- data/spec/lib/open_dota_api/matches/player_spec.rb +125 -0
- data/spec/lib/open_dota_api/team_spec.rb +58 -0
- data/spec/lib/open_dota_api_spec.rb +11 -0
- data/spec/spec_helper.rb +23 -0
- metadata +181 -0
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OpenDotaApi::Client do
|
4
|
+
|
5
|
+
let(:client) { described_class.new }
|
6
|
+
let(:endpoint) { }
|
7
|
+
let(:match_id) { 3149215336 }
|
8
|
+
let(:leagues_file) { File.read('spec/data/leagues.json') }
|
9
|
+
let(:teams_file) { File.read('spec/data/teams.json') }
|
10
|
+
let(:match_file) { File.read('spec/data/match.json') }
|
11
|
+
let(:heroes_file) { File.read('spec/data/heroes.json') }
|
12
|
+
let(:data_file) { }
|
13
|
+
let(:headers) do
|
14
|
+
{
|
15
|
+
"content-type"=>["application/json; charset=utf-8"]
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
let(:response_json) { JSON.parse(data_file) }
|
20
|
+
let(:expected_leagues) { OpenDotaApi::League.instantiate(response_json) }
|
21
|
+
let(:expected_teams) { OpenDotaApi::Team.instantiate(response_json) }
|
22
|
+
let(:expected_match) { OpenDotaApi::Match.new(response_json) }
|
23
|
+
let(:expected_heroes) { OpenDotaApi::Hero.instantiate(response_json) }
|
24
|
+
|
25
|
+
before do
|
26
|
+
stub_request(:get, "http://api.opendota.com/api/#{endpoint}/").
|
27
|
+
with(headers: {'Accept': '*/*', 'Accept-Encoding': 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent': 'Ruby'}).
|
28
|
+
to_return(status: 200, body: data_file, headers: headers)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'returns interface' do
|
32
|
+
expect(OpenDotaApi::Client::INTERFACE).to eq 'api'
|
33
|
+
end
|
34
|
+
|
35
|
+
describe 'default attributes' do
|
36
|
+
describe '#leagues' do
|
37
|
+
let(:endpoint) { OpenDotaApi::League::ENDPOINT }
|
38
|
+
let(:data_file) { leagues_file }
|
39
|
+
|
40
|
+
it 'returns array of objects' do
|
41
|
+
expect(client.leagues.all? { |league| league.kind_of? OpenDotaApi::League }).to be_truthy
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'returns list' do
|
45
|
+
expect(client.leagues.to_deep_hash).to eq expected_leagues.to_deep_hash
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '#teams' do
|
50
|
+
let(:endpoint) { OpenDotaApi::Team::ENDPOINT }
|
51
|
+
let(:data_file) { teams_file }
|
52
|
+
|
53
|
+
it 'returns array of objects' do
|
54
|
+
expect(client.teams.all? { |team| team.kind_of? OpenDotaApi::Team }).to be_truthy
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'returns list' do
|
58
|
+
expect(client.teams.to_deep_hash).to eq expected_teams.to_deep_hash
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe '#matches' do
|
63
|
+
let(:endpoint) { "#{OpenDotaApi::Match::ENDPOINT}/#{match_id}" }
|
64
|
+
let(:data_file) { match_file }
|
65
|
+
|
66
|
+
it 'returns object' do
|
67
|
+
expect(client.matches(match_id).kind_of? OpenDotaApi::Match).to be_truthy
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'returns match' do
|
71
|
+
expect(client.matches(match_id).to_deep_hash).to eq expected_match.to_deep_hash
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
describe '#heroes' do
|
77
|
+
let(:endpoint) { "#{OpenDotaApi::Hero::ENDPOINT}" }
|
78
|
+
let(:data_file) { heroes_file }
|
79
|
+
|
80
|
+
it 'returns array of objects' do
|
81
|
+
expect(client.heroes.all? { |hero| hero.kind_of? OpenDotaApi::Hero }).to be_truthy
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'returns list' do
|
85
|
+
expect(client.heroes.to_deep_hash).to eq expected_heroes.to_deep_hash
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OpenDotaApi::Connection do
|
4
|
+
describe 'default attributes' do
|
5
|
+
let(:pathname) { '/' }
|
6
|
+
|
7
|
+
it 'includes httparty methods' do
|
8
|
+
allow(OpenDotaApi::Connection).to receive(:get)
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'returns response object' do
|
12
|
+
stub_request(:get, "http://api.opendota.com/").
|
13
|
+
with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
|
14
|
+
to_return(status: 200, body: "", headers: {})
|
15
|
+
|
16
|
+
expect(OpenDotaApi::Connection.get(pathname).class).to eq HTTParty::Response
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'must have the base url set to Steam endpoint' do
|
20
|
+
expect(OpenDotaApi::Connection.base_uri).to eq 'http://api.opendota.com'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OpenDotaApi::Hero do
|
4
|
+
let(:id) { 1 }
|
5
|
+
let(:name) { 'npc_dota_hero_antimage' }
|
6
|
+
let(:localized_name) { 'Anti-Mage' }
|
7
|
+
let(:primary_attr) { 'agi' }
|
8
|
+
let(:attack_type) { 'Melee' }
|
9
|
+
let(:roles) { %w(Carry Escape Nuker) }
|
10
|
+
let(:legs) { 2 }
|
11
|
+
|
12
|
+
let(:heroes_file) { File.read('spec/data/heroes.json') }
|
13
|
+
let(:response_json) { JSON.parse(heroes_file) }
|
14
|
+
let(:heroes) { OpenDotaApi::Hero.instantiate(response_json) }
|
15
|
+
let(:hero) { heroes.first }
|
16
|
+
|
17
|
+
it 'returns endpoint' do
|
18
|
+
expect(described_class::ENDPOINT).to eq 'heroes'
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'inherits entity object' do
|
22
|
+
expect(hero).to be_a OpenDotaApi::Entity
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'is instantiable' do
|
26
|
+
expect(hero).to be_a OpenDotaApi::Entities::Instantiatable
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'default attributes' do
|
30
|
+
it 'returns id' do
|
31
|
+
expect(hero.id).to eq id
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'returns name' do
|
35
|
+
expect(hero.name).to eq name
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'returns localized name' do
|
39
|
+
expect(hero.localized_name).to eq localized_name
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'returns primary attribute' do
|
43
|
+
expect(hero.primary_attr).to eq primary_attr
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'returns attack type' do
|
47
|
+
expect(hero.attack_type).to eq attack_type
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'returns roles' do
|
51
|
+
expect(hero.roles).to eq roles
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'returns legs' do
|
55
|
+
expect(hero.legs).to eq legs
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OpenDotaApi::League do
|
4
|
+
let(:league_id) { 1415 }
|
5
|
+
let(:ticket) { 'econ/leagues/subscriptions_cebu' }
|
6
|
+
let(:banner) { 'econ/leagues/subscriptions_cebu_ingame' }
|
7
|
+
let(:tier) { 'amateur' }
|
8
|
+
let(:name) { 'Dota 2 Cebu League Season 5' }
|
9
|
+
|
10
|
+
let(:leagues_file) { File.read('spec/data/leagues.json') }
|
11
|
+
let(:response_json) { JSON.parse(leagues_file) }
|
12
|
+
let(:leagues) { OpenDotaApi::League.instantiate(response_json) }
|
13
|
+
let(:league) { leagues.first }
|
14
|
+
|
15
|
+
it 'returns endpoint' do
|
16
|
+
expect(described_class::ENDPOINT).to eq 'leagues'
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'inherits entity object' do
|
20
|
+
expect(league).to be_a OpenDotaApi::Entity
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'is instantiable' do
|
24
|
+
expect(league).to be_a OpenDotaApi::Entities::Instantiatable
|
25
|
+
end
|
26
|
+
|
27
|
+
describe 'default attributes' do
|
28
|
+
it 'returns league id' do
|
29
|
+
expect(league.league_id).to eq league_id
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'returns ticket' do
|
33
|
+
expect(league.ticket).to eq ticket
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'returns banner' do
|
37
|
+
expect(league.banner).to eq banner
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'returns tier' do
|
41
|
+
expect(league.tier).to eq tier
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'returns name' do
|
45
|
+
expect(league.name).to eq name
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OpenDotaApi::Match do
|
4
|
+
let(:match_id) { 3149215336 }
|
5
|
+
let(:start_time) { 1493566333 }
|
6
|
+
let(:duration) { 2109 }
|
7
|
+
let(:series_id) { 135248 }
|
8
|
+
let(:series_type) { 2 }
|
9
|
+
let(:radiant_team_id) { 2586976 }
|
10
|
+
let(:dire_team_id) { 1883502 }
|
11
|
+
let(:match_seq_num) { 2750393746 }
|
12
|
+
let(:league_id) { 5157 }
|
13
|
+
let(:first_blood_time) { 53 }
|
14
|
+
let(:winner) { :dire }
|
15
|
+
let(:cluster) { 136 }
|
16
|
+
let(:replay_salt) { 565926067 }
|
17
|
+
let(:replay_url) { 'http://replay136.valve.net/570/3149215336_565926067.dem.bz2' }
|
18
|
+
let(:players_length) { 10 }
|
19
|
+
let(:player_class) { OpenDotaApi::Match::Player }
|
20
|
+
|
21
|
+
let(:match_file) { File.read('spec/data/match.json') }
|
22
|
+
let(:response_json) { JSON.parse(match_file) }
|
23
|
+
let(:match) { OpenDotaApi::Match.new(response_json) }
|
24
|
+
|
25
|
+
it 'returns endpoint' do
|
26
|
+
expect(described_class::ENDPOINT).to eq 'matches'
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'inherits entity object' do
|
30
|
+
expect(match).to be_a OpenDotaApi::Entity
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'is instantiable' do
|
34
|
+
expect(match).to_not be_a OpenDotaApi::Entities::Instantiatable
|
35
|
+
end
|
36
|
+
|
37
|
+
describe 'default attributes' do
|
38
|
+
it 'returns match id' do
|
39
|
+
expect(match.match_id).to eq match_id
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'returns start time' do
|
43
|
+
expect(match.start_time).to eq start_time
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'returns duration' do
|
47
|
+
expect(match.duration).to eq duration
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'returns series id' do
|
51
|
+
expect(match.series_id).to eq series_id
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'returns series type' do
|
55
|
+
expect(match.series_type).to eq series_type
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'returns radiant team id' do
|
59
|
+
expect(match.radiant_team_id).to eq radiant_team_id
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'returns dire team id' do
|
63
|
+
expect(match.dire_team_id).to eq dire_team_id
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'returns match sequence number' do
|
67
|
+
expect(match.match_seq_num).to eq match_seq_num
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'returns league id' do
|
71
|
+
expect(match.league_id).to eq league_id
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'returns first blood time' do
|
75
|
+
expect(match.first_blood_time).to eq first_blood_time
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'returns winner' do
|
79
|
+
expect(match.winner).to eq winner
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'returns cluster' do
|
83
|
+
expect(match.cluster).to eq cluster
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'returns replay salt' do
|
87
|
+
expect(match.replay_salt).to eq replay_salt
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'returns replay url' do
|
91
|
+
expect(match.replay_url).to eq replay_url
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'returns players' do
|
95
|
+
expect(match.players.length).to eq players_length
|
96
|
+
expect(match.players.all? { |player| player.kind_of? player_class }).to be_truthy
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OpenDotaApi::Matches::Player do
|
4
|
+
let(:match_id) { 3149215336 }
|
5
|
+
let(:player_slot) { 0 }
|
6
|
+
let(:account_id) { 94155156 }
|
7
|
+
let(:assists) { 13 }
|
8
|
+
let(:camps_stacked) { 4 }
|
9
|
+
let(:deaths) { 7 }
|
10
|
+
let(:denies) { 1 }
|
11
|
+
let(:gold_per_min) { 329 }
|
12
|
+
let(:hero_id) { 110 }
|
13
|
+
let(:kills) { 6 }
|
14
|
+
let(:obs_placed) { 7 }
|
15
|
+
let(:sen_placed) { 19 }
|
16
|
+
let(:rune_pickups) { 9 }
|
17
|
+
let(:stuns) { 0 }
|
18
|
+
let(:xp_per_min) { 385 }
|
19
|
+
let(:name) { 'Fly' }
|
20
|
+
let(:side) { :radiant }
|
21
|
+
let(:kda) { 2 }
|
22
|
+
let(:tower_kills) { 0 }
|
23
|
+
let(:roshan_kills) { 0 }
|
24
|
+
let(:hero_healing) { 606 }
|
25
|
+
|
26
|
+
let(:match_file) { File.read('spec/data/match.json') }
|
27
|
+
let(:response_json) { JSON.parse(match_file) }
|
28
|
+
let(:match) { OpenDotaApi::Match.new(response_json) }
|
29
|
+
let(:players) { match.players }
|
30
|
+
let(:player) { players.first }
|
31
|
+
|
32
|
+
it 'inherits entity object' do
|
33
|
+
expect(player).to be_a OpenDotaApi::Entity
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'is instantiable' do
|
37
|
+
expect(player).to_not be_a OpenDotaApi::Entities::Instantiatable
|
38
|
+
end
|
39
|
+
|
40
|
+
describe 'default attributes' do
|
41
|
+
it 'returns match id' do
|
42
|
+
expect(player.match_id).to eq match_id
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'returns player slot' do
|
46
|
+
expect(player.player_slot).to eq player_slot
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'returns account id' do
|
50
|
+
expect(player.account_id).to eq account_id
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'returns assists' do
|
54
|
+
expect(player.assists).to eq assists
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'returns camps stacked' do
|
58
|
+
expect(player.camps_stacked).to eq camps_stacked
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'returns deaths' do
|
62
|
+
expect(player.deaths).to eq deaths
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'returns denies' do
|
66
|
+
expect(player.denies).to eq denies
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'returns gold per minute' do
|
70
|
+
expect(player.gold_per_min).to eq gold_per_min
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'returns hero id' do
|
74
|
+
expect(player.hero_id).to eq hero_id
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'returns kills' do
|
78
|
+
expect(player.kills).to eq kills
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'returns observer wards placed' do
|
82
|
+
expect(player.obs_placed).to eq obs_placed
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'returns sentry wards placed' do
|
86
|
+
expect(player.sen_placed).to eq sen_placed
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'returns rune pickups' do
|
90
|
+
expect(player.rune_pickups).to eq rune_pickups
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'returns stuns' do
|
94
|
+
expect(player.stuns).to eq stuns
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'returns experience points per minute' do
|
98
|
+
expect(player.xp_per_min).to eq xp_per_min
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'returns name' do
|
102
|
+
expect(player.name).to eq name
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'returns side' do
|
106
|
+
expect(player.side).to eq side
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'returns kda' do
|
110
|
+
expect(player.kda).to eq kda
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'returns tower kills' do
|
114
|
+
expect(player.tower_kills).to eq tower_kills
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'returns roshan kills' do
|
118
|
+
expect(player.roshan_kills).to eq roshan_kills
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'returns hero healing' do
|
122
|
+
expect(player.hero_healing).to eq hero_healing
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|