Updated the configuration handling code.
git-svn-id: https://google-api-ruby-client.googlecode.com/svn/trunk@10 c1d61fac-ed7f-fcc1-18f7-ff78120a04ef
This commit is contained in:
parent
0d45cbe27b
commit
a6d7aa570e
|
@ -76,7 +76,7 @@ module Google #:nodoc:
|
|||
#
|
||||
# @return [Google::APIClient::OAuth1] The OAuth 1.0a handler.
|
||||
def initialize(options={})
|
||||
if options[:service]
|
||||
if options[:service] && SERVICE_DEFAULTS[options[:service]]
|
||||
@options = DEFAULTS.merge(SERVICE_DEFAULTS[options[:service]])
|
||||
else
|
||||
@options = DEFAULTS.clone
|
||||
|
@ -107,6 +107,15 @@ module Google #:nodoc:
|
|||
}
|
||||
)
|
||||
end
|
||||
|
||||
##
|
||||
# Returns the configuration of the handler. Configuration options that
|
||||
# are not recognized by the handler are ignored.
|
||||
#
|
||||
# @return [Hash] The configuration options.
|
||||
def options
|
||||
return @options
|
||||
end
|
||||
|
||||
##
|
||||
# Returns the current request token. Obtains a new request token if
|
||||
|
@ -174,6 +183,23 @@ module Google #:nodoc:
|
|||
return @options[:scopes]
|
||||
end
|
||||
|
||||
##
|
||||
# Returns the callback for the handler.
|
||||
#
|
||||
# @return [String] The OAuth 1.0a callback for the consumer.
|
||||
def callback
|
||||
return @options[:callback]
|
||||
end
|
||||
|
||||
##
|
||||
# Returns a human-readable service name to present to the user when they
|
||||
# visit the <code>:authorization_uri</code>.
|
||||
#
|
||||
# @return [String] The display name for the consumer.
|
||||
def display_name
|
||||
return @options[:display_name]
|
||||
end
|
||||
|
||||
##
|
||||
# Returns the consumer key.
|
||||
#
|
||||
|
|
|
@ -18,7 +18,42 @@ require "addressable/template"
|
|||
module Google #:nodoc:
|
||||
class APIClient #:nodoc:
|
||||
class Discovery
|
||||
##
|
||||
# The default discovery configuration values. These may be overrided
|
||||
# simply by passing in the same key to the constructor.
|
||||
DEFAULTS = {
|
||||
}
|
||||
|
||||
##
|
||||
# A set of default configuration values specific to each service. These
|
||||
# may be overrided simply by passing in the same key to the constructor.
|
||||
SERVICE_DEFAULTS = {
|
||||
}
|
||||
|
||||
##
|
||||
# Creates a new API discovery handler.
|
||||
#
|
||||
# @param [Hash] options
|
||||
#
|
||||
# @return [Google::APIClient::Discovery] The API discovery handler.
|
||||
def initialize(options={})
|
||||
if options[:service] && SERVICE_DEFAULTS[options[:service]]
|
||||
@options = DEFAULTS.merge(SERVICE_DEFAULTS[options[:service]])
|
||||
else
|
||||
@options = DEFAULTS.clone
|
||||
end
|
||||
@options.merge!(options)
|
||||
# Handle any remaining configuration here
|
||||
end
|
||||
|
||||
##
|
||||
# Returns the configuration of the handler. Configuration options that
|
||||
# are not recognized by the handler are ignored.
|
||||
#
|
||||
# @return [Hash] The configuration options.
|
||||
def options
|
||||
return @options
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -57,3 +57,28 @@ describe Google::APIClient::OAuth1, "in the default configuration" do
|
|||
end).should raise_error(TypeError)
|
||||
end
|
||||
end
|
||||
|
||||
describe Google::APIClient::OAuth1, "configured for use with bogus service" do
|
||||
before do
|
||||
@oauth = Google::APIClient::OAuth1.new(:service => :bogus)
|
||||
end
|
||||
|
||||
it "should have the default configuration" do
|
||||
@oauth.request_token_uri.should ==
|
||||
Google::APIClient::OAuth1::DEFAULTS[:request_token_uri]
|
||||
@oauth.authorization_endpoint_uri.should ==
|
||||
Google::APIClient::OAuth1::DEFAULTS[:authorization_uri]
|
||||
@oauth.access_token_uri.should ==
|
||||
Google::APIClient::OAuth1::DEFAULTS[:access_token_uri]
|
||||
@oauth.scopes.should ==
|
||||
Google::APIClient::OAuth1::DEFAULTS[:scopes]
|
||||
@oauth.callback.should ==
|
||||
Google::APIClient::OAuth1::DEFAULTS[:callback]
|
||||
@oauth.display_name.should ==
|
||||
Google::APIClient::OAuth1::DEFAULTS[:display_name]
|
||||
@oauth.consumer_key.should ==
|
||||
Google::APIClient::OAuth1::DEFAULTS[:consumer_key]
|
||||
@oauth.consumer_secret.should ==
|
||||
Google::APIClient::OAuth1::DEFAULTS[:consumer_secret]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -23,6 +23,13 @@ describe Google::APIClient::OAuth1, "configured for use with Buzz" do
|
|||
@oauth = Google::APIClient::OAuth1.new(:service => :buzz)
|
||||
end
|
||||
|
||||
it "should not have the default configuration" do
|
||||
@oauth.authorization_endpoint_uri.should_not ==
|
||||
Google::APIClient::OAuth1::DEFAULTS[:authorization_uri]
|
||||
@oauth.scopes.should_not ==
|
||||
Google::APIClient::OAuth1::DEFAULTS[:scopes]
|
||||
end
|
||||
|
||||
it "should have the correct authorization_uri" do
|
||||
@oauth.authorization_endpoint_uri.should ==
|
||||
"https://www.google.com/buzz/api/auth/OAuthAuthorizeToken"
|
||||
|
|
Loading…
Reference in New Issue