Sha256: 8ccd7da0a60ddb5e0b63da991ba0ffab5644759eddf5e99652be083030a340e6

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

module TophatterMerchant
  class Variation < Resource

    attr_accessor :identifier, :size, :color, :quantity, :created_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

1 entries across 1 versions & 1 rubygems

Version Path
tophatter-merchant-1.0 lib/tophatter_merchant/variation.rb