3scale_client 2.8.1 → 2.8.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/VERSION +1 -1
- data/lib/3scale/authorize_response.rb +20 -11
- data/lib/3scale/client.rb +10 -2
- data/lib/3scale/client/version.rb +1 -1
- data/test/client_test.rb +61 -0
- 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: 28ffdb9dae79d7cf57bba5fd70090b08ae4e7294
|
4
|
+
data.tar.gz: 8e47fe8d96fc80bc7cc21c5550b177db5c86a01c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4fb00544bd08be909781d624dcacb0fe8b997d1000e74a0339b720530624695e462adfdaa5b138b838256bfeb6613f36f85150c1c8e58b438fc49ec700c6a08a
|
7
|
+
data.tar.gz: 41e02fdb1210e8aeede906e3bb34134bd90da8e719ba9ab197f252ba7a5429c2dae7af24c03149f65785bac56dc33b65c801cdba448210fd88b0f9c2233d8225
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
# Change Log
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
+
## [2.8.2] - 2016-10-18
|
5
|
+
### Added
|
6
|
+
- Added support for retrieving metric hierarchies in authorize calls.
|
7
|
+
This is an experimental feature and its support is not guaranteed for
|
8
|
+
future releases.
|
9
|
+
|
4
10
|
## [2.8.1] - 2016-10-11
|
5
11
|
### Changed
|
6
12
|
- Improved parsing performance of the response of the authorize call.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.8.
|
1
|
+
2.8.2
|
@@ -2,16 +2,6 @@ require 'time'
|
|
2
2
|
|
3
3
|
module ThreeScale
|
4
4
|
class AuthorizeResponse < Response
|
5
|
-
def initialize
|
6
|
-
super
|
7
|
-
@usage_reports = []
|
8
|
-
end
|
9
|
-
|
10
|
-
attr_accessor :plan
|
11
|
-
attr_accessor :app_key
|
12
|
-
attr_accessor :redirect_url
|
13
|
-
attr_accessor :service_id
|
14
|
-
|
15
5
|
class UsageReport
|
16
6
|
attr_reader :metric
|
17
7
|
attr_reader :period
|
@@ -37,10 +27,29 @@ module ThreeScale
|
|
37
27
|
end
|
38
28
|
end
|
39
29
|
|
30
|
+
attr_accessor :plan
|
31
|
+
attr_accessor :app_key
|
32
|
+
attr_accessor :redirect_url
|
33
|
+
attr_accessor :service_id
|
40
34
|
attr_reader :usage_reports
|
35
|
+
attr_reader :hierarchy # Not part of the stable API
|
36
|
+
|
37
|
+
def initialize
|
38
|
+
super
|
39
|
+
@usage_reports = []
|
40
|
+
|
41
|
+
# hierarchy is a hash where the keys are metric names, and the values
|
42
|
+
# their children (array of metric names).
|
43
|
+
# Only metrics that have at least one child appear as keys.
|
44
|
+
@hierarchy = {}
|
45
|
+
end
|
41
46
|
|
42
47
|
def add_usage_report(options)
|
43
48
|
@usage_reports << UsageReport.new(options)
|
44
49
|
end
|
50
|
+
|
51
|
+
def add_metric_to_hierarchy(metric_name, children)
|
52
|
+
@hierarchy[metric_name] = children
|
53
|
+
end
|
45
54
|
end
|
46
|
-
end
|
55
|
+
end
|
data/lib/3scale/client.rb
CHANGED
@@ -275,8 +275,10 @@ module ThreeScale
|
|
275
275
|
|
276
276
|
private
|
277
277
|
|
278
|
-
|
279
|
-
|
278
|
+
# The support for the 'hierarchy' param is experimental. Its support is not
|
279
|
+
# guaranteed for future versions.
|
280
|
+
OAUTH_PARAMS = [:app_id, :app_key, :service_id, :redirect_url, :usage, :hierarchy]
|
281
|
+
ALL_PARAMS = [:user_key, :app_id, :app_key, :service_id, :redirect_url, :usage, :hierarchy]
|
280
282
|
REPORT_PARAMS = [:user_key, :app_id, :service_id, :timestamp]
|
281
283
|
|
282
284
|
def options_to_params(options, allowed_keys)
|
@@ -363,6 +365,12 @@ module ThreeScale
|
|
363
365
|
:max_value => node.at('max_value').content.to_i)
|
364
366
|
end
|
365
367
|
|
368
|
+
doc.css('hierarchy metric').each do |node|
|
369
|
+
metric_name = node['name'].to_s.strip
|
370
|
+
children = node['children'].to_s.strip.split(' ')
|
371
|
+
response.add_metric_to_hierarchy(metric_name, children)
|
372
|
+
end
|
373
|
+
|
366
374
|
response
|
367
375
|
end
|
368
376
|
|
data/test/client_test.rb
CHANGED
@@ -257,6 +257,67 @@ class ThreeScale::ClientTest < MiniTest::Test
|
|
257
257
|
assert_equal 'usage limits are exceeded', response.error_message
|
258
258
|
end
|
259
259
|
|
260
|
+
def test_hierarchy
|
261
|
+
# Hierarchies can be retrieved in authorize, authrep, and oauth_authorize
|
262
|
+
# calls.
|
263
|
+
urls = [:authorize, :authrep, :oauth_authorize].inject({}) do |acc, method|
|
264
|
+
acc[method] = "http://#{@host}/transactions/#{method}.xml?"\
|
265
|
+
"provider_key=1234abcd&app_id=foo&hierarchy=1"
|
266
|
+
acc[method] << "&%5Busage%5D%5Bhits%5D=1" if method == :authrep
|
267
|
+
acc
|
268
|
+
end
|
269
|
+
|
270
|
+
body = '<status>
|
271
|
+
<authorized>true</authorized>
|
272
|
+
<plan>Ultimate</plan>
|
273
|
+
|
274
|
+
<usage_reports>
|
275
|
+
<usage_report metric="parent1" period="day">
|
276
|
+
<period_start>2016-01-01 00:00:00 +0000</period_start>
|
277
|
+
<period_end>2016-01-02 00:00:00 +0000</period_end>
|
278
|
+
<max_value>1000</max_value>
|
279
|
+
<current_value>10</current_value>
|
280
|
+
</usage_report>
|
281
|
+
<usage_report metric="parent2" period="day">
|
282
|
+
<period_start>2016-01-01 00:00:00 +0000</period_start>
|
283
|
+
<period_end>2016-01-02 00:00:00 +0000</period_end>
|
284
|
+
<max_value>100</max_value>
|
285
|
+
<current_value>1</current_value>
|
286
|
+
</usage_report>
|
287
|
+
<usage_report metric="child1" period="day">
|
288
|
+
<period_start>2016-01-01 00:00:00 +0000</period_start>
|
289
|
+
<period_end>2016-01-02 00:00:00 +0000</period_end>
|
290
|
+
<max_value>1000</max_value>
|
291
|
+
<current_value>5</current_value>
|
292
|
+
</usage_report>
|
293
|
+
<usage_report metric="child2" period="day">
|
294
|
+
<period_start>2016-01-01 00:00:00 +0000</period_start>
|
295
|
+
<period_end>2016-01-02 00:00:00 +0000</period_end>
|
296
|
+
<max_value>1000</max_value>
|
297
|
+
<current_value>5</current_value>
|
298
|
+
</usage_report>
|
299
|
+
<usage_report metric="child3" period="day">
|
300
|
+
<period_start>2016-01-01 00:00:00 +0000</period_start>
|
301
|
+
<period_end>2016-01-02 00:00:00 +0000</period_end>
|
302
|
+
<max_value>100</max_value>
|
303
|
+
<current_value>5</current_value>
|
304
|
+
</usage_report>
|
305
|
+
</usage_reports>
|
306
|
+
|
307
|
+
<hierarchy>
|
308
|
+
<metric name="parent1" children="child1 child2" />
|
309
|
+
<metric name="parent2" children="child3" />
|
310
|
+
</hierarchy>
|
311
|
+
</status>'
|
312
|
+
|
313
|
+
urls.each do |method, url|
|
314
|
+
FakeWeb.register_uri(:get, url, :status => ['200', 'OK'], :body => body)
|
315
|
+
response = @client.send(method, :app_id => 'foo', :hierarchy => 1)
|
316
|
+
assert_equal response.hierarchy, { 'parent1' => ['child1', 'child2'],
|
317
|
+
'parent2' => ['child3'] }
|
318
|
+
end
|
319
|
+
end
|
320
|
+
|
260
321
|
def test_successful_oauth_authorize
|
261
322
|
body = '<status>
|
262
323
|
<authorized>true</authorized>
|
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.8.
|
4
|
+
version: 2.8.2
|
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-18 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: bundler
|