Sha256: 44c4f2b742637d780d7c608b97cda44c192d5ce8858d80fa63cc8a81d0fe8013
Contents?: true
Size: 1.49 KB
Versions: 43
Compression:
Stored size: 1.49 KB
Contents
# frozen_string_literal: true module ErpIntegration module Fulfil # 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. # # @example without any context, the main warehouse will be used as configured # in Fulfil through the application settings. # # $ ErpIntegration::Product.find_by(sku: "PT123").quantity_available # => 25 # # @example with context, the given warehouse will be used to find the requested # data in Fulfil. # # $ ErpIntegration::Product.with_context(locations: [25]).find_by(sku: "PT123").quantity_available # => 15 module Context extend ActiveSupport::Concern included do attr_accessor :context end # Verifies whether or not the context is set. # # @return [Boolean] def context? !@context.nil? && !@context.empty? end # Allows setting the context for the HTTP request to the Fulfil API endpoints. # # @param context [Hash] The context for the HTTP request. # @return [ErpIntegration::Fulfil::ApiResource] def with_context(context) @context = (@context || {}).merge(context) self end end end end
Version data entries
43 entries across 43 versions & 1 rubygems