dota 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ad118a276cb0f8883e5072b9c41cc0a98767dc93
4
- data.tar.gz: 5ccf4337d2d9c333d92fa58508e4f80dcdf7a9b2
3
+ metadata.gz: 13969c4e3573f338e6b8b08a86f69c8c2809ff8a
4
+ data.tar.gz: 2d53b80d2477534ebfd99822000a43cf38761da4
5
5
  SHA512:
6
- metadata.gz: f63a7ae4e6cd23a9f6489a2e1d92ae312565ca05edce17465265c842a8747d0b6a06bced04929987077470371948e0acef9e24be947a39351c38f6fbbc2377b8
7
- data.tar.gz: c3107344c0616c4c39f9abcac67fd86325411f4c79e684853149dc863e12ce3dd2afcf10a792f8572b41dfcdd641c7abee19431e91063d3c861a96ab71cbf535
6
+ metadata.gz: f0810e4563f659467a8c7392c66f1cd5f17fc71f9ef67b8424522ec3b77abd23e5f75759fe5ab68ad04015629c57ed47158cf09dcdc59701fc09c1bd07e201b0
7
+ data.tar.gz: 1a0de2076dbe4f5cce57d52ee1a3dc2dc88f6ee19c3a12baa1e1bb697ed671ff370ed9cd02a00c8e7cf5548f2595bfcd5ad1a2f3931eb1cd7ea189a272d364e0
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # Dota
2
2
 
