1 # Copyright 2010 Google Inc.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # Define a BasicObject implementation if one doesn't already exist.
16 unless defined?(BasicObject)
18 instance_methods.each do |m|
19 if m.to_s !~ /^(?:!=?|==|__.*__|equal\?|instance_(?:eval|exec))$/
26 module Google #:nodoc:
27 class APIClient #:nodoc:
29 # A builder class for assembling requests.
30 class MethodBuilder < BasicObject
32 # Creates a new {MethodBuilder}.
34 # @param [Google::APIClient] client
35 # The client the {MethodBuilder} will use to build requests.
36 def initialize(client, callback=:build_request)
43 # Appends a segment to the builder.
45 # @param [String, Symbol, #to_s] segment The segment to append.
47 @segments << segment.to_s
51 # Returns the assembled segments. This maps to the <code>rpcName</code>
52 # field in the discovery document.
54 # @return [String] The RPC name of the method.
56 return @segments.join(".")
58 alias_method :to_str, :to_s
61 # The call method will force the builder to finish assembling segments
62 # and build the request.
64 # @return [Enumerable]
65 def call(*args, &block)
66 return @client.build_request(self.to_str, *args, &block)
70 # Any methods called on the {MethodBuilder} will cause segments to be
73 # @return [Enumerable, Google::APIClient::MethodBuilder]
74 # Allows chaining methods to build an endpoint name. The request
75 # is built when parameters are sent. If an endpoint does not take
76 # parameters, the {#call} method may be used to terminate the
78 def method_missing(method, *args, &block)
80 if !args.empty? || block
81 return @client.send(callback, self.to_str, *args, &block)