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

- old
+ new

@@ -18,23 +18,31 @@ # @param path [String] The path of the request with leading "/". Parts starting with a ":" will be interpolated # @param params [Hash] params to be included in the query string or interpolated into the url. # # @return [String] # - def generate_url(path, params={}) - raise Hubspot::ConfigurationError.new("'hapikey' not configured") unless Hubspot::Config.hapikey + def generate_url(path, params={}, options={}) + Hubspot::Config.ensure! :hapikey path = path.clone params = params.clone - params["hapikey"] = Hubspot::Config.hapikey + base_url = options[:base_url] || Hubspot::Config.base_url + params["hapikey"] = Hubspot::Config.hapikey unless options[:hapikey] == false + + if path =~ /:portal_id/ + Hubspot::Config.ensure! :portal_id + params["portal_id"] = Hubspot::Config.portal_id if path =~ /:portal_id/ + end + params.each do |k,v| if path.match(":#{k}") 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("&") - Hubspot::Config.base_url + path + "?" + query + path += "?" if query.present? + base_url + path + query end end end end \ No newline at end of file