battlenet 0.1.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +31 -45
- data/VERSION +1 -0
- data/battlenet.gemspec +13 -2
- data/lib/battlenet.rb +95 -2
- data/lib/battlenet/authentication.rb +21 -0
- data/lib/battlenet/modules/arena.rb +13 -0
- data/lib/battlenet/modules/auction.rb +18 -0
- data/lib/battlenet/modules/character.rb +12 -0
- data/lib/battlenet/modules/data.rb +23 -0
- data/lib/battlenet/modules/guild.rb +12 -0
- data/lib/battlenet/modules/item.rb +7 -0
- data/lib/battlenet/modules/realm.rb +7 -0
- data/spec/fixtures/cassettes/arena_fun_and_profit.yml +29 -0
- data/spec/fixtures/cassettes/auction_data.yml +63 -0
- data/spec/fixtures/cassettes/auction_files.yml +30 -0
- data/spec/fixtures/cassettes/character_classes.yml +33 -0
- data/spec/fixtures/cassettes/character_mortawa.yml +30 -0
- data/spec/fixtures/cassettes/character_mortawa_es.yml +48 -0
- data/spec/fixtures/cassettes/character_mortawa_titles.yml +32 -0
- data/spec/fixtures/cassettes/character_nonstandard_name.yml +30 -0
- data/spec/fixtures/cassettes/character_races.yml +34 -0
- data/spec/fixtures/cassettes/guild_perks.yml +91 -0
- data/spec/fixtures/cassettes/guild_rewards.yml +175 -0
- data/spec/fixtures/cassettes/guild_rl_bl.yml +28 -0
- data/spec/fixtures/cassettes/guild_rl_bl_members.yml +28 -0
- data/spec/fixtures/cassettes/item_classes.yml +33 -0
- data/spec/fixtures/cassettes/item_hooooooooooo.yml +29 -0
- data/spec/fixtures/cassettes/realm.yml +69 -0
- data/spec/integration/arena_spec.rb +14 -0
- data/spec/integration/auction_spec.rb +22 -0
- data/spec/integration/character_spec.rb +29 -0
- data/spec/integration/data_spec.rb +41 -0
- data/spec/integration/guild_spec.rb +20 -0
- data/spec/integration/item_spec.rb +13 -0
- data/spec/integration/locale_spec.rb +23 -0
- data/spec/integration/realm_spec.rb +15 -0
- data/spec/spec_helper.rb +7 -0
- data/spec/unit/battlenet_authentication_spec.rb +31 -0
- data/spec/unit/battlenet_spec.rb +158 -0
- metadata +151 -51
- data/lib/battlenet/adapter/abstract_adapter.rb +0 -11
- data/lib/battlenet/adapter/net_http.rb +0 -14
- data/lib/battlenet/adapter/typhoeus.rb +0 -13
- data/lib/battlenet/adapter_manager.rb +0 -51
- data/lib/battlenet/api.rb +0 -73
- data/lib/battlenet/api/realm.rb +0 -14
- data/lib/battlenet/version.rb +0 -3
- data/spec/abstract_adapter_spec.rb +0 -15
- data/spec/adapter_manager_spec.rb +0 -55
- data/spec/api_spec.rb +0 -115
data/spec/api_spec.rb
DELETED
@@ -1,115 +0,0 @@
|
|
1
|
-
require 'battlenet/api'
|
2
|
-
|
3
|
-
describe Battlenet::API do
|
4
|
-
context "configuration management" do
|
5
|
-
it "defauls to nil when getting an unset option" do
|
6
|
-
subject.get_option(:a_fake_setting_i_made_up).should be_nil
|
7
|
-
end
|
8
|
-
|
9
|
-
it "returns a passed value if an option is not set" do
|
10
|
-
subject.get_option(:a_fake_setting_i_made_up, "value").should == "value"
|
11
|
-
end
|
12
|
-
|
13
|
-
it "allows setting and retrieving a value" do
|
14
|
-
subject.set_option(:a_fake_setting_i_made_up, "my_value")
|
15
|
-
subject.get_option(:a_fake_setting_i_made_up).should == "my_value"
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
context "default configuration" do
|
20
|
-
it "defaults to the US region" do
|
21
|
-
subject.get_option(:region).should == :us
|
22
|
-
end
|
23
|
-
|
24
|
-
it "defaults to indifferent hashes" do
|
25
|
-
subject.get_option(:indifferent_hashes).should == true
|
26
|
-
end
|
27
|
-
|
28
|
-
it "defaults to the Net::HTTP library" do
|
29
|
-
subject.get_option(:http_adapter).should == :net_http
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
context "HTTP adapter" do
|
34
|
-
it "retrieval is via the Adapter module" do
|
35
|
-
adapter = subject.get_option(:http_adapter)
|
36
|
-
Battlenet::AdapterManager.should_receive(:fetch).with(adapter)
|
37
|
-
subject.send(:adapter)
|
38
|
-
end
|
39
|
-
|
40
|
-
it "caches its adapter" do
|
41
|
-
mock_adapter = mock("adapter")
|
42
|
-
Battlenet::AdapterManager.should_receive(:fetch).with(any_args()).and_return(mock_adapter)
|
43
|
-
adapter = subject.send(:adapter)
|
44
|
-
subject.set_option(:http_adapter, :fake_adapter)
|
45
|
-
subject.send(:adapter).should == mock_adapter
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
it "returns a base URL dependant on the region" do
|
50
|
-
old_region = subject.get_option(:region)
|
51
|
-
subject.set_option(:region, :eu)
|
52
|
-
subject.send(:base_url).should == "http://eu.battle.net/api/wow"
|
53
|
-
subject.set_option(:region, old_region)
|
54
|
-
end
|
55
|
-
|
56
|
-
context "#make_query_string" do
|
57
|
-
it "produces an empty string with an empty hash" do
|
58
|
-
str = subject.send(:make_query_string, {})
|
59
|
-
str.should be_empty
|
60
|
-
end
|
61
|
-
|
62
|
-
it "starts with a question mark" do
|
63
|
-
str = subject.send(:make_query_string, {:first => "value1", :second => "value2"})
|
64
|
-
str.start_with?("?").should == true
|
65
|
-
end
|
66
|
-
|
67
|
-
it "parses a basic hash" do
|
68
|
-
str = subject.send(:make_query_string, {:first => "value1", :second => "value2"})
|
69
|
-
str.should == "?first=value1&second=value2"
|
70
|
-
end
|
71
|
-
|
72
|
-
it "parses a hash with array values" do
|
73
|
-
str = subject.send(:make_query_string, {:first => ["value1", "value2"], :second => "value3"})
|
74
|
-
str.should == "?first=value1&first=value2&second=value3"
|
75
|
-
end
|
76
|
-
|
77
|
-
it "escapes values" do
|
78
|
-
str = subject.send(:make_query_string, {:first => ["value1", "va&lue2"], :second => "val&ue3"})
|
79
|
-
str.should == "?first=value1&first=va%26lue2&second=val%26ue3"
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
context "#make_api_call" do
|
84
|
-
it "makes a get call with the correct URL" do
|
85
|
-
subject.should_receive(:get).once.with("http://us.battle.net/api/wow/my/path").and_return([200, '{"testing": "value"}'])
|
86
|
-
subject.send(:make_api_call, '/my/path')
|
87
|
-
end
|
88
|
-
|
89
|
-
it "adds a slash to the path if necessary" do
|
90
|
-
subject.should_receive(:get).once.with("http://us.battle.net/api/wow/my/path").and_return([200, '{"testing": "value"}'])
|
91
|
-
subject.send(:make_api_call, 'my/path')
|
92
|
-
end
|
93
|
-
|
94
|
-
it "converts the second parameter into a query string" do
|
95
|
-
options = {:first => ["value1", "va&lue2"], :second => "val&ue3"}
|
96
|
-
query_string = subject.send(:make_query_string, options)
|
97
|
-
subject.should_receive(:get).once.with("http://us.battle.net/api/wow/my/path#{query_string}").and_return([200, '{"testing": "value"}'])
|
98
|
-
subject.send(:make_api_call, 'my/path', options)
|
99
|
-
end
|
100
|
-
|
101
|
-
it "raises an exception on an error" do
|
102
|
-
subject.adapter.should_receive(:get).and_return([404, "not found"])
|
103
|
-
lambda {
|
104
|
-
subject.make_api_call('my/path')
|
105
|
-
}.should raise_error Battlenet::API::APIError, /404 (.*) not found/
|
106
|
-
end
|
107
|
-
|
108
|
-
it "returns the data as JSON" do
|
109
|
-
subject.adapter.should_receive(:get).and_return([200, '{"testing": "value"}'])
|
110
|
-
data = subject.make_api_call('my/path')
|
111
|
-
data.should be_a Hash
|
112
|
-
data["testing"].should == "value"
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|