Sha256: 27d148cc78167ae454162dc2e9fde19fe87a878a055017a2fd976402cb1235b6

Contents?: true

Size: 1.16 KB

Versions: 7

Compression:

Stored size: 1.16 KB

Contents

require 'uri'
require 'httparty'

class Caboose::MediaImage < ActiveRecord::Base

  self.table_name = "media_images"
  belongs_to :media_category  
  has_attached_file :image, 
    :path => 'media-images/:id_:style.:extension',
    :default_url => "#{Caboose::cdn_domain}/media-images/default_user_image.jpg",    
    :styles => {
      :tiny  => '150x200>',
      :thumb => '300x400>',
      :large => '600x800>'
    }
  do_not_validate_attachment_file_type :image  
  attr_accessible :id, :media_category_id, :name, :description

  def process
    
    config = YAML.load(File.read(Rails.root.join('config', 'aws.yml')))[Rails.env]
    bucket = config['bucket']
    
    uri = "http://#{bucket}.s3.amazonaws.com/media-images/#{self.id}#{File.extname(self.name.downcase)}"
    puts "Processing #{uri}..."
    
    self.image = URI.parse(uri)
    self.save                
  end
  
  def api_hash
    {
      :id => self.id,
      :name => self.name,
      :description => self.description,
      :tiny_url => self.image.url(:tiny),
      :thumb_url => self.image.url(:thumb),
      :large_url => self.image.url(:large),
      :original_url => self.image.url(:original)
    }
  end
  
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
caboose-cms-0.4.78 app/models/caboose/media_image.rb
caboose-cms-0.4.77 app/models/caboose/media_image.rb
caboose-cms-0.4.76 app/models/caboose/media_image.rb
caboose-cms-0.4.75 app/models/caboose/media_image.rb
caboose-cms-0.4.74 app/models/caboose/media_image.rb
caboose-cms-0.4.73 app/models/caboose/media_image.rb
caboose-cms-0.4.72 app/models/caboose/media_image.rb