Skip to content

Commit 6fd7e5d

Browse files
committed
Merge pull request #9 from 3scale/add_service_id_support
Add service_id as an option
2 parents be44245 + 4f9c278 commit 6fd7e5d

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

lib/3scale/authorize_response.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ def initialize
1010
attr_accessor :plan
1111
attr_accessor :app_key
1212
attr_accessor :redirect_url
13+
attr_accessor :service_id
1314

1415
class UsageReport
1516
attr_reader :metric
@@ -42,4 +43,4 @@ def add_usage_report(options)
4243
@usage_reports << UsageReport.new(options)
4344
end
4445
end
45-
end
46+
end

lib/3scale/client.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,10 @@ def report(*transactions)
158158
#
159159
# Hash with options:
160160
#
161-
# app_id:: id of the application to authorize. This is required.
162-
# app_key:: secret key assigned to the application. Required only if application has
163-
# a key defined.
161+
# app_id:: id of the application to authorize. This is required.
162+
# app_key:: secret key assigned to the application. Required only if application has
163+
# a key defined.
164+
# service_id:: id of the service (required if you have more than one service)
164165
#
165166
# == Return
166167
#
@@ -186,6 +187,7 @@ def authorize(options)
186187
"?provider_key=#{CGI.escape(provider_key)}" +
187188
"&app_id=#{CGI.escape(options[:app_id].to_s)}"
188189
path += "&app_key=#{CGI.escape(options[:app_key])}" if options[:app_key]
190+
path += "&service_id=#{CGI.escape(options[:service_id])}" if options[:service_id]
189191

190192
uri = URI.parse("http://#{host}#{path}")
191193
http_response = Net::HTTP.get_response(uri)
@@ -207,6 +209,7 @@ def authorize(options)
207209
# Hash with options:
208210
#
209211
# app_id:: id of the application to authorize. This is required.
212+
# service_id:: id of the service (required if you have more than one service)
210213
#
211214
# == Return
212215
#
@@ -235,6 +238,7 @@ def oauth_authorize(options)
235238
"?provider_key=#{CGI.escape(provider_key)}" +
236239
"&app_id=#{CGI.escape(options[:app_id].to_s)}"
237240
path += "&app_key=#{CGI.escape(options[:app_key])}" if options[:app_key]
241+
path += "&service_id=#{CGI.escape(options[:service_id])}" if options[:service_id]
238242
path += "&redirect_url=#{CGI.escape(options[:redirect_url])}" if options[:redirect_url]
239243

240244
uri = URI.parse("http://#{host}#{path}")
@@ -316,4 +320,4 @@ def build_error_response(body)
316320
response
317321
end
318322
end
319-
end
323+
end

test/client_test.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ def test_authrep_supports_app_id_app_key_auth_mode
5555
@client.authrep(:app_id => "appid", :app_key => "appkey")
5656
end
5757

58+
def test_authrep_supports_service_id
59+
assert_authrep_url_with_params "&%5Busage%5D%5Bhits%5D=1&service_id=serviceid"
60+
61+
@client.authrep(:service_id => "serviceid")
62+
end
63+
5864
#TODO these authrep tests
5965
def test_authrep_supports_api_key_auth_mode; end
6066
def test_authrep_log_is_encoded;end
@@ -358,4 +364,4 @@ def assert_authrep_url_with_params(str)
358364
# this is the actual assertion, if fakeweb raises the client is submiting with wrong params
359365
FakeWeb.register_uri(:get, parsed_authrep_url, :status => ['200', 'OK'], :body => body)
360366
end
361-
end
367+
end

0 commit comments

Comments
 (0)