3
- The Dota gem can be used integration with the Dota 2 WebAPI.
3
+ Dota is a Ruby client for the [Dota 2 WebAPI](https://wiki.teamfortress.com/wiki/WebAPI#Dota_2). It provides an easy way to access matches, players, heroes, items, and other public Dota 2 objects in an opinionated manner.
4
+
5
+ This gem is in alpha, keep that in mind when upgrading. Documentation is also still lacking. In the meantime, you can do `SomeClass.instance_methods(false)` to see what methods are exposed. See [Core Classes](#core-classes) for more info.
4
6
 
5
7
  ## Installation
6
8
 
@@ -22,13 +24,57 @@ Or install it yourself as:
22
24
 
23
25
  ```ruby
24
26
  Dota.configure do |config|
25
- config.api_key = "STEAM_API_KEY"
27
+ config.api_key = "YOUR_STEAM_API_KEY"
26
28
  end
29
+
30
+ api = Dota.api
31
+ ```
32
+
33
+ Get your Steam API key [here](http://steamcommunity.com/dev/apikey). What follows is a list of API methods supported by the gem:
34
+
35
+ #### Get a single match
36
+
37
+ Returns an instance of `Dota::API::Match`.
38
+
39
+ ```ruby
40
+ api.match(MATCH_ID)
41
+ ```
42
+
43
+ ## API Objects
44
+
45
+ Only for reference. You won't need to instantiate on these classes directly and it's not advisable to do so as the API might change anytime. Using `Dota.api` alone should be enough in most cases.
46
+
47
+ ### Dota::API::Item
48
+
49
+ ```ruby
50
+ item.id # => 114
51
+ item.name # => "Heart of Tarrasque"
52
+ item.image_url # => "http://cdn.dota2.com/apps/dota2/images/items/heart_lg.png"
53
+ ```
54
+
55
+ ### Dota::API::Hero
56
+
57
+ ```ruby
58
+ hero.id # => 43
59
+ hero.name # => "Death Prophet"
60
+ hero.image_url # => "http://cdn.dota2.com/apps/dota2/images/heroes/death_prophet_full.png"
61
+ ```
62
+
63
+ ### Dota::API::Match
64
+
65
+ ```ruby
66
+ XXX: TODO
67
+ ```
68
+
69
+ ###Dota::API::Match::Player
70
+
71
+ ```ruby
72
+ XXX: TODO
27
73
  ```
28
74
 
29
75
  ## Contributing
30
76
 
31
- 1. Fork it ( https://github.com/[my-github-username]/dota/fork )
77
+ 1. [Fork It](https://github.com/vinnicc/dota/fork)
32
78
  2. Create your feature branch (`git checkout -b my-new-feature`)
33
79
  3. Commit your changes (`git commit -am 'Add some feature'`)
34
80
  4. Push to the branch (`git push origin my-new-feature`)
@@ -4,6 +4,7 @@ require 'dota/version'
4
4
  require 'dota/utils/inspect'
5
5
 
6
6
  require 'dota/api/client'
7
+ require 'dota/api/hero'
7
8
  require 'dota/api/item'
8
9
  require 'dota/api/match'
9
10
  require 'dota/api/match/player'
@@ -0,0 +1,132 @@
1
+ module Dota
2
+ module API
3
+ class Hero
4
+ MAPPING = {
5
+ 1 => ["antimage", "Anti-Mage"],
6
+ 2 => ["axe", "Axe"],
7
+ 3 => ["bane", "Bane"],
8
+ 4 => ["bloodseeker", "Bloodseeker"],
9
+ 5 => ["crystal_maiden", "Crystal Maiden"],
10
+ 6 => ["drow_ranger", "Drow Ranger"],
11
+ 7 => ["earthshaker", "Earthshaker"],
12
+ 8 => ["juggernaut", "Juggernaut"],
13
+ 9 => ["mirana", "Mirana"],
14
+ 10 => ["morphling", "Morphling"],
15
+ 11 => ["nevermore", "Shadow Fiend"],
16
+ 12 => ["phantom_lancer", "Phantom Lancer"],
17
+ 13 => ["puck", "Puck"],
18
+ 14 => ["pudge", "Pudge"],
19
+ 15 => ["razor", "Razor"],
20
+ 16 => ["sand_king", "Sand King"],
21
+ 17 => ["storm_spirit", "Storm Spirit"],
22
+ 18 => ["sven", "Sven"],
23
+ 19 => ["tiny", "Tiny"],
24
+ 20 => ["vengefulspirit", "Vengeful Spirit"],
25
+ 21 => ["windrunner", "Windranger"],
26
+ 22 => ["zuus", "Zeus"],
27
+ 23 => ["kunkka", "Kunkka"],
28
+ 25 => ["lina", "Lina"],
29
+ 26 => ["lion", "Lion"],
30
+ 27 => ["shadow_shaman", "Shadow Shaman"],
31
+ 28 => ["slardar", "Slardar"],
32
+ 29 => ["tidehunter", "Tidehunter"],
33
+ 30 => ["witch_doctor", "Witch Doctor"],
34
+ 31 => ["lich", "Lich"],
35
+ 32 => ["riki", "Riki"],
36
+ 33 => ["enigma", "Enigma"],
37
+ 34 => ["tinker", "Tinker"],
38
+ 35 => ["sniper", "Sniper"],
39
+ 36 => ["necrolyte", "Necrophos"],
40
+ 37 => ["warlock", "Warlock"],
41
+ 38 => ["beastmaster", "Beastmaster"],
42
+ 39 => ["queenofpain", "Queen of Pain"],
43
+ 40 => ["venomancer", "Venomancer"],
44
+ 41 => ["faceless_void", "Faceless Void"],
45
+ 42 => ["skeleton_king", "Wraith King"],
46
+ 43 => ["death_prophet", "Death Prophet"],
47
+ 44 => ["phantom_assassin", "Phantom Assassin"],
48
+ 45 => ["pugna", "Pugna"],
49
+ 46 => ["templar_assassin", "Templar Assassin"],
50
+ 47 => ["viper", "Viper"],
51
+ 48 => ["luna", "Luna"],
52
+ 49 => ["dragon_knight", "Dragon Knight"],
53
+ 50 => ["dazzle", "Dazzle"],
54
+ 51 => ["rattletrap", "Clockwerk"],
55
+ 52 => ["leshrac", "Leshrac"],
56
+ 53 => ["furion", "Nature's Prophet"],
57
+ 54 => ["life_stealer", "Lifestealer"],
58
+ 55 => ["dark_seer", "Dark Seer"],
59
+ 56 => ["clinkz", "Clinkz"],
60
+ 57 => ["omniknight", "Omniknight"],
61
+ 58 => ["enchantress", "Enchantress"],
62
+ 59 => ["huskar", "Huskar"],
63
+ 60 => ["night_stalker", "Night Stalker"],
64
+ 61 => ["broodmother", "Broodmother"],
65
+ 62 => ["bounty_hunter", "Bounty Hunter"],
66
+ 63 => ["weaver", "Weaver"],
67
+ 64 => ["jakiro", "Jakiro"],
68
+ 65 => ["batrider", "Batrider"],
69
+ 66 => ["chen", "Chen"],
70
+ 67 => ["spectre", "Spectre"],
71
+ 68 => ["ancient_apparition", "Ancient Apparition"],
72
+ 69 => ["doom_bringer", "Doom"],
73
+ 70 => ["ursa", "Ursa"],
74
+ 71 => ["spirit_breaker", "Spirit Breaker"],
75
+ 72 => ["gyrocopter", "Gyrocopter"],
76
+ 73 => ["alchemist", "Alchemist"],
77
+ 74 => ["invoker", "Invoker"],
78
+ 75 => ["silencer", "Silencer"],
79
+ 76 => ["obsidian_destroyer", "Outworld Devourer"],
80
+ 77 => ["lycan", "Lycan"],
81
+ 78 => ["brewmaster", "Brewmaster"],
82
+ 79 => ["shadow_demon", "Shadow Demon"],
83
+ 80 => ["lone_druid", "Lone Druid"],
84
+ 81 => ["chaos_knight", "Chaos Knight"],
85
+ 82 => ["meepo", "Meepo"],
86
+ 83 => ["treant", "Treant Protector"],
87
+ 84 => ["ogre_magi", "Ogre Magi"],
88
+ 85 => ["undying", "Undying"],
89
+ 86 => ["rubick", "Rubick"],
90
+ 87 => ["disruptor", "Disruptor"],
91
+ 88 => ["nyx_assassin", "Nyx Assassin"],
92
+ 89 => ["naga_siren", "Naga Siren"],
93
+ 90 => ["keeper_of_the_light", "Keeper of the Light"],
94
+ 91 => ["wisp", "Io"],
95
+ 92 => ["visage", "Visage"],
96
+ 93 => ["slark", "Slark"],
97
+ 94 => ["medusa", "Medusa"],
98
+ 95 => ["troll_warlord", "Troll Warlord"],
99
+ 96 => ["centaur", "Centaur Warrunner"],
100
+ 97 => ["magnataur", "Magnus"],
101
+ 98 => ["shredder", "Timbersaw"],
102
+ 99 => ["bristleback", "Bristleback"],
103
+ 100 => ["tusk", "Tusk"],
104
+ 101 => ["skywrath_mage", "Skywrath Mage"],
105
+ 102 => ["abaddon", "Abaddon"],
106
+ 103 => ["elder_titan", "Elder Titan"],
107
+ 104 => ["legion_commander", "Legion Commander"],
108
+ 105 => ["techies", "Techies"],
109
+ 106 => ["ember_spirit", "Ember Spirit"],
110
+ 107 => ["earth_spirit", "Earth Spirit"],
111
+ 109 => ["terrorblade", "Terrorblade"],
112
+ 110 => ["phoenix", "Phoenix"]
113
+ }.freeze
114
+
115
+ attr_reader :id, :name
116
+
117
+ def initialize(id)
118
+ @id = id
119
+ @internal_name = MAPPING[id][0]
120
+ @name = MAPPING[id][1]
121
+ end
122
+
123
+ def image_url(type = :full)
124
+ "http://cdn.dota2.com/apps/dota2/images/heroes/#{internal_name}_#{type}.png"
125
+ end
126
+
127
+ private
128
+
129
+ attr_reader :internal_name
130
+ end
131
+ end
132
+ end
@@ -247,6 +247,10 @@ module Dota
247
247
  @id = id
248
248
  @name = MAPPING[id]
249
249
  end
250
+
251
+ def image_url(type = :lg)
252
+ "http://cdn.dota2.com/apps/dota2/images/items/#{name}_#{type}.png"
253
+ end
250
254
  end
251
255
  end
252
256
  end
@@ -27,6 +27,10 @@ module Dota
27
27
  end
28
28
  end
29
29
 
30
+ def hero
31
+ Hero.new(raw["hero_id"])
32
+ end
33
+
30
34
  def level
31
35
  raw["level"]
32
36
  end
@@ -1,3 +1,3 @@
1
1
  module Dota
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,19 @@
1
+ describe Dota::API::Hero do
2
+ let(:item) do
3
+ VCR.use_cassette("GetMatchDetails") do
4
+ test_client.match(sample_match_id).players.first.hero
5
+ end
6
+ end
7
+
8
+ specify "#id" do
9
+ expect(item.id).to eq 69
10
+ end
11
+
12
+ specify "#name" do
13
+ expect(item.name).to eq "Doom"
14
+ end
15
+
16
+ specify "#image_url" do
17
+ expect(item.image_url).to eq "http://cdn.dota2.com/apps/dota2/images/heroes/doom_bringer_full.png"
18
+ end
19
+ end
@@ -12,4 +12,8 @@ describe Dota::API::Item do
12
12
  specify "#name" do
13
13
  expect(item.name).to eq "blink"
14
14
  end
15
+
16
+ specify "#image_url" do
17
+ expect(item.image_url).to eq "http://cdn.dota2.com/apps/dota2/images/items/blink_lg.png"
18
+ end
15
19
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dota
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vinni Carlo Caños
@@ -153,12 +153,14 @@ files:
153
153
  - dota.gemspec
154
154
  - lib/dota.rb
155
155
  - lib/dota/api/client.rb
156
+ - lib/dota/api/hero.rb
156
157
  - lib/dota/api/item.rb
157
158
  - lib/dota/api/match.rb
158
159
  - lib/dota/api/match/player.rb
159
160
  - lib/dota/configuration.rb
160
161
  - lib/dota/utils/inspect.rb
161
162
  - lib/dota/version.rb
163
+ - spec/dota/api/hero_spec.rb
162
164
  - spec/dota/api/item_spec.rb
163
165
  - spec/dota/api/match/player_spec.rb
164
166
  - spec/dota/api/match_spec.rb
@@ -191,6 +193,7 @@ signing_key:
191
193
  specification_version: 4
192
194
  summary: Ruby client for the Dota 2 WebAPI
193
195
  test_files:
196
+ - spec/dota/api/hero_spec.rb
194
197
  - spec/dota/api/item_spec.rb
195
198
  - spec/dota/api/match/player_spec.rb
196
199
  - spec/dota/api/match_spec.rb