covetous 0.0.1 → 0.1.0

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.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Covetous
2
2
 
3
- TODO: Write a gem description
3
+ Covetous is a Ruby Wrapper for the Diablo 3 Web API
4
4
 
5
5
  ## Installation
6
6
 
@@ -18,7 +18,40 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- TODO: Write usage instructions here
21
+ As of now, Covetous is just a plain ol' gee-- Ruby gem. He is basically just a Ruby wrapper(as I keep repeating...)
22
+ for the Diablo 3 Web API. After installing, all you have to do is require it where you like and just use it!
23
+
24
+ Some example usage would be:
25
+
26
+ ### Career Profile
27
+
28
+ **Note**: Top level keys from the hashes are available as methods for your convenience
29
+
30
+ my_profile = Covetous::Profile::Career.new 'corroded-6950'
31
+ puts my_profile.heroes
32
+ puts my_profile.kills
33
+
34
+ ### Hero Profile
35
+
36
+ my_hero = Covetous::Profile::Hero.new 'corroded-6950', '12793941'
37
+ puts my_hero.skills
38
+ puts my_hero.paragon_level
39
+
40
+ ### Artisan Data
41
+
42
+ artisan = Covetous::Data::Artisan.new 'blacksmith'
43
+ puts artisan.name
44
+
45
+ ### Follower Data
46
+
47
+ follower = Covetous::Data::Follower.new 'enchantress'
48
+ puts artisan.name
49
+
50
+ ### Item Data
51
+
52
+ item = Covetous::Data::Item.new 'CkMIz4LU4AoSBwgEFX35Tl0dLWYPvh194Mt2Ha3H5XEdElz0_B2H9XtuIgsIARWFQgMAGAAgCjAJOLYEQABIAVAOYPkEGPrl99QLUAZYAA'
53
+ puts item.name
54
+ puts item.attributes
22
55
 
23
56
  ## Contributing
24
57
 
@@ -1,3 +1,6 @@
1
+ class NoHeroFoundForProfileError < StandardError
2
+ end
3
+
1
4
  module Covetous
2
5
  module Profile
3
6
  class Career < Covetous::Shen
@@ -9,6 +12,14 @@ module Covetous
9
12
  def hero_names
10
13
  heroes.map{ |hero| hero['name'] }
11
14
  end
15
+
16
+ def get_hero_details_of(hero_name)
17
+ raise NoHeroFoundForProfileError, "No such hero was found under #{battle_tag}" unless hero_names.include? hero_name
18
+
19
+ hero_index = hero_names.index hero_name
20
+ battle_tag_for_api = battle_tag.gsub('#', '-')
21
+ Covetous::Profile::Hero.new battle_tag_for_api, heroes[hero_index]['id']
22
+ end
12
23
  end
13
24
  end
14
25
  end
@@ -1,3 +1,3 @@
1
1
  module Covetous
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
File without changes
File without changes
@@ -15,6 +15,13 @@ describe 'Item' do
15
15
  it 'should have the correct url' do
16
16
  @my_item.url.must_equal 'http://us.battle.net/api/d3/data/item/CkMIz4LU4AoSBwgEFX35Tl0dLWYPvh194Mt2Ha3H5XEdElz0_B2H9XtuIgsIARWFQgMAGAAgCjAJOLYEQABIAVAOYPkEGPrl99QLUAZYAA'
17
17
  end
18
- end
19
18
 
19
+ it 'should have the top level keys available as methods' do
20
+ top_level_keys = %w{ id name icon displayColor tooltipParams requiredLevel itemLevel bonusAffixes typeName type armor attributes attributesRaw socketEffects salvage gems }
21
+
22
+ top_level_keys.each do |tl_key|
23
+ @my_item.send(tl_key).must_equal @my_item.response[tl_key.camelize(:lower)]
24
+ end
25
+ end
26
+ end
20
27
  end
@@ -34,4 +34,29 @@ describe 'Career' do
34
34
  lambda { @my_profile.foo_attribute }.must_raise NoMethodError
35
35
  end
36
36
  end
37
+
38
+ describe '#get_hero_details_of' do
39
+ before do
40
+ VCR.use_cassette('sample_hero_data') do
41
+ @sample_hero_data = Covetous::Profile::Hero.new 'corroded-6950', '20042961'
42
+ end
43
+
44
+ VCR.use_cassette('get_hero_response') do
45
+ @get_hero_response = @my_profile.get_hero_details_of('corrodee')
46
+ end
47
+ end
48
+
49
+ after do
50
+ VCR.eject_cassette
51
+ VCR.eject_cassette
52
+ end
53
+
54
+ it 'should return a hero object' do
55
+ @get_hero_response.must_be_instance_of Covetous::Profile::Hero
56
+ end
57
+
58
+ it 'should raise a NoHeroFoundForProfileError when given a wrong hero name' do
59
+ lambda { @my_profile.get_hero_details_of('multipleman') }.must_raise NoHeroFoundForProfileError
60
+ end
61
+ end
37
62
  end