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