Skip to content

Instantly share code, notes, and snippets.

@Soleone
Created April 20, 2010 16:30
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 Soleone/372710 to your computer and use it in GitHub Desktop.
Save Soleone/372710 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'builder'
require 'net/http'
API_KEY, PASSWORD = "your-key", "your-password"
URL = "http://your-shop.myshopify.com/admin/webhooks.xml"
xml = Builder::XmlMarkup.new(:indent => 2)
xml.instruct!
xml.webhook do
xml.address "http://my-hook-address.com/endpoint"
xml.topic "orders/create"
end
xml_body = xml.target!
url = URI.parse(URL)
request = Net::HTTP::Post.new(url.path)
request.basic_auth(API_KEY, PASSWORD)
request.body = xml_body
request.content_type = 'text/xml'
response = Net::HTTP.start(url.host, url.port) {|http| http.request(request)}
puts "Request: #{xml_body}"
puts "Response: #{response.body}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment