Added some stubs for OAuth and HTTP.
authorbobaman@google.com <bobaman@google.com@c1d61fac-ed7f-fcc1-18f7-ff78120a04ef>
Tue, 10 Aug 2010 04:44:14 +0000 (04:44 +0000)
committerbobaman@google.com <bobaman@google.com@c1d61fac-ed7f-fcc1-18f7-ff78120a04ef>
Tue, 10 Aug 2010 04:44:14 +0000 (04:44 +0000)
git-svn-id: https://google-api-ruby-client.googlecode.com/svn/trunk@3 c1d61fac-ed7f-fcc1-18f7-ff78120a04ef

lib/google/api_client.rb
lib/google/api_client/auth/oauth_1.rb [new file with mode: 0644]
lib/google/api_client/transport/http_transport.rb [new file with mode: 0644]
lib/google/api_client/version.rb
spec/google/api_client/auth/oauth_1_spec.rb [new file with mode: 0644]
tasks/gem.rake
tasks/rdoc.rake
tasks/yard.rake [new file with mode: 0644]

index 684d70f6a8e877ab72cb23ecf057827d3fe871b1..081ba7d54c0bf513423e37a500af011dc75aa8e9 100644 (file)
 # limitations under the License.
 
 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
diff --git a/lib/google/api_client/auth/oauth_1.rb b/lib/google/api_client/auth/oauth_1.rb
new file mode 100644 (file)
index 0000000..17f53fe
--- /dev/null
@@ -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
diff --git a/lib/google/api_client/transport/http_transport.rb b/lib/google/api_client/transport/http_transport.rb
new file mode 100644 (file)
index 0000000..823dca7
--- /dev/null
@@ -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
index dd8e8a806173a10740c345ebf3238670bd0ddca9..6b93ae8be3c8ecb5824e9018720f7e6935d19228 100644 (file)
@@ -14,8 +14,8 @@
 
 # Used to prevent the class/module from being loaded more than once
 unless defined? Google::APIClient::VERSION
-  module Google
-    module APIClient #:nodoc:
+  module Google #:nodoc:
+    class APIClient #:nodoc:
       module VERSION #:nodoc:
         MAJOR = 0
         MINOR = 1
diff --git a/spec/google/api_client/auth/oauth_1_spec.rb b/spec/google/api_client/auth/oauth_1_spec.rb
new file mode 100644 (file)
index 0000000..ec6d151
--- /dev/null
@@ -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
index e6f9c74e61cb85ad8c3f0258efca81fee6f7fd31..627a9cb28e45defb4c50d3a1fe1773d3a5548006 100644 (file)
@@ -18,9 +18,13 @@ namespace :gem do
     s.extra_rdoc_files = %w( README )
     s.rdoc_options.concat ["--main",  "README"]
 
-    s.add_development_dependency("rake", ">= 0.8.3")
-    s.add_development_dependency("rspec", ">= 1.1.11")
+    s.add_runtime_dependency("oauth", ">= 0.4.1")
+    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("diff-lcs", ">= 1.1.2")
 
     s.require_path = "lib"
 
index 1f636c9691cf74c57bf122076ea1c50cb46c7a77..00ef19be1025b5a7f1205f07ae9d78d10d9d79ac 100644 (file)
@@ -23,7 +23,4 @@ namespace :doc do
   end
 end
 
-desc "Alias to doc:rdoc"
-task "doc" => "doc:rdoc"
-
 task "clobber" => ["doc:clobber_rdoc", "doc:clobber_ri"]
diff --git a/tasks/yard.rake b/tasks/yard.rake
new file mode 100644 (file)
index 0000000..62d6283
--- /dev/null
@@ -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