Skip to content

Commit

Permalink
Merge pull request #9 from 3scale/add_service_id_support
Browse files Browse the repository at this point in the history
Add service_id as an option
  • Loading branch information
mikz committed Nov 6, 2013
2 parents be44245 + 4f9c278 commit 6fd7e5d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
3 changes: 2 additions & 1 deletion lib/3scale/authorize_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def initialize
attr_accessor :plan
attr_accessor :app_key
attr_accessor :redirect_url
attr_accessor :service_id

class UsageReport
attr_reader :metric
Expand Down Expand Up @@ -42,4 +43,4 @@ def add_usage_report(options)
@usage_reports << UsageReport.new(options)
end
end
end
end
12 changes: 8 additions & 4 deletions lib/3scale/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,10 @@ def report(*transactions)
#
# Hash with options:
#
# app_id:: id of the application to authorize. This is required.
# app_key:: secret key assigned to the application. Required only if application has
# a key defined.
# app_id:: id of the application to authorize. This is required.
# app_key:: secret key assigned to the application. Required only if application has
# a key defined.
# service_id:: id of the service (required if you have more than one service)
#
# == Return
#
Expand All @@ -186,6 +187,7 @@ def authorize(options)
"?provider_key=#{CGI.escape(provider_key)}" +
"&app_id=#{CGI.escape(options[:app_id].to_s)}"
path += "&app_key=#{CGI.escape(options[:app_key])}" if options[:app_key]
path += "&service_id=#{CGI.escape(options[:service_id])}" if options[:service_id]

uri = URI.parse("http://#{host}#{path}")
http_response = Net::HTTP.get_response(uri)
Expand All @@ -207,6 +209,7 @@ def authorize(options)
# Hash with options:
#
# app_id:: id of the application to authorize. This is required.
# service_id:: id of the service (required if you have more than one service)
#
# == Return
#
Expand Down Expand Up @@ -235,6 +238,7 @@ def oauth_authorize(options)
"?provider_key=#{CGI.escape(provider_key)}" +
"&app_id=#{CGI.escape(options[:app_id].to_s)}"
path += "&app_key=#{CGI.escape(options[:app_key])}" if options[:app_key]
path += "&service_id=#{CGI.escape(options[:service_id])}" if options[:service_id]
path += "&redirect_url=#{CGI.escape(options[:redirect_url])}" if options[:redirect_url]

uri = URI.parse("http://#{host}#{path}")
Expand Down Expand Up @@ -316,4 +320,4 @@ def build_error_response(body)
response
end
end
end
end
8 changes: 7 additions & 1 deletion test/client_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ def test_authrep_supports_app_id_app_key_auth_mode
@client.authrep(:app_id => "appid", :app_key => "appkey")
end

def test_authrep_supports_service_id
assert_authrep_url_with_params "&%5Busage%5D%5Bhits%5D=1&service_id=serviceid"

@client.authrep(:service_id => "serviceid")
end

#TODO these authrep tests
def test_authrep_supports_api_key_auth_mode; end
def test_authrep_log_is_encoded;end
Expand Down Expand Up @@ -358,4 +364,4 @@ def assert_authrep_url_with_params(str)
# this is the actual assertion, if fakeweb raises the client is submiting with wrong params
FakeWeb.register_uri(:get, parsed_authrep_url, :status => ['200', 'OK'], :body => body)
end
end
end

0 comments on commit 6fd7e5d

Please sign in to comment.