Permalink
Browse files

Two failing tests, neither of which I can do much about.

  • Loading branch information...
1 parent 45bc8f4 commit 992a698b0a9def23ffd2067cc18545ad1e1b8391 Bob Aman committed Jul 31, 2012
Showing with 49 additions and 18 deletions.
  1. +3 −3 lib/google/api_client/discovery/method.rb
  2. +46 −15 lib/google/api_client/reference.rb
@@ -163,7 +163,7 @@ def normalize_parameters(parameters={})
unless k.kind_of?(String)
raise TypeError, "Expected String, got #{k.class}."
end
- accu << [k,v]
+ accu << [k, v]
accu
end
else
@@ -204,7 +204,7 @@ def generate_uri(parameters={})
# encode all non-template parameters
params = ""
unless query_parameters.empty?
- params = "?" + Addressable::URI.form_encode(query_parameters)
+ params = "?" + Addressable::URI.form_encode(query_parameters.sort)
end
# Normalization is necessary because of undesirable percent-escaping
# during URI template expansion
@@ -311,7 +311,7 @@ def validate_parameters(parameters={})
required_variables = ((self.parameter_descriptions.select do |k, v|
v['required']
end).inject({}) { |h,(k,v)| h[k]=v; h }).keys
- missing_variables = required_variables - parameters.map(&:first)
+ missing_variables = required_variables - parameters.map { |(k, _)| k }
if missing_variables.size > 0
raise ArgumentError,
"Missing required parameters: #{missing_variables.join(', ')}."
@@ -41,34 +41,57 @@ def initialize(options={})
self.parameters = options[:parameters] || {}
# These parameters are handled differently because they're not
# parameters to the API method, but rather to the API system.
- self.parameters['key'] ||= options[:key] if options[:key]
- self.parameters['userIp'] ||= options[:user_ip] if options[:user_ip]
+ if self.parameters.kind_of?(Array)
+ if options[:key]
+ self.parameters.reject! { |k, _| k == 'key' }
+ self.parameters << ['key', options[:key]]
+ end
+ if options[:user_ip]
+ self.parameters.reject! { |k, _| k == 'userIp' }
+ self.parameters << ['userIp', options[:user_ip]]
+ end
+ elsif self.parameters.kind_of?(Hash)
+ self.parameters['key'] ||= options[:key] if options[:key]
+ self.parameters['userIp'] ||= options[:user_ip] if options[:user_ip]
+ # Convert to Array, because they're easier to work with when
+ # repeated parameters are an issue.
+ self.parameters = self.parameters.to_a
+ else
+ raise TypeError,
+ "Expected Array or Hash, got #{self.parameters.class}."
+ end
self.headers = options[:headers] || {}
if options[:media]
self.media = options[:media]
upload_type = parameters['uploadType'] || parameters['upload_type']
case upload_type
when "media"
if options[:body] || options[:body_object]
- raise ArgumentError, "Can not specify body & body object for simple uploads"
+ raise ArgumentError,
+ "Can not specify body & body object for simple uploads."
end
self.headers['Content-Type'] ||= self.media.content_type
self.body = self.media
when "multipart"
unless options[:body_object]
- raise ArgumentError, "Multipart requested but no body object"
+ raise ArgumentError, "Multipart requested but no body object."
end
- # This is all a bit of a hack due to signet requiring body to be a string
- # Ideally, update signet to delay serialization so we can just pass
- # streams all the way down through to the HTTP lib
+ # This is all a bit of a hack due to Signet requiring body to be a
+ # string. Ideally, update Signet to delay serialization so we can
+ # just pass streams all the way down through to the HTTP library.
metadata = StringIO.new(serialize_body(options[:body_object]))
env = {
- :request_headers => {'Content-Type' => "multipart/related;boundary=#{MULTIPART_BOUNDARY}"},
- :request => { :boundary => MULTIPART_BOUNDARY }
+ :request_headers => {
+ 'Content-Type' =>
+ "multipart/related;boundary=#{MULTIPART_BOUNDARY}"
+ },
+ :request => {:boundary => MULTIPART_BOUNDARY}
}
multipart = Faraday::Request::Multipart.new
self.body = multipart.create_multipart(env, [
- [nil,Faraday::UploadIO.new(metadata, 'application/json', 'file.json')],
+ [nil, Faraday::UploadIO.new(
+ metadata, 'application/json', 'file.json'
+ )],
[nil, self.media]])
self.headers.update(env[:request_headers])
when "resumable"
@@ -82,7 +105,7 @@ def initialize(options={})
self.body = ''
end
else
- raise ArgumentError, "Invalid uploadType for media"
+ raise ArgumentError, "Invalid uploadType for media."
end
elsif options[:body]
self.body = options[:body]
@@ -96,8 +119,12 @@ def initialize(options={})
self.http_method = options[:http_method] || 'GET'
self.uri = options[:uri]
unless self.parameters.empty?
- self.uri.query_values =
- (self.uri.query_values || {}).merge(self.parameters)
+ query_values = (self.uri.query_values(Array) || [])
+ self.uri.query = Addressable::URI.form_encode(
+ (query_values + self.parameters).sort
+ )
+ self.uri.query = nil if self.uri.query == ""
+ puts "reference: " + self.uri.to_s
end
end
end
@@ -199,7 +226,8 @@ def body=(new_body)
accu
end).string
else
- raise TypeError, "Expected body to be String, IO, or Enumerable chunks."
+ raise TypeError,
+ "Expected body to be String, IO, or Enumerable chunks."
end
end
@@ -248,6 +276,7 @@ def to_request
return self.connection.build_request(
self.http_method.to_s.downcase.to_sym
) do |req|
+ puts "request: " + Addressable::URI.parse(self.uri).normalize.to_s
req.url(Addressable::URI.parse(self.uri).normalize.to_s)
req.headers = Faraday::Utils::Headers.new(self.headers)
req.body = self.body
@@ -267,7 +296,9 @@ def to_hash
options[:headers] = self.headers
options[:body] = self.body
options[:connection] = self.connection
- options[:authorization] = self.authorization unless self.authorization.nil?
+ unless self.authorization.nil?
+ options[:authorization] = self.authorization
+ end
return options
end
end

0 comments on commit 992a698

Please sign in to comment.