davidbiehl/ecwid_api

View on GitHub
lib/ecwid_api/product_combination.rb

Summary

Maintainability
A
0 mins
Test Coverage
module EcwidApi
  class ProductCombination < Entity
    attr_reader :product

    self.url_root = -> { "products/#{product.id}/combinations" }

    ecwid_reader :id, :combinationNumber, :options, :sku, :smallThumbnailUrl,
                 :thumbnailUrl, :imageUrl, :originalImageUrl, :quantity,
                 :unlimited, :price, :wholesalePrices, :weight, :warningLimit

    ecwid_writer :options, :sku, :quantity, :unlimited, :price,
                 :wholesalePrices, :weight, :warningLimit, :inventoryDelta

    def initialize(data, opts={})
      super(data, opts)
      @product = opts[:product]
    end

    # Public: Uploads a primary image for a ProductCombination
    #
    # filename - a String that is either a local file name or URL
    #
    # Raises ResponseError if the API returns an error
    #
    # Returns a Faraday::Response object
    def upload_image!(filename)
      client.post_image("#{url}/image", filename)
    end
  end
end