wot_api 1.2.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -0
- data/lib/wot_api/version.rb +1 -1
- data/lib/wot_api/wrapper.rb +5 -4
- data/spec/wot_api_spec.rb +13 -3
- data/spec/wrapper_spec.rb +19 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 465ca78b685225af5587bfab32cee9ac93555cb5
|
4
|
+
data.tar.gz: 77075ce7dd3a01d805091958041709fbd6f098f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c1c510ed773ecafef541de6ac8f6db19eaced474f3a0f215b6d51e58a537b70edace9463e4b66e49f34b02f4cbd35e407cc561d982f0b84fbe1b8b3e7a11c39
|
7
|
+
data.tar.gz: 327698d41f512e033d6b0f3c78d4a08986fed8a3aab4686d6594cd0d42b837c06788346dd283abe192a14a159daae1eb47af2c25a1b62d572f0bb68d8a36e09c
|
data/README.md
CHANGED
@@ -51,6 +51,12 @@ Which wraps the '/wot/account/list' endpoint, with 'search' params and in the :r
|
|
51
51
|
|
52
52
|
Will return an array or hash with the results, or throw an error with a message on a failure.
|
53
53
|
|
54
|
+
For endpoints that do not start with '/wot/' you can use a method like such:
|
55
|
+
|
56
|
+
WotApi.wgn_clans_list(search: 'bananas')
|
57
|
+
|
58
|
+
to use /wgn/clans/list instead of /wot/clans/list
|
59
|
+
|
54
60
|
NOTE: Version 1.2.0 removes the need for all api methods to be called with "WotApi::Base.method", instead can just use "WotApi.method" for less keystrokes. However, the existing methods are still available at WotApi::Base for compatibility.
|
55
61
|
|
56
62
|
## Clan member resources
|
data/lib/wot_api/version.rb
CHANGED
data/lib/wot_api/wrapper.rb
CHANGED
@@ -28,7 +28,7 @@ module WotApi
|
|
28
28
|
def wot_api_post(method_sym, params)
|
29
29
|
params ||= {}
|
30
30
|
endpoint = method_to_endpoint(method_sym)
|
31
|
-
region = params.delete(:region).to_sym
|
31
|
+
region = !params[:region].nil? ? params.delete(:region).to_sym : get_default_region
|
32
32
|
set_base_uri(region)
|
33
33
|
begin
|
34
34
|
response = merged_post(endpoint, region, params)
|
@@ -40,7 +40,7 @@ module WotApi
|
|
40
40
|
|
41
41
|
def wot_web_get(endpoint, params)
|
42
42
|
params ||= {}
|
43
|
-
region = params.delete(:region).to_sym
|
43
|
+
region = !params[:region].nil? ? params.delete(:region).to_sym : get_default_region
|
44
44
|
set_base_uri(region, true)
|
45
45
|
begin
|
46
46
|
return self.get(endpoint, params).parsed_response
|
@@ -50,13 +50,14 @@ module WotApi
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def valid_endpoint?(method_sym)
|
53
|
-
!(method_sym.to_s =~ /^([^_]
|
53
|
+
!(method_sym.to_s =~ /^([^_]+)_([^_]+)$/).nil? || !(method_sym.to_s =~ /^([^_]+)_([^_]+)_([^_]+)$/).nil?
|
54
54
|
end
|
55
55
|
|
56
56
|
private
|
57
57
|
|
58
58
|
def method_to_endpoint(method_sym)
|
59
|
-
|
59
|
+
method_sym = ('wot_' + method_sym.to_s).to_sym if method_sym.to_s.count('_') == 1
|
60
|
+
"/" + method_sym.to_s.gsub('_','/') + "/"
|
60
61
|
end
|
61
62
|
|
62
63
|
def set_base_uri(region, web=false)
|
data/spec/wot_api_spec.rb
CHANGED
@@ -41,9 +41,19 @@ describe WotApi do
|
|
41
41
|
WotApi.fake_method
|
42
42
|
end
|
43
43
|
|
44
|
-
|
45
|
-
|
46
|
-
|
44
|
+
context "with a two-part method name" do
|
45
|
+
it "calls WotApi::Wrapper.wot_api_post with method symbol and parameters" do
|
46
|
+
expect(WotApi::Wrapper).to receive(:wot_api_post).with(:fake_method, {hi: true})
|
47
|
+
WotApi.fake_method(hi: true)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context "with a three-part method name" do
|
52
|
+
it "calls WotApi::Wrapper.wot_api_post with method symbol and parameters" do
|
53
|
+
allow(WotApi::Wrapper).to receive(:valid_endpoint?).with(:quite_fake_method).and_return(true)
|
54
|
+
expect(WotApi::Wrapper).to receive(:wot_api_post).with(:quite_fake_method, {hi: true})
|
55
|
+
WotApi.quite_fake_method(hi: true)
|
56
|
+
end
|
47
57
|
end
|
48
58
|
end
|
49
59
|
|
data/spec/wrapper_spec.rb
CHANGED
@@ -30,10 +30,20 @@ describe WotApi::Wrapper do
|
|
30
30
|
FakeWeb.register_uri(:post, "https://api.worldoftanks.com/wot/thing/stuff/", :response => File.join(File.dirname(__FILE__), 'fixtures', "success.json"))
|
31
31
|
WotApi.config({'na' => '123456'})
|
32
32
|
end
|
33
|
-
it "
|
33
|
+
it "returns an array" do
|
34
34
|
expect(WotApi::Wrapper.wot_api_post(:thing_stuff, {})).to be_an Array
|
35
35
|
end
|
36
36
|
end
|
37
|
+
|
38
|
+
context "with a valid endpoint on a different path header" do
|
39
|
+
before(:example) do
|
40
|
+
FakeWeb.register_uri(:post, "https://api.worldoftanks.com/wgn/misc/etc/", :response => File.join(File.dirname(__FILE__), 'fixtures', "success.json"))
|
41
|
+
WotApi.config({'na' => '123456'})
|
42
|
+
end
|
43
|
+
it "returns an array" do
|
44
|
+
expect(WotApi::Wrapper.wot_api_post(:wgn_misc_etc, {})).to be_an Array
|
45
|
+
end
|
46
|
+
end
|
37
47
|
end
|
38
48
|
|
39
49
|
describe ".wot_web_get" do
|
@@ -62,6 +72,14 @@ describe WotApi::Wrapper do
|
|
62
72
|
it "returns true for endponts like prefix _underscore_ suffix" do
|
63
73
|
expect(WotApi::Wrapper.valid_endpoint?(:test_things)).to eq true
|
64
74
|
end
|
75
|
+
it "returns true for three-part endpoints" do
|
76
|
+
expect(WotApi::Wrapper.valid_endpoint?(:what_ever_dude)).to eq true
|
77
|
+
end
|
78
|
+
it "returns false for other stuff" do
|
79
|
+
expect(WotApi::Wrapper.valid_endpoint?(:things)).to eq false
|
80
|
+
expect(WotApi::Wrapper.valid_endpoint?(:stuff_blah_things_and)).to eq false
|
81
|
+
expect(WotApi::Wrapper.valid_endpoint?(:whee_)).to eq false
|
82
|
+
end
|
65
83
|
end
|
66
84
|
|
67
85
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wot_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jesse Cantara
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|