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 +4 -4
- data/examples/example.rb +6 -10
- data/lib/wow.rb +1 -0
- data/lib/wow/base.rb +9 -4
- data/lib/wow/features.rb +1 -1
- data/lib/wow/features/character.rb +66 -0
- data/lib/wow/version.rb +1 -1
- data/spec/features/README.md +57 -0
- data/spec/features/character_profile_spec.rb +56 -17
- metadata +4 -2
- data/lib/wow/features/character_profile.rb +0 -48
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 377cb66f84d3cc45b4c592a6f72f40e2ea650fff
|
4
|
+
data.tar.gz: f9a903b65b3a628482f8c2a94e69e94acda1c8ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
16
|
-
|
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
|
20
|
-
|
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/
|
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
@@ -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::
|
4
|
-
subject { WoW::
|
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::
|
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::
|
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::
|
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::
|
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::
|
40
|
-
}.to raise_error
|
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::
|
46
|
-
}.to raise_error
|
45
|
+
WoW::Character.new("", "Imnotaguyatalllolplz")
|
46
|
+
}.to raise_error
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
-
describe "#
|
51
|
-
it "
|
52
|
-
subject.
|
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 "#
|
57
|
-
it "
|
58
|
-
subject
|
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
|
-
|
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.
|
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/
|
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
|