- def normalize_api_method(options)
- method = options[:api_method]
- version = options[:version]
- if method.kind_of?(Google::APIClient::Method) || method == nil
- return method
- elsif method.respond_to?(:to_str) || method.kind_of?(Symbol)
- # This method of guessing the API is unreliable. This will fail for
- # APIs where the first segment of the RPC name does not match the
- # service name. However, this is a fallback mechanism anyway.
- # Developers should be passing in a reference to the method, rather
- # than passing in a string or symbol. This should raise an error
- # in the case of a mismatch.
- method = method.to_s
- api = method[/^([^.]+)\./, 1]
- api_method = self.discovered_method(method, api, version)
- if api_method.nil?
- raise ArgumentError, "API method could not be found."
- end
- return api_method
- else
- raise TypeError,
- "Expected Google::APIClient::Method, got #{new_api_method.class}."
- end
- end
-