battlenet 0.1.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/README.md +31 -45
  2. data/VERSION +1 -0
  3. data/battlenet.gemspec +13 -2
  4. data/lib/battlenet.rb +95 -2
  5. data/lib/battlenet/authentication.rb +21 -0
  6. data/lib/battlenet/modules/arena.rb +13 -0
  7. data/lib/battlenet/modules/auction.rb +18 -0
  8. data/lib/battlenet/modules/character.rb +12 -0
  9. data/lib/battlenet/modules/data.rb +23 -0
  10. data/lib/battlenet/modules/guild.rb +12 -0
  11. data/lib/battlenet/modules/item.rb +7 -0
  12. data/lib/battlenet/modules/realm.rb +7 -0
  13. data/spec/fixtures/cassettes/arena_fun_and_profit.yml +29 -0
  14. data/spec/fixtures/cassettes/auction_data.yml +63 -0
  15. data/spec/fixtures/cassettes/auction_files.yml +30 -0
  16. data/spec/fixtures/cassettes/character_classes.yml +33 -0
  17. data/spec/fixtures/cassettes/character_mortawa.yml +30 -0
  18. data/spec/fixtures/cassettes/character_mortawa_es.yml +48 -0
  19. data/spec/fixtures/cassettes/character_mortawa_titles.yml +32 -0
  20. data/spec/fixtures/cassettes/character_nonstandard_name.yml +30 -0
  21. data/spec/fixtures/cassettes/character_races.yml +34 -0
  22. data/spec/fixtures/cassettes/guild_perks.yml +91 -0
  23. data/spec/fixtures/cassettes/guild_rewards.yml +175 -0
  24. data/spec/fixtures/cassettes/guild_rl_bl.yml +28 -0
  25. data/spec/fixtures/cassettes/guild_rl_bl_members.yml +28 -0
  26. data/spec/fixtures/cassettes/item_classes.yml +33 -0
  27. data/spec/fixtures/cassettes/item_hooooooooooo.yml +29 -0
  28. data/spec/fixtures/cassettes/realm.yml +69 -0
  29. data/spec/integration/arena_spec.rb +14 -0
  30. data/spec/integration/auction_spec.rb +22 -0
  31. data/spec/integration/character_spec.rb +29 -0
  32. data/spec/integration/data_spec.rb +41 -0
  33. data/spec/integration/guild_spec.rb +20 -0
  34. data/spec/integration/item_spec.rb +13 -0
  35. data/spec/integration/locale_spec.rb +23 -0
  36. data/spec/integration/realm_spec.rb +15 -0
  37. data/spec/spec_helper.rb +7 -0
  38. data/spec/unit/battlenet_authentication_spec.rb +31 -0
  39. data/spec/unit/battlenet_spec.rb +158 -0
  40. metadata +151 -51
  41. data/lib/battlenet/adapter/abstract_adapter.rb +0 -11
  42. data/lib/battlenet/adapter/net_http.rb +0 -14
  43. data/lib/battlenet/adapter/typhoeus.rb +0 -13
  44. data/lib/battlenet/adapter_manager.rb +0 -51
  45. data/lib/battlenet/api.rb +0 -73
  46. data/lib/battlenet/api/realm.rb +0 -14
  47. data/lib/battlenet/version.rb +0 -3
  48. data/spec/abstract_adapter_spec.rb +0 -15
  49. data/spec/adapter_manager_spec.rb +0 -55
  50. data/spec/api_spec.rb +0 -115
metadata CHANGED
@@ -1,87 +1,187 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: battlenet
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
4
5
  prerelease:
5
- version: 0.1.1
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Brandon Tilley
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-05-02 00:00:00 -07:00
14
- default_executable:
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
12
+ date: 2011-11-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: &70134987231600 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70134987231600
25
+ - !ruby/object:Gem::Dependency
17
26
  name: rspec
27
+ requirement: &70134987231020 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70134987231020
36
+ - !ruby/object:Gem::Dependency
37
+ name: timecop
38
+ requirement: &70134987230560 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70134987230560
47
+ - !ruby/object:Gem::Dependency
48
+ name: vcr
49
+ requirement: &70134987229320 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
18
56
  prerelease: false
19
- requirement: &id001 !ruby/object:Gem::Requirement
57
+ version_requirements: *70134987229320
58
+ - !ruby/object:Gem::Dependency
59
+ name: webmock
60
+ requirement: &70134987228880 !ruby/object:Gem::Requirement
20
61
  none: false
21
- requirements:
22
- - - ">="
23
- - !ruby/object:Gem::Version
24
- version: "0"
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
25
66
  type: :development
