Added some stubs for OAuth and HTTP.
git-svn-id: https://google-api-ruby-client.googlecode.com/svn/trunk@3 c1d61fac-ed7f-fcc1-18f7-ff78120a04ef
This commit is contained in:
1 parent
d371bc3cbf
commit
70ed84ffec
8 files changed
+198
-7
No files matched your search
@@ -0,0 +1,79 @@
|
||||
# Copyright 2010 Google Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
require "addressable/uri"
|
||||
require "oauth"
|
||||
|
||||
module Google #:nodoc:
|
||||
class APIClient #:nodoc:
|
||||
class OAuth1
|
||||
def initialize(options={})
|
||||
@options = {
|
||||
:request_token_uri =>
|
||||
'https://www.google.com/accounts/OAuthGetRequestToken',
|
||||
:authorization_uri =>
|
||||
'https://www.google.com/accounts/OAuthAuthorizeToken',
|
||||
:access_token_uri =>
|
||||
'https://www.google.com/accounts/OAuthGetAccessToken',
|
||||
:consumer_key => "anonymous",
|
||||
:consumer_secret => "anonymous"
|
||||
}.merge(options)
|
||||
@options[:request_token_uri] =
|
||||
Addressable::URI.parse(@options[:request_token_uri])
|
||||
@options[:authorization_uri] =
|
||||
Addressable::URI.parse(@options[:authorization_uri])
|
||||
@options[:access_token_uri] =
|
||||
Addressable::URI.parse(@options[:access_token_uri])
|
||||
if (@options[:request_token_uri].site !=
|
||||
@options[:authorization_uri].site) ||
|
||||
(@options[:request_token_uri].site !=
|
||||
@options[:authorization_uri].site)
|
||||
raise ArgumentError, "All OAuth endpoints must be on the same site."
|
||||
end
|
||||
@oauth_consumer = ::OAuth::Consumer.new(
|
||||
@options[:consumer_key], @options[:consumer_secret], {
|
||||
# This is an extremely unfortunate way to configure the consumer,
|
||||
# but not worth forking or patching to resolve. Yet.
|
||||
:site => @options[:request_token_uri].site,
|
||||
:scheme => :header,
|
||||
:http_method => :post,
|
||||
:request_token_path => @options[:request_token_uri].request_uri,
|
||||
:access_token_path => @options[:access_token_uri].request_uri,
|
||||
:authorize_path => @options[:authorization_uri].request_uri
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
def consumer_key
|
||||
return @oauth_consumer.key
|
||||
end
|
||||
|
||||
def consumer_secret
|
||||
return @oauth_consumer.secret
|
||||
end
|
||||
|
||||
def request_token_uri
|
||||
return @oauth_consumer.request_token_url
|
||||
end
|
||||
|
||||
def authorization_uri
|
||||
return @oauth_consumer.authorize_url
|
||||
end
|
||||
|
||||
def access_token_uri
|
||||
return @oauth_consumer.access_token_url
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user