wow 0.0.3 → 0.0.4

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: 6e57690e52632a1d8f631ab3faab9e626d49506a
4
- data.tar.gz: db53cfe90b6dadb0a30da15dddb61f9cf23c86b3
3
+ metadata.gz: 377cb66f84d3cc45b4c592a6f72f40e2ea650fff
4
+ data.tar.gz: f9a903b65b3a628482f8c2a94e69e94acda1c8ae
5
5
  SHA512:
6
- metadata.gz: 67e3f24949de0b24f669d30e0e204f925ba6ad648fc14fe586b5656c3febb799bcce25c4d05ae7721fa0df51b076aaffbe3959c58566347aa153299947e109c9
7
- data.tar.gz: 8b3d27db5fa1ddcfab0271ee5fd4f3beb7ef13abd30521d999beceee7eccff5d957cd127053d0d28de08390466c878bd8041cf1aeb8a15f1545425e22bb6d5bc
6
+ metadata.gz: 63966434e738399f93767aabf04580db97504f56680e674bb2202c7e6f7f068cac8c69131672ae897b5466f1574e832c4c2fad045359338781194d8c20efd60d
7
+ data.tar.gz: 68985a434342c46b547294bfc7ad8b915d96d491c2b347a3951ba95cbb1def64d803d29677a9b1004cd59d0b8f5a374abb36e987842dcecbd0544cc2b8329788
data/examples/example.rb CHANGED
@@ -1,12 +1,8 @@
1
1
  require "wow"
2
2
 
3
- # 25.times do |i|
4
- # begin
5
- # achive = WoW::Achievement.new(i)
6
- # puts "#{achive[:id]} : #{achive[:title]}"
7
- # rescue WoW::APIError
8
- # puts "#{i} : No Achievement"
9
- # end
10
- # end
11
-
12
- puts WoW::CharacterProfile.new("Stormreaver", "Epicgrim").lookup(:class)
3
+ epicgrim = WoW::Character.new("Stormreaver", "Epicgrim", [:items, :talents])
4
+ puts epicgrim["achievementPoints"]
5
+ puts epicgrim["items"]["averageItemLevelEquipped"]
6
+ p epicgrim.gets
7
+ puts epicgrim.get?("class")
8
+ puts epicgrim.get("class")
data/lib/wow.rb CHANGED
@@ -6,6 +6,7 @@ require 'wow/base'
6
6
  module WoW
7
7
  class ConfigurationError < StandardError; end
8
8
  class APIError < StandardError; end
9
+ class FieldMissingError < StandardError; end
9
10
 
10
11
  # Blizzard defined hosts, and locales.
11
12
  # See http://blizzard.github.io/api-wow-docs/#features/access-and-regions
data/lib/wow/base.rb CHANGED
@@ -12,13 +12,18 @@ module WoW
12
12
  end
13
13
  end
14
14
 
15
- def [](key)
16
- super(key.to_sym)
15
+ def gets
16
+ private_methods.select { |m| m =~ /get_/ }.map do |name|
17
+ name.to_s.gsub(/get_/, "")
18
+ end
17
19
  end
18
20
 
19
- def []=(key, value)
20
- super(key.to_sym, value)
21
+ def get(method)
22
+ self.send("get_#{method}")
21
23
  end
22
24
 
25
+ def get?(method)
26
+ gets.include?(method)
27
+ end
23
28
  end
24
29
  end
data/lib/wow/features.rb CHANGED
@@ -2,7 +2,7 @@ require 'wow/features/achievement'
2
2
  require 'wow/features/auction_data'
3
3
  require 'wow/features/battle_pet'
4
4
  require 'wow/features/challenge_mode'
5
- require 'wow/features/character_profile'
5
+ require 'wow/features/character'
6
6
  require 'wow/features/guild'
7
7
  require 'wow/features/item'
8
8
  require 'wow/features/leaderboard'
