Sha256: f87abfbe6d21f976ea9123b5f39d4e626adf5b34acd1f084121c296215445fb8

Contents?: true

Size: 1.11 KB

Versions: 9

Compression:

Stored size: 1.11 KB

Contents

module TophatterMerchant
  class Variation < Resource
    attr_accessor :product_identifier, :identifier,
                  :size, :color, :quantity,
                  :created_at, :disabled_at, :deleted_at

    def id
      created_at.present? ? identifier : nil
    end

    class << self
      # ap TophatterMerchant::Variation.schema
      def schema
        get(url: "#{path}/schema.json")
      end

      # ap TophatterMerchant::Variation.retrieve('FOOBAR-R').to_h
      def retrieve(identifier)
        Variation.new get(url: "#{path}/retrieve.json", params: { identifier: identifier })
      end

      # ap Variation.create(product_identifier: '6631A', identifier: '6631A-GRAY', color: 'Gray', quantity: 33).to_h
      def create(params)
        Variation.new post(url: "#{path}.json", params: params)
      end

      # ap TophatterMerchant::Variation.update('FOOBAR-R', quantity: 100).to_h
      def update(identifier, data)
        Variation.new post(url: "#{path}/update.json", params: data.merge(identifier: identifier))
      end

      protected

      def path
        super + '/variations'
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
tophatter-merchant-1.2.2 lib/tophatter_merchant/variation.rb
tophatter-merchant-1.2.1 lib/tophatter_merchant/variation.rb
tophatter-merchant-1.2.0 lib/tophatter_merchant/variation.rb
tophatter-merchant-1.1.9 lib/tophatter_merchant/variation.rb
tophatter-merchant-1.1.8 lib/tophatter_merchant/variation.rb
tophatter-merchant-1.1.7 lib/tophatter_merchant/variation.rb
tophatter-merchant-1.1.6 lib/tophatter_merchant/variation.rb
tophatter-merchant-1.1.5 lib/tophatter_merchant/variation.rb
tophatter-merchant-1.1.4 lib/tophatter_merchant/variation.rb