ruby-lol 0.12.1 → 0.12.2
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.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/lib/lol/request.rb +23 -19
- data/lib/lol/tournament_provider_request.rb +4 -6
- data/lib/lol/version.rb +1 -1
- data/ruby-lol.gemspec +1 -2
- data/spec/lol/request_spec.rb +40 -38
- data/spec/lol/tournament_provider_request_spec.rb +21 -17
- data/spec/support/helpers.rb +3 -3
- metadata +6 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7905f3bdcac7fda308692df41aff8d9537551896
|
4
|
+
data.tar.gz: e1630306ddc4bc8ece93e8453c14935fdb75700b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69fc42943c76aa7dedab87b97d367e8f9dad3e7834b6a1694e4f9c9b0915749f3343c8e12030e5d94aa4ced8518c7f0fd26701e47002dedbb703b5e895270b34
|
7
|
+
data.tar.gz: 954c3a76a2e147b97146151cc05b1ea14afa8b0ed7db1751760fc664c79ddb1b16338a8db7327fb902c47daf0a80d7aaedc1f55cc401ff34b03208640ed4e455
|
data/.travis.yml
CHANGED
data/lib/lol/request.rb
CHANGED
@@ -38,18 +38,6 @@ module Lol
|
|
38
38
|
"#{url}?#{api_query_string params}"
|
39
39
|
end
|
40
40
|
|
41
|
-
def post_api_url path, params = {}
|
42
|
-
{
|
43
|
-
url: api_url(path, params),
|
44
|
-
options: {
|
45
|
-
headers: {
|
46
|
-
"X-Riot-Token" => api_key,
|
47
|
-
"Content-Type" => "application/json"
|
48
|
-
}
|
49
|
-
}
|
50
|
-
}
|
51
|
-
end
|
52
|
-
|
53
41
|
def api_base_url
|
54
42
|
"https://#{region}.api.pvp.net"
|
55
43
|
end
|
@@ -72,23 +60,39 @@ module Lol
|
|
72
60
|
# @param body [Hash] Body for POST request
|
73
61
|
# @param options [Hash] Options passed to HTTParty
|
74
62
|
# @return [String] raw response of the call
|
75
|
-
def perform_request url, verb = :get, body =
|
63
|
+
def perform_request url, verb = :get, body = nil, options = {}
|
64
|
+
options_id = options.inspect
|
76
65
|
can_cache = [:post, :put].include?(verb) ? false : cached?
|
77
|
-
if can_cache && result = store.get("#{clean_url(url)}#{
|
66
|
+
if can_cache && result = store.get("#{clean_url(url)}#{options_id}")
|
78
67
|
return JSON.parse(result)
|
79
68
|
end
|
69
|
+
response = perform_uncached_request url, verb, body, options
|
70
|
+
store.setex "#{clean_url(url)}#{options_id}", ttl, response.to_json if can_cache
|
71
|
+
response
|
72
|
+
end
|
80
73
|
|
81
|
-
|
82
|
-
|
74
|
+
def perform_uncached_request url, verb = :get, body = nil, options = {}
|
75
|
+
options[:headers] ||= {}
|
76
|
+
options[:headers].merge!({
|
77
|
+
"Content-Type" => "application/json",
|
78
|
+
"Accept" => "application/json"
|
79
|
+
})
|
80
|
+
if [:post, :put].include?(verb)
|
81
|
+
options[:body] = body.to_json if body
|
82
|
+
options[:headers]['X-Riot-Token'] = api_key
|
83
|
+
end
|
84
|
+
response = self.class.send(verb, url, options)
|
83
85
|
if response.respond_to?(:code) && !(200...300).include?(response.code)
|
84
86
|
raise NotFound.new("404 Not Found") if response.not_found?
|
85
87
|
raise TooManyRequests.new('429 Rate limit exceeded') if response.code == 429
|
86
88
|
raise InvalidAPIResponse.new(url, response)
|
87
89
|
end
|
88
90
|
|
89
|
-
|
90
|
-
|
91
|
-
|
91
|
+
if response.respond_to?(:parsed_response)
|
92
|
+
response.parsed_response
|
93
|
+
else
|
94
|
+
response
|
95
|
+
end
|
92
96
|
end
|
93
97
|
|
94
98
|
# @return [Redis] returns the cache store
|
@@ -14,12 +14,11 @@ module Lol
|
|
14
14
|
# @param path [String] API path to call
|
15
15
|
# @return [String] full fledged url
|
16
16
|
def api_url path, params = {}
|
17
|
-
|
17
|
+
"#{api_base_url}/tournament/public/#{self.class.api_version}/#{path}"
|
18
18
|
end
|
19
19
|
|
20
20
|
def tournament_request path, body
|
21
|
-
|
22
|
-
perform_request(pau[:url], :post, body, pau[:options]).body
|
21
|
+
perform_request(api_url(path), :post, body)
|
23
22
|
end
|
24
23
|
|
25
24
|
# Returns a tournament code
|
@@ -57,7 +56,7 @@ module Lol
|
|
57
56
|
body.merge!({password: password}) if password
|
58
57
|
|
59
58
|
params = URI.encode_www_form({tournamentId: tournament_id, count: count})
|
60
|
-
|
59
|
+
tournament_request "code?#{params}", body
|
61
60
|
end
|
62
61
|
|
63
62
|
# Returns the details of the tournament code
|
@@ -87,8 +86,7 @@ module Lol
|
|
87
86
|
mapType: map_type
|
88
87
|
}.reject{ |k,v| v.nil? }
|
89
88
|
|
90
|
-
|
91
|
-
perform_request(pau[:url], :put, body, pau[:options])
|
89
|
+
perform_request(api_url("code/#{tournament_code}"), :put, body)
|
92
90
|
get_code tournament_code
|
93
91
|
end
|
94
92
|
|
data/lib/lol/version.rb
CHANGED
data/ruby-lol.gemspec
CHANGED
@@ -26,8 +26,7 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.add_development_dependency "guard-rspec"
|
27
27
|
spec.add_development_dependency "ZenTest"
|
28
28
|
spec.add_development_dependency "autotest-growl"
|
29
|
-
spec.add_development_dependency "
|
30
|
-
spec.add_development_dependency "codeclimate-test-reporter"
|
29
|
+
spec.add_development_dependency "codeclimate-test-reporter", '~> 0.5.0'
|
31
30
|
spec.add_development_dependency "coveralls"
|
32
31
|
spec.add_development_dependency "vcr"
|
33
32
|
spec.add_development_dependency "webmock", ">= 1.8.0", "< 1.16"
|
data/spec/lol/request_spec.rb
CHANGED
@@ -37,25 +37,60 @@ describe Request do
|
|
37
37
|
|
38
38
|
it "calls HTTParty get" do
|
39
39
|
expect(subject.class).to receive(:get).and_return(error401)
|
40
|
-
expect { subject.perform_request "foo
|
40
|
+
expect { subject.perform_request subject.api_url("foo")}.to raise_error(InvalidAPIResponse)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "sets content type in get requests" do
|
44
|
+
expect(subject.class).to receive(:get) do |url, options|
|
45
|
+
expect(options[:headers]["Content-Type"]).to eq "application/json"
|
46
|
+
end
|
47
|
+
subject.perform_request subject.api_url("foo")
|
48
|
+
end
|
49
|
+
|
50
|
+
it "sets the accept header in get requests" do
|
51
|
+
expect(subject.class).to receive(:get) do |url, options|
|
52
|
+
expect(options[:headers]["Accept"]).to eq "application/json"
|
53
|
+
end
|
54
|
+
subject.perform_request subject.api_url("foo")
|
55
|
+
end
|
56
|
+
|
57
|
+
it "sets content type in post requests" do
|
58
|
+
expect(subject.class).to receive(:post) do |url, options|
|
59
|
+
expect(options[:headers]["Content-Type"]).to eq "application/json"
|
60
|
+
end
|
61
|
+
subject.perform_request subject.api_url("foo"), :post
|
62
|
+
end
|
63
|
+
|
64
|
+
it "sets the accept header in post requests" do
|
65
|
+
expect(subject.class).to receive(:post) do |url, options|
|
66
|
+
expect(options[:headers]["Accept"]).to eq "application/json"
|
67
|
+
end
|
68
|
+
subject.perform_request subject.api_url("foo"), :post
|
69
|
+
end
|
70
|
+
|
71
|
+
it "sets the api key header in post requests" do
|
72
|
+
expect(subject.class).to receive(:post) do |url, options|
|
73
|
+
expect(options[:headers]["X-Riot-Token"]).to eq(subject.api_key)
|
74
|
+
end
|
75
|
+
subject.perform_request subject.api_url("foo"), :post
|
41
76
|
end
|
42
77
|
|
43
78
|
it "handles 401" do
|
44
79
|
expect(subject.class).to receive(:get).and_return(error401)
|
45
|
-
expect { subject.perform_request "foo
|
80
|
+
expect { subject.perform_request subject.api_url("foo") }.to raise_error(InvalidAPIResponse)
|
46
81
|
end
|
47
82
|
|
48
83
|
it "handles 404" do
|
49
84
|
expect(error401).to receive(:respond_to?).at_least(:once).and_return(true)
|
50
85
|
expect(error401).to receive(:not_found?).and_return(true)
|
51
86
|
expect(subject.class).to receive(:get).and_return(error401)
|
52
|
-
expect { subject.perform_request "foo
|
87
|
+
expect { subject.perform_request subject.api_url("foo")}.to raise_error(NotFound)
|
53
88
|
end
|
54
89
|
|
55
90
|
it 'handles 429' do
|
56
91
|
expect(error429).to receive(:respond_to?).and_return(true)
|
57
92
|
expect(subject.class).to receive(:get).and_return(error429)
|
58
|
-
expect { subject.perform_request "foo
|
93
|
+
expect { subject.perform_request subject.api_url("foo")}.to raise_error(TooManyRequests)
|
59
94
|
end
|
60
95
|
|
61
96
|
context "post requests" do
|
@@ -88,7 +123,7 @@ describe Request do
|
|
88
123
|
let(:fake_redis) { FakeRedis.new }
|
89
124
|
let(:request) { Request.new "api_key", "euw", {redis: fake_redis, ttl: 60, cached: true }}
|
90
125
|
before :each do
|
91
|
-
expect(request.class).to receive(:get).with("/foo?api_key=asd").and_return({foo: "bar"}).at_least(:once)
|
126
|
+
expect(request.class).to receive(:get).with("/foo?api_key=asd", instance_of(Hash)).and_return({foo: "bar"}).at_least(:once)
|
92
127
|
first_result = request.perform_request "/foo?api_key=asd"
|
93
128
|
end
|
94
129
|
|
@@ -157,39 +192,6 @@ describe Request do
|
|
157
192
|
end
|
158
193
|
end
|
159
194
|
|
160
|
-
describe "post_api_url" do
|
161
|
-
let(:pau) { subject.post_api_url "/foo" }
|
162
|
-
|
163
|
-
it "returns an hash" do
|
164
|
-
expect(pau).to be_a(Hash)
|
165
|
-
end
|
166
|
-
|
167
|
-
it "contains an url key" do
|
168
|
-
expect(pau).to have_key(:url)
|
169
|
-
end
|
170
|
-
|
171
|
-
it "contains an options key" do
|
172
|
-
expect(pau).to have_key(:options)
|
173
|
-
end
|
174
|
-
|
175
|
-
it "contains a header key in options" do
|
176
|
-
expect(pau[:options]).to have_key(:headers)
|
177
|
-
end
|
178
|
-
|
179
|
-
it "returns the api key in an header" do
|
180
|
-
expect(pau[:options][:headers]).to have_key("X-Riot-Token")
|
181
|
-
expect(pau[:options][:headers]["X-Riot-Token"]).to eq(subject.api_key)
|
182
|
-
end
|
183
|
-
|
184
|
-
it "includes a content-type header" do
|
185
|
-
expect(pau[:options][:headers]["Content-Type"]).to eq("application/json")
|
186
|
-
end
|
187
|
-
|
188
|
-
it "uses api_url for the url part" do
|
189
|
-
expect(pau[:url]).to eq(subject.api_url "/foo")
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
195
|
describe "#api_base_url" do
|
194
196
|
it "returns the base domain" do
|
195
197
|
expect(subject.api_base_url).to eq "https://euw.api.pvp.net"
|
@@ -21,20 +21,25 @@ describe TournamentProviderRequest do
|
|
21
21
|
describe "#provider" do
|
22
22
|
subject { request.provider("EUW", "https://foo.com") }
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
24
|
+
before(:each) do
|
25
|
+
expect(TournamentProviderRequest).to receive(:perform_request).and_return 10
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'return the provider id' do
|
29
|
+
expect(subject).to eq 10
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#tournament" do
|
34
|
+
subject { request.provider("test", 10) }
|
35
|
+
|
36
|
+
before(:each) do
|
37
|
+
expect(TournamentProviderRequest).to receive(:perform_request).and_return 20
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'return the tournament provider id' do
|
41
|
+
expect(subject).to eq 20
|
42
|
+
end
|
38
43
|
end
|
39
44
|
|
40
45
|
describe "#get_code" do
|
@@ -43,7 +48,7 @@ describe TournamentProviderRequest do
|
|
43
48
|
full_url = request.api_url "code/CODE-FOR-TEST?#{request.api_query_string}"
|
44
49
|
fixture_json = load_fixture('get-code', TournamentProviderRequest.api_version)
|
45
50
|
|
46
|
-
expect(TournamentProviderRequest).to receive(:get).with(full_url).and_return(fixture_json)
|
51
|
+
expect(TournamentProviderRequest).to receive(:get).with(full_url, instance_of(Hash)).and_return(fixture_json)
|
47
52
|
end
|
48
53
|
subject { request.get_code "CODE-FOR-TEST" }
|
49
54
|
|
@@ -59,8 +64,7 @@ describe TournamentProviderRequest do
|
|
59
64
|
expect(request).to receive(:perform_request).once.ordered.with(
|
60
65
|
instance_of(String),
|
61
66
|
:put,
|
62
|
-
{ allowedParticipants: "1,2,3,4,5,6,7,8,9,10" }
|
63
|
-
instance_of(Hash)
|
67
|
+
{ allowedParticipants: "1,2,3,4,5,6,7,8,9,10" }
|
64
68
|
)
|
65
69
|
expect(request).to receive(:perform_request).once.ordered.with(instance_of(String)).and_return(fixture)
|
66
70
|
request.update_code "CODE-FOR-TEST", { allowed_participants: [1,2,3,4,5,6,7,8,9,10] }
|
data/spec/support/helpers.rb
CHANGED
@@ -51,13 +51,13 @@ module Helpers
|
|
51
51
|
full_url = request_object.api_url(url, params)
|
52
52
|
fixture_json = load_fixture(fixture_name, request_class.api_version, :get)
|
53
53
|
|
54
|
-
expect(request_class).to receive(:get).with(full_url).and_return(fixture_json)
|
54
|
+
expect(request_class).to receive(:get).with(full_url, instance_of(Hash)).and_return(fixture_json)
|
55
55
|
end
|
56
56
|
|
57
57
|
def stub_request_raw(request_object, raw_response, url, params={})
|
58
58
|
request_class = request_object.class
|
59
59
|
full_url = request_object.api_url(url, params)
|
60
60
|
|
61
|
-
expect(request_class).to receive(:get).with(full_url).and_return(raw_response)
|
61
|
+
expect(request_class).to receive(:get).with(full_url, instance_of(Hash)).and_return(raw_response)
|
62
62
|
end
|
63
|
-
end
|
63
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-lol
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.12.
|
4
|
+
version: 0.12.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Giovanni Intini
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-10-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -122,34 +122,20 @@ dependencies:
|
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
|
-
- !ruby/object:Gem::Dependency
|
126
|
-
name: autotest-fsevent
|
127
|
-
requirement: !ruby/object:Gem::Requirement
|
128
|
-
requirements:
|
129
|
-
- - ">="
|
130
|
-
- !ruby/object:Gem::Version
|
131
|
-
version: '0'
|
132
|
-
type: :development
|
133
|
-
prerelease: false
|
134
|
-
version_requirements: !ruby/object:Gem::Requirement
|
135
|
-
requirements:
|
136
|
-
- - ">="
|
137
|
-
- !ruby/object:Gem::Version
|
138
|
-
version: '0'
|
139
125
|
- !ruby/object:Gem::Dependency
|
140
126
|
name: codeclimate-test-reporter
|
141
127
|
requirement: !ruby/object:Gem::Requirement
|
142
128
|
requirements:
|
143
|
-
- - "
|
129
|
+
- - "~>"
|
144
130
|
- !ruby/object:Gem::Version
|
145
|
-
version:
|
131
|
+
version: 0.5.0
|
146
132
|
type: :development
|
147
133
|
prerelease: false
|
148
134
|
version_requirements: !ruby/object:Gem::Requirement
|
149
135
|
requirements:
|
150
|
-
- - "
|
136
|
+
- - "~>"
|
151
137
|
- !ruby/object:Gem::Version
|
152
|
-
version:
|
138
|
+
version: 0.5.0
|
153
139
|
- !ruby/object:Gem::Dependency
|
154
140
|
name: coveralls
|
155
141
|
requirement: !ruby/object:Gem::Requirement
|