Class: Retailer::CostcoCredentials
- Inherits:
-
Object
- Object
- Retailer::CostcoCredentials
- Defined in:
- app/services/retailer/costco_credentials.rb
Overview
Discovers and caches the Costco.ca catalog-API credentials.
Costco's product pages embed a machine-readable API config blob
(priceDetailsServiceConfig) that publishes the price endpoint, the
required Client-Identifier header credential, the per-region clientId
parameter, and the warehouse number. These values are static across
visits but Costco can rotate them on a site deploy — so rather than
hardcoding, we scrape them once (via Oxylabs), cache them, and re-scrape
when an API call rejects them.
Defined Under Namespace
Classes: Config, ConfigError
Constant Summary collapse
- REGION =
Region key inside the config blob.
cabc= Costco Canada consumer
(the only live Costco catalog —COSTCO_USAis discontinued). 'cabc'- CACHE_KEY =
'retailer:costco:credentials:cabc'- CACHE_TTL =
30.days
- CONFIG_SOURCE_URL =
A stable Costco.ca product page used to (re)discover the API config.
Any product page carries the same global blob; this one is a
long-lived WarmlyYours listing. 'https://www.costco.ca/p/-/warmlyyours-cable-floor-heating-kit-for-under-tile-and-hardwood-floor/100328844'
Class Method Summary collapse
-
.fetch ⇒ Config
Cached credentials, scraping on a cold cache.
-
.refresh!(source_url: CONFIG_SOURCE_URL) ⇒ Config
Force a fresh scrape and overwrite the cache.
Class Method Details
.fetch ⇒ Config
Cached credentials, scraping on a cold cache.
48 49 50 |
# File 'app/services/retailer/costco_credentials.rb', line 48 def fetch Rails.cache.read(CACHE_KEY) || refresh! end |
.refresh!(source_url: CONFIG_SOURCE_URL) ⇒ Config
Force a fresh scrape and overwrite the cache. Called on a cold cache
and whenever Retailer::CostcoApi sees an auth rejection.
58 59 60 61 62 63 |
# File 'app/services/retailer/costco_credentials.rb', line 58 def refresh!(source_url: CONFIG_SOURCE_URL) config = scrape_config(source_url) Rails.cache.write(CACHE_KEY, config, expires_in: CACHE_TTL) Rails.logger.info "[CostcoCredentials] Refreshed: endpoint=#{config.price_endpoint} warehouse=#{config.warehouse}" config end |