dota 0.0.16 → 0.0.17

Sign up to get free protection for your applications and to get access to all the features.
@@ -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"
@@ -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
@@ -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
@@ -12,7 +12,13 @@ module Dota
12
12
  end
13
13
 
14
14
  def image_url(type = :full)
15
- "http://cdn.dota2.com/apps/dota2/images/heroes/#{internal_name}_#{type}.png"
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
@@ -12,6 +12,10 @@ module Dota
12
12
  end
13
13
 
14
14
  def image_url(type = :lg)
15
+ # Possible values for type:
16
+ # :lg - 85x64 PNG image
17
+ # :eg - 27x20 PNG image
18
+
15
19
  "http://cdn.dota2.com/apps/dota2/images/items/#{internal_name}_#{type}.png"
16
20
  end
17
21
 
@@ -0,0 +1,15 @@
1
+ module Dota
2
+ module API
3
+ class Match
4
+ class AbilityUpgrade
5
+ attr_reader :ability, :level, :time
6
+
7
+ def initialize(raw)
8
+ @ability = Ability.new(raw["ability"])
9
+ @level = raw["level"]
10
+ @time = raw["time"]
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -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
- (0..5).map { |i| Item.new(raw["item_#{i}"]) }
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
@@ -0,0 +1,14 @@
1
+ module Dota
2
+ module API
3
+ class Match
4
+ class Unit
5
+ attr_reader :name, :items
6
+
7
+ def initialize(name, items)
8
+ @name = name.titlecase
9
+ @items = items
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,3 +1,3 @@
1
1
  module Dota
2
- VERSION = "0.0.16"
2
+ VERSION = "0.0.17"
3
3
  end
@@ -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
@@ -1,4 +1,4 @@
1
- describe Dota::API::Cosmetic::Rarity do
1
+ RSpec.describe Dota::API::Cosmetic::Rarity do
2
2
  let(:rarity) do
3
3
  VCR.use_cassette("GetRarities") do
4
4
  test_client.cosmetic_rarities.last
@@ -1,4 +1,4 @@
1
- describe Dota::API::Friend do
1
+ RSpec.describe Dota::API::Friend do
2
2
  let(:friend) do
3
3
  VCR.use_cassette("GetFriendList") do
4
4
  test_client.friends(sample_user_id).first
@@ -1,4 +1,4 @@
1
- describe Dota::API::Hero do
1
+ RSpec.describe Dota::API::Hero do
2
2
  let(:hero) { described_class.new(69) }
3
3
 
4
4
  specify ".all" do
@@ -1,4 +1,4 @@
1
- describe Dota::API::Item do
1
+ RSpec.describe Dota::API::Item do
2
2
  let(:item) { described_class.new(1) }
3
3
 
4
4
  specify ".all" do
@@ -1,4 +1,4 @@
1
- describe Dota::API::League do
1
+ RSpec.describe Dota::API::League do
2
2
  let(:league) do
3
3
  VCR.use_cassette("GetLeagueListing") do
4
4
  test_client.leagues.first
@@ -1,4 +1,4 @@
1
- describe Dota::API::LiveMatch::Player do
1
+ RSpec.describe Dota::API::LiveMatch::Player do
2
2
  let(:live_match) do
3
3
  VCR.use_cassette("GetLiveLeagueGames") do
4
4
  test_client.live_matches.first
@@ -1,4 +1,4 @@
1
- describe Dota::API::LiveMatch::Side do
1
+ RSpec.describe Dota::API::LiveMatch::Side do
2
2
  let(:live_match) do
3
3
  VCR.use_cassette("GetLiveLeagueGames") do
4
4
  test_client.live_matches.first
@@ -1,4 +1,4 @@
1
- describe Dota::API::LiveMatch do
1
+ RSpec.describe Dota::API::LiveMatch do
2
2
  let(:live_match) do
3
3
  VCR.use_cassette("GetLiveLeagueGames") do
4
4
  test_client.live_matches.first
@@ -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,4 +1,4 @@
1
- describe Dota::API::Match::Draft do
1
+ RSpec.describe Dota::API::Match::Draft do
2
2
  let(:draft) do
3
3
  VCR.use_cassette("GetMatchDetails") do
4
4
  test_client
@@ -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("GetMatchDetails") do
4
- test_client.matches(sample_match_id)
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.radiant.players.first }
7
+ let(:player) { match.dire.players[1] }
8
8
 
9
9
  specify "#id" do
10
- expect(player.id).to eq 98887913
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 1
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 11
29
+ expect(player.level).to eq 17
30
30
  end
31
31
 
32
32
  specify "#kills" do
33
- expect(player.kills).to eq 2
33
+ expect(player.kills).to eq 7
34
34
  end
35
35
 
36
36
  specify "#deaths" do
37
- expect(player.deaths).to eq 1
37
+ expect(player.deaths).to eq 0
38
38
  end
39
39
 
40
40
  specify "#assists" do
41
- expect(player.assists).to eq 13
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
45
+ expect(player.last_hits).to eq 240
46
46
  end
47
47
 
48
48
  specify "#denies" do
49
- expect(player.denies).to eq 0
49
+ expect(player.denies).to eq 6
50
50
  end
51
51
 
52
52
  specify "#gold" do
53
- expect(player.gold).to eq 649
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 6670
57
+ expect(player.gold_spent).to eq 19120
58
58
  end
59
59
 
60
60
  specify "#gpm" do
61
- expect(player.gpm).to eq 437
61
+ expect(player.gpm).to eq 660
62
62
  end
63
63
 
64
64
  specify "#xpm" do
65
- expect(player.xpm).to eq 460
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 3577
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 153
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 526
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
@@ -1,4 +1,4 @@
1
- describe Dota::API::Match::Side do
1
+ RSpec.describe Dota::API::Match::Side do
2
2
  let(:match) do
3
3
  VCR.use_cassette("GetMatchDetails") do
4
4
  test_client.matches(sample_match_id)
@@ -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