Class: Jekyll::Shopsavvy::Client
- Inherits:
-
Object
- Object
- Jekyll::Shopsavvy::Client
- Defined in:
- lib/jekyll/shopsavvy/client.rb
Overview
Thin HTTP wrapper that calls the ShopSavvy Data API at build time. Caches responses per Jekyll site build to keep rebuilds fast.
Constant Summary collapse
- DEFAULT_BASE_URL =
"https://api.shopsavvy.com/v1".freeze
Instance Method Summary collapse
- #current_offers(identifier, retailer: nil) ⇒ Object
- #deals(category: nil, limit: 10, sort: "trending", grade: nil) ⇒ Object
-
#initialize(api_key:, base_url: DEFAULT_BASE_URL, cache: nil) ⇒ Client
constructor
A new instance of Client.
- #price_history(identifier, days: 90) ⇒ Object
- #product_details(identifier) ⇒ Object
Constructor Details
#initialize(api_key:, base_url: DEFAULT_BASE_URL, cache: nil) ⇒ Client
Returns a new instance of Client.
12 13 14 15 16 17 |
# File 'lib/jekyll/shopsavvy/client.rb', line 12 def initialize(api_key:, base_url: DEFAULT_BASE_URL, cache: nil) raise ArgumentError, "ShopSavvy API key is required" if api_key.nil? || api_key.empty? @api_key = api_key @base_url = base_url @cache = cache || {} end |
Instance Method Details
#current_offers(identifier, retailer: nil) ⇒ Object
23 24 25 26 27 |
# File 'lib/jekyll/shopsavvy/client.rb', line 23 def current_offers(identifier, retailer: nil) params = { id: identifier } params[:retailer] = retailer if retailer get("/products/offers", **params) end |
#deals(category: nil, limit: 10, sort: "trending", grade: nil) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/jekyll/shopsavvy/client.rb', line 33 def deals(category: nil, limit: 10, sort: "trending", grade: nil) params = { limit: limit, sort: sort } params[:category] = category if category params[:min_grade] = grade if grade get("/deals", **params) end |
#price_history(identifier, days: 90) ⇒ Object
29 30 31 |
# File 'lib/jekyll/shopsavvy/client.rb', line 29 def price_history(identifier, days: 90) get("/products/history", id: identifier, days: days) end |
#product_details(identifier) ⇒ Object
19 20 21 |
# File 'lib/jekyll/shopsavvy/client.rb', line 19 def product_details(identifier) get("/products/details", id: identifier) end |