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
build, delete, headers
Constructor Details
#initialize(attributes, persisted = false) ⇒ ProductImage
Returns a new instance of ProductImage.
6
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/versacommerce_api/resources/product_image.rb', line 6
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
|
Instance Method Details
#icon ⇒ Object
23
24
25
|
# File 'lib/versacommerce_api/resources/product_image.rb', line 23
def icon
generate_resized_url(original, :resize, '32x32')
end
|
#large ⇒ Object
39
40
41
|
# File 'lib/versacommerce_api/resources/product_image.rb', line 39
def large
generate_resized_url(original, :resize, '480x480')
end
|
#medium ⇒ Object
35
36
37
|
# File 'lib/versacommerce_api/resources/product_image.rb', line 35
def medium
generate_resized_url(original, :resize, '240x240')
end
|
#original ⇒ Object
51
52
53
|
# File 'lib/versacommerce_api/resources/product_image.rb', line 51
def original
"http://images.versacommerce.net/++/#{src.gsub("http://", "")}"
end
|
#pico ⇒ Object
19
20
21
|
# File 'lib/versacommerce_api/resources/product_image.rb', line 19
def pico
generate_resized_url(original, :resize, '16x16')
end
|
#small ⇒ Object
31
32
33
|
# File 'lib/versacommerce_api/resources/product_image.rb', line 31
def small
generate_resized_url(original, :resize, '100x100')
end
|
#standard ⇒ Object
47
48
49
|
# File 'lib/versacommerce_api/resources/product_image.rb', line 47
def standard
generate_resized_url(original, :resize, '1024x1024')
end
|
#thumb ⇒ Object
27
28
29
|
# File 'lib/versacommerce_api/resources/product_image.rb', line 27
def thumb
generate_resized_url(original, :resize, '50x50')
end
|
#upload_image(data, filename = nil) ⇒ Object
55
56
57
58
|
# File 'lib/versacommerce_api/resources/product_image.rb', line 55
def upload_image(data, filename = nil)
attributes['image_data'] = Base64.encode64(data)
attributes['filename'] = filename unless filename.nil?
end
|
#xlarge ⇒ Object
43
44
45
|
# File 'lib/versacommerce_api/resources/product_image.rb', line 43
def xlarge
generate_resized_url(original, :resize, '960x960')
end
|