26
- version_requirements: *id001
67
+ prerelease: false
68
+ version_requirements: *70134987228880
69
+ - !ruby/object:Gem::Dependency
70
+ name: httparty
71
+ requirement: &70134987228400 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: *70134987228400
27
80
  description: Easily consume Blizzard's Community Platform API.
28
- email:
81
+ email:
29
82
  - brandon@brandontilley.com
30
83
  executables: []
31
-
32
84
  extensions: []
33
-
34
85
  extra_rdoc_files: []
35
-
36
- files:
86
+ files:
37
87
  - .gitignore
38
88
  - Gemfile
39
89
  - LICENSE
40
90
  - README.md
41
91
  - Rakefile
92
+ - VERSION
42
93
  - battlenet.gemspec
43
94
  - lib/battlenet.rb
44
- - lib/battlenet/adapter/abstract_adapter.rb
45
- - lib/battlenet/adapter/net_http.rb
46
- - lib/battlenet/adapter/typhoeus.rb
47
- - lib/battlenet/adapter_manager.rb
48
- - lib/battlenet/api.rb
49
- - lib/battlenet/api/realm.rb
50
- - lib/battlenet/version.rb
51
- - spec/abstract_adapter_spec.rb
52
- - spec/adapter_manager_spec.rb
53
- - spec/api_spec.rb
95
+ - lib/battlenet/authentication.rb
96
+ - lib/battlenet/modules/arena.rb
97
+ - lib/battlenet/modules/auction.rb
98
+ - lib/battlenet/modules/character.rb
99
+ - lib/battlenet/modules/data.rb
100
+ - lib/battlenet/modules/guild.rb
101
+ - lib/battlenet/modules/item.rb
102
+ - lib/battlenet/modules/realm.rb
103
+ - spec/fixtures/cassettes/arena_fun_and_profit.yml
104
+ - spec/fixtures/cassettes/auction_data.yml
105
+ - spec/fixtures/cassettes/auction_files.yml
106
+ - spec/fixtures/cassettes/character_classes.yml
107
+ - spec/fixtures/cassettes/character_mortawa.yml
108
+ - spec/fixtures/cassettes/character_mortawa_es.yml
109
+ - spec/fixtures/cassettes/character_mortawa_titles.yml
110
+ - spec/fixtures/cassettes/character_nonstandard_name.yml
111
+ - spec/fixtures/cassettes/character_races.yml
112
+ - spec/fixtures/cassettes/guild_perks.yml
113
+ - spec/fixtures/cassettes/guild_rewards.yml
114
+ - spec/fixtures/cassettes/guild_rl_bl.yml
115
+ - spec/fixtures/cassettes/guild_rl_bl_members.yml
116
+ - spec/fixtures/cassettes/item_classes.yml
117
+ - spec/fixtures/cassettes/item_hooooooooooo.yml
118
+ - spec/fixtures/cassettes/realm.yml
119
+ - spec/integration/arena_spec.rb
120
+ - spec/integration/auction_spec.rb
121
+ - spec/integration/character_spec.rb
122
+ - spec/integration/data_spec.rb
123
+ - spec/integration/guild_spec.rb
124
+ - spec/integration/item_spec.rb
125
+ - spec/integration/locale_spec.rb
126
+ - spec/integration/realm_spec.rb
54
127
  - spec/spec_helper.rb
55
- has_rdoc: true
56
- homepage: ""
128
+ - spec/unit/battlenet_authentication_spec.rb
129
+ - spec/unit/battlenet_spec.rb
130
+ homepage: ''
57
131
  licenses: []
58
-
59
132
  post_install_message:
60
133
  rdoc_options: []
61
-
62
- require_paths:
134
+ require_paths:
63
135
  - lib
64
- required_ruby_version: !ruby/object:Gem::Requirement
136
+ required_ruby_version: !ruby/object:Gem::Requirement
65
137
  none: false
66
- requirements:
67
- - - ">="
68
- - !ruby/object:Gem::Version
69
- version: "0"
70
- required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ segments:
143
+ - 0
144
+ hash: 1432348448402265031
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
146
  none: false
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: "0"
147
+ requirements:
148
+ - - ! '>='
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ segments:
152
+ - 0
153
+ hash: 1432348448402265031
76
154
  requirements: []
77
-
78
155
  rubyforge_project:
79
- rubygems_version: 1.5.0
156
+ rubygems_version: 1.8.10
80
157
  signing_key:
81
158
  specification_version: 3
82
159
  summary: Easily consume Blizzard's Community Platform API.
