Created
April 20, 2010 16:40
-
-
Save Soleone/372726 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/http' | |
require "rexml/document" | |
include REXML # so that we don't have to prefix everything with REXML::... | |
API_KEY, PASSWORD = "your-api-key", "your-password" | |
doc = Document.new | |
doc << XMLDecl.new('1.0', 'UTF-8') | |
root = doc.add_element 'product' | |
type = root.add_element "product-type" | |
body = root.add_element "body" | |
title = root.add_element "title" | |
tags = root.add_element "tags" | |
vendor = root.add_element "vendor" | |
sku = root.add_element "sku" | |
type.text = "Art Print" | |
body.text = "Body text" | |
title.text = "Title text" | |
tags.text = "animal,water" | |
vendor.text = "My name" | |
sku.text = "123456" | |
shopify_url = 'http://your-shop.myshopify.com/admin/products.xml' | |
xml_string = '' | |
doc.write(xml_string, 2) | |
url = URI.parse(test_url) | |
request = Net::HTTP::Post.new(url.path) | |
request.basic_auth(API_KEY, PASSWORD) | |
request.body = xml_string | |
request.content_type = 'text/xml' | |
response = Net::HTTP.start(url.host, url.port) {|http| http.request(request)} | |
puts xml_string | |
puts response |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment