dota 0.0.16 → 0.0.17
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 +4 -4
- data/README.md +35 -2
- data/data/ability.yml +2240 -0
- data/dota.gemspec +1 -0
- data/lib/dota.rb +4 -0
- data/lib/dota/api/ability.rb +33 -0
- data/lib/dota/api/client.rb +11 -7
- data/lib/dota/api/hero.rb +7 -1
- data/lib/dota/api/item.rb +4 -0
- data/lib/dota/api/match/ability_upgrade.rb +15 -0
- data/lib/dota/api/match/player.rb +15 -1
- data/lib/dota/api/match/unit.rb +14 -0
- data/lib/dota/version.rb +1 -1
- data/spec/dota/api/ability_spec.rb +25 -0
- data/spec/dota/api/cosmetic/rarity_spec.rb +1 -1
- data/spec/dota/api/friend_spec.rb +1 -1
- data/spec/dota/api/hero_spec.rb +1 -1
- data/spec/dota/api/item_spec.rb +1 -1
- data/spec/dota/api/league_spec.rb +1 -1
- data/spec/dota/api/live_match/player_spec.rb +1 -1
- data/spec/dota/api/live_match/side_spec.rb +1 -1
- data/spec/dota/api/live_match_spec.rb +1 -1
- data/spec/dota/api/match/ability_upgrade_spec.rb +25 -0
- data/spec/dota/api/match/draft_spec.rb +1 -1
- data/spec/dota/api/match/player_spec.rb +24 -19
- data/spec/dota/api/match/side_spec.rb +1 -1
- data/spec/dota/api/match/unit_spec.rb +21 -0
- data/spec/dota/api/match_spec.rb +1 -1
- data/spec/dota/api/scheduled_match_spec.rb +1 -1
- data/spec/dota/api/team_spec.rb +1 -1
- data/spec/fixtures/vcr_cassettes/GetMatchDetailsUnits.yml +276 -0
- data/spec/spec_helper.rb +4 -0
- metadata +28 -2
data/dota.gemspec
CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_dependency "faraday", "~> 0.9.1"
|
22
22
|
spec.add_dependency "faraday_middleware", "~> 0.9.1"
|
23
|
+
spec.add_dependency "facets", "~> 3.0.0"
|
23
24
|
|
24
25
|
spec.add_development_dependency "rake"
|
25
26
|
spec.add_development_dependency "rspec"
|
data/lib/dota.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'yaml'
|
2
|
+
require 'facets/string/titlecase'
|
2
3
|
|
3
4
|
require 'dota/configuration'
|
4
5
|
require 'dota/version'
|
@@ -23,8 +24,11 @@ require 'dota/api/match'
|
|
23
24
|
require 'dota/api/match/draft'
|
24
25
|
require 'dota/api/match/player'
|
25
26
|
require 'dota/api/match/side'
|
27
|
+
require 'dota/api/match/unit'
|
28
|
+
require 'dota/api/match/ability_upgrade'
|
26
29
|
require 'dota/api/scheduled_match'
|
27
30
|
require 'dota/api/team'
|
31
|
+
require 'dota/api/ability'
|
28
32
|
|
29
33
|
module Dota
|
30
34
|
class << self
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Dota
|
2
|
+
module API
|
3
|
+
class Ability
|
4
|
+
include Utilities::Mapped
|
5
|
+
|
6
|
+
attr_reader :id, :name, :full_name
|
7
|
+
|
8
|
+
def initialize(id)
|
9
|
+
@id = id
|
10
|
+
@internal_name = mapping[id][0]
|
11
|
+
@name = mapping[id][1]
|
12
|
+
@full_name = mapping[id][2]
|
13
|
+
end
|
14
|
+
|
15
|
+
def image_url(type = :lg)
|
16
|
+
# Possible values for type:
|
17
|
+
# :hp1 - 90x90 PNG image
|
18
|
+
# :hp2 - 105x105 PNG image
|
19
|
+
# :lg - 128x128 PNG image
|
20
|
+
|
21
|
+
if internal_name == 'stats'
|
22
|
+
"https://steamcdn-a.akamaihd.net/apps/dota2/images/workshop/itembuilder/stats.png"
|
23
|
+
else
|
24
|
+
"http://cdn.dota2.com/apps/dota2/images/abilities/#{internal_name}_#{type}.png"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
attr_reader :internal_name
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/dota/api/client.rb
CHANGED
@@ -20,6 +20,10 @@ module Dota
|
|
20
20
|
id ? Item.new(id) : Item.all
|
21
21
|
end
|
22
22
|
|
23
|
+
def abilities(id = nil)
|
24
|
+
id ? Ability.new(id) : Ability.all
|
25
|
+
end
|
26
|
+
|
23
27
|
def teams(options = {})
|
24
28
|
if options.is_a?(Integer)
|
25
29
|
id = options
|
@@ -30,7 +34,7 @@ module Dota
|
|
30
34
|
options[:teams_requested] = options.delete(:limit) if options[:limit]
|
31
35
|
|
32
36
|
response = get("IDOTA2Match_570", "GetTeamInfoByTeamID", options)["result"]
|
33
|
-
if response && (teams = response["teams"])
|
37
|
+
if response && (teams = response["teams"] || [])
|
34
38
|
teams.map { |team| Team.new(team) }
|
35
39
|
end
|
36
40
|
end
|
@@ -52,7 +56,7 @@ module Dota
|
|
52
56
|
options[:tournament_games_only] = options.delete(:league_only) if options[:league_only]
|
53
57
|
|
54
58
|
response = get("IDOTA2Match_570", "GetMatchHistory", options)["result"]
|
55
|
-
if response && (matches = response["matches"])
|
59
|
+
if response && (matches = response["matches"] || [])
|
56
60
|
matches.map { |match| Match.new(match) }
|
57
61
|
end
|
58
62
|
end
|
@@ -60,14 +64,14 @@ module Dota
|
|
60
64
|
|
61
65
|
def leagues
|
62
66
|
response = get("IDOTA2Match_570", "GetLeagueListing", language: "en")["result"]
|
63
|
-
if response && (leagues = response["leagues"])
|
67
|
+
if response && (leagues = response["leagues"] || [])
|
64
68
|
leagues.map { |league| League.new(league) }
|
65
69
|
end
|
66
70
|
end
|
67
71
|
|
68
72
|
def live_matches(options = {})
|
69
73
|
response = get("IDOTA2Match_570", "GetLiveLeagueGames", options)["result"]
|
70
|
-
if response && (live_matches = response["games"])
|
74
|
+
if response && (live_matches = response["games"] || [])
|
71
75
|
live_matches.map { |game| LiveMatch.new(game) }
|
72
76
|
end
|
73
77
|
end
|
@@ -77,21 +81,21 @@ module Dota
|
|
77
81
|
options[:date_max] = options.delete(:to) if options[:to]
|
78
82
|
|
79
83
|
response = get("IDOTA2Match_570", "GetScheduledLeagueGames", options)["result"]
|
80
|
-
if response && (scheduled_matches = response["games"])
|
84
|
+
if response && (scheduled_matches = response["games"] || [])
|
81
85
|
scheduled_matches.map { |game| ScheduledMatch.new(game) }
|
82
86
|
end
|
83
87
|
end
|
84
88
|
|
85
89
|
def cosmetic_rarities
|
86
90
|
response = get("IEconDOTA2_570", "GetRarities", language: "en")["result"]
|
87
|
-
if response && (rarities = response["rarities"])
|
91
|
+
if response && (rarities = response["rarities"] || [])
|
88
92
|
rarities.map { |rarity| Cosmetic::Rarity.new(rarity) }
|
89
93
|
end
|
90
94
|
end
|
91
95
|
|
92
96
|
def friends(user_id)
|
93
97
|
response = get("ISteamUser", "GetFriendList", steamid: user_id)["friendslist"]
|
94
|
-
if response && (friends = response["friends"])
|
98
|
+
if response && (friends = response["friends"] || [])
|
95
99
|
friends.map { |friend| Friend.new(friend) }
|
96
100
|
end
|
97
101
|
end
|
data/lib/dota/api/hero.rb
CHANGED
@@ -12,7 +12,13 @@ module Dota
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def image_url(type = :full)
|
15
|
-
|
15
|
+
# Possible values for type:
|
16
|
+
# :full - full quality horizontal portrait (256x114px, PNG)
|
17
|
+
# :lg - large horizontal portrait (205x11px, PNG)
|
18
|
+
# :sb - small horizontal portrait (59x33px, PNG)
|
19
|
+
# :vert - full quality vertical portrait (234x272px, JPEG)
|
20
|
+
|
21
|
+
"http://cdn.dota2.com/apps/dota2/images/heroes/#{internal_name}_#{type}.#{type == :vert ? 'jpg' : 'png'}"
|
16
22
|
end
|
17
23
|
|
18
24
|
private
|
data/lib/dota/api/item.rb
CHANGED
@@ -35,8 +35,22 @@ module Dota
|
|
35
35
|
raw["hero_healing"]
|
36
36
|
end
|
37
37
|
|
38
|
+
def additional_units
|
39
|
+
raw["additional_units"].map { |unit| Unit.new(unit["unitname"], extract_items_from(unit)) }
|
40
|
+
end
|
41
|
+
|
42
|
+
def ability_upgrades
|
43
|
+
raw["ability_upgrades"].map { |ability_upgrade| AbilityUpgrade.new(ability_upgrade) }
|
44
|
+
end
|
45
|
+
|
38
46
|
def items
|
39
|
-
|
47
|
+
extract_items_from raw
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def extract_items_from(obj)
|
53
|
+
(0..5).map { |i| Item.new(obj["item_#{i}"]) }
|
40
54
|
end
|
41
55
|
end
|
42
56
|
end
|
data/lib/dota/version.rb
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
RSpec.describe Dota::API::Ability do
|
2
|
+
let(:ability) { described_class.new(5003) }
|
3
|
+
|
4
|
+
specify ".all" do
|
5
|
+
abilities = described_class.all
|
6
|
+
expect(abilities.first).to be_a described_class
|
7
|
+
expect(abilities.count).to eq 560
|
8
|
+
end
|
9
|
+
|
10
|
+
specify "#id" do
|
11
|
+
expect(ability.id).to eq 5003
|
12
|
+
end
|
13
|
+
|
14
|
+
specify "#name" do
|
15
|
+
expect(ability.name).to eq "Mana Break"
|
16
|
+
end
|
17
|
+
|
18
|
+
specify "#full_name" do
|
19
|
+
expect(ability.full_name).to eq "Antimage Mana Break"
|
20
|
+
end
|
21
|
+
|
22
|
+
specify "#image_url" do
|
23
|
+
expect(ability.image_url).to eq "http://cdn.dota2.com/apps/dota2/images/abilities/antimage_mana_break_lg.png"
|
24
|
+
end
|
25
|
+
end
|
data/spec/dota/api/hero_spec.rb
CHANGED
data/spec/dota/api/item_spec.rb
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
RSpec.describe Dota::API::Match::AbilityUpgrade do
|
2
|
+
let(:ability_upgrade) do
|
3
|
+
VCR.use_cassette("GetMatchDetails") do
|
4
|
+
test_client
|
5
|
+
.matches(sample_match_id)
|
6
|
+
.radiant
|
7
|
+
.players
|
8
|
+
.first
|
9
|
+
.ability_upgrades
|
10
|
+
.last
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
specify "#ability" do
|
15
|
+
expect(ability_upgrade.ability).to be_a Dota::API::Ability
|
16
|
+
end
|
17
|
+
|
18
|
+
specify "#level" do
|
19
|
+
expect(ability_upgrade.level).to eq 11
|
20
|
+
end
|
21
|
+
|
22
|
+
specify "#time" do
|
23
|
+
expect(ability_upgrade.time).to eq 1506
|
24
|
+
end
|
25
|
+
end
|
@@ -1,13 +1,13 @@
|
|
1
|
-
describe Dota::API::Match::Player do
|
1
|
+
RSpec.describe Dota::API::Match::Player do
|
2
2
|
let(:match) do
|
3
|
-
VCR.use_cassette("
|
4
|
-
test_client.matches(
|
3
|
+
VCR.use_cassette("GetMatchDetailsUnits") do
|
4
|
+
test_client.matches(sample_match_id_with_units)
|
5
5
|
end
|
6
6
|
end
|
7
|
-
let(:player) { match.
|
7
|
+
let(:player) { match.dire.players[1] }
|
8
8
|
|
9
9
|
specify "#id" do
|
10
|
-
expect(player.id).to eq
|
10
|
+
expect(player.id).to eq 76482434
|
11
11
|
end
|
12
12
|
|
13
13
|
specify "#hero" do
|
@@ -15,7 +15,7 @@ describe Dota::API::Match::Player do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
specify "#slot" do
|
18
|
-
expect(player.slot).to eq
|
18
|
+
expect(player.slot).to eq 2
|
19
19
|
|
20
20
|
expect(match.radiant.players.map(&:slot)).to eq [1, 2, 3, 4, 5]
|
21
21
|
expect(match.dire.players.map(&:slot)).to eq [1, 2, 3, 4, 5]
|
@@ -26,55 +26,60 @@ describe Dota::API::Match::Player do
|
|
26
26
|
end
|
27
27
|
|
28
28
|
specify "#level" do
|
29
|
-
expect(player.level).to eq
|
29
|
+
expect(player.level).to eq 17
|
30
30
|
end
|
31
31
|
|
32
32
|
specify "#kills" do
|
33
|
-
expect(player.kills).to eq
|
33
|
+
expect(player.kills).to eq 7
|
34
34
|
end
|
35
35
|
|
36
36
|
specify "#deaths" do
|
37
|
-
expect(player.deaths).to eq
|
37
|
+
expect(player.deaths).to eq 0
|
38
38
|
end
|
39
39
|
|
40
40
|
specify "#assists" do
|
41
|
-
expect(player.assists).to eq
|
41
|
+
expect(player.assists).to eq 10
|
42
42
|
end
|
43
43
|
|
44
44
|
specify "#last_hits" do
|
45
|
-
expect(player.last_hits).to eq
|
45
|
+
expect(player.last_hits).to eq 240
|
46
46
|
end
|
47
47
|
|
48
48
|
specify "#denies" do
|
49
|
-
expect(player.denies).to eq
|
49
|
+
expect(player.denies).to eq 6
|
50
50
|
end
|
51
51
|
|
52
52
|
specify "#gold" do
|
53
|
-
expect(player.gold).to eq
|
53
|
+
expect(player.gold).to eq 1938
|
54
54
|
end
|
55
55
|
|
56
56
|
specify "#gold_spent" do
|
57
|
-
expect(player.gold_spent).to eq
|
57
|
+
expect(player.gold_spent).to eq 19120
|
58
58
|
end
|
59
59
|
|
60
60
|
specify "#gpm" do
|
61
|
-
expect(player.gpm).to eq
|
61
|
+
expect(player.gpm).to eq 660
|
62
62
|
end
|
63
63
|
|
64
64
|
specify "#xpm" do
|
65
|
-
expect(player.xpm).to eq
|
65
|
+
expect(player.xpm).to eq 502
|
66
66
|
end
|
67
67
|
|
68
68
|
specify "#hero_damage" do
|
69
|
-
expect(player.hero_damage).to eq
|
69
|
+
expect(player.hero_damage).to eq 12601
|
70
70
|
end
|
71
71
|
|
72
72
|
specify "#tower_damage" do
|
73
|
-
expect(player.tower_damage).to eq
|
73
|
+
expect(player.tower_damage).to eq 10972
|
74
74
|
end
|
75
75
|
|
76
76
|
specify "#hero_healing" do
|
77
|
-
expect(player.hero_healing).to eq
|
77
|
+
expect(player.hero_healing).to eq 0
|
78
|
+
end
|
79
|
+
|
80
|
+
specify "#additional_units" do
|
81
|
+
expect(player.additional_units.count).to eq 1
|
82
|
+
expect(player.additional_units.first).to be_a Dota::API::Match::Unit
|
78
83
|
end
|
79
84
|
|
80
85
|
specify "#items" do
|
@@ -0,0 +1,21 @@
|
|
1
|
+
RSpec.describe Dota::API::Match::Unit do
|
2
|
+
let(:additional_unit) do
|
3
|
+
VCR.use_cassette("GetMatchDetailsUnits") do
|
4
|
+
test_client
|
5
|
+
.matches(sample_match_id_with_units)
|
6
|
+
.dire
|
7
|
+
.players[1]
|
8
|
+
.additional_units.first
|
9
|
+
end
|
10
|
+
end
|
11
|
+
let(:item) { additional_unit.items.first }
|
12
|
+
|
13
|
+
specify "#name" do
|
14
|
+
expect(additional_unit.name).to eq "Spirit Bear"
|
15
|
+
end
|
16
|
+
|
17
|
+
specify "#items" do
|
18
|
+
expect(item).to be_a Dota::API::Item
|
19
|
+
expect(item.name).to eq "Phase Boots"
|
20
|
+
end
|
21
|
+
end
|