83
- test_files:
84
- - spec/abstract_adapter_spec.rb
85
- - spec/adapter_manager_spec.rb
86
- - spec/api_spec.rb
160
+ test_files:
161
+ - spec/fixtures/cassettes/arena_fun_and_profit.yml
162
+ - spec/fixtures/cassettes/auction_data.yml
163
+ - spec/fixtures/cassettes/auction_files.yml
164
+ - spec/fixtures/cassettes/character_classes.yml
165
+ - spec/fixtures/cassettes/character_mortawa.yml
166
+ - spec/fixtures/cassettes/character_mortawa_es.yml
167
+ - spec/fixtures/cassettes/character_mortawa_titles.yml
168
+ - spec/fixtures/cassettes/character_nonstandard_name.yml
169
+ - spec/fixtures/cassettes/character_races.yml
170
+ - spec/fixtures/cassettes/guild_perks.yml
171
+ - spec/fixtures/cassettes/guild_rewards.yml
172
+ - spec/fixtures/cassettes/guild_rl_bl.yml
173
+ - spec/fixtures/cassettes/guild_rl_bl_members.yml
174
+ - spec/fixtures/cassettes/item_classes.yml
175
+ - spec/fixtures/cassettes/item_hooooooooooo.yml
176
+ - spec/fixtures/cassettes/realm.yml
177
+ - spec/integration/arena_spec.rb
178
+ - spec/integration/auction_spec.rb
179
+ - spec/integration/character_spec.rb
180
+ - spec/integration/data_spec.rb
181
+ - spec/integration/guild_spec.rb
182
+ - spec/integration/item_spec.rb
183
+ - spec/integration/locale_spec.rb
184
+ - spec/integration/realm_spec.rb
87
185
  - spec/spec_helper.rb
