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

Examples:

without any context, the main warehouse will be used as configured

in Fulfil through the application settings.

with context, the given warehouse will be used to find the requested

data in Fulfil.

Instance Method Summary collapse

Instance Method Details

#context?Boolean

Verifies whether or not the context is set.

Returns:

  • (Boolean)


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.

Parameters:

  • context (Hash)

    The context for the HTTP request.

Returns:



41
42
43
44
# File 'lib/erp_integration/fulfil/context.rb', line 41

def with_context(context)
  @context = (@context || {}).merge(context)
  self
end