@@ -0,0 +1,66 @@
1
+ module WoW
2
+ class Character < Base
3
+ CLASSES = {
4
+ 1 => "warrior",
5
+ 2 => "paladin",
6
+ 3 => "hunter",
7
+ 4 => "rogue",
8
+ 5 => "priest",
9
+ 6 => "death_knight",
10
+ 7 => "shaman",
11
+ 8 => "mage",
12
+ 9 => "warlock",
13
+ 10 => "monk",
14
+ 11 => "druid",
15
+ }
16
+
17
+ base_uri "#{WoW.host}/api/wow/character"
18
+
19
+ def initialize(realm, character_name, fields = [], params = {})
20
+ if realm.to_s.empty?
21
+ raise ArgumentError.new("realm cannot be blank")
22
+ end
23
+ if character_name.to_s.empty?
24
+ raise ArgumentError.new("character name cannot be blank")
25
+ end
26
+
27
+ params = params.merge({fields: fields.join(',')})
28
+ super(self.class.data(realm, character_name, params))
29
+ end
30
+
31
+ class << self
32
+ def data(realm, character_name, params = {})
33
+ params.merge!({locale: WoW.locale})
34
+ get("/#{CGI::escape(realm)}/#{CGI::escape(character_name)}",
35
+ query: params).parsed_response
36
+ end
37
+ end
38
+
39
+ private
40
+
41
+ def get_class
42
+ CLASSES[self["class"]]
43
+ end
44
+
45
+ def get_active_spec
46
+ unless self["talents"]
47
+ raise FieldMissingError.new("missing field \"talents\"")
48
+ end
49
+
50
+ self["talents"].detect { |t| t["selected"] }
51
+ end
52
+
53
+ def get_inactive_spec
54
+ unless self["talents"]
55
+ raise FieldMissingError.new("missing field \"talents\"")
56
+ end
57
+
58
+ self["talents"].detect { |t| !t["selected"] }
59
+ end
60
+
61
+ def get_thumbnail
62
+ "http://us.battle.net/static-render/us/#{self["thumbnail"]}"
63
+ end
64
+
65
+ end
66
+ end
data/lib/wow/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module WoW
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -0,0 +1,57 @@
1
+ # WoW
2
+
3
+ Ruby API wrapper for Blizzards [WoW API](http://blizzard.github.io/api-wow-docs/).
4
+
5
+ ## Ideology
6
+
7
+ This library exists for 2 purposes.
8
+
9
+ 1. Direct one-to-one mapping of the WoW API to a ruby hash.
10
+ 2. Defined helper functions to help accessing data.
11
+
12
+ ### Object Instantiation
13
+
14
+ Every endpoint of the WoW API has a class. For example `WoW::Character` is the class representing the endpoint of `http://us.battle.net//api/wow/character/`. The name of the class is the CamelCased equivalent of the endpoint name. `http://us.battle.net//api/wow/battlePet/` for example is `WoW::BattlePet`.
15
+
16
+ The initializer function for the class takes as many *non-blank* arguments as the WoW API requires.
17
+
18
+ For example, the API dictates the following URL structure for a character.
19
+ ```
20
+ URL = Host + "/api/wow/character/" + Realm + "/" + CharacterName
21
+ ```
22
+
23
+ so the Ruby syntax is
24
+ ```ruby
25
+ WoW::Character.new(realm, character_name)
26
+ ```
27
+
28
+ Additionally if there are optional fields then they can be requested by passing an array as the third argument.
29
+ ```ruby
30
+ WoW::Character.new(realm, character_name, [:items, :talents])
31
+ ```
32
+
33
+ Other params may be specified as a hash in the fourth argument.
34
+ ```ruby
35
+ WoW::Character.new(realm, character_name, locale: "es_MX")
36
+ WoW::Character.new(realm, character_name, [:items, :talents], locale: "es_MX")
37
+ ```
38
+
39
+ ### Object Attribute Access
40
+
41
+ Accessing the data from the object is very simple. Each object subclasses from the ruby `Hash` so access is done on the object as a hash.
42
+
43
+ ```ruby
44
+ character["achievementPoints"] #=> 13450
45
+ character["items"]["averageItemLevel"] #=> 573
46
+ ```
47
+ **Note:** Attribute access is only done through string keys.
48
+
49
+ ### Object Methods
50
+
51
+ Sometimes the WoW API itself makes getting the data we want harder than we'd like, in these cases this wrapper attempts to help. To keep the API of this wrapper as simple as possible we only define 3 functions.
52
+
53
+ ```ruby
54
+ # Character#gets #=> Array ["class", "active_spec"]
55
+ # Character#get(String) #=> Value, ex get("class") might return "druid"
56
+ # Character#get?(String) #=> Boolean true if object can `get` on the given string.
57
+ ```
@@ -1,7 +1,7 @@
1
1
  require "spec_helper"
2
2
 
3
- describe WoW::CharacterProfile do
4
- subject { WoW::CharacterProfile.new("Stormreaver", "Epicgrim") }
3
+ describe WoW::Character do
4
+ subject { WoW::Character.new("Stormreaver", "Epicgrim", [:talents]) }
5
5
 
6
6
  describe "#initialize" do
7
7
  it "is valid server, and name" do
@@ -12,51 +12,90 @@ describe WoW::CharacterProfile do
12
12
 
13
13
  it "is valid with special characters in name" do
14
14
  expect {
15
- WoW::CharacterProfile.new("Stormreaver", "Disciplíne")
15
+ WoW::Character.new("Stormreaver", "Disciplíne")
16
16
  }.not_to raise_error
17
17
  end
18
18
 
19
19
  it "is invalid server" do
20
20
  expect {
21
- WoW::CharacterProfile.new("Notaserver", "Epicgrim")
21
+ WoW::Character.new("Notaserver", "Epicgrim")
22
22
  }.to raise_error
23
23
  end
24
24
 
25
25
  it "is invalid name" do
26
26
  expect {
27
- WoW::CharacterProfile.new("Stormreaver", "Imnotaguyatalllolplz")
27
+ WoW::Character.new("Stormreaver", "Imnotaguyatalllolplz")
28
28
  }.to raise_error
29
29
  end
30
30
 
31
31
  it "is invalid server and name" do
32
32
  expect {
33
- WoW::CharacterProfile.new("Notaserver", "Imnotaguyatalllolplz")
33
+ WoW::Character.new("Notaserver", "Imnotaguyatalllolplz")
34
34
  }.to raise_error
35
35
  end
36
36
 
37
37
  it "raises WoW::APIError when given nil or server" do
38
38
  expect {
39
- WoW::CharacterProfile.new(nil, "Imnotaguyatalllolplz")
40
- }.to raise_error(WoW::APIError)
39
+ WoW::Character.new(nil, "Imnotaguyatalllolplz")
40
+ }.to raise_error
41
41
  end
42
42
 
43
43
  it "raises WoW::APIError when given blank or server" do
44
44
  expect {
45
- WoW::CharacterProfile.new("", "Imnotaguyatalllolplz")
46
- }.to raise_error(WoW::APIError)
45
+ WoW::Character.new("", "Imnotaguyatalllolplz")
46
+ }.to raise_error
47
47
  end
48
48
  end
49
49
 
50
- describe "#lookup" do
51
- it "looks up class" do
52
- subject.lookup(:class).should eq(:druid)
50
+ describe "#[]" do
51
+ it "acts as a hash with strings" do
52
+ subject["name"].should eq("Epicgrim")
53
+ end
54
+
55
+ it "doesn't act as a hash with symbols" do
56
+ subject[:name].should_not eq("Epicgrim")
53
57
  end
54
58
  end
55
59
 
56
- describe "#[]" do
57
- it "acts as a hash" do
58
- subject[:name].should eq("Epicgrim")
60
+ describe "#gets" do
61
+ it "returns an array" do
62
+ subject.gets.should be_an(Array)
63
+ end
64
+
65
+ it "contains strings that are valids arguments to #get" do
66
+ subject.gets.each do |name|
67
+ expect { subject.get(name) }.not_to raise_error
68
+ end
59
69
  end
60
70
  end
61
71
 
62
- end
72
+ describe "#get?" do
73
+ it "returns true when calling #get would succeed" do
74
+ subject.get?("class").should be_true
75
+ end
76
+
77
+ it "returns false when calling #get would fail" do
78
+ subject.get?("foo").should be_false
79
+ end
80
+ end
81
+
82
+ describe "#get" do
83
+ it "gets the characters class" do
84
+ subject.get("class").should eq("druid")
85
+ end
86
+
87
+ it "gets the characters active spec" do
88
+ spec_name = subject.get("active_spec")["spec"]["name"]
89
+ ["Balance", "Guardian"].should include(spec_name)
90
+ end
91
+
92
+ it "gets the characters inactive spec" do
93
+ spec_name = subject.get("inactive_spec")["spec"]["name"]
94
+ ["Balance", "Guardian"].should include(spec_name)
95
+ end
96
+
97
+ it "gets the characters thumbnail" do
98
+ subject.get("thumbnail").should match(/http.*/)
99
+ end
100
+ end
101
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Lilienthal
@@ -83,7 +83,7 @@ files:
83
83
  - lib/wow/features/auction_data.rb
84
84
  - lib/wow/features/battle_pet.rb
85
85
  - lib/wow/features/challenge_mode.rb
86
- - lib/wow/features/character_profile.rb
86
+ - lib/wow/features/character.rb
87
87
  - lib/wow/features/guild.rb
88
88
  - lib/wow/features/item.rb
89
89
  - lib/wow/features/leaderboard.rb
@@ -92,6 +92,7 @@ files:
92
92
  - lib/wow/features/recipe.rb
93
93
  - lib/wow/features/spell.rb
94
94
  - lib/wow/version.rb
95
+ - spec/features/README.md
95
96
  - spec/features/character_profile_spec.rb
96
97
  - spec/spec_helper.rb
97
98
  - wow.gemspec
@@ -120,5 +121,6 @@ signing_key:
120
121
  specification_version: 4
121
122
  summary: World of Warcraft API Access.
122
123
  test_files:
124
+ - spec/features/README.md
123
125
  - spec/features/character_profile_spec.rb
124
126
  - spec/spec_helper.rb
@@ -1,48 +0,0 @@
1
- module WoW
2
- class CharacterProfile < Base
3
- CLASSES = {
4
- 1 => :warrior,
5
- 2 => :paladin,
6
- 3 => :hunter,
7
- 4 => :rogue,
8
- 5 => :priest,
9
- 6 => :death_knight,
10
- 7 => :shaman,
11
- 8 => :mage,
12
- 9 => :warlock,
13
- 10 => :monk,
14
- 11 => :druid,
15
- }
16
-
17
- base_uri "#{WoW.host}/api/wow/character"
18
-
19
- def initialize(realm, character_name, fields = [], params = {})
20
- if realm.to_s.empty?
21
- raise WoW::APIError.new "Realm cannot be blank"
22
- end
23
- if character_name.to_s.empty?
24
- raise WoW::APIError.new "Character name cannot be blank"
25
- end
26
-
27
- params = params.merge({fields: fields.join(',')})
28
- super(self.class.data(realm, character_name, params))
29
- end
30
-
31
- def lookup(key)
32
- case key
33
- when :class
34
- CLASSES[self[key]]
35
- else
36
- raise "No lookup mapping for #{key}"
37
- end
38
- end
39
-
40
- class << self
41
- def data(realm, character_name, params = {})
42
- params.merge!({locale: WoW.locale})
43
- get("/#{CGI::escape(realm)}/#{CGI::escape(character_name)}",
44
- query: params).parsed_response
45
- end
46
- end
47
- end
48
- end