186
+ - spec/unit/battlenet_authentication_spec.rb
187
+ - spec/unit/battlenet_spec.rb
@@ -1,11 +0,0 @@
1
- module Battlenet
2
- module Adapter
3
- class NotImplementedException < Exception; end
4
-
5
- class AbstractAdapter
6
- def get(url)
7
- raise NotImplementedException.new("Please implement #get in your adapter")
8
- end
9
- end
10
- end
11
- end
@@ -1,14 +0,0 @@
1
- require 'battlenet/adapter/abstract_adapter'
2
- require 'net/http'
3
-
4
- module Battlenet
5
- module Adapter
6
- class NetHTTP < AbstractAdapter
7
- def get(url)
8
- uri = URI.parse url
9
- response = Net::HTTP.get_response uri
10
- [response.code.to_i, response.body]
11
- end
12
- end
13
- end
14
- end
@@ -1,13 +0,0 @@
1
- require 'battlenet/adapter/abstract_adapter'
2
- require 'typhoeus'
3
-
4
- module Battlenet
5
- module Adapter
6
- class Typhoeus < AbstractAdapter
7
- def get(url)
8
- response = ::Typhoeus::Request.get url
9
- [response.code.to_i, response.body]
10
- end
11
- end
12
- end
13
- end
@@ -1,51 +0,0 @@
1
- module Battlenet
2
- module Adapter; end
3
-
4
- module AdapterManager
5
- class InvalidAdapter < Exception; end
6
-
7
- extend self
8
-
9
- @adapters = {
10
- :net_http => "NetHTTP",
11
- :typhoeus => "Typhoeus"
12
- }
13
-
14
- def adapters
15
- @adapters
16
- end
17
-
18
- def fetch(adapter_name)
19
- unless adapters.include? adapter_name
20
- raise InvalidAdapter.new("#{adapter_name.to_s} is not a valid adapter")
21
- end
22
-
23
- adapter_class = adapters[adapter_name]
24
- adapter = load_adapter adapter_name, adapter_class
25
- end
26
-
27
- def register(identifier, klass)
28
- @adapters[identifier] = klass
29
- end
30
-
31
- private
32
-
33
- def load_adapter(adapter_name, klass_name)
34
- begin
35
- klass = Battlenet::Adapter.const_get("#{klass_name}", false)
36
- rescue NameError
37
- begin
38
- adapter_file = "battlenet/adapter/#{adapter_name.to_s}"
39
- require adapter_file
40
- klass = Battlenet::Adapter.const_get("#{klass_name}", false)
41
- rescue LoadError
42
- raise InvalidAdapter.new("adapter #{klass_name} does not exist, and file #{adapter_file} does not exist")
43
- rescue NameError
44
- raise InvalidAdapter.new("expected #{adapter_file} to define Battlenet::Adapter::#{klass_name}")
45
- end
46
- end
47
-
48
- return klass.new
49
- end
50
- end
51
- end
@@ -1,73 +0,0 @@
1
- require 'battlenet/adapter_manager'
2
- require 'cgi'
3
- require 'json'
4
-
5
- module Battlenet
6
- module API
7
- class APIError < Exception
8
- attr_reader :code, :body
9
- def initialize(code, body)
10
- @code = code
11
- @body = body
12
- end
13
-
14
- def to_s
15
- "Status: #{code} Body: #{body}"
16
- end
17
- end
18
-
19
- extend self
20
-
21
- @config = {
22
- :indifferent_hashes => true,
23
- :http_adapter => :net_http,
24
- :region => :us
25
- }
26
-
27
- def set_option(setting, value)
28
- @config[setting] = value
29
- end
30
-
31
- def get_option(setting, default = nil)
32
- @config[setting] || default
33
- end
34
-
35
- def adapter
36
- @adapter ||= Battlenet::AdapterManager.fetch get_option(:http_adapter)
37
- end
38
-
39
- def base_url
40
- region = get_option(:region, :us).to_s
41
- "http://#{region}.battle.net/api/wow"
42
- end
43
-
44
- def make_api_call(path, query = {})
45
- query_string = query.empty? ? '' : make_query_string(query)
46
- url = base_url
47
- url << (path.start_with?('/') ? '' : '/')
48
- url << path
49
- url << query_string
50
- code, body = get url
51
- raise APIError.new(code, body) unless code == 200
52
- JSON::parse body
53
- end
54
-
55
- def get(url)
56
- adapter.get(url)
57
- end
58
-
59
- def make_query_string(query)
60
- query_string = "?"
61
- query.each do |key, value|
62
- case value
63
- when String
64
- query_string << "#{key}=#{CGI.escape value}&"
65
- when Array
66
- value.each { |v| query_string << "#{key}=#{CGI.escape v}&" }
67
- end
68
- end
69
-
70
- query_string.chomp("&").chomp("?")
71
- end
72
- end
73
- end
@@ -1,14 +0,0 @@
1
- module Battlenet
2
- module API
3
- module Realm
4
- extend self
5
-
6
- @api = Battlenet::API
7
-
8
- def status(options = {})
9
- data = @api.make_api_call 'realm/status', options
10
- data["realms"]
11
- end
12
- end
13
- end
14
- end
@@ -1,3 +0,0 @@
1
- module Battlenet
2
- VERSION = "0.1.1"
3
- end
@@ -1,15 +0,0 @@
1
- require 'battlenet/adapter/abstract_adapter'
2
-
3
- describe Battlenet::Adapter::AbstractAdapter do
4
- it "has a method 'get'" do
5
- subject.should respond_to :get
6
- end
7
-
8
- context "#get" do
9
- it "is abstract" do
10
- lambda {
11
- subject.get('fake_url')
12
- }.should raise_error Battlenet::Adapter::NotImplementedException
13
- end
14
- end
15
- end
@@ -1,55 +0,0 @@
1
- require 'battlenet/adapter_manager'
2
-
3
- describe Battlenet::AdapterManager do
4
- it "has a list of adapters" do
5
- subject.adapters.should be_a Hash
6
- end
7
-
8
- context "#fetch" do
9
- it "raises an exception if an invalid adapter is passed" do
10
- lambda {
11
- subject.fetch(:some_fake_adapter)
12
- }.should raise_error Battlenet::AdapterManager::InvalidAdapter
13
- end
14
-
15
- it "requires a library file based on the adapter chosen if the class doesn't exist" do
16
- subject.should_receive(:require).once.with('battlenet/adapter/net_http')
17
- begin
18
- subject.fetch(:net_http)
19
- rescue Battlenet::AdapterManager::InvalidAdapter
20
- # expected
21
- end
22
- end
23
-
24
- it "raises an error if the adapter class doesn't exist and the library can't be loaded" do
25
- old_adapters = subject.adapters
26
- subject.instance_variable_set(:@adapters, {:adapter => "SuperAdapter"})
27
-
28
- lambda {
29
- subject.fetch(:adapter)
30
- }.should raise_error Battlenet::AdapterManager::InvalidAdapter, /does not exist/
31
-
32
- subject.instance_variable_set(:@adapters, old_adapters)
33
- end
34
-
35
- it "raises an error if the adapter library is loaded but doesn't define the adapter class" do
36
- subject.should_receive(:require).once.with('battlenet/adapter/net_http').and_return(nil)
37
- lambda {
38
- subject.fetch(:net_http)
39
- }.should raise_error Battlenet::AdapterManager::InvalidAdapter, /expected (.*) to define/
40
- end
41
-
42
- it "returns an instance of the adapter" do
43
- adapter = subject.fetch(:net_http)
44
- adapter.should be_a Battlenet::Adapter::NetHTTP
45
- end
46
- end
47
-
48
- context "#register" do
49
- it "registers an adapter" do
50
- lambda do
51
- subject.register(:adapter_identifier, 'AdapterClass')
52
- end.should change(subject.adapters, :count).by(1)
53
- end
54
- end
55
- end