Last active
April 26, 2017 11:42
-
-
Save mopuriiswaryalakshmi/c70cc45845e5f456f68c89c81ca58473 to your computer and use it in GitHub Desktop.
In Spec Folder
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 'httparty15' | |
describe Product do | |
it "gives product details" do #actuall test | |
#skip | |
url = "http://redsky.target.com/v2/pdp/tcin/52029745?excludes=taxonomy" | |
product = Product.new(url) | |
product_details = product.product_details | |
expect(product_details["Title"]).to include "Alligator" | |
#expect(product_details).to include "URL" | |
end | |
end | |
=begin | |
-----output----------- | |
Enter your Entered URL | |
http://redsky.target.com/v2/pdp/tcin/52029745?excludes=taxonomy | |
D, [2017-04-26T16:11:00.661278 #7504] DEBUG -- : MONGODB | Topology type 'unknown' initializing. | |
D, [2017-04-26T16:11:00.661596 #7504] DEBUG -- : MONGODB | Server 127.0.0.1:27017 initializing. | |
D, [2017-04-26T16:11:00.664383 #7504] DEBUG -- : MONGODB | Topology type 'unknown' changed to type 'single'. | |
D, [2017-04-26T16:11:00.664637 #7504] DEBUG -- : MONGODB | Server description for 127.0.0.1:27017 changed from 'unknown' to 'standalone'. | |
D, [2017-04-26T16:11:00.664840 #7504] DEBUG -- : MONGODB | There was a change in the members of the 'single' topology. | |
I, [2017-04-26T16:11:01.275486 #7504] INFO -- : {"URL"=>"http://www.target.com/p/alligator-sherpa-throw-50-x60-gray-green-lush-d-233-cor/-/A-52029745", "Title"=>"Alligator Sherpa Throw (50\"x60\") Gray & Green - Lush Décor", "Details"=>"This lively and creative throw is a great pickup for children of all ages.Playful alligators are literally scattered throughout this entire piece.", "Description"=>["<B>Fiber Content:</B> 100% , Polyester", "<B>Dimensions:</B> L 50 inches x 60 inches W", "<B>Care and Cleaning:</B> Machine wash, gentle or delicate, , Tumble dry, gentle, low heat"], "Price"=>"$32.29", "Manufacturer_Brand"=>"Lush Decor", "mined_at"=>1493203261} | |
D, [2017-04-26T16:11:01.276429 #7504] DEBUG -- : MONGODB | 127.0.0.1:27017 | test.insert | STARTED | {"insert"=>"Product4", "documents"=>[{"URL"=>"http://www.target.com/p/alligator-sherpa-throw-50-x60-gray-green-lush-d-233-cor/-/A-52029745", "Title"=>"Alligator Sherpa Throw (50\"x60\") Gray & Green - Lush Décor", "Details"=>"This lively and crea... | |
D, [2017-04-26T16:11:01.278007 #7504] DEBUG -- : MONGODB | 127.0.0.1:27017 | test.insert | SUCCEEDED | 0.001427361s | |
I, [2017-04-26T16:11:01.278210 #7504] INFO -- : {"URL"=>"http://www.target.com/p/alligator-sherpa-throw-50-x60-gray-green-lush-d-233-cor/-/A-52029745", "Title"=>"Alligator Sherpa Throw (50\"x60\") Gray & Green - Lush Décor", "Details"=>"This lively and creative throw is a great pickup for children of all ages.Playful alligators are literally scattered throughout this entire piece.", "Description"=>["<B>Fiber Content:</B> 100% , Polyester", "<B>Dimensions:</B> L 50 inches x 60 inches W", "<B>Care and Cleaning:</B> Machine wash, gentle or delicate, , Tumble dry, gentle, low heat"], "Price"=>"$32.29", "Manufacturer_Brand"=>"Lush Decor", "mined_at"=>1493203261} | |
D, [2017-04-26T16:11:01.278691 #7504] DEBUG -- : MONGODB | 127.0.0.1:27017 | test.insert | STARTED | {"insert"=>"Product4", "documents"=>[{"URL"=>"http://www.target.com/p/alligator-sherpa-throw-50-x60-gray-green-lush-d-233-cor/-/A-52029745", "Title"=>"Alligator Sherpa Throw (50\"x60\") Gray & Green - Lush Décor", "Details"=>"This lively and crea... | |
D, [2017-04-26T16:11:01.279294 #7504] DEBUG -- : MONGODB | 127.0.0.1:27017 | test.insert | SUCCEEDED | 0.00048779600000000003s | |
#<Mongo::Operation::Write::Insert::Result:0x00000002691c00> | |
D, [2017-04-26T16:11:01.285255 #7504] DEBUG -- : MONGODB | Topology type 'unknown' initializing. | |
D, [2017-04-26T16:11:01.285463 #7504] DEBUG -- : MONGODB | Server 127.0.0.1:27017 initializing. | |
D, [2017-04-26T16:11:01.287512 #7504] DEBUG -- : MONGODB | Topology type 'unknown' changed to type 'single'. | |
D, [2017-04-26T16:11:01.287662 #7504] DEBUG -- : MONGODB | Server description for 127.0.0.1:27017 changed from 'unknown' to 'standalone'. | |
D, [2017-04-26T16:11:01.287775 #7504] DEBUG -- : MONGODB | There was a change in the members of the 'single' topology. | |
I, [2017-04-26T16:11:01.665806 #7504] INFO -- : {"URL"=>"http://www.target.com/p/alligator-sherpa-throw-50-x60-gray-green-lush-d-233-cor/-/A-52029745", "Title"=>"Alligator Sherpa Throw (50\"x60\") Gray & Green - Lush Décor", "Details"=>"This lively and creative throw is a great pickup for children of all ages.Playful alligators are literally scattered throughout this entire piece.", "Description"=>["<B>Fiber Content:</B> 100% , Polyester", "<B>Dimensions:</B> L 50 inches x 60 inches W", "<B>Care and Cleaning:</B> Machine wash, gentle or delicate, , Tumble dry, gentle, low heat"], "Price"=>"$32.29", "Manufacturer_Brand"=>"Lush Decor", "mined_at"=>1493203261} | |
. | |
Finished in 0.38463 seconds (files took 26.35 seconds to load) | |
1 example, 0 failures | |
=end |
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 'mongo' | |
require 'httparty' | |
require 'logger' | |
require 'pry' | |
class Product | |
attr_accessor :url | |
def initialize(url) | |
@product_details = {} | |
@mongo = Mongo::Client.new([ '127.0.0.1:27017' ], :database => 'test') | |
@logger = Logger.new(STDOUT) | |
@collection = @mongo[:Product4] | |
@url = url | |
@doc = HTTParty.get(url) | |
end | |
def store | |
product_details | |
storeproductdetails | |
end | |
def product_details | |
begin | |
@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"] || nil | |
@product_details["Price"] = @doc["product"]["price"]["offerPrice"]["formattedPrice"] | |
#@product_details["Rating_Count"] = @doc["product"]["rating_and_review_statistics"]["result"]["52029745"]["coreStats"]["TotalReviewCount"] || nil | |
#@product_details["Rating"] = @doc["product"]["rating_and_review_statistics"]["result"]["52029745"]["coreStats"]["AverageOverallRating"] || nil | |
#@product_details["Size"] = @doc["product"]["item"]["variation"]["size"] || nil | |
#@product_details["Color"]= @doc["product"]["item"]["variation"]["color"] || nil | |
@product_details["Manufacturer_Brand"] = @doc["product"]["item"]["product_brand"]["brand"] | |
@product_details['mined_at'] = Time.now.to_i | |
@logger.info {@product_details} | |
@product_details | |
rescue Exception => ex | |
@logger.info { "There was an error - #{ex.inspect} - #{ex.backtrace}"} | |
@product_details['error'] = true | |
@product_details['error_message'] = ex.backtrace.join("\n") | |
@product_details | |
end | |
end | |
def storeproductdetails | |
@collection.insert_one(@product_details) | |
end | |
end | |
puts "Enter your Entered URL" | |
entered_url = gets.chomp | |
product = Product.new(entered_url) | |
store = product.store | |
puts product.store | |
=begin | |
Enter your Entered URL | |
http://redsky.target.com/v2/pdp/tcin/52029745?excludes=taxonomy | |
D, [2017-04-26T15:05:59.785264 #6598] DEBUG -- : MONGODB | Topology type 'unknown' initializing. | |
D, [2017-04-26T15:05:59.785572 #6598] DEBUG -- : MONGODB | Server 127.0.0.1:27017 initializing. | |
D, [2017-04-26T15:05:59.788377 #6598] DEBUG -- : MONGODB | Topology type 'unknown' changed to type 'single'. | |
D, [2017-04-26T15:05:59.788631 #6598] DEBUG -- : MONGODB | Server description for 127.0.0.1:27017 changed from 'unknown' to 'standalone'. | |
D, [2017-04-26T15:05:59.788838 #6598] DEBUG -- : MONGODB | There was a change in the members of the 'single' topology. | |
I, [2017-04-26T15:06:00.719565 #6598] INFO -- : {"URL"=>"http://www.target.com/p/alligator-sherpa-throw-50-x60-gray-green-lush-d-233-cor/-/A-52029745", "Title"=>"Alligator Sherpa Throw (50\"x60\") Gray & Green - Lush Décor", "Details"=>"This lively and creative throw is a great pickup for children of all ages.Playful alligators are literally scattered throughout this entire piece.", "Description"=>["<B>Fiber Content:</B> 100% , Polyester", "<B>Dimensions:</B> L 50 inches x 60 inches W", "<B>Care and Cleaning:</B> Machine wash, gentle or delicate, , Tumble dry, gentle, low heat"], "Price"=>"$32.29", "Manufacturer_Brand"=>"Lush Decor", "mined_at"=>1493199360} | |
{"URL"=>"http://www.target.com/p/alligator-sherpa-throw-50-x60-gray-green-lush-d-233-cor/-/A-52029745", "Title"=>"Alligator Sherpa Throw (50\"x60\") Gray & Green - Lush Décor", "Details"=>"This lively and creative throw is a great pickup for children of all ages.Playful alligators are literally scattered throughout this entire piece.", "Description"=>["<B>Fiber Content:</B> 100% , Polyester", "<B>Dimensions:</B> L 50 inches x 60 inches W", "<B>Care and Cleaning:</B> Machine wash, gentle or delicate, , Tumble dry, gentle, low heat"], "Price"=>"$32.29", "Manufacturer_Brand"=>"Lush Decor", "mined_at"=>1493199360} | |
D, [2017-04-26T15:06:00.720624 #6598] DEBUG -- : MONGODB | 127.0.0.1:27017 | test.insert | STARTED | {"insert"=>"Product4", "documents"=>[{"URL"=>"http://www.target.com/p/alligator-sherpa-throw-50-x60-gray-green-lush-d-233-cor/-/A-52029745", "Title"=>"Alligator Sherpa Throw (50\"x60\") Gray & Green - Lush Décor", "Details"=>"This lively and crea... | |
D, [2017-04-26T15:06:00.722289 #6598] DEBUG -- : MONGODB | 127.0.0.1:27017 | test.insert | SUCCEEDED | 0.001531621s | |
#<Mongo::Operation::Write::Insert::Result:0x00000003d51580> | |
=end |
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
RSpec.configure do |config| | |
config.expect_with :rspec do |expectations| | |
expectations.include_chain_clauses_in_custom_matcher_descriptions = true | |
end | |
config.mock_with :rspec do |mocks| | |
mocks.verify_partial_doubles = true | |
end | |
config.shared_context_metadata_behavior = :apply_to_host_groups | |
=begin | |
config.filter_run_when_matching :focus | |
config.example_status_persistence_file_path = "spec/examples.txt" | |
config.disable_monkey_patching! | |
config.warnings = true | |
if config.files_to_run.one? | |
config.default_formatter = 'doc' | |
end | |
config.profile_examples = 10 | |
config.order = :random | |
Kernel.srand config.seed | |
=end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment