dota 0.0.18 → 0.0.19

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2ff7c49731de8c4814a4135dff2de240853f733f
4
- data.tar.gz: 90c8a81064bde49c0e540f9b001ab1c571fbd126
3
+ metadata.gz: d96a945aaf9d39392aa65f1bc19051304bbdd143
4
+ data.tar.gz: d7ac4845c2627e16fa887f91404ca1dc1886caaa
5
5
  SHA512:
6
- metadata.gz: ba9aa6924b85bd9bcca501f3b9c2ab7140a4f5c3cf12ac5a9bed7c802c061f4bd569311b66cfbc1387a139b2a8e9b9718b63fa6a9ae05ec12db980325e38e861
7
- data.tar.gz: 1d307e7401ac6b70b3ddf1f1f1d7d7d04742148fa7d40beec0475f557c97d422747090a4f35615f5d2c929ab2575163eac8b5cd0b33e9e75d3611d7ba7457b79
6
+ metadata.gz: d49d7105f8d74f307580dc5f2a162ffa5c6fdd61130783603ecfeed8a222ca5b27b2c43fb97d1446ced0f30f6dc4104c6a19e0a7dd87d68ef676e5d904769267
7
+ data.tar.gz: 4e52f0ed5b26aa31f2fc8ef2ce943305b26b82ca0fe3a0b0a670404ef5a8ccf72711b085529e86e427b0f384cda4997a634bafca83d87753756ebe91c400b98d
data/README.md CHANGED
@@ -42,6 +42,9 @@ Get your Steam API key [here](http://steamcommunity.com/dev/apikey) and make sur
42
42
  ```ruby
43
43
  Dota.configure do |config|
44
44
  config.api_key = ENV.fetch("STEAM_API_KEY")
45
+
46
+ # Set API version (defaults to "v1")
47
+ # config.api_version = "v1"
45
48
  end
46
49
  ```
47
50
 
@@ -74,7 +77,7 @@ api.matches(789645621) # => A single match - "Newbee vs Vici Gaming"
74
77
  api.matches # => A list of matches
75
78
  api.matches(hero_id: 43) # Allowed options:
76
79
  #
77
- # :hero_id - Integer, With this hero. See Dota::API::Hero::MAPPING
80
+ # :hero_id - Integer, With this hero. See Dota::API::Hero.mapping
78
81
  # :after - Integer, With match IDs equal or greater than this
79
82
  # :player_id - Integer, With this player (32-bit Steam ID)
80
83
  # :league_id - Integer, In this league. Use Dota.leagues to get a list of leagues
@@ -109,6 +112,12 @@ For the unsupported endpoints, you can use `api.get`. For example, the following
109
112
  api.get("IDOTA2Match_570", "GetMatchDetails", match_id: 789645621)
110
113
  ```
111
114
 
115
+ Setting `api_version` here also overrides the current configuration:
116
+
117
+ ```ruby
118
+ api.get("IDOTA2Match_570", "GetMatchDetails", match_id: 789645621, api_version: "v1")
119
+ ```
120
+
112
121
  ### API Objects
113
122
 
114
123
  #### Heroes
@@ -185,7 +194,7 @@ match.drafts # Array[Dota::API::Match::Draft], Picks and bans in the mat
185
194
  draft.order # Integer, 1-20
186
195
  draft.pick? # Boolean, true if the draft is a pick, and not a ban
187
196
  draft.team # Symbol, :radiant or :dire
188
- draft.hero # Dota::API::Hero, Picked or banned hero
197
+ draft.hero # Dota::API::Hero || Dota::API::MissingHero, Picked or banned hero
189
198
  ```
190
199
 
191
200
  #### Live Matches
@@ -239,7 +248,7 @@ radiant.series_wins # Integer, Number of wins in the series so far
239
248
 
240
249
  ```ruby
241
250
  player.id # Integer, 32-bit Steam ID
242
- player.hero # Dota::API::Hero, Player's hero
251
+ player.hero # Dota::API::Hero || Dota::API::MissingHero, Player's hero
243
252
  player.items # Array[Dota::API::Item], Player's inventory (6 items)
244
253
  player.slot # Integer, (1-5)
245
254
  player.level # Integer, The player's level at match end
@@ -27,6 +27,7 @@ require 'dota/api/match/player'
27
27
  require 'dota/api/match/side'
28
28
  require 'dota/api/match/unit'
29
29
  require 'dota/api/match/ability_upgrade'
30
+ require 'dota/api/missing_hero'
30
31
  require 'dota/api/scheduled_match'
31
32
  require 'dota/api/team'
32
33
  require 'dota/api/ability'
@@ -25,7 +25,7 @@ module Dota
25
25
  end
26
26
 
27
27
  def hero
28
- Hero.new(raw["hero_id"])
28
+ Hero.find(raw["hero_id"])
29
29
  end
30
30
 
31
31
  def level
@@ -13,7 +13,7 @@ module Dota
13
13
  end
14
14
 
15
15
  def heroes(id = nil)
16
- id ? Hero.new(id) : Hero.all
16
+ id ? Hero.find(id) : Hero.all
17
17
  end
18
18
 
19
19
  def items(id = nil)
@@ -100,13 +100,14 @@ module Dota
100
100
  end
101
101
  end
102
102
 
103
- def get(interface, method, params = {}, *args)
104
- do_request(method, params, interface, *args)
103
+ def get(interface, method, params = {})
104
+ do_request(method, params, interface)
105
105
  end
106
106
 
107
107
  private
108
108
 
109
- def do_request(method, params, interface = "IDOTA2Match_570", method_version = "V001")
109
+ def do_request(method, params, interface = "IDOTA2Match_570")
110
+ method_version = params.delete(:api_version) || configuration.api_version
110
111
  url = "https://api.steampowered.com/#{interface}/#{method}/#{method_version}/"
111
112
 
112
113
  @faraday = Faraday.new(url) do |faraday|
@@ -5,6 +5,11 @@ module Dota
5
5
 
6
6
  attr_reader :id, :name
7
7
 
8
+ def self.find(id)
9
+ hero = mapping[id]
10
+ hero ? new(id) : Dota::API::MissingHero.new(id)
11
+ end
12
+
8
13
  def initialize(id)
9
14
  @id = id
10
15
  @internal_name = mapping[id][0]
@@ -62,7 +62,7 @@ module Dota
62
62
  end
63
63
 
64
64
  def drafts
65
- @drafts ||= raw["picks_bans"].map do |raw_draft|
65
+ @drafts ||= (raw["picks_bans"] || []).map do |raw_draft|
66
66
  Draft.new(raw_draft)
67
67
  end
68
68
  end
@@ -36,11 +36,15 @@ module Dota
36
36
  end
37
37
 
38
38
  def additional_units
39
- raw["additional_units"].map { |unit| Unit.new(unit["unitname"], extract_items_from(unit)) }
39
+ raw["additional_units"] ?
40
+ raw["additional_units"].map { |unit| Unit.new(unit["unitname"], extract_items_from(unit)) } :
41
+ []
40
42
  end
41
43
 
42
44
  def ability_upgrades
43
- raw["ability_upgrades"].map { |ability_upgrade| AbilityUpgrade.new(ability_upgrade) }
45
+ raw["ability_upgrades"] ?
46
+ raw["ability_upgrades"].map { |ability_upgrade| AbilityUpgrade.new(ability_upgrade) } :
47
+ []
44
48
  end
45
49
 
46
50
  def items
@@ -0,0 +1,13 @@
1
+ module Dota
2
+ module API
3
+ class MissingHero
4
+ attr_reader :id, :name
5
+
6
+ def initialize(id = nil)
7
+ end
8
+
9
+ def image_url(type = nil)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,7 +1,12 @@
1
1
  module Dota
2
2
  class Configuration
3
- OPTIONS = [:api_key].freeze
3
+ DEFAULT_API_VERSION = "v1"
4
+ OPTIONS = [:api_key, :api_version].freeze
4
5
 
5
- attr_accessor :api_key
6
+ attr_accessor :api_key, :api_version
7
+
8
+ def initialize
9
+ @api_version = DEFAULT_API_VERSION
10
+ end
6
11
  end
7
12
  end
@@ -1,3 +1,3 @@
1
1
  module Dota
2
- VERSION = "0.0.18"
2
+ VERSION = "0.0.19"
3
3
  end
@@ -7,6 +7,12 @@ RSpec.describe Dota::API::Hero do
7
7
  expect(heroes.count).to eq 110
8
8
  end
9
9
 
10
+ specify ".find" do
11
+ expect(described_class.find(69)).to be_a Dota::API::Hero
12
+ expect(described_class.find(nil)).to be_a Dota::API::MissingHero
13
+ expect(described_class.find("abc")).to be_a Dota::API::MissingHero
14
+ end
15
+
10
16
  specify "#id" do
11
17
  expect(hero.id).to eq 69
12
18
  end
@@ -17,6 +17,7 @@ RSpec.describe Dota::API::LiveMatch::Player do
17
17
  end
18
18
 
19
19
  specify "#hero" do
20
+ expect(Dota::API::Hero).to receive(:find).and_call_original
20
21
  expect(player.hero).to be_a Dota::API::Hero
21
22
  end
22
23
 
@@ -11,6 +11,7 @@ RSpec.describe Dota::API::Match::Player do
11
11
  end
12
12
 
13
13
  specify "#hero" do
14
+ expect(Dota::API::Hero).to receive(:find).and_call_original
14
15
  expect(player.hero).to be_a Dota::API::Hero
15
16
  end
16
17
 
@@ -29,10 +29,17 @@ RSpec.describe Dota::API::Match do
29
29
  expect(match.mode_id).to eq 2
30
30
  end
31
31
 
32
- specify "#drafts" do
33
- drafts = match.drafts
34
- expect(drafts.count).to eq 20
35
- expect(drafts.first).to be_a Dota::API::Match::Draft
32
+ describe "#drafts" do
33
+ specify "match with drafts" do
34
+ drafts = match.drafts
35
+ expect(drafts.count).to eq 20
36
+ expect(drafts.first).to be_a Dota::API::Match::Draft
37
+ end
38
+
39
+ specify "match without drafts" do
40
+ expect(match.raw).to receive(:[]).with("picks_bans") { nil }
41
+ expect(match.drafts).to eq []
42
+ end
36
43
  end
37
44
 
38
45
  specify "#sequence" do
@@ -0,0 +1,16 @@
1
+ RSpec.describe Dota::API::MissingHero do
2
+ let(:hero) { described_class.new(nil) }
3
+
4
+ specify "#id" do
5
+ expect(hero.id).to eq nil
6
+ end
7
+
8
+ specify "#name" do
9
+ expect(hero.name).to eq nil
10
+ end
11
+
12
+ specify "#image_url" do
13
+ expect(hero.image_url).to eq nil
14
+ expect(hero.image_url(:something)).to eq nil
15
+ end
16
+ end
@@ -1,12 +1,22 @@
1
1
  RSpec.describe Dota do
2
2
  describe "configuration" do
3
3
  it "accepts an api key" do
4
- random_string = SecureRandom.hex
4
+ api_key = SecureRandom.hex
5
5
  Dota.configure do |config|
6
- config.api_key = random_string
6
+ config.api_key = api_key
7
7
  end
8
8
 
9
- expect(Dota.configuration.api_key).to eq random_string
9
+ expect(Dota.configuration.api_key).to eq api_key
10
+ end
11
+
12
+ it "accepts an api version" do
13
+ expect(Dota.configuration.api_version).to eq "v1"
14
+
15
+ Dota.configure do |config|
16
+ config.api_version = "v2"
17
+ end
18
+
19
+ expect(Dota.configuration.api_version).to eq "v2"
10
20
  end
11
21
  end
12
22
 
@@ -207,7 +217,11 @@ RSpec.describe Dota do
207
217
  describe "#get" do
208
218
  it "allows custom API requests" do
209
219
  VCR.use_cassette("GetRarities") do
210
- response = api.get("IEconDOTA2_570", "GetRarities", language: "en")
220
+ # Expect api_version override to work
221
+ api.configuration.api_version = "v99999"
222
+ expect(Faraday).to receive(:new).with(/\/v1/).and_call_original
223
+
224
+ response = api.get("IEconDOTA2_570", "GetRarities", { api_version: "v1", language: "en" })
211
225
  expect(response["result"]["count"]).to eq 8
212
226
  end
213
227
  end
@@ -2,7 +2,7 @@
2
2
  http_interactions:
3
3
  - request:
4
4
  method: get
5
- uri: https://api.steampowered.com/ISteamUser/GetFriendList/V001/?key=<STEAM_API_KEY>&steamid=76561198052976237
5
+ uri: https://api.steampowered.com/ISteamUser/GetFriendList/v1/?key=<STEAM_API_KEY>&steamid=76561198052976237
6
6
  body:
7
7
  encoding: US-ASCII
8
8
  string: ''
@@ -2,7 +2,7 @@
2
2
  http_interactions:
3
3
  - request:
4
4
  method: get
5
- uri: https://api.steampowered.com/IDOTA2Match_570/GetLeagueListing/V001/?key=<STEAM_API_KEY>&language=en
5
+ uri: https://api.steampowered.com/IDOTA2Match_570/GetLeagueListing/v1/?key=<STEAM_API_KEY>&language=en
6
6
  body:
7
7
  encoding: US-ASCII
8
8
  string: ''
@@ -2,7 +2,7 @@
2
2
  http_interactions:
3
3
  - request:
4
4
  method: get
5
- uri: https://api.steampowered.com/IDOTA2Match_570/GetLiveLeagueGames/V001/?key=<STEAM_API_KEY>
5
+ uri: https://api.steampowered.com/IDOTA2Match_570/GetLiveLeagueGames/v1/?key=<STEAM_API_KEY>
6
6
  body:
7
7
  encoding: US-ASCII
8
8
  string: ''
@@ -2,7 +2,7 @@
2
2
  http_interactions:
3
3
  - request:
4
4
  method: get
5
- uri: https://api.steampowered.com/IDOTA2Match_570/GetMatchDetails/V001/?key=<STEAM_API_KEY>&match_id=1430857330
5
+ uri: https://api.steampowered.com/IDOTA2Match_570/GetMatchDetails/v1/?key=<STEAM_API_KEY>&match_id=1430857330
6
6
  body:
7
7
  encoding: US-ASCII
8
8
  string: ''
@@ -2,7 +2,7 @@
2
2
  http_interactions:
3
3
  - request:
4
4
  method: get
5
- uri: https://api.steampowered.com/IDOTA2Match_570/GetMatchHistory/V001/?key=<STEAM_API_KEY>
5
+ uri: https://api.steampowered.com/IDOTA2Match_570/GetMatchHistory/v1/?key=<STEAM_API_KEY>
6
6
  body:
7
7
  encoding: US-ASCII
8
8
  string: ''
@@ -2,7 +2,7 @@
2
2
  http_interactions:
3
3
  - request:
4
4
  method: get
5
- uri: https://api.steampowered.com/IEconDOTA2_570/GetRarities/V001/?key=<STEAM_API_KEY>&language=en
5
+ uri: https://api.steampowered.com/IEconDOTA2_570/GetRarities/v1/?key=<STEAM_API_KEY>&language=en
6
6
  body:
7
7
  encoding: US-ASCII
8
8
  string: ''
@@ -2,7 +2,7 @@
2
2
  http_interactions:
3
3
  - request:
4
4
  method: get
5
- uri: https://api.steampowered.com/IDOTA2Match_570/GetScheduledLeagueGames/V001/?key=<STEAM_API_KEY>
5
+ uri: https://api.steampowered.com/IDOTA2Match_570/GetScheduledLeagueGames/v1/?key=<STEAM_API_KEY>
6
6
  body:
7
7
  encoding: US-ASCII
8
8
  string: ''
@@ -2,7 +2,7 @@
2
2
  http_interactions:
3
3
  - request:
4
4
  method: get
5
- uri: https://api.steampowered.com/IDOTA2Match_570/GetTeamInfoByTeamID/V001/?key=<STEAM_API_KEY>&start_at_team_id=1375614&teams_requested=1
5
+ uri: https://api.steampowered.com/IDOTA2Match_570/GetTeamInfoByTeamID/v1/?key=<STEAM_API_KEY>&start_at_team_id=1375614&teams_requested=1
6
6
  body:
7
7
  encoding: US-ASCII
8
8
  string: ''
@@ -2,7 +2,7 @@
2
2
  http_interactions:
3
3
  - request:
4
4
  method: get
5
- uri: https://api.steampowered.com/IDOTA2Match_570/GetTeamInfoByTeamID/V001/?key=<STEAM_API_KEY>
5
+ uri: https://api.steampowered.com/IDOTA2Match_570/GetTeamInfoByTeamID/v1/?key=<STEAM_API_KEY>
6
6
  body:
7
7
  encoding: US-ASCII
8
8
  string: ''
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dota
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.18
4
+ version: 0.0.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vinni Carlo Caños
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-17 00:00:00.000000000 Z
11
+ date: 2015-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -205,6 +205,7 @@ files:
205
205
  - lib/dota/api/match/player.rb
206
206
  - lib/dota/api/match/side.rb
207
207
  - lib/dota/api/match/unit.rb
208
+ - lib/dota/api/missing_hero.rb
208
209
  - lib/dota/api/scheduled_match.rb
209
210
  - lib/dota/api/team.rb
210
211
  - lib/dota/configuration.rb
@@ -226,6 +227,7 @@ files:
226
227
  - spec/dota/api/match/side_spec.rb
227
228
  - spec/dota/api/match/unit_spec.rb
228
229
  - spec/dota/api/match_spec.rb
230
+ - spec/dota/api/missing_hero_spec.rb
229
231
  - spec/dota/api/scheduled_match_spec.rb
230
232
  - spec/dota/api/team_spec.rb
231
233
  - spec/dota_spec.rb
@@ -280,6 +282,7 @@ test_files:
280
282
  - spec/dota/api/match/side_spec.rb
281
283
  - spec/dota/api/match/unit_spec.rb
282
284
  - spec/dota/api/match_spec.rb
285
+ - spec/dota/api/missing_hero_spec.rb
283
286
  - spec/dota/api/scheduled_match_spec.rb
284
287
  - spec/dota/api/team_spec.rb
285
288
  - spec/dota_spec.rb