Skip to content

Commit

Permalink
extracted encoded path preparation
Browse files Browse the repository at this point in the history
  • Loading branch information
Diego Scataglini committed Sep 20, 2011
1 parent 87d152b commit 21eadf0
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/databasedotcom/client.rb
Expand Up @@ -310,15 +310,19 @@ def http_multipart_post(path, parts, parameters={}, headers={})
def within_request(path, opts = {}, parameters={}, headers={})
req = Net::HTTP.new(URI.parse(self.instance_url).host, 443)
req.use_ssl = true
path_parameters = (parameters || {}).collect { |k, v| "#{URI.escape(k.to_s)}=#{URI.escape(v.to_s)}" }.join('&')
encoded_path = [URI.escape(path), path_parameters.empty? ? nil : path_parameters].compact.join('?')
encoded_path = prepare_encoded_path_from(path, parameters)
log_request(encoded_path, opts[:data]) #data is passed only in post
result = yield(req, encoded_path)
log_response(result)
raise SalesForceError.new(result) unless result.is_a?(opts[:expected_result_class] || Net::HTTPSuccess)
result
end

def prepare_encoded_path_from(path, parameters={})
path_parameters = (parameters || {}).collect { |k, v| "#{URI.escape(k.to_s)}=#{URI.escape(v.to_s)}" }.join('&')
[URI.escape(path), path_parameters.empty? ? nil : path_parameters].compact.join('?')
end

def log_request(path, data=nil)
puts "***** REQUEST: #{path.include?(':') ? path : URI.join(self.instance_url, path)}#{data ? " => #{data}" : ''}" if self.debugging
end
Expand Down

0 comments on commit 21eadf0

Please sign in to comment.