wow_community_api 0.0.6 → 0.0.7

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.
@@ -1,14 +1,18 @@
1
1
  module WowCommunityApi
2
2
  class BattleNet
3
3
  include HTTParty
4
+
5
+ # TODO: make this configurable?
6
+ DEFAULT_REGION = Regions::US
4
7
 
5
8
  def self.region(name)
6
9
  self.base_uri "#{name}.battle.net/api/wow"
7
10
  end
8
- base_uri region(Regions::US)
11
+ base_uri region(DEFAULT_REGION)
9
12
 
10
13
  def self.get(path, options = {})
11
- super(URI.encode(path), options).to_ostruct
14
+ results = super(URI.encode(path), options)
15
+ results.to_ostruct if results.response.code == "200"
12
16
  end
13
17
 
14
18
  end
@@ -1,7 +1,7 @@
1
1
  module WowCommunityApi
2
2
  class Character < BattleNet
3
3
  def self.find_by_realm_and_name(realm, name, *field)
4
- fields = { :fields => field.join(",") } if field.size > 0
4
+ fields = { :fields => field.join(",") } unless field.empty?
5
5
  get("/character/#{realm}/#{name}", :query => fields)
6
6
  end
7
7
  end
@@ -1,7 +1,7 @@
1
1
  module WowCommunityApi
2
2
  class Guild < BattleNet
3
3
  def self.find_by_realm_and_name(realm, name, *field)
4
- fields = { :fields => field.join(",") } if field.size > 0
4
+ fields = { :fields => field.join(",") } unless field.empty?
5
5
  get("/guild/#{realm}/#{name}", :query => fields)
6
6
  end
7
7
  end
@@ -1,11 +1,11 @@
1
1
  module WowCommunityApi
2
2
  class Realm < BattleNet
3
3
  def self.find_by_name(*name)
4
- names = { :realms => name.join(",") } if name.size > 0
4
+ names = { :realms => name.join(",") } unless name.empty?
5
5
  results = get("/realm/status", :query => names)
6
6
  (name.size == 1) ? results.realms.first : results.realms
7
7
  end
8
-
8
+
9
9
  def self.find_all()
10
10
  find_by_name
11
11
  end
@@ -1,3 +1,3 @@
1
1
  module WowCommunityApi
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -2,11 +2,29 @@ require 'spec_helper'
2
2
 
3
3
  describe BattleNet do
4
4
  describe "#region" do
5
+ before(:each) { BattleNet.region(Regions::US) }
6
+
5
7
  it "sets the base uri to a region" do
6
8
  BattleNet.region(Regions::US).should == "http://us.battle.net/api/wow"
7
9
  BattleNet.region(Regions::EU).should == "http://eu.battle.net/api/wow"
8
10
  BattleNet.region(Regions::KR).should == "http://kr.battle.net/api/wow"
9
11
  BattleNet.region(Regions::TW).should == "http://tw.battle.net/api/wow"
10
12
  end
13
+
14
+ it "defaults to US region" do
15
+ BattleNet::DEFAULT_REGION.should == Regions::US
16
+ end
17
+
18
+ it "returns nil for 404 not found error" do
19
+ stub_error 'http://us.battle.net/api/wow/xyz', 404
20
+
21
+ BattleNet.get("/xyz").should be_nil
22
+ end
23
+
24
+ it "returns nil for 500 server error" do
25
+ stub_error 'http://us.battle.net/api/wow/guild/arygos/xyz', 500
26
+
27
+ BattleNet.get("/guild/arygos/xyz").should be_nil
28
+ end
11
29
  end
12
30
  end
@@ -0,0 +1 @@
1
+ {"status":"nok", "reason": "An error message."}
data/spec/spec_helper.rb CHANGED
@@ -7,3 +7,8 @@ def stub_json(uri, filename)
7
7
  body = open("spec/fixtures/#{filename}")
8
8
  stub_request(:get, uri).to_return(:body => body, :headers => { 'Content-Type' => 'application/json' })
9
9
  end
10
+
11
+ def stub_error(uri, status)
12
+ body = open("spec/fixtures/error.json")
13
+ stub_request(:get, uri).to_return(:body => body, :status => status)
14
+ end
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.0.6
5
+ version: 0.0.7
6
6
  platform: ruby
7
7
  authors:
8
8
  - eddie cianci
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-07-20 00:00:00 Z
13
+ date: 2011-07-22 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: httparty
@@ -86,6 +86,7 @@ files:
86
86
  - spec/fixtures/character-doe.json
87
87
  - spec/fixtures/character-guild.json
88
88
  - spec/fixtures/character.json
89
+ - spec/fixtures/error.json
89
90
  - spec/fixtures/guild-all-fields.json
90
91
  - spec/fixtures/guild-dmc.json
91
92
  - spec/fixtures/guild-members.json
@@ -132,6 +133,7 @@ test_files:
132
133
  - spec/fixtures/character-doe.json
133
134
  - spec/fixtures/character-guild.json
134
135
  - spec/fixtures/character.json
136
+ - spec/fixtures/error.json
135
137
  - spec/fixtures/guild-all-fields.json
136
138
  - spec/fixtures/guild-dmc.json
137
139
  - spec/fixtures/guild-members.json