Made the builder more flexible by adding a callback parameter.

git-svn-id: https://google-api-ruby-client.googlecode.com/svn/trunk@27 c1d61fac-ed7f-fcc1-18f7-ff78120a04ef
This commit is contained in:
bobaman@google.com 2010-08-24 21:59:53 +00:00
parent 5b71f47a4d
commit 541054e88d
2 changed files with 14 additions and 2 deletions

View File

@ -42,6 +42,17 @@ module Google #:nodoc:
def parser def parser
return @options[:parser] return @options[:parser]
end end
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
end end
end end

View File

@ -33,9 +33,10 @@ module Google #:nodoc:
# #
# @param [Google::APIClient] client # @param [Google::APIClient] client
# The client the {MethodBuilder} will use to build requests. # The client the {MethodBuilder} will use to build requests.
def initialize(client) def initialize(client, callback=:build_request)
@segments = [] @segments = []
@client = client @client = client
@callback = callback
end end
## ##
@ -77,7 +78,7 @@ module Google #:nodoc:
def method_missing(method, *args, &block) def method_missing(method, *args, &block)
self << method self << method
if !args.empty? || block if !args.empty? || block
return @client.build_request(self.to_str, *args, &block) return @client.send(callback, self.to_str, *args, &block)
else else
return self return self
end end