Skip to content

Instantly share code, notes, and snippets.

@klochner
Created July 30, 2009 00:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save klochner/158486 to your computer and use it in GitHub Desktop.
Save klochner/158486 to your computer and use it in GitHub Desktop.
def send_to_sales_force(info_request)
sf_url = "www.salesforce.com"
sfhash = {"oid"=>"GET_THIS_FROM_SALES_FORCE",
"retURL"=>"http://www.mycompany.com",
"first_name"=>info_request.first_name,
"last_name"=>info_request.last_name,
"email"=>info_request.email,
"company"=>info_request.company,
"phone"=>info_request.phone}
params = "encoding=UTF-8&"
params << sfhash.collect{|v| v.join("=")}.join("&")
http = Net::HTTP.new(sf_url, 443)
http.use_ssl = true
path = '/servlet/servlet.WebToLead'
headers = {
'Referer' => 'http://www.mycompany.com/',
'Content-Type' => 'application/x-www-form-urlencoded',
'content-length' => params.length.to_s
}
resp, data = http.post(path, params, headers)
# We should get either a 302 redirect or an error page
ActiveRecord::Base.logger.warn("sales force return: code #{resp.code}")
ActiveRecord::Base.logger.warn("sales force return message: #{resp.message}")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment