Class: SpreeClient::API::V1
- Inherits:
-
Object
- Object
- SpreeClient::API::V1
- Includes:
- HTTParty
- Defined in:
- lib/spree_client/api/v1.rb,
lib/spree_client/api/v1/products.rb,
lib/spree_client/api/v1/variants.rb,
lib/spree_client/api/v1/resources.rb,
lib/spree_client/api/v1/properties.rb,
lib/spree_client/api/v1/taxonomies.rb,
lib/spree_client/api/v1/stock_items.rb,
lib/spree_client/api/v1/stock_locations.rb,
lib/spree_client/api/v1/stock_movements.rb
Defined Under Namespace
Classes: Products, Properties, Resources, StockItems, StockLocations, StockMovements, Taxonomies, Variants
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#store ⇒ Object
readonly
Returns the value of attribute store.
Instance Method Summary collapse
- #headers(extra = {}) ⇒ Object
-
#initialize(api_key:, spree_url: 'http://localhost:3000', store: nil) ⇒ V1
constructor
A new instance of V1.
-
#products(**args) ⇒ Object
TODO: Meta programming.
- #stock_items(**args) ⇒ Object
- #stock_locations(**args) ⇒ Object
- #stock_movements(**args) ⇒ Object
- #variants(**args) ⇒ Object
Constructor Details
#initialize(api_key:, spree_url: 'http://localhost:3000', store: nil) ⇒ V1
Returns a new instance of V1.
16 17 18 19 20 |
# File 'lib/spree_client/api/v1.rb', line 16 def initialize(api_key:, spree_url: 'http://localhost:3000', store: nil) @api_key = api_key @store = HTTParty.normalize_base_uri(store) if store self.class.[:base_uri] = HTTParty.normalize_base_uri(spree_url) end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
14 15 16 |
# File 'lib/spree_client/api/v1.rb', line 14 def api_key @api_key end |
#store ⇒ Object (readonly)
Returns the value of attribute store.
14 15 16 |
# File 'lib/spree_client/api/v1.rb', line 14 def store @store end |
Instance Method Details
#headers(extra = {}) ⇒ Object
48 49 50 |
# File 'lib/spree_client/api/v1.rb', line 48 def headers(extra = {}) extra.merge({ 'Content-Type' => 'application/json', 'X-Spree-Token' => api_key, 'Origin' => store }) end |
#products(**args) ⇒ Object
TODO: Meta programming
23 24 25 26 |
# File 'lib/spree_client/api/v1.rb', line 23 def products(**args) @products ||= {} @products[args.hash.to_s] ||= Products.new **{ api: self }.merge(args) end |
#stock_items(**args) ⇒ Object
43 44 45 46 |
# File 'lib/spree_client/api/v1.rb', line 43 def stock_items(**args) @stock_items ||= {} @stock_items[args.hash.to_s] ||= StockItems.new **{ api: self }.merge(args) end |
#stock_locations(**args) ⇒ Object
33 34 35 36 |
# File 'lib/spree_client/api/v1.rb', line 33 def stock_locations(**args) @stock_locations ||= {} @stock_locations[args.hash.to_s] ||= StockLocations.new **{ api: self }.merge(args) end |
#stock_movements(**args) ⇒ Object
38 39 40 41 |
# File 'lib/spree_client/api/v1.rb', line 38 def stock_movements(**args) @stock_movements ||= {} @stock_movements[args.hash.to_s] ||= StockMovements.new **{ api: self }.merge(args) end |