Skip to content

Instantly share code, notes, and snippets.

@speedmax
Created May 4, 2009 04:34
Show Gist options
  • Select an option

  • Save speedmax/106307 to your computer and use it in GitHub Desktop.

Select an option

Save speedmax/106307 to your computer and use it in GitHub Desktop.
require 'json'
require 'pp'
require 'open-uri'
require 'money'
url = "http://www.google.com/base/feeds/snippets/-/products%7Cservices?bq=headphone&max-results=100&content=all&adjust=false&alt=json"
product = open(url)
products = JSON.parse(product.read)["feed"]["entry"]
results = []
pp products and return
products.each do |json|
results.push({
:name => json["title"]["$t"],
:description => json["content"]["$t"],
# create retailer
:retailer => json["author"].first["name"]["$t"],
:product_type => json["g$product_type"][0]["$t"],
:brand => json["g$brand"][0]["gm$adjusted_value"]["$t"],
:url => json["link"][0]["href"],
:features => json["g$functions"].map{|f| f["$t"] },
:keywords => json["g$keywords"].map{|k| k["$t"] },
:image_url => json["g$image_link"][0]["$t"],
:code => json["g$model_number"][0]["$t"],
:price_in_cents => json["g$price"][0]["$t"].to_money.cents
})
end
pp results
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment