3scale_client 2.2.7 → 2.2.8
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/3scale_client.gemspec +6 -2
- data/README.rdoc +24 -7
- data/Rakefile +3 -2
- data/VERSION +1 -1
- data/lib/3scale/authorize_response.rb +3 -1
- data/lib/3scale/client.rb +62 -7
- data/test/client_test.rb +115 -10
- data/test/remote_test.rb +17 -2
- metadata +49 -9
data/.gitignore
CHANGED
data/3scale_client.gemspec
CHANGED
@@ -5,14 +5,14 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{3scale_client}
|
8
|
-
s.version = "2.2.
|
8
|
+
s.version = "2.2.8"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Adam Cigánek", "Tiago Macedo"]
|
12
12
|
s.date = %q{2011-01-27}
|
13
13
|
s.description = %q{This gem allows to easily connect an application that provides a Web Service with the 3scale API Management System to authorize it's users and report the usage.
|
14
14
|
}
|
15
|
-
s.email = %q{adam@3scale.net}
|
15
|
+
s.email = %q{adam@3scale.net tiago@3scale.net}
|
16
16
|
s.extra_rdoc_files = [
|
17
17
|
"README.rdoc"
|
18
18
|
]
|
@@ -51,5 +51,9 @@ Gem::Specification.new do |s|
|
|
51
51
|
else
|
52
52
|
s.add_dependency(%q<nokogiri>, [">= 0"])
|
53
53
|
end
|
54
|
+
|
55
|
+
s.add_development_dependency 'fakeweb'
|
56
|
+
s.add_development_dependency 'jeweler'
|
57
|
+
s.add_development_dependency 'mocha'
|
54
58
|
end
|
55
59
|
|
data/README.rdoc
CHANGED
@@ -6,12 +6,18 @@ This library is distributed as a gem:
|
|
6
6
|
|
7
7
|
gem install 3scale_client
|
8
8
|
|
9
|
-
Or alternatively, download the source code from github:
|
9
|
+
Or alternatively, download the source code from github:
|
10
10
|
http://github.com/3scale/3scale_ws_api_for_ruby
|
11
11
|
|
12
|
-
If you are using
|
12
|
+
If you are using Bundler, please add this to your Gemfile:
|
13
13
|
|
14
|
-
|
14
|
+
gem '3scale_client', :require => '3scale/client'
|
15
|
+
|
16
|
+
and do a bundle install.
|
17
|
+
|
18
|
+
If you are using Rails' config.gems, put this into your config/environment.rb
|
19
|
+
|
20
|
+
config.gem "3scale_client", :lib => '3scale/client'
|
15
21
|
|
16
22
|
Otherwise, require the gem in whatever way is natural to your framework of choice.
|
17
23
|
|
@@ -28,7 +34,7 @@ Because the object is stateless, you can create just one and store it globally.
|
|
28
34
|
To authorize an application, call the +authorize+ method passing it the application's id and
|
29
35
|
optionally a key:
|
30
36
|
|
31
|
-
response = client.authorize(:app_id => "the app id", :
|
37
|
+
response = client.authorize(:app_id => "the app id", :app_key => "the app key")
|
32
38
|
|
33
39
|
Then call the +success?+ method on the returned object to see if the authorization was
|
34
40
|
successful.
|
@@ -68,12 +74,23 @@ down by the metrics and usage limit periods.
|
|
68
74
|
# If the limit is exceeded, this will be true, otherwise false:
|
69
75
|
usage_report.exceeded? # false
|
70
76
|
|
71
|
-
If the authorization failed, the +error_code+ returns system error code and +error_message+
|
77
|
+
If the authorization failed, the +error_code+ returns system error code and +error_message+
|
72
78
|
human readable error description:
|
73
|
-
|
79
|
+
|
74
80
|
response.error_code # "usage_limits_exceeded"
|
75
81
|
response.error_message # "Usage limits are exceeded"
|
76
82
|
|
83
|
+
=== OAuth Authorize
|
84
|
+
|
85
|
+
To authorize an application with OAuth, call the +oauth_authorize+ method passing it the application's id.
|
86
|
+
|
87
|
+
response = client.authorize(:app_id => "the app id")
|
88
|
+
|
89
|
+
If the authorization is successful, the response will contain the +app_key+ and +redirect_url+ defined for this application:
|
90
|
+
|
91
|
+
response.app_key
|
92
|
+
response.redirect_url
|
93
|
+
|
77
94
|
=== Report
|
78
95
|
|
79
96
|
To report usage, use the +report+ method. You can report multiple transaction at the same time:
|
@@ -93,7 +110,7 @@ string has to be in a format parseable by the Time.parse method. For example:
|
|
93
110
|
|
94
111
|
"2010-04-28 12:38:33 +0200"
|
95
112
|
|
96
|
-
If the timestamp is not in UTC, you have to specify a time offset. That's the "+0200"
|
113
|
+
If the timestamp is not in UTC, you have to specify a time offset. That's the "+0200"
|
97
114
|
(two hours ahead of the Universal Coordinate Time) in the example abowe.
|
98
115
|
|
99
116
|
Then call the +success?+ method on the returned response object to see if the report was
|
data/Rakefile
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
require "rubygems"
|
3
|
+
require "bundler/setup"
|
2
4
|
|
3
5
|
require 'rake'
|
4
6
|
require 'rake/testtask'
|
5
|
-
require '
|
7
|
+
require 'rdoc/task'
|
6
8
|
|
7
9
|
desc 'Default: run unit tests.'
|
8
10
|
task :default => :test
|
@@ -11,7 +13,6 @@ desc 'Run unit tests.'
|
|
11
13
|
Rake::TestTask.new(:test) do |t|
|
12
14
|
t.pattern = 'test/**/*_test.rb'
|
13
15
|
t.verbose = true
|
14
|
-
t.ruby_opts << '-rubygems'
|
15
16
|
end
|
16
17
|
|
17
18
|
desc 'Generate documentation.'
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.2.
|
1
|
+
2.2.7
|
@@ -8,6 +8,8 @@ module ThreeScale
|
|
8
8
|
end
|
9
9
|
|
10
10
|
attr_accessor :plan
|
11
|
+
attr_accessor :app_key
|
12
|
+
attr_accessor :redirect_url
|
11
13
|
|
12
14
|
class UsageReport
|
13
15
|
attr_reader :metric
|
@@ -32,7 +34,7 @@ module ThreeScale
|
|
32
34
|
def exceeded?
|
33
35
|
current_value > max_value
|
34
36
|
end
|
35
|
-
end
|
37
|
+
end
|
36
38
|
|
37
39
|
attr_reader :usage_reports
|
38
40
|
|
data/lib/3scale/client.rb
CHANGED
@@ -8,7 +8,7 @@ require '3scale/authorize_response'
|
|
8
8
|
|
9
9
|
module ThreeScale
|
10
10
|
Error = Class.new(RuntimeError)
|
11
|
-
|
11
|
+
|
12
12
|
class ServerError < Error
|
13
13
|
def initialize(response)
|
14
14
|
super('server error')
|
@@ -61,11 +61,11 @@ module ThreeScale
|
|
61
61
|
# app_id:: ID of the application to report the transaction for. This parameter is
|
62
62
|
# required.
|
63
63
|
# usage:: Hash of usage values. The keys are metric names and values are
|
64
|
-
# correspoding numeric values. Example: {'hits' => 1, 'transfer' => 1024}.
|
64
|
+
# correspoding numeric values. Example: {'hits' => 1, 'transfer' => 1024}.
|
65
65
|
# This parameter is required.
|
66
66
|
# timestamp:: Timestamp of the transaction. This can be either a object of the
|
67
67
|
# ruby's Time class, or a string in the "YYYY-MM-DD HH:MM:SS" format
|
68
|
-
# (if the time is in the UTC), or a string in
|
68
|
+
# (if the time is in the UTC), or a string in
|
69
69
|
# the "YYYY-MM-DD HH:MM:SS ZZZZZ" format, where the ZZZZZ is the time offset
|
70
70
|
# from the UTC. For example, "US Pacific Time" has offset -0800, "Tokyo"
|
71
71
|
# has offset +0900. This parameter is optional, and if not provided, equals
|
@@ -98,7 +98,7 @@ module ThreeScale
|
|
98
98
|
|
99
99
|
uri = URI.parse("http://#{host}/transactions.xml")
|
100
100
|
http_response = Net::HTTP.post_form(uri, payload)
|
101
|
-
|
101
|
+
|
102
102
|
case http_response
|
103
103
|
when Net::HTTPSuccess
|
104
104
|
build_report_response
|
@@ -112,7 +112,7 @@ module ThreeScale
|
|
112
112
|
# Authorize an application.
|
113
113
|
#
|
114
114
|
# == Parameters
|
115
|
-
#
|
115
|
+
#
|
116
116
|
# Hash with options:
|
117
117
|
#
|
118
118
|
# app_id:: id of the application to authorize. This is required.
|
@@ -157,11 +157,61 @@ module ThreeScale
|
|
157
157
|
end
|
158
158
|
end
|
159
159
|
|
160
|
+
# Authorize an application with OAuth.
|
161
|
+
#
|
162
|
+
# == Parameters
|
163
|
+
#
|
164
|
+
# Hash with options:
|
165
|
+
#
|
166
|
+
# app_id:: id of the application to authorize. This is required.
|
167
|
+
#
|
168
|
+
# == Return
|
169
|
+
#
|
170
|
+
# A ThreeScale::AuthorizeResponse object. It's +success?+ method returns true if
|
171
|
+
# the authorization is successful, false otherwise. It contains additional information
|
172
|
+
# about the status of the usage. See the ThreeScale::AuthorizeResponse for more information.
|
173
|
+
#
|
174
|
+
# It also returns the app_key that corresponds to the given app_id
|
175
|
+
#
|
176
|
+
# In case of error, the +error_code+ returns code of the error and +error_message+
|
177
|
+
# human readable error description.
|
178
|
+
#
|
179
|
+
# In case of unexpected internal server error, this method raises a ThreeScale::ServerError
|
180
|
+
# exception.
|
181
|
+
#
|
182
|
+
# == Examples
|
183
|
+
#
|
184
|
+
# response = client.authorize(:app_id => '1234')
|
185
|
+
#
|
186
|
+
# if response.success?
|
187
|
+
# # All good. Proceed...
|
188
|
+
# end
|
189
|
+
#
|
190
|
+
def oauth_authorize(options)
|
191
|
+
path = "/transactions/oauth_authorize.xml" +
|
192
|
+
"?provider_key=#{CGI.escape(provider_key)}" +
|
193
|
+
"&app_id=#{CGI.escape(options[:app_id].to_s)}"
|
194
|
+
path += "&app_key=#{CGI.escape(options[:app_key])}" if options[:app_key]
|
195
|
+
path += "&redirect_url=#{CGI.escape(options[:redirect_url])}" if options[:redirect_url]
|
196
|
+
|
197
|
+
uri = URI.parse("http://#{host}#{path}")
|
198
|
+
http_response = Net::HTTP.get_response(uri)
|
199
|
+
|
200
|
+
case http_response
|
201
|
+
when Net::HTTPSuccess,Net::HTTPConflict
|
202
|
+
build_authorize_response(http_response.body)
|
203
|
+
when Net::HTTPClientError
|
204
|
+
build_error_response(http_response.body)
|
205
|
+
else
|
206
|
+
raise ServerError.new(http_response)
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
160
210
|
private
|
161
211
|
|
162
212
|
def encode_transactions(transactions)
|
163
213
|
result = {}
|
164
|
-
|
214
|
+
|
165
215
|
transactions.each_with_index do |transaction, index|
|
166
216
|
append_encoded_value(result, index, [:app_id], transaction[:app_id])
|
167
217
|
append_encoded_value(result, index, [:timestamp], transaction[:timestamp])
|
@@ -195,6 +245,11 @@ module ThreeScale
|
|
195
245
|
response.error!(doc.at_css('reason').content)
|
196
246
|
end
|
197
247
|
|
248
|
+
if doc.at_css('application')
|
249
|
+
response.app_key = doc.at_css('application key').content.to_s.strip
|
250
|
+
response.redirect_url = doc.at_css('application redirect_url').content.to_s.strip
|
251
|
+
end
|
252
|
+
|
198
253
|
response.plan = doc.at_css('plan').content.to_s.strip
|
199
254
|
|
200
255
|
doc.css('usage_reports usage_report').each do |node|
|
@@ -212,7 +267,7 @@ module ThreeScale
|
|
212
267
|
def build_error_response(body)
|
213
268
|
doc = Nokogiri::XML(body)
|
214
269
|
node = doc.at_css('error')
|
215
|
-
|
270
|
+
|
216
271
|
response = Response.new
|
217
272
|
response.error!(node.content.to_s.strip, node['code'].to_s.strip)
|
218
273
|
response
|
data/test/client_test.rb
CHANGED
@@ -29,7 +29,7 @@ class ThreeScale::ClientTest < Test::Unit::TestCase
|
|
29
29
|
body = '<status>
|
30
30
|
<authorized>true</authorized>
|
31
31
|
<plan>Ultimate</plan>
|
32
|
-
|
32
|
+
|
33
33
|
<usage_reports>
|
34
34
|
<usage_report metric="hits" period="day">
|
35
35
|
<period_start>2010-04-26 00:00:00 +0000</period_start>
|
@@ -54,7 +54,7 @@ class ThreeScale::ClientTest < Test::Unit::TestCase
|
|
54
54
|
assert response.success?
|
55
55
|
assert_equal 'Ultimate', response.plan
|
56
56
|
assert_equal 2, response.usage_reports.size
|
57
|
-
|
57
|
+
|
58
58
|
assert_equal :day, response.usage_reports[0].period
|
59
59
|
assert_equal Time.utc(2010, 4, 26), response.usage_reports[0].period_start
|
60
60
|
assert_equal Time.utc(2010, 4, 27), response.usage_reports[0].period_end
|
@@ -67,7 +67,7 @@ class ThreeScale::ClientTest < Test::Unit::TestCase
|
|
67
67
|
assert_equal 999872, response.usage_reports[1].current_value
|
68
68
|
assert_equal 150000, response.usage_reports[1].max_value
|
69
69
|
end
|
70
|
-
|
70
|
+
|
71
71
|
def test_successful_authorize_with_app_keys
|
72
72
|
body = '<status>
|
73
73
|
<authorized>true</authorized>
|
@@ -86,7 +86,7 @@ class ThreeScale::ClientTest < Test::Unit::TestCase
|
|
86
86
|
<reason>usage limits are exceeded</reason>
|
87
87
|
|
88
88
|
<plan>Ultimate</plan>
|
89
|
-
|
89
|
+
|
90
90
|
<usage_reports>
|
91
91
|
<usage_report metric="hits" period="day" exceeded="true">
|
92
92
|
<period_start>2010-04-26 00:00:00 +0000</period_start>
|
@@ -103,9 +103,9 @@ class ThreeScale::ClientTest < Test::Unit::TestCase
|
|
103
103
|
</usage_report>
|
104
104
|
</usage_reports>
|
105
105
|
</status>'
|
106
|
-
|
106
|
+
|
107
107
|
FakeWeb.register_uri(:get, "http://#{@host}/transactions/authorize.xml?provider_key=1234abcd&app_id=foo", :status => ['409'], :body => body)
|
108
|
-
|
108
|
+
|
109
109
|
response = @client.authorize(:app_id => 'foo')
|
110
110
|
|
111
111
|
assert !response.success?
|
@@ -115,7 +115,7 @@ class ThreeScale::ClientTest < Test::Unit::TestCase
|
|
115
115
|
|
116
116
|
def test_authorize_with_invalid_app_id
|
117
117
|
body = '<error code="application_not_found">application with id="foo" was not found</error>'
|
118
|
-
|
118
|
+
|
119
119
|
FakeWeb.register_uri(:get, "http://#{@host}/transactions/authorize.xml?provider_key=1234abcd&app_id=foo", :status => ['403', 'Forbidden'], :body => body)
|
120
120
|
|
121
121
|
response = @client.authorize(:app_id => 'foo')
|
@@ -124,7 +124,7 @@ class ThreeScale::ClientTest < Test::Unit::TestCase
|
|
124
124
|
assert_equal 'application_not_found', response.error_code
|
125
125
|
assert_equal 'application with id="foo" was not found', response.error_message
|
126
126
|
end
|
127
|
-
|
127
|
+
|
128
128
|
def test_authorize_with_server_error
|
129
129
|
FakeWeb.register_uri(:get, "http://#{@host}/transactions/authorize.xml?provider_key=1234abcd&app_id=foo", :status => ['500', 'Internal Server Error'], :body => 'OMG! WTF!')
|
130
130
|
|
@@ -133,6 +133,111 @@ class ThreeScale::ClientTest < Test::Unit::TestCase
|
|
133
133
|
end
|
134
134
|
end
|
135
135
|
|
136
|
+
def test_successful_oauth_authorize
|
137
|
+
body = '<status>
|
138
|
+
<authorized>true</authorized>
|
139
|
+
<application>
|
140
|
+
<id>94bd2de3</id>
|
141
|
+
<key>883bdb8dbc3b6b77dbcf26845560fdbb</key>
|
142
|
+
<redirect_url>http://localhost:8080/oauth/oauth_redirect</redirect_url>
|
143
|
+
</application>
|
144
|
+
<plan>Ultimate</plan>
|
145
|
+
<usage_reports>
|
146
|
+
<usage_report metric="hits" period="week">
|
147
|
+
<period_start>2012-01-30 00:00:00 +0000</period_start>
|
148
|
+
<period_end>2012-02-06 00:00:00 +0000</period_end>
|
149
|
+
<max_value>5000</max_value>
|
150
|
+
<current_value>1</current_value>
|
151
|
+
</usage_report>
|
152
|
+
<usage_report metric="update" period="minute">
|
153
|
+
<period_start>2012-02-03 00:00:00 +0000</period_start>
|
154
|
+
<period_end>2012-02-03 00:00:00 +0000</period_end>
|
155
|
+
<max_value>0</max_value>
|
156
|
+
<current_value>0</current_value>
|
157
|
+
</usage_report>
|
158
|
+
</usage_reports>
|
159
|
+
</status>'
|
160
|
+
|
161
|
+
FakeWeb.register_uri(:get, "http://#{@host}/transactions/oauth_authorize.xml?provider_key=1234abcd&app_id=foo&redirect_url=http%3A%2F%2Flocalhost%3A8080%2Foauth%2Foauth_redirect", :status => ['200', 'OK'], :body => body)
|
162
|
+
|
163
|
+
response = @client.oauth_authorize(:app_id => 'foo', :redirect_url => "http://localhost:8080/oauth/oauth_redirect")
|
164
|
+
assert response.success?
|
165
|
+
|
166
|
+
assert_equal '883bdb8dbc3b6b77dbcf26845560fdbb', response.app_key
|
167
|
+
assert_equal 'http://localhost:8080/oauth/oauth_redirect', response.redirect_url
|
168
|
+
|
169
|
+
assert_equal 'Ultimate', response.plan
|
170
|
+
assert_equal 2, response.usage_reports.size
|
171
|
+
|
172
|
+
assert_equal :week, response.usage_reports[0].period
|
173
|
+
assert_equal Time.utc(2012, 1, 30), response.usage_reports[0].period_start
|
174
|
+
assert_equal Time.utc(2012, 02, 06), response.usage_reports[0].period_end
|
175
|
+
assert_equal 1, response.usage_reports[0].current_value
|
176
|
+
assert_equal 5000, response.usage_reports[0].max_value
|
177
|
+
|
178
|
+
assert_equal :minute, response.usage_reports[1].period
|
179
|
+
assert_equal Time.utc(2012, 2, 03), response.usage_reports[1].period_start
|
180
|
+
assert_equal Time.utc(2012, 2, 03), response.usage_reports[1].period_end
|
181
|
+
assert_equal 0, response.usage_reports[1].current_value
|
182
|
+
assert_equal 0, response.usage_reports[1].max_value
|
183
|
+
end
|
184
|
+
|
185
|
+
def test_oauth_authorize_with_exceeded_usage_limits
|
186
|
+
body = '<status>
|
187
|
+
<authorized>false</authorized>
|
188
|
+
<reason>usage limits are exceeded</reason>
|
189
|
+
<application>
|
190
|
+
<id>94bd2de3</id>
|
191
|
+
<key>883bdb8dbc3b6b77dbcf26845560fdbb</key>
|
192
|
+
<redirect_url>http://localhost:8080/oauth/oauth_redirect</redirect_url>
|
193
|
+
</application>
|
194
|
+
<plan>Ultimate</plan>
|
195
|
+
<usage_reports>
|
196
|
+
<usage_report metric="hits" period="day" exceeded="true">
|
197
|
+
<period_start>2010-04-26 00:00:00 +0000</period_start>
|
198
|
+
<period_end>2010-04-27 00:00:00 +0000</period_end>
|
199
|
+
<current_value>50002</current_value>
|
200
|
+
<max_value>50000</max_value>
|
201
|
+
</usage_report>
|
202
|
+
|
203
|
+
<usage_report metric="hits" period="month">
|
204
|
+
<period_start>2010-04-01 00:00:00 +0000</period_start>
|
205
|
+
<period_end>2010-05-01 00:00:00 +0000</period_end>
|
206
|
+
<current_value>999872</current_value>
|
207
|
+
<max_value>150000</max_value>
|
208
|
+
</usage_report>
|
209
|
+
</usage_reports>
|
210
|
+
</status>'
|
211
|
+
|
212
|
+
FakeWeb.register_uri(:get, "http://#{@host}/transactions/oauth_authorize.xml?provider_key=1234abcd&app_id=foo", :status => ['409'], :body => body)
|
213
|
+
|
214
|
+
response = @client.oauth_authorize(:app_id => 'foo')
|
215
|
+
|
216
|
+
assert !response.success?
|
217
|
+
assert_equal 'usage limits are exceeded', response.error_message
|
218
|
+
assert response.usage_reports[0].exceeded?
|
219
|
+
end
|
220
|
+
|
221
|
+
def test_oauth_authorize_with_invalid_app_id
|
222
|
+
body = '<error code="application_not_found">application with id="foo" was not found</error>'
|
223
|
+
|
224
|
+
FakeWeb.register_uri(:get, "http://#{@host}/transactions/oauth_authorize.xml?provider_key=1234abcd&app_id=foo", :status => ['403', 'Forbidden'], :body => body)
|
225
|
+
|
226
|
+
response = @client.oauth_authorize(:app_id => 'foo')
|
227
|
+
|
228
|
+
assert !response.success?
|
229
|
+
assert_equal 'application_not_found', response.error_code
|
230
|
+
assert_equal 'application with id="foo" was not found', response.error_message
|
231
|
+
end
|
232
|
+
|
233
|
+
def test_authorize_with_server_error
|
234
|
+
FakeWeb.register_uri(:get, "http://#{@host}/transactions/oauth_authorize.xml?provider_key=1234abcd&app_id=foo", :status => ['500', 'Internal Server Error'], :body => 'OMG! WTF!')
|
235
|
+
|
236
|
+
assert_raise ThreeScale::ServerError do
|
237
|
+
@client.oauth_authorize(:app_id => 'foo')
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
136
241
|
def test_report_raises_an_exception_if_no_transactions_given
|
137
242
|
assert_raise ArgumentError do
|
138
243
|
@client.report
|
@@ -180,8 +285,8 @@ class ThreeScale::ClientTest < Test::Unit::TestCase
|
|
180
285
|
FakeWeb.register_uri(:post, "http://#{@host}/transactions.xml",
|
181
286
|
:status => ['403', 'Forbidden'],
|
182
287
|
:body => error_body)
|
183
|
-
|
184
|
-
client = ThreeScale::Client.new(:provider_key => 'foo')
|
288
|
+
|
289
|
+
client = ThreeScale::Client.new(:provider_key => 'foo')
|
185
290
|
response = client.report({:app_id => 'abc', :usage => {'hits' => 1}})
|
186
291
|
|
187
292
|
assert !response.success?
|
data/test/remote_test.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'test/unit'
|
2
2
|
require '3scale/client'
|
3
3
|
|
4
|
-
if ENV['TEST_3SCALE_PROVIDER_KEY'] &&
|
4
|
+
if ENV['TEST_3SCALE_PROVIDER_KEY'] &&
|
5
5
|
ENV['TEST_3SCALE_APP_IDS'] &&
|
6
6
|
ENV['TEST_3SCALE_APP_KEYS']
|
7
7
|
class ThreeScale::RemoteTest < Test::Unit::TestCase
|
@@ -24,7 +24,7 @@ if ENV['TEST_3SCALE_PROVIDER_KEY'] &&
|
|
24
24
|
def test_successful_authorize
|
25
25
|
@app_keys.each do |app_key|
|
26
26
|
response = @client.authorize(:app_id => @app_ids[0], :app_key => app_key)
|
27
|
-
assert response.success?, "Authorize should succeed for app_id=#{@app_ids[0]} and app_key=#{app_key}, but it
|
27
|
+
assert response.success?, "Authorize should succeed for app_id=#{@app_ids[0]} and app_key=#{app_key}, but it failed with: '#{response.error_message}'"
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
@@ -35,6 +35,21 @@ if ENV['TEST_3SCALE_PROVIDER_KEY'] &&
|
|
35
35
|
assert_equal 'application with id="invalid-id" was not found', response.error_message
|
36
36
|
end
|
37
37
|
|
38
|
+
def test_successful_oauth_authorize
|
39
|
+
@app_keys.each do |app_key|
|
40
|
+
response = @client.oauth_authorize(:app_id => @app_ids[0])
|
41
|
+
assert response.success?, "Authorize should succeed for app_id=#{@app_ids[0]} and app_key=#{app_key}, but it failed with: '#{response.error_message}'"
|
42
|
+
assert_equal app_key, response.app_key
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_failed_oauth_authorize
|
47
|
+
response = @client.oauth_authorize(:app_id => 'invalid-id')
|
48
|
+
assert !response.success?
|
49
|
+
assert_equal 'application_not_found', response.error_code
|
50
|
+
assert_equal 'application with id="invalid-id" was not found', response.error_message
|
51
|
+
end
|
52
|
+
|
38
53
|
def test_successful_report
|
39
54
|
transactions = @app_ids.map do |app_id|
|
40
55
|
{:app_id => app_id, :usage => {'hits' => 1}}
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: 3scale_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 23
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 2.2.
|
9
|
+
- 8
|
10
|
+
version: 2.2.8
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- "Adam Cig\xC3\xA1nek"
|
@@ -16,8 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-01-27 00:00:00
|
20
|
-
default_executable:
|
19
|
+
date: 2011-01-27 00:00:00 Z
|
21
20
|
dependencies:
|
22
21
|
- !ruby/object:Gem::Dependency
|
23
22
|
name: nokogiri
|
@@ -33,10 +32,52 @@ dependencies:
|
|
33
32
|
version: "0"
|
34
33
|
type: :runtime
|
35
34
|
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: fakeweb
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: jeweler
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
type: :development
|
62
|
+
version_requirements: *id003
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: mocha
|
65
|
+
prerelease: false
|
66
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
hash: 3
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
version: "0"
|
75
|
+
type: :development
|
76
|
+
version_requirements: *id004
|
36
77
|
description: |
|
37
78
|
This gem allows to easily connect an application that provides a Web Service with the 3scale API Management System to authorize it's users and report the usage.
|
38
79
|
|
39
|
-
email: adam@3scale.net
|
80
|
+
email: adam@3scale.net tiago@3scale.net
|
40
81
|
executables: []
|
41
82
|
|
42
83
|
extensions: []
|
@@ -55,7 +96,6 @@ files:
|
|
55
96
|
- lib/3scale/response.rb
|
56
97
|
- test/client_test.rb
|
57
98
|
- test/remote_test.rb
|
58
|
-
has_rdoc: true
|
59
99
|
homepage: http://www.3scale.net
|
60
100
|
licenses: []
|
61
101
|
|
@@ -85,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
85
125
|
requirements: []
|
86
126
|
|
87
127
|
rubyforge_project:
|
88
|
-
rubygems_version: 1.
|
128
|
+
rubygems_version: 1.8.10
|
89
129
|
signing_key:
|
90
130
|
specification_version: 3
|
91
131
|
summary: Client for 3scale Web Service Management System API
|