Sha256: 7169c7791a77e465b6034acd551ad7ba7a5242f390e6245e4dc73f3989666b53

Contents?: true

Size: 1.94 KB

Versions: 11

Compression:

Stored size: 1.94 KB

Contents

# frozen_string_literal: true

module ShopifyAPI
  class InventoryLevel < Base

    # The default path structure in ActiveResource for delete would result in:
    # /admin/inventory_levels/#{ inventory_level.id }.json?#{ params }, but since
    # InventroyLevels are a second class resource made up of a Where and a What
    # (Location and InventoryItem), it does not have a resource ID. Here we
    # redefine element_path to remove the id so HTTP DELETE requests go to
    # /admin/inventory_levels.json?#{ params } instead.
    #
    def self.element_path(prefix_options = {}, query_options = nil)
      prefix_options, query_options = split_options(prefix_options) if query_options.nil?
      "#{prefix(prefix_options)}#{collection_name}.#{format.extension}#{query_string(query_options)}"
    end

    def destroy
      load_attributes_from_response(
        self.class.delete('/', location_id: location_id, inventory_item_id: inventory_item_id)
      )
    end

    def connect(relocate_if_necessary: nil)
      body = { location_id: location_id, inventory_item_id: inventory_item_id }
      body[:relocate_if_necessary] = relocate_if_necessary unless relocate_if_necessary.nil?
      load_attributes_from_response(
        self.class.post(:connect, {}, body.to_json)
      )
    end

    def set(new_available, disconnect_if_necessary: nil)
      body = {
        location_id: location_id,
        inventory_item_id: inventory_item_id,
        available: new_available
      }
      body[:disconnect_if_necessary] = disconnect_if_necessary unless disconnect_if_necessary.nil?
      load_attributes_from_response(
        self.class.post(:set, {}, body.to_json)
      )
    end

    def adjust(available_adjustment)
      body = {
        location_id: location_id,
        inventory_item_id: inventory_item_id,
        available_adjustment: available_adjustment
      }
      load_attributes_from_response(
        self.class.post(:adjust, {}, body.to_json)
      )
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
shopify_api-6.0.0 lib/shopify_api/resources/inventory_level.rb
shopify_api-5.2.4 lib/shopify_api/resources/inventory_level.rb
shopify_api-5.2.3 lib/shopify_api/resources/inventory_level.rb
shopify_api-5.2.2 lib/shopify_api/resources/inventory_level.rb
shopify_api-5.2.1 lib/shopify_api/resources/inventory_level.rb
shopify_api-5.2.0 lib/shopify_api/resources/inventory_level.rb
shopify_api-5.1.0 lib/shopify_api/resources/inventory_level.rb
shopify_api-5.0.0 lib/shopify_api/resources/inventory_level.rb
shopify_api-4.13.0 lib/shopify_api/resources/inventory_level.rb
shopify_api-4.12.0 lib/shopify_api/resources/inventory_level.rb
shopify_api-4.11.0 lib/shopify_api/resources/inventory_level.rb