Sha256: e4b5d2b8a18315557c4f5797fd302b605f9712aeb55dc6895897cc1d4fa1a379

Contents?: true

Size: 1.47 KB

Versions: 2

Compression:

Stored size: 1.47 KB

Contents

module Fulfillment
  module Resources
    module Inventories
      FIND_ALL_RESPONSE_MODELS = {
        "outbox" => ::Outbox::Models::Event
      }
      FIND_ALL_RESPONSE_MODELS.default = OpenStruct
      FIND_RESPONSE_MODELS = {
        "outbox" => ::Outbox::Models::PriceLevelSeat
      }
      FIND_RESPONSE_MODELS.default = OpenStruct

      extend self

      def find_all(fulfillment_method:, wrap: true, **params)
        response = Request.new("inventories", id: fulfillment_method, query: params).get
        if wrap
          Models::Collection.new(FIND_ALL_RESPONSE_MODELS[fulfillment_method], response.body)
        else
          response.body
        end
      end

      # We don't use a resource ID here but rather the fulfillment method as the ID
      # because different fulfillment methods use different ways of finding resources
      # other than just a plain ID. Any applicable resource ID should be passed to the params.
      def find(fulfillment_method:, wrap: true, **params)
        response = Request.new("inventories/#{fulfillment_method}", query: params).get
        return if response.body.nil? || response.body.empty?
        if wrap
          Models::Collection.new(FIND_RESPONSE_MODELS[fulfillment_method], response.body)
        else
          response.body
        end
      end

      def update(fulfillment_method:, **params)
        response = Request.new("inventories/#{fulfillment_method}", query: params).put
        response.success?
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fulfillment-api-1.1.9 lib/fulfillment/resources/inventories.rb
fulfillment-api-1.1.7 lib/fulfillment/resources/inventories.rb