lib/hubspot/utils.rb in hubspot-ruby-0.1.2 vs lib/hubspot/utils.rb in hubspot-ruby-0.1.3

- old
+ new

@@ -37,12 +37,32 @@ path.gsub!(":#{k}",v.to_s) params.delete(k) end end raise(Hubspot::MissingInterpolation.new("Interpolation not resolved")) if path =~ /:/ - query = params.map{ |k,v| "#{k}=#{v}" }.join("&") + query = params.map{ |k,v| param_string(k,v) }.join("&") path += "?" if query.present? base_url + path + query end + + + private + + def converted_value(value) + if (value.is_a?(Time)) + (value.to_i * 1000) # convert into milliseconds since epoch + else + value + end + end + + def param_string(key,value) + if (key =~ /range/) + raise "Value must be a range" unless value.is_a?(Range) + "#{key}=#{converted_value(value.begin)}&#{key}=#{converted_value(value.end)}" + else + "#{key}=#{converted_value(value)}" + end + end end end -end \ No newline at end of file +end