Skip to content

Instantly share code, notes, and snippets.

@mopuriiswaryalakshmi
Created April 24, 2017 08:28
Show Gist options
  • Save mopuriiswaryalakshmi/6d3ec6be985be784f021898d9c3fa70b to your computer and use it in GitHub Desktop.
Save mopuriiswaryalakshmi/6d3ec6be985be784f021898d9c3fa70b to your computer and use it in GitHub Desktop.
Host as Params in constructor
require 'mongo'
require 'httparty'
class Product
attr_accessor :host
def initialize(host)
@product_details = {}
@host = host
@doc = HTTParty.get(host)
@mongo = Mongo::Client.new([ '127.0.0.1:27017' ], :database => 'test')
@collection = @mongo[:Product5]
end
def store
@product_details["URL"] = @doc["product"]["item"]["buy_url"]
@product_details["Title"] = @doc["product"]["item"]["product_description"]["title"]
@product_details["Details"] = @doc["product"]["item"]["product_description"]["downstream_description"]
@product_details["Description"] = @doc["product"]["item"]["product_description"]["bullet_description"]
@product_details["#{@doc["product"]["item"]["product_description"]["soft_bullets"]["title"]}"]= @doc["product"]["item"]["product_description"]["soft_bullets"]["bullets"]
@product_details["Price"] = @doc["product"]["price"]["offerPrice"]["formattedPrice"]
#@product_details["Rating_Count"] = @doc["product"]["rating_and_review_statistics"]["result"]["52029895"]["coreStats"]["TotalReviewCount"]
#@product_details["Rating"] = @doc["product"]["rating_and_review_statistics"]["result"]["52029895"]["coreStats"]["AverageOverallRating"]
@product_details["Size"] = @doc["product"]["item"]["variation"]["size"]
@product_details["Color"]= @doc["product"]["item"]["variation"]["color"]
@product_details["Manufacturer_Brand"] = @doc["product"]["item"]["product_brand"]["brand"]
puts @product_details
#binding.pry
storeproductdetails
end
def storeproductdetails
@collection.insert_one(@product_details)
end
end
product = Product.new("https://redsky.target.com/v2/pdp/tcin/52029895?excludes=taxonomy")
puts product.store
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment