wow_community_api 0.1.0 → 0.2.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/lib/wow_community_api.rb +2 -0
- data/lib/wow_community_api/battle_net.rb +17 -9
- data/lib/wow_community_api/character.rb +1 -1
- data/lib/wow_community_api/guild.rb +1 -1
- data/lib/wow_community_api/locales.rb +26 -0
- data/lib/wow_community_api/realm.rb +1 -1
- data/lib/wow_community_api/regions.rb +6 -8
- data/lib/wow_community_api/version.rb +1 -1
- data/spec/battle_net_spec.rb +7 -5
- data/spec/character_spec.rb +9 -0
- data/spec/fixtures/character-mexican.json +17 -0
- data/spec/locale_spec.rb +14 -0
- data/spec/spec_helper.rb +4 -0
- data/wow_community_api.gemspec +2 -0
- metadata +35 -8
data/lib/wow_community_api.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
+
require 'active_support/core_ext/class'
|
1
2
|
require 'httparty'
|
2
3
|
require 'hash-to-ostruct'
|
3
4
|
require 'uri'
|
4
5
|
|
5
6
|
require "wow_community_api/version"
|
6
7
|
require "wow_community_api/regions"
|
8
|
+
require "wow_community_api/locales"
|
7
9
|
require "wow_community_api/battle_net"
|
8
10
|
require "wow_community_api/realm"
|
9
11
|
require "wow_community_api/character"
|
@@ -4,19 +4,27 @@ module WowCommunityApi
|
|
4
4
|
|
5
5
|
# TODO: make this configurable?
|
6
6
|
DEFAULT_REGION = Regions::US
|
7
|
+
DEFAULT_LOCALE = nil
|
7
8
|
|
8
|
-
|
9
|
-
|
9
|
+
cattr_accessor(:region) { DEFAULT_REGION }
|
10
|
+
cattr_accessor(:locale) { DEFAULT_LOCALE }
|
11
|
+
|
12
|
+
def self.get(path, options = nil)
|
13
|
+
base_uri "http://#{self.region}/api/wow"
|
14
|
+
|
15
|
+
results = super(URI.encode(path), build_query(options))
|
16
|
+
results.parsed_response.to_ostruct if results.response.code == "200"
|
10
17
|
end
|
11
|
-
|
12
|
-
|
18
|
+
|
19
|
+
def self.build_query(options)
|
20
|
+
query = { :query => options }
|
21
|
+
query[:query].merge!(:locale => locale) if locale
|
22
|
+
query
|
13
23
|
end
|
14
|
-
self.region = DEFAULT_REGION
|
15
24
|
|
16
|
-
def self.
|
17
|
-
|
18
|
-
|
19
|
-
results.parsed_response.to_ostruct if results.response.code == "200"
|
25
|
+
def self.reset!
|
26
|
+
self.region = DEFAULT_REGION
|
27
|
+
self.locale = DEFAULT_LOCALE
|
20
28
|
end
|
21
29
|
|
22
30
|
end
|
@@ -2,7 +2,7 @@ module WowCommunityApi
|
|
2
2
|
class Character < BattleNet
|
3
3
|
def self.find_by_realm_and_name(realm, name, *field)
|
4
4
|
fields = { :fields => field.join(",") } unless field.empty?
|
5
|
-
get("/character/#{realm}/#{name}",
|
5
|
+
get("/character/#{realm}/#{name}", fields)
|
6
6
|
end
|
7
7
|
end
|
8
8
|
end
|
@@ -2,7 +2,7 @@ module WowCommunityApi
|
|
2
2
|
class Guild < BattleNet
|
3
3
|
def self.find_by_realm_and_name(realm, name, *field)
|
4
4
|
fields = { :fields => field.join(",") } unless field.empty?
|
5
|
-
get("/guild/#{realm}/#{name}",
|
5
|
+
get("/guild/#{realm}/#{name}", fields)
|
6
6
|
end
|
7
7
|
end
|
8
8
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module WowCommunityApi::Locales
|
2
|
+
module US
|
3
|
+
EN_US = "en_US"
|
4
|
+
ES_MX = "es_MX"
|
5
|
+
end
|
6
|
+
|
7
|
+
module EU
|
8
|
+
EN_GB = "en_GB"
|
9
|
+
ES_ES = "es_ES"
|
10
|
+
FR_FR = "fr_FR"
|
11
|
+
RU_RU = "ru_RU"
|
12
|
+
DE_DE = "de_DE"
|
13
|
+
end
|
14
|
+
|
15
|
+
module KR
|
16
|
+
KO_KR = "ko_KR"
|
17
|
+
end
|
18
|
+
|
19
|
+
module TW
|
20
|
+
ZH_TW = "zh_TW"
|
21
|
+
end
|
22
|
+
|
23
|
+
module CN
|
24
|
+
ZH_CN = "zh_CN"
|
25
|
+
end
|
26
|
+
end
|
@@ -2,7 +2,7 @@ module WowCommunityApi
|
|
2
2
|
class Realm < BattleNet
|
3
3
|
def self.find_by_name(*name)
|
4
4
|
names = { :realms => name.join(",") } unless name.empty?
|
5
|
-
results = get("/realm/status",
|
5
|
+
results = get("/realm/status", names)
|
6
6
|
(name.size == 1) ? results.realms.first : results.realms
|
7
7
|
end
|
8
8
|
|
@@ -1,9 +1,7 @@
|
|
1
|
-
module WowCommunityApi
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
CN = "www.battlenet.com.cn"
|
8
|
-
end
|
1
|
+
module WowCommunityApi::Regions
|
2
|
+
US = "us.battle.net"
|
3
|
+
EU = "eu.battle.net"
|
4
|
+
KR = "kr.battle.net"
|
5
|
+
TW = "tw.battle.net"
|
6
|
+
CN = "www.battlenet.com.cn"
|
9
7
|
end
|
data/spec/battle_net_spec.rb
CHANGED
@@ -6,19 +6,19 @@ describe BattleNet do
|
|
6
6
|
|
7
7
|
it "sets the base uri to a region" do
|
8
8
|
BattleNet.region = Regions::US
|
9
|
-
BattleNet.region.should == "
|
9
|
+
BattleNet.region.should == "us.battle.net"
|
10
10
|
|
11
11
|
BattleNet.region = Regions::EU
|
12
|
-
BattleNet.region.should == "
|
12
|
+
BattleNet.region.should == "eu.battle.net"
|
13
13
|
|
14
14
|
BattleNet.region = Regions::KR
|
15
|
-
BattleNet.region.should == "
|
15
|
+
BattleNet.region.should == "kr.battle.net"
|
16
16
|
|
17
17
|
BattleNet.region = Regions::TW
|
18
|
-
BattleNet.region.should == "
|
18
|
+
BattleNet.region.should == "tw.battle.net"
|
19
19
|
|
20
20
|
BattleNet.region = Regions::CN
|
21
|
-
BattleNet.region.should == "
|
21
|
+
BattleNet.region.should == "www.battlenet.com.cn"
|
22
22
|
end
|
23
23
|
|
24
24
|
it "defaults to US region" do
|
@@ -28,9 +28,11 @@ describe BattleNet do
|
|
28
28
|
it "can switch regions" do
|
29
29
|
BattleNet.region = Regions::EU
|
30
30
|
BattleNet.region.should == Realm.region
|
31
|
+
Realm.region.should == "eu.battle.net"
|
31
32
|
|
32
33
|
BattleNet.region = Regions::KR
|
33
34
|
BattleNet.region.should == Realm.region
|
35
|
+
Realm.region.should == "kr.battle.net"
|
34
36
|
end
|
35
37
|
|
36
38
|
it "returns nil for 404 not found error" do
|
data/spec/character_spec.rb
CHANGED
@@ -33,5 +33,14 @@ describe Character do
|
|
33
33
|
character.titles.size.should == 3
|
34
34
|
character.titles[0].name.should == "Centurion %s"
|
35
35
|
end
|
36
|
+
|
37
|
+
it 'gets a character with foreign locale' do
|
38
|
+
BattleNet.locale = Locales::US::ES_MX
|
39
|
+
|
40
|
+
stub_json 'http://us.battle.net/api/wow/character/uther/malkyth?fields=titles&locale=es_MX', 'character-mexican.json'
|
41
|
+
|
42
|
+
character = Character.find_by_realm_and_name('uther', 'malkyth', :titles)
|
43
|
+
character.titles[0].name.should == "Conquistador %s"
|
44
|
+
end
|
36
45
|
end
|
37
46
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
{
|
2
|
+
"lastModified":1311430176000,
|
3
|
+
"name":"Malkyth",
|
4
|
+
"realm":"Uther",
|
5
|
+
"class":9,
|
6
|
+
"race":5,
|
7
|
+
"gender":0,
|
8
|
+
"level":85,
|
9
|
+
"achievementPoints":11050,
|
10
|
+
"thumbnail":"uther/243/6004211-avatar.jpg",
|
11
|
+
"titles":[
|
12
|
+
{
|
13
|
+
"id":47,
|
14
|
+
"name":"Conquistador %s"
|
15
|
+
}
|
16
|
+
]
|
17
|
+
}
|
data/spec/locale_spec.rb
ADDED
data/spec/spec_helper.rb
CHANGED
@@ -3,6 +3,10 @@ require 'webmock/rspec'
|
|
3
3
|
|
4
4
|
include WowCommunityApi
|
5
5
|
|
6
|
+
RSpec.configure do |config|
|
7
|
+
config.after(:each) { BattleNet.reset! }
|
8
|
+
end
|
9
|
+
|
6
10
|
def stub_json(uri, filename)
|
7
11
|
body = open("spec/fixtures/#{filename}")
|
8
12
|
stub_request(:get, uri).to_return(:body => body, :headers => { 'Content-Type' => 'application/json' })
|
data/wow_community_api.gemspec
CHANGED
@@ -18,6 +18,8 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
|
21
|
+
s.add_dependency "activesupport"
|
22
|
+
s.add_dependency "i18n"
|
21
23
|
s.add_dependency "httparty"
|
22
24
|
s.add_dependency "hash-to-ostruct"
|
23
25
|
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: wow_community_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.2.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- eddie cianci
|
@@ -13,7 +13,7 @@ cert_chain: []
|
|
13
13
|
date: 2011-07-23 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
16
|
+
name: activesupport
|
17
17
|
prerelease: false
|
18
18
|
requirement: &id001 !ruby/object:Gem::Requirement
|
19
19
|
none: false
|
@@ -24,7 +24,7 @@ dependencies:
|
|
24
24
|
type: :runtime
|
25
25
|
version_requirements: *id001
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
|
-
name:
|
27
|
+
name: i18n
|
28
28
|
prerelease: false
|
29
29
|
requirement: &id002 !ruby/object:Gem::Requirement
|
30
30
|
none: false
|
@@ -35,7 +35,7 @@ dependencies:
|
|
35
35
|
type: :runtime
|
36
36
|
version_requirements: *id002
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
|
-
name:
|
38
|
+
name: httparty
|
39
39
|
prerelease: false
|
40
40
|
requirement: &id003 !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
- - ">="
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: "0"
|
46
|
-
type: :
|
46
|
+
type: :runtime
|
47
47
|
version_requirements: *id003
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
|
-
name:
|
49
|
+
name: hash-to-ostruct
|
50
50
|
prerelease: false
|
51
51
|
requirement: &id004 !ruby/object:Gem::Requirement
|
52
52
|
none: false
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
- - ">="
|
55
55
|
- !ruby/object:Gem::Version
|
56
56
|
version: "0"
|
57
|
-
type: :
|
57
|
+
type: :runtime
|
58
58
|
version_requirements: *id004
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
|
-
name:
|
60
|
+
name: rake
|
61
61
|
prerelease: false
|
62
62
|
requirement: &id005 !ruby/object:Gem::Requirement
|
63
63
|
none: false
|
@@ -67,6 +67,28 @@ dependencies:
|
|
67
67
|
version: "0"
|
68
68
|
type: :development
|
69
69
|
version_requirements: *id005
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rspec
|
72
|
+
prerelease: false
|
73
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: "0"
|
79
|
+
type: :development
|
80
|
+
version_requirements: *id006
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: webmock
|
83
|
+
prerelease: false
|
84
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: "0"
|
90
|
+
type: :development
|
91
|
+
version_requirements: *id007
|
70
92
|
description: a Ruby library for Blizzard's World of Warcraft Community Platform API
|
71
93
|
email:
|
72
94
|
- defeated2k4@gmail.com
|
@@ -89,6 +111,7 @@ files:
|
|
89
111
|
- lib/wow_community_api/battle_net.rb
|
90
112
|
- lib/wow_community_api/character.rb
|
91
113
|
- lib/wow_community_api/guild.rb
|
114
|
+
- lib/wow_community_api/locales.rb
|
92
115
|
- lib/wow_community_api/realm.rb
|
93
116
|
- lib/wow_community_api/regions.rb
|
94
117
|
- lib/wow_community_api/version.rb
|
@@ -97,6 +120,7 @@ files:
|
|
97
120
|
- spec/fixtures/character-all-fields.json
|
98
121
|
- spec/fixtures/character-doe.json
|
99
122
|
- spec/fixtures/character-guild.json
|
123
|
+
- spec/fixtures/character-mexican.json
|
100
124
|
- spec/fixtures/character.json
|
101
125
|
- spec/fixtures/error.json
|
102
126
|
- spec/fixtures/guild-all-fields.json
|
@@ -107,6 +131,7 @@ files:
|
|
107
131
|
- spec/fixtures/realms-aos.json
|
108
132
|
- spec/fixtures/realms.json
|
109
133
|
- spec/guild_spec.rb
|
134
|
+
- spec/locale_spec.rb
|
110
135
|
- spec/realm_spec.rb
|
111
136
|
- spec/regions_spec.rb
|
112
137
|
- spec/spec_helper.rb
|
@@ -144,6 +169,7 @@ test_files:
|
|
144
169
|
- spec/fixtures/character-all-fields.json
|
145
170
|
- spec/fixtures/character-doe.json
|
146
171
|
- spec/fixtures/character-guild.json
|
172
|
+
- spec/fixtures/character-mexican.json
|
147
173
|
- spec/fixtures/character.json
|
148
174
|
- spec/fixtures/error.json
|
149
175
|
- spec/fixtures/guild-all-fields.json
|
@@ -154,6 +180,7 @@ test_files:
|
|
154
180
|
- spec/fixtures/realms-aos.json
|
155
181
|
- spec/fixtures/realms.json
|
156
182
|
- spec/guild_spec.rb
|
183
|
+
- spec/locale_spec.rb
|
157
184
|
- spec/realm_spec.rb
|
158
185
|
- spec/regions_spec.rb
|
159
186
|
- spec/spec_helper.rb
|