Class: VersacommerceAPI::ProductImage

Inherits:
Base show all
Defined in:
lib/versacommerce_api/resources/product_image.rb

Instance Method Summary collapse

Methods inherited from Base

activate_session, all, clear_session, headers, root!

Methods included from Countable

#count

Methods inherited from ActiveResource::Base

build, delete, headers

Constructor Details

#initialize(attributes) ⇒ ProductImage

Returns a new instance of ProductImage.



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/versacommerce_api/resources/product_image.rb', line 5

def initialize(attributes)
  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

Instance Method Details

#icon ⇒ Object



22
23
24
# File 'lib/versacommerce_api/resources/product_image.rb', line 22

def icon
  generate_resized_url(original, :resize, '32x32')
end

#large ⇒ Object



38
39
40
# File 'lib/versacommerce_api/resources/product_image.rb', line 38

def large
  generate_resized_url(original, :resize, '480x480')
end

#medium ⇒ Object



34
35
36
# File 'lib/versacommerce_api/resources/product_image.rb', line 34

def medium
  generate_resized_url(original, :resize, '240x240')
end

#original ⇒ Object



50
51
52
# File 'lib/versacommerce_api/resources/product_image.rb', line 50

def original
  "http://images.versacommerce.net/++/#{src.gsub("http://", "")}"
end

#pico ⇒ Object



18
19
20
# File 'lib/versacommerce_api/resources/product_image.rb', line 18

def pico
  generate_resized_url(original, :resize, '16x16')
end

#small ⇒ Object



30
31
32
# File 'lib/versacommerce_api/resources/product_image.rb', line 30

def small
  generate_resized_url(original, :resize, '100x100')
end

#standard ⇒ Object



46
47
48
# File 'lib/versacommerce_api/resources/product_image.rb', line 46

def standard
  generate_resized_url(original, :resize, '1024x1024')
end

#thumb ⇒ Object



26
27
28
# File 'lib/versacommerce_api/resources/product_image.rb', line 26

def thumb
  generate_resized_url(original, :resize, '50x50')
end

#upload_image(data, filename = nil) ⇒ Object



54
55
56
57
# 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 ⇒ Object



42
43
44
# File 'lib/versacommerce_api/resources/product_image.rb', line 42

def xlarge
  generate_resized_url(original, :resize, '960x960')
end