Accept repeated parameters
This commit is contained in:
parent
abf64d5314
commit
01229ff710
|
@ -112,16 +112,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
|
||||||
|
@ -147,7 +145,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
|
||||||
|
@ -244,7 +242,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(', ')}."
|
||||||
|
|
Loading…
Reference in New Issue