Skip to content

Instantly share code, notes, and snippets.

@coderberry
Created December 1, 2009 20:59
Show Gist options
  • Select an option

  • Save coderberry/246642 to your computer and use it in GitHub Desktop.

Select an option

Save coderberry/246642 to your computer and use it in GitHub Desktop.
require 'net/http'
require 'uri'
# Create te http object
url = "http://POST_URL_HERE/api/create_custom_order"
uri = URI.parse(url)
http = Net::HTTP.new(uri.host, uri.port)
xml = <<-EOF
<order>
<company-id>1</company-id>
<shipping-profile>t1</shipping-profile>
<shipping-full-name>John Doe</shipping-full-name>
<shipping-care-of/>
<shipping-address-1>123 Easy St</shipping-address-1>
<shipping-address-2/>
<shipping-city>Eau Claire</shipping-city>
<shipping-state>WI</shipping-state>
<shipping-zip>77593</shipping-zip>
<shipping-country>US</shipping-country>
<items>
<item>
<inventory-item-id>1</inventory-item-id>
<quantity>1</quantity>
</item>
</items>
</order>
EOF
# Set Headers
headers = {
'Referer' => 'http://www.my_url_here.com',
'Content-Type' => 'text/xml',
'Host' => uri.host,
'Content-Length' => xml.length.to_s
}
# Post the request
resp, data = http.post(uri.path, xml, headers)
# Output the results
puts 'Code = ' + resp.code
puts 'Message = ' + resp.message
resp.each { |key, val| puts key + ' = ' + val }
puts data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment