Class: Retailer::CostcoProbe
- Inherits:
-
Object
- Object
- Retailer::CostcoProbe
- Defined in:
- app/services/retailer/costco_probe.rb
Overview
Runs a retailer price/stock probe for a Costco catalog item.
This is the Costco-specific replacement for the generic Oxylabs
scrape-and-extract pipeline. Costco's grouped products have no
per-variant URL, so a rendered scrape can only read the page-default
variant. Instead this probe calls CostcoApi, which is keyed
by the item's Costco item number and returns accurate per-variant data.
Both PriceChecker (realtime "Probe Now") and
BatchPriceChecker (scheduled runs) delegate Costco items
here, so all probe bookkeeping lives in one place.
Constant Summary collapse
- SCRAPER_SOURCE =
'costco_api'
Instance Method Summary collapse
-
#initialize(api: Retailer::CostcoApi.new, logger: Rails.logger) ⇒ CostcoProbe
constructor
A new instance of CostcoProbe.
-
#probe(catalog_item) ⇒ CatalogItemRetailerProbe?
Probe one Costco catalog item and record the result.
Constructor Details
#initialize(api: Retailer::CostcoApi.new, logger: Rails.logger) ⇒ CostcoProbe
Returns a new instance of CostcoProbe.
18 19 20 21 |
# File 'app/services/retailer/costco_probe.rb', line 18 def initialize(api: Retailer::CostcoApi.new, logger: Rails.logger) @api = api @logger = logger end |
Instance Method Details
#probe(catalog_item) ⇒ CatalogItemRetailerProbe?
Probe one Costco catalog item and record the result.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/services/retailer/costco_probe.rb', line 27 def probe(catalog_item) return nil if catalog_item.skip_url_checks? check = catalog_item.retailer_probes.build( status: 'pending', url: catalog_item.url, geo_location: 'CAN' ) check.scraper_source = SCRAPER_SOURCE check.currency = 'CAD' run(check, catalog_item) check.save! update_catalog_item(catalog_item, check) Retailer::ProbeAutoSkipper.maybe_skip!(catalog_item) unless check.status == 'success' check end |