class VersacommerceAPI::ProductImage

Public Class Methods

new(attributes, persisted = false) click to toggle source
Calls superclass method
# File lib/versacommerce_api/resources/product_image.rb, line 5
def initialize(attributes, persisted = false)
  super
  if self.attributes['file']
    file     = self.attributes['file']
    data     = file.read
    type, suffix = file.content_type.split("/")
    raise ArgumentError.new("file must be an image") unless ((type == "image") && %w(jpeg jpg gif png).include?(suffix))
    filename = "upload_file.#{suffix}"
    upload_image(data, filename)
    self.attributes.delete 'file'
  end
end

Public Instance Methods

icon() click to toggle source
# File lib/versacommerce_api/resources/product_image.rb, line 22
def icon
  generate_resized_url(original, :resize, '32x32')
end
large() click to toggle source
# File lib/versacommerce_api/resources/product_image.rb, line 38
def large
  generate_resized_url(original, :resize, '480x480')
end
medium() click to toggle source
# File lib/versacommerce_api/resources/product_image.rb, line 34
def medium
  generate_resized_url(original, :resize, '240x240')
end
original() click to toggle source
# File lib/versacommerce_api/resources/product_image.rb, line 50
def original
  "https://images.versacommerce.net/++/#{src.gsub("http://", "")}"
end
pico() click to toggle source
# File lib/versacommerce_api/resources/product_image.rb, line 18
def pico
  generate_resized_url(original, :resize, '16x16')
end
small() click to toggle source
# File lib/versacommerce_api/resources/product_image.rb, line 30
def small
  generate_resized_url(original, :resize, '100x100')
end
standard() click to toggle source
# File lib/versacommerce_api/resources/product_image.rb, line 46
def standard
  generate_resized_url(original, :resize, '1024x1024')
end
thumb() click to toggle source
# File lib/versacommerce_api/resources/product_image.rb, line 26
def thumb
  generate_resized_url(original, :resize, '50x50')
end
upload_image(data, filename = nil) click to toggle source
# File lib/versacommerce_api/resources/product_image.rb, line 54
def upload_image(data, filename = nil)
  attributes['image_data'] = Base64.encode64(data)
  attributes['filename']   = filename unless filename.nil?
end
xlarge() click to toggle source
# File lib/versacommerce_api/resources/product_image.rb, line 42
def xlarge
  generate_resized_url(original, :resize, '960x960')
end

Private Instance Methods

generate_resized_url(url, command, value) click to toggle source
# File lib/versacommerce_api/resources/product_image.rb, line 61
def generate_resized_url(url, command, value)
  refit_url = url.gsub("\/++\/", "\/#{command}=#{value}\/++\/")
end