Merge branch 'master' of ../martinsarsale-support-for-repeats
This commit is contained in:
commit
04ec835ca1
|
@ -140,16 +140,14 @@ module Google
|
|||
def normalize_parameters(parameters={})
|
||||
# Convert keys to Strings when appropriate
|
||||
if parameters.kind_of?(Hash) || parameters.kind_of?(Array)
|
||||
# Is a Hash or an Array a better return type? Do we ever need to
|
||||
# worry about the same parameter being sent twice with different
|
||||
# values?
|
||||
parameters = parameters.inject({}) do |accu, (k, v)|
|
||||
# Returning an array since parameters can be repeated (ie, Adsense Management API)
|
||||
parameters = parameters.inject([]) do |accu, (k, v)|
|
||||
k = k.to_s if k.kind_of?(Symbol)
|
||||
k = k.to_str if k.respond_to?(:to_str)
|
||||
unless k.kind_of?(String)
|
||||
raise TypeError, "Expected String, got #{k.class}."
|
||||
end
|
||||
accu[k] = v
|
||||
accu << [k,v]
|
||||
accu
|
||||
end
|
||||
else
|
||||
|
@ -175,7 +173,7 @@ module Google
|
|||
template_variables.include?(k)
|
||||
end
|
||||
if query_parameters.size > 0
|
||||
uri.query_values = (uri.query_values || {}).merge(query_parameters)
|
||||
uri.query_values = (uri.query_values || []) + query_parameters
|
||||
end
|
||||
# Normalization is necessary because of undesirable percent-escaping
|
||||
# during URI template expansion
|
||||
|
@ -272,7 +270,7 @@ module Google
|
|||
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.keys
|
||||
missing_variables = required_variables - parameters.map(&:first)
|
||||
if missing_variables.size > 0
|
||||
raise ArgumentError,
|
||||
"Missing required parameters: #{missing_variables.join(', ')}."
|
||||
|
|
|
@ -174,7 +174,16 @@ describe Google::APIClient do
|
|||
(headers.inject({}) { |h,(k,v)| h[k]=v; h }).should == {}
|
||||
body.should respond_to(:each)
|
||||
end
|
||||
|
||||
it 'should generate valid requests when repeated parameters are passed' do
|
||||
request = @client.generate_request(
|
||||
:api_method => @prediction.training.insert,
|
||||
:parameters => [['data', '1'],['data','2']]
|
||||
)
|
||||
method, uri, headers, body = request
|
||||
method.should == 'POST'
|
||||
uri.should ==
|
||||
'https://www.googleapis.com/prediction/v1.2/training?data=1&data=2'
|
||||
end
|
||||
it 'should generate requests against the correct URIs' do
|
||||
request = @client.generate_request(
|
||||
:api_method => @prediction.training.insert,
|
||||
|
|
Loading…
Reference in New Issue