From 541054e88dad90258e583a726b5f63a2bf811138 Mon Sep 17 00:00:00 2001 From: "bobaman@google.com" Date: Tue, 24 Aug 2010 21:59:53 +0000 Subject: [PATCH] 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 --- lib/google/api_client.rb | 11 +++++++++++ lib/google/api_client/discovery/method_builder.rb | 5 +++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/google/api_client.rb b/lib/google/api_client.rb index 907170caa..9c6ffd3ee 100644 --- a/lib/google/api_client.rb +++ b/lib/google/api_client.rb @@ -42,6 +42,17 @@ module Google #:nodoc: def parser return @options[:parser] 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 diff --git a/lib/google/api_client/discovery/method_builder.rb b/lib/google/api_client/discovery/method_builder.rb index 06a1ae00d..ed1f69ea7 100644 --- a/lib/google/api_client/discovery/method_builder.rb +++ b/lib/google/api_client/discovery/method_builder.rb @@ -33,9 +33,10 @@ module Google #:nodoc: # # @param [Google::APIClient] client # The client the {MethodBuilder} will use to build requests. - def initialize(client) + def initialize(client, callback=:build_request) @segments = [] @client = client + @callback = callback end ## @@ -77,7 +78,7 @@ module Google #:nodoc: def method_missing(method, *args, &block) self << method if !args.empty? || block - return @client.build_request(self.to_str, *args, &block) + return @client.send(callback, self.to_str, *args, &block) else return self end