Module: ErpIntegration::Fulfil::Context
- Extended by:
- ActiveSupport::Concern
- Included in:
- ApiResource
- Defined in:
- lib/erp_integration/fulfil/context.rb
Overview
When making HTTP requests to the Fulfil API endpoints, it’s possible to define the warehouses that should be considered part of the querying context.
This means that it’s possible to fetch the stock levels for a specific “warehouse” when it’s specified in the context of the HTTP request to the API endpoints of Fulfil.
$ ErpIntegration::Product.find_by(sku: "PT123").quantity_available
=> 25
$ ErpIntegration::Product.with_context(locations: [25]).find_by(sku: "PT123").quantity_available
=> 15
Instance Method Summary collapse
-
#context? ⇒ Boolean
Verifies whether or not the context is set.
-
#with_context(context) ⇒ ErpIntegration::Fulfil::ApiResource
Allows setting the context for the HTTP request to the Fulfil API endpoints.
Instance Method Details
#context? ⇒ Boolean
Verifies whether or not the context is set.
33 34 35 |
# File 'lib/erp_integration/fulfil/context.rb', line 33 def context? !@context.nil? && !@context.empty? end |
#with_context(context) ⇒ ErpIntegration::Fulfil::ApiResource
Allows setting the context for the HTTP request to the Fulfil API endpoints.
41 42 43 44 |
# File 'lib/erp_integration/fulfil/context.rb', line 41 def with_context(context) @context = (@context || {}).merge(context) self end |