Updated to use Signet.

git-svn-id: https://google-api-ruby-client.googlecode.com/svn/trunk@31 c1d61fac-ed7f-fcc1-18f7-ff78120a04ef
This commit is contained in:
bobaman@google.com 2010-09-13 21:54:43 +00:00
parent 4787954779
commit 719e576051
2 changed files with 38 additions and 11 deletions

View File

@ -26,14 +26,23 @@ module Google #:nodoc:
# NOTE: Do not rely on this default value, as it may change # NOTE: Do not rely on this default value, as it may change
@options[:parser] = JSONParser.new @options[:parser] = JSONParser.new
end end
unless @options[:authentication] unless @options[:authorization]
require 'google/api_client/auth/oauth_1' require 'signet/oauth_1/client'
# NOTE: Do not rely on this default value, as it may change # NOTE: Do not rely on this default value, as it may change
@options[:authentication] = OAuth1.new @options[:authorization] = Signet::OAuth1::Client.new(
:temporary_credential_uri =>
'https://www.google.com/accounts/OAuthGetRequestToken',
:authorization_uri =>
'https://www.google.com/accounts/OAuthAuthorizeToken',
:token_credential_uri =>
'https://www.google.com/accounts/OAuthGetAccessToken',
:client_credential_key => 'anonymous',
:client_credential_secret => 'anonymous'
)
end end
unless @options[:transport] unless @options[:http_adapter]
require 'google/api_client/transport/http_transport' require 'httpadapter/adapters/net_http'
@options[:transport] = HTTPTransport @options[:http_adapter] = HTTPAdapter::NetHTTPRequestAdapter
end end
end end
@ -43,6 +52,12 @@ module Google #:nodoc:
return @options[:parser] return @options[:parser]
end end
##
# Returns the authorization mechanism used by the client.
def authorization
return @options[:authorization]
end
def build_request(*args, &block) def build_request(*args, &block)
if !args.empty? || block if !args.empty? || block
# Build the request! # Build the request!

View File

@ -14,12 +14,12 @@
require 'spec_helper' require 'spec_helper'
require 'signet/oauth_1/client'
require 'httpadapter/adapters/net_http'
require 'google/api_client' require 'google/api_client'
require 'google/api_client/version' require 'google/api_client/version'
require 'google/api_client/parser/json_parser' require 'google/api_client/parser/json_parser'
require 'google/api_client/auth/oauth_1'
require 'google/api_client/transport/http_transport'
describe Google::APIClient, 'with default configuration' do describe Google::APIClient, 'with default configuration' do
before do before do
@ -33,6 +33,18 @@ describe Google::APIClient, 'with default configuration' do
it 'should use the default JSON parser' do it 'should use the default JSON parser' do
@client.parser.should be_instance_of(Google::APIClient::JSONParser) @client.parser.should be_instance_of(Google::APIClient::JSONParser)
end end
it 'should use the default OAuth1 client configuration' do
@client.authorization.temporary_credential_uri.to_s.should ==
'https://www.google.com/accounts/OAuthGetRequestToken'
@client.authorization.authorization_uri.to_s.should include(
'https://www.google.com/accounts/OAuthAuthorizeToken'
)
@client.authorization.token_credential_uri.to_s.should ==
'https://www.google.com/accounts/OAuthGetAccessToken'
@client.authorization.client_credential_key.should == 'anonymous'
@client.authorization.client_credential_secret.should == 'anonymous'
end
end end
describe Google::APIClient, 'with custom pluggable parser' do describe Google::APIClient, 'with custom pluggable parser' do