Last active
April 22, 2017 08:03
-
-
Save mopuriiswaryalakshmi/55278c7bb1391bd0d3d0e6a06ff9505e to your computer and use it in GitHub Desktop.
using insert_one command
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
#class Product | |
require 'mongo' | |
require 'httparty' | |
mongo = Mongo::Client.new([ '127.0.0.1:27017' ], :database => 'test') | |
collection = mongo[:Product] | |
#def store | |
product_details = { | |
doc: 'HTTParty.get("http://redsky.target.com/v2/pdp/tcin/52029895?excludes=taxonomy")', | |
'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"]' | |
} | |
collection.insert_one(product_details) | |
#end | |
#end | |
#product = Product.new | |
#product.store |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment