image.rb 511 B

12345678910111213141516
  1. module ShopifyAPI
  2. class Image < Base
  3. init_prefix :product
  4. # generate a method for each possible image variant
  5. [:pico, :icon, :thumb, :small, :compact, :medium, :large, :grande, :original].each do |m|
  6. reg_exp_match = "/\\1_#{m}.\\2"
  7. define_method(m) { src.gsub(/\/(.*)\.(\w{2,4})/, reg_exp_match) }
  8. end
  9. def attach_image(data, filename = nil)
  10. attributes['attachment'] = Base64.encode64(data)
  11. attributes['filename'] = filename unless filename.nil?
  12. end
  13. end
  14. end