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:
parent
d371bc3cbf
commit
70ed84ffec
|
@ -13,3 +13,24 @@
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
require "google/api_client/version"
|
require "google/api_client/version"
|
||||||
|
|
||||||
|
module Google #:nodoc:
|
||||||
|
##
|
||||||
|
# This class manages communication with a single API.
|
||||||
|
class APIClient
|
||||||
|
def initialize(options={})
|
||||||
|
@options = {
|
||||||
|
# TODO: What configuration options need to go here?
|
||||||
|
}.merge(options)
|
||||||
|
unless @options[:authentication]
|
||||||
|
require "google/api_client/auth/oauth_1"
|
||||||
|
# NOTE: Do not rely on this default value, as it may change
|
||||||
|
@options[:authentication] = OAuth1.new
|
||||||
|
end
|
||||||
|
unless @options[:transport]
|
||||||
|
require "google/api_client/transport/http_transport"
|
||||||
|
@options[:transport] = HTTPTransport
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
|
@ -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
|
|
@ -0,0 +1,21 @@
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
module Google #:nodoc:
|
||||||
|
class APIClient #:nodoc:
|
||||||
|
class HTTPTransport
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -14,8 +14,8 @@
|
||||||
|
|
||||||
# Used to prevent the class/module from being loaded more than once
|
# Used to prevent the class/module from being loaded more than once
|
||||||
unless defined? Google::APIClient::VERSION
|
unless defined? Google::APIClient::VERSION
|
||||||
module Google
|
module Google #:nodoc:
|
||||||
module APIClient #:nodoc:
|
class APIClient #:nodoc:
|
||||||
module VERSION #:nodoc:
|
module VERSION #:nodoc:
|
||||||
MAJOR = 0
|
MAJOR = 0
|
||||||
MINOR = 1
|
MINOR = 1
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
# 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 "google/api_client/auth/oauth_1"
|
||||||
|
|
||||||
|
describe Google::APIClient::OAuth1, "in the default configuration" do
|
||||||
|
before do
|
||||||
|
@oauth = Google::APIClient::OAuth1.new
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should have the correct request_token_uri" do
|
||||||
|
@oauth.request_token_uri.should ==
|
||||||
|
"https://www.google.com/accounts/OAuthGetRequestToken"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should have the correct authorization_uri" do
|
||||||
|
@oauth.authorization_uri.should ==
|
||||||
|
"https://www.google.com/accounts/OAuthAuthorizeToken"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should have the correct access_token_uri" do
|
||||||
|
@oauth.access_token_uri.should ==
|
||||||
|
"https://www.google.com/accounts/OAuthGetAccessToken"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should have the correct consumer_key" do
|
||||||
|
@oauth.consumer_key.should == "anonymous"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should have the correct consumer_secret" do
|
||||||
|
@oauth.consumer_secret.should == "anonymous"
|
||||||
|
end
|
||||||
|
end
|
|
@ -18,9 +18,13 @@ namespace :gem do
|
||||||
s.extra_rdoc_files = %w( README )
|
s.extra_rdoc_files = %w( README )
|
||||||
s.rdoc_options.concat ["--main", "README"]
|
s.rdoc_options.concat ["--main", "README"]
|
||||||
|
|
||||||
s.add_development_dependency("rake", ">= 0.8.3")
|
s.add_runtime_dependency("oauth", ">= 0.4.1")
|
||||||
s.add_development_dependency("rspec", ">= 1.1.11")
|
s.add_runtime_dependency("addressable", ">= 2.2.0")
|
||||||
|
|
||||||
|
s.add_development_dependency("rake", ">= 0.7.3")
|
||||||
|
s.add_development_dependency("rspec", ">= 1.0.8")
|
||||||
s.add_development_dependency("launchy", ">= 0.3.2")
|
s.add_development_dependency("launchy", ">= 0.3.2")
|
||||||
|
s.add_development_dependency("diff-lcs", ">= 1.1.2")
|
||||||
|
|
||||||
s.require_path = "lib"
|
s.require_path = "lib"
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,4 @@ namespace :doc do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "Alias to doc:rdoc"
|
|
||||||
task "doc" => "doc:rdoc"
|
|
||||||
|
|
||||||
task "clobber" => ["doc:clobber_rdoc", "doc:clobber_ri"]
|
task "clobber" => ["doc:clobber_rdoc", "doc:clobber_ri"]
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
require "rake"
|
||||||
|
|
||||||
|
begin
|
||||||
|
require "yard/rake/yardoc_task"
|
||||||
|
|
||||||
|
namespace :doc do
|
||||||
|
desc "Generate Yardoc documentation"
|
||||||
|
YARD::Rake::YardocTask.new do |yardoc|
|
||||||
|
yardoc.name = "yard"
|
||||||
|
yardoc.options = "-o doc/"
|
||||||
|
yardoc.files = FileList[
|
||||||
|
"lib/**/*.rb", "ext/**/*.c", "-", "README", "CHANGELOG", "LICENSE"
|
||||||
|
].exclude(/^[_\.]/)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
task "clobber" => ["doc:clobber_yard"]
|
||||||
|
|
||||||
|
desc "Alias to doc:yard"
|
||||||
|
task "doc" => "doc:yard"
|
||||||
|
rescue LoadError
|
||||||
|
# If yard isn't available, it's not the end of the world
|
||||||
|
desc "Alias to doc:rdoc"
|
||||||
|
task "doc" => "doc:rdoc"
|
||||||
|
end
|
Loading…
Reference in New Issue