3scale_client 2.8.2 → 2.9.0
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 +10 -13
- data/3scale_client.gemspec +2 -2
- data/CHANGELOG.md +8 -0
- data/README.md +9 -8
- data/lib/3scale/authorize_response.rb +13 -0
- data/lib/3scale/client.rb +5 -5
- data/lib/3scale/client/version.rb +1 -1
- data/test/client_test.rb +14 -2
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8fd79baa77606faea09171e9c577d1694c17ea5a
|
4
|
+
data.tar.gz: 87ab11fd2aee6b31888ba5f22dcce546ee36d265
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 172557eb19d4c5bdca48c89e8a3d8785defdafc0300aac49d5d6692b9d32279fb78d5b059b8aea936cd1fa636ff62c4a559a11fdc06f88ffb79407f829d48845
|
7
|
+
data.tar.gz: 631bea0687f9ae848ba1622ceb375edf27d82b039963651c8fb969e1a25e96ae350b27a21cb6f4bfa04155c851f15d5162e1de9c21cea77e32adf819f0518abc
|
data/.travis.yml
CHANGED
@@ -1,27 +1,24 @@
|
|
1
|
+
sudo: required
|
2
|
+
dist: trusty
|
1
3
|
language: ruby
|
2
4
|
cache: bundler
|
3
|
-
sudo: false
|
4
5
|
rvm:
|
5
|
-
- 2.
|
6
|
-
- 2.
|
7
|
-
- 2.
|
8
|
-
- 2.3.0
|
9
|
-
- jruby
|
6
|
+
- 2.1
|
7
|
+
- 2.2
|
8
|
+
- 2.3
|
10
9
|
gemfile:
|
11
10
|
- Gemfile
|
12
|
-
- gemfiles/rack_1.gemfile
|
13
11
|
matrix:
|
14
12
|
exclude:
|
15
|
-
- rvm: 2.0.0
|
16
|
-
gemfile: Gemfile
|
17
13
|
- rvm: 2.1
|
18
14
|
gemfile: Gemfile
|
19
|
-
|
20
|
-
|
21
|
-
|
15
|
+
include:
|
16
|
+
- rvm: 2.1
|
17
|
+
gemfile: gemfiles/rack_1.gemfile
|
18
|
+
- rvm: jruby-9.1.5.0
|
22
19
|
gemfile: Gemfile
|
20
|
+
jdk: oraclejdk8
|
23
21
|
env:
|
24
22
|
global:
|
25
23
|
- TEST_3SCALE_APP_IDS=4d4b20b9 TEST_3SCALE_APP_KEYS=ecce202ecc2eb8dc7a499c34a34d5987
|
26
24
|
- secure: VSElS0KvnufcZKStV7kj6xHFEiWvQkpxk1IEuhKq5JqywniN/6ScaNUFxbBKrOUrqhzXIRUCteBP2wvYRjlNhLFZSnYskzh7dLkOp/WV+WK6KjrdflTiF6UTxW4pBSsg6YDJ/wWJlmwsPVty1pRvOE3ru6uco+dTWCCLn4BvWqc=
|
27
|
-
- JRUBY_OPTS="--2.0"
|
data/3scale_client.gemspec
CHANGED
@@ -18,9 +18,9 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.required_ruby_version = '>= 2.
|
21
|
+
spec.required_ruby_version = '>= 2.1'
|
22
22
|
|
23
|
-
spec.add_development_dependency "bundler", "~> 1.
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
24
24
|
spec.add_development_dependency "rake"
|
25
25
|
spec.add_development_dependency "rdoc"
|
26
26
|
spec.add_development_dependency "fakeweb"
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
# Change Log
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
+
## [2.9.0] - 2016-10-21
|
5
|
+
This version drops support for Ruby versions < 2.1 and JRuby < 9.1.1.0.
|
6
|
+
|
7
|
+
### Added
|
8
|
+
- Added method `ThreeScale::Client::AuthorizeResponse#limits_exceeded?`
|
9
|
+
to check whether an authorization is denied and is so because at least
|
10
|
+
one metric went over the limits.
|
11
|
+
|
4
12
|
## [2.8.2] - 2016-10-18
|
5
13
|
### Added
|
6
14
|
- Added support for retrieving metric hierarchies in authorize calls.
|
data/README.md
CHANGED
@@ -12,7 +12,8 @@ Analytics Setup: https://support.3scale.net/quickstarts/3scale-api-analytics
|
|
12
12
|
|
13
13
|
## Installation
|
14
14
|
|
15
|
-
This library is distributed as a gem
|
15
|
+
This library is distributed as a gem, for which Ruby 2.1 or JRuby 9.1.1.0 are
|
16
|
+
minimum requirements:
|
16
17
|
```sh
|
17
18
|
gem install 3scale_client
|
18
19
|
```
|
@@ -92,19 +93,19 @@ The example is using the app_id authentication pattern, but you can also use oth
|
|
92
93
|
class ApplicationController < ActionController
|
93
94
|
# Call the authenticate method on each request to the API
|
94
95
|
before_filter :authenticate
|
95
|
-
|
96
|
+
|
96
97
|
# You only need to instantiate a new Client once and store it as a global variable
|
97
98
|
# You should store your provider key in the environment because this key is secret!
|
98
99
|
def create_client
|
99
|
-
@@threescale_client ||= ThreeScale::Client.new(:provider_key => ENV['PROVIDER_KEY'])
|
100
|
+
@@threescale_client ||= ThreeScale::Client.new(:provider_key => ENV['PROVIDER_KEY'])
|
100
101
|
end
|
101
|
-
|
102
|
-
# To record usage, create a new metric in your application plan. You will use the
|
103
|
-
# "system name" that you specifed on the metric/method to pass in as the key to the usage hash.
|
104
|
-
# The key needs to be a symbol.
|
102
|
+
|
103
|
+
# To record usage, create a new metric in your application plan. You will use the
|
104
|
+
# "system name" that you specifed on the metric/method to pass in as the key to the usage hash.
|
105
|
+
# The key needs to be a symbol.
|
105
106
|
# A way to pass the metric is to add a parameter that will pass the name of the metric/method along
|
106
107
|
def authenticate
|
107
|
-
response = create_client.authrep(:app_id => params["app_id"],
|
108
|
+
response = create_client.authrep(:app_id => params["app_id"],
|
108
109
|
:app_key => params["app_key"],
|
109
110
|
:usage => { params[:metric].to_sym => 1 })
|
110
111
|
if response.success?
|
@@ -27,6 +27,13 @@ module ThreeScale
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
+
# These 2 constants are defined according to what the 3scale
|
31
|
+
# backend returns in the response of authorize calls.
|
32
|
+
LIMITS_EXCEEDED = 'limits_exceeded'.freeze
|
33
|
+
private_constant :LIMITS_EXCEEDED
|
34
|
+
LIMITS_EXCEEDED_MSG = 'usage limits are exceeded'.freeze
|
35
|
+
private_constant :LIMITS_EXCEEDED_MSG
|
36
|
+
|
30
37
|
attr_accessor :plan
|
31
38
|
attr_accessor :app_key
|
32
39
|
attr_accessor :redirect_url
|
@@ -51,5 +58,11 @@ module ThreeScale
|
|
51
58
|
def add_metric_to_hierarchy(metric_name, children)
|
52
59
|
@hierarchy[metric_name] = children
|
53
60
|
end
|
61
|
+
|
62
|
+
# The response already specifies whether any usage report (if present)
|
63
|
+
# is over the limits, so use that instead of scanning the reports.
|
64
|
+
def limits_exceeded?
|
65
|
+
error_code == LIMITS_EXCEEDED || error_message == LIMITS_EXCEEDED_MSG
|
66
|
+
end
|
54
67
|
end
|
55
68
|
end
|
data/lib/3scale/client.rb
CHANGED
@@ -92,7 +92,7 @@ module ThreeScale
|
|
92
92
|
when Net::HTTPSuccess,Net::HTTPConflict
|
93
93
|
build_authorize_response(http_response.body)
|
94
94
|
when Net::HTTPClientError
|
95
|
-
build_error_response(http_response.body)
|
95
|
+
build_error_response(http_response.body, AuthorizeResponse)
|
96
96
|
else
|
97
97
|
raise ServerError.new(http_response)
|
98
98
|
end
|
@@ -218,7 +218,7 @@ module ThreeScale
|
|
218
218
|
when Net::HTTPSuccess,Net::HTTPConflict
|
219
219
|
build_authorize_response(http_response.body)
|
220
220
|
when Net::HTTPClientError
|
221
|
-
build_error_response(http_response.body)
|
221
|
+
build_error_response(http_response.body, AuthorizeResponse)
|
222
222
|
else
|
223
223
|
raise ServerError.new(http_response)
|
224
224
|
end
|
@@ -267,7 +267,7 @@ module ThreeScale
|
|
267
267
|
when Net::HTTPSuccess,Net::HTTPConflict
|
268
268
|
build_authorize_response(http_response.body)
|
269
269
|
when Net::HTTPClientError
|
270
|
-
build_error_response(http_response.body)
|
270
|
+
build_error_response(http_response.body, AuthorizeResponse)
|
271
271
|
else
|
272
272
|
raise ServerError.new(http_response)
|
273
273
|
end
|
@@ -374,11 +374,11 @@ module ThreeScale
|
|
374
374
|
response
|
375
375
|
end
|
376
376
|
|
377
|
-
def build_error_response(body)
|
377
|
+
def build_error_response(body, klass = Response)
|
378
378
|
doc = Nokogiri::XML(body)
|
379
379
|
node = doc.at_css('error')
|
380
380
|
|
381
|
-
response =
|
381
|
+
response = klass.new
|
382
382
|
response.error!(node.content.to_s.strip, node['code'].to_s.strip)
|
383
383
|
response
|
384
384
|
end
|
data/test/client_test.rb
CHANGED
@@ -119,6 +119,7 @@ class ThreeScale::ClientTest < MiniTest::Test
|
|
119
119
|
response = @client.authorize(:app_id => 'foo')
|
120
120
|
|
121
121
|
assert response.success?
|
122
|
+
assert !response.limits_exceeded?
|
122
123
|
assert_equal 'Ultimate', response.plan
|
123
124
|
assert_equal 2, response.usage_reports.size
|
124
125
|
|
@@ -188,8 +189,9 @@ class ThreeScale::ClientTest < MiniTest::Test
|
|
188
189
|
response = @client.authorize(:app_id => 'foo')
|
189
190
|
|
190
191
|
assert !response.success?
|
192
|
+
assert response.limits_exceeded?
|
191
193
|
assert_equal 'usage limits are exceeded', response.error_message
|
192
|
-
assert response.usage_reports
|
194
|
+
assert response.usage_reports.any? { |report| report.exceeded? }
|
193
195
|
end
|
194
196
|
|
195
197
|
def test_authorize_with_invalid_app_id
|
@@ -200,6 +202,7 @@ class ThreeScale::ClientTest < MiniTest::Test
|
|
200
202
|
response = @client.authorize(:app_id => 'foo')
|
201
203
|
|
202
204
|
assert !response.success?
|
205
|
+
assert !response.limits_exceeded?
|
203
206
|
assert_equal 'application_not_found', response.error_code
|
204
207
|
assert_equal 'application with id="foo" was not found', response.error_message
|
205
208
|
end
|
@@ -227,6 +230,7 @@ class ThreeScale::ClientTest < MiniTest::Test
|
|
227
230
|
:usage => { 'metric1' => 1, 'metric2' => 2 })
|
228
231
|
|
229
232
|
assert response.success?
|
233
|
+
assert !response.limits_exceeded?
|
230
234
|
end
|
231
235
|
|
232
236
|
def test_authorize_with_usage_and_limits_exceeded
|
@@ -254,6 +258,7 @@ class ThreeScale::ClientTest < MiniTest::Test
|
|
254
258
|
response = @client.authorize(:app_id => 'foo', :usage => { 'hits' => 1 })
|
255
259
|
|
256
260
|
assert !response.success?
|
261
|
+
assert response.limits_exceeded?
|
257
262
|
assert_equal 'usage limits are exceeded', response.error_message
|
258
263
|
end
|
259
264
|
|
@@ -347,6 +352,7 @@ class ThreeScale::ClientTest < MiniTest::Test
|
|
347
352
|
|
348
353
|
response = @client.oauth_authorize(:app_id => 'foo', :redirect_url => "http://localhost:8080/oauth/oauth_redirect")
|
349
354
|
assert response.success?
|
355
|
+
assert !response.limits_exceeded?
|
350
356
|
|
351
357
|
assert_equal '883bdb8dbc3b6b77dbcf26845560fdbb', response.app_key
|
352
358
|
assert_equal 'http://localhost:8080/oauth/oauth_redirect', response.redirect_url
|
@@ -399,8 +405,9 @@ class ThreeScale::ClientTest < MiniTest::Test
|
|
399
405
|
response = @client.oauth_authorize(:app_id => 'foo')
|
400
406
|
|
401
407
|
assert !response.success?
|
408
|
+
assert response.limits_exceeded?
|
402
409
|
assert_equal 'usage limits are exceeded', response.error_message
|
403
|
-
assert response.usage_reports
|
410
|
+
assert response.usage_reports.any? { |report| report.exceeded? }
|
404
411
|
end
|
405
412
|
|
406
413
|
def test_oauth_authorize_with_invalid_app_id
|
@@ -411,6 +418,7 @@ class ThreeScale::ClientTest < MiniTest::Test
|
|
411
418
|
response = @client.oauth_authorize(:app_id => 'foo')
|
412
419
|
|
413
420
|
assert !response.success?
|
421
|
+
assert !response.limits_exceeded?
|
414
422
|
assert_equal 'application_not_found', response.error_code
|
415
423
|
assert_equal 'application with id="foo" was not found', response.error_message
|
416
424
|
end
|
@@ -439,6 +447,7 @@ class ThreeScale::ClientTest < MiniTest::Test
|
|
439
447
|
:app_id => 'foo', :usage => { 'metric1' => 1, 'metric2' => 2 })
|
440
448
|
|
441
449
|
assert response.success?
|
450
|
+
assert !response.limits_exceeded?
|
442
451
|
end
|
443
452
|
|
444
453
|
def test_oauth_authorize_with_usage_and_limits_exceeded
|
@@ -467,6 +476,7 @@ class ThreeScale::ClientTest < MiniTest::Test
|
|
467
476
|
:usage => { 'hits' => 1 })
|
468
477
|
|
469
478
|
assert !response.success?
|
479
|
+
assert response.limits_exceeded?
|
470
480
|
assert_equal 'usage limits are exceeded', response.error_message
|
471
481
|
end
|
472
482
|
|
@@ -653,6 +663,7 @@ class ThreeScale::ClientTest < MiniTest::Test
|
|
653
663
|
response = client.authorize(:app_id => 'foo')
|
654
664
|
|
655
665
|
assert response.success?
|
666
|
+
assert !response.limits_exceeded?
|
656
667
|
request = FakeWeb.last_request
|
657
668
|
assert_equal "plugin-ruby-v#{version}", request["X-3scale-User-Agent"]
|
658
669
|
assert_equal "su1.3scale.net", request["host"]
|
@@ -685,6 +696,7 @@ class ThreeScale::ClientTest < MiniTest::Test
|
|
685
696
|
response = client.authrep(:app_id => 'abc')
|
686
697
|
|
687
698
|
assert response.success?
|
699
|
+
assert !response.limits_exceeded?
|
688
700
|
request = FakeWeb.last_request
|
689
701
|
assert_equal "plugin-ruby-v#{version}", request["X-3scale-User-Agent"]
|
690
702
|
assert_equal "su1.3scale.net", request["host"]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: 3scale_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michal Cichra
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2016-10-
|
15
|
+
date: 2016-10-21 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: bundler
|
@@ -20,14 +20,14 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - "~>"
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: '1.
|
23
|
+
version: '1.11'
|
24
24
|
type: :development
|
25
25
|
prerelease: false
|
26
26
|
version_requirements: !ruby/object:Gem::Requirement
|
27
27
|
requirements:
|
28
28
|
- - "~>"
|
29
29
|
- !ruby/object:Gem::Version
|
30
|
-
version: '1.
|
30
|
+
version: '1.11'
|
31
31
|
- !ruby/object:Gem::Dependency
|
32
32
|
name: rake
|
33
33
|
requirement: !ruby/object:Gem::Requirement
|
@@ -198,7 +198,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
198
198
|
requirements:
|
199
199
|
- - ">="
|
200
200
|
- !ruby/object:Gem::Version
|
201
|
-
version: '2.
|
201
|
+
version: '2.1'
|
202
202
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
203
203
|
requirements:
|
204
204
|
- - ">="
|
@@ -206,7 +206,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
206
206
|
version: '0'
|
207
207
|
requirements: []
|
208
208
|
rubyforge_project:
|
209
|
-
rubygems_version: 2.6.
|
209
|
+
rubygems_version: 2.6.4
|
210
210
|
signing_key:
|
211
211
|
specification_version: 4
|
212
212
|
summary: Client for 3scale Web Service Management System API
|