2010-07-28 19:30:56 +00:00
|
|
|
# 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.
|
|
|
|
|
2010-08-10 04:44:14 +00:00
|
|
|
module Google #:nodoc:
|
|
|
|
##
|
|
|
|
# This class manages communication with a single API.
|
|
|
|
class APIClient
|
2010-08-19 23:21:45 +00:00
|
|
|
|
2010-08-10 04:44:14 +00:00
|
|
|
def initialize(options={})
|
|
|
|
@options = {
|
|
|
|
# TODO: What configuration options need to go here?
|
|
|
|
}.merge(options)
|
2010-08-19 23:21:45 +00:00
|
|
|
unless @options[:parser]
|
|
|
|
require 'google/api_client/parser/json_parser'
|
|
|
|
# NOTE: Do not rely on this default value, as it may change
|
|
|
|
@options[:parser] = JSONParser.new
|
|
|
|
end
|
2010-09-13 21:54:43 +00:00
|
|
|
unless @options[:authorization]
|
|
|
|
require 'signet/oauth_1/client'
|
2010-08-10 04:44:14 +00:00
|
|
|
# NOTE: Do not rely on this default value, as it may change
|
2010-09-13 21:54:43 +00:00
|
|
|
@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'
|
|
|
|
)
|
2010-08-10 04:44:14 +00:00
|
|
|
end
|
2010-09-13 21:54:43 +00:00
|
|
|
unless @options[:http_adapter]
|
|
|
|
require 'httpadapter/adapters/net_http'
|
|
|
|
@options[:http_adapter] = HTTPAdapter::NetHTTPRequestAdapter
|
2010-08-10 04:44:14 +00:00
|
|
|
end
|
|
|
|
end
|
2010-09-13 21:54:43 +00:00
|
|
|
|
2010-08-19 23:21:45 +00:00
|
|
|
##
|
|
|
|
# Returns the parser used by the client.
|
|
|
|
def parser
|
|
|
|
return @options[:parser]
|
|
|
|
end
|
2010-09-13 21:54:43 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
# Returns the authorization mechanism used by the client.
|
|
|
|
def authorization
|
|
|
|
return @options[:authorization]
|
|
|
|
end
|
|
|
|
|
2010-08-24 21:59:53 +00:00
|
|
|
def build_request(*args, &block)
|
|
|
|
if !args.empty? || block
|
|
|
|
# Build the request!
|
|
|
|
# TODO(bobaman): No-op / Debug code!
|
|
|
|
return args
|
|
|
|
else
|
|
|
|
require 'google/api_client/discovery/method_builder'
|
|
|
|
return ::Google::APIClient::MethodBuilder.new(self, :build_request)
|
|
|
|
end
|
|
|
|
end
|
2010-08-10 04:44:14 +00:00
|
|
|
end
|
|
|
|
end
|
2010-08-19 23:21:45 +00:00
|
|
|
|
|
|
|
require 'google/api_client/version'
|