Sha256: 447078a366501e0c194a77c1a600af03785a5fb026d38638c52899e543fc15b1

Contents?: true

Size: 1.07 KB

Versions: 36

Compression:

Stored size: 1.07 KB

Contents

require 'restclient'

class MLS::Flyer < MLS::Resource

  property :id, Fixnum
  property :digest, String
  property :avatar_digest, String
  property :file_name, String
  property :file_size, Fixnum
  
  def url(protocol='http')
    "#{protocol}://#{MLS.asset_host}/flyers/#{digest}/compressed/#{file_name}"
  end
  
  def avatar(size='150x100#', protocol='http')
    "#{protocol}://#{MLS.image_host}/#{avatar_digest}.jpg?s=#{URI.escape(size)}"
  end
  
  def self.create(attrs)
    attrs[:file].rewind
    url = MLS.url.dup
    url.user = nil
    url.path = "/api/flyers"
    
    if attrs[:subject]
      attrs[:subject_id] = attrs[:subject].id
      attrs[:subject_type] = attrs[:subject].class.name.split("::").last
      attrs.delete(:subject)
    end
    response = RestClient.post(url.to_s, {:flyer => attrs}, MLS.headers)
    attrs[:file].close unless attrs[:file].closed?

    MLS::Flyer::Parser.parse(response.body)
  end
  
  def self.find(id)
    response = MLS.get("/flyers/#{id}")
    MLS::Flyer::Parser.parse(response.body)
  end
  
end

class MLS::Flyer::Parser < MLS::Parser

end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
mls-0.11.3 lib/mls/models/flyer.rb
mls-0.11.2 lib/mls/models/flyer.rb
mls-0.11.1 lib/mls/models/flyer.rb
mls-0.11.0 lib/mls/models/flyer.rb
mls-0.9.9 lib/mls/models/flyer.rb
mls-0.9.8 lib/mls/models/flyer.rb
mls-0.9.6 lib/mls/models/flyer.rb
mls-0.9.5 lib/mls/models/flyer.rb
mls-0.9.4 lib/mls/models/flyer.rb
mls-0.9.3 lib/mls/models/flyer.rb
mls-0.9.2 lib/mls/models/flyer.rb
mls-0.9.1 lib/mls/models/flyer.rb
mls-0.9.0 lib/mls/models/flyer.rb
mls-0.8.2 lib/mls/models/flyer.rb
mls-0.8.1 lib/mls/models/flyer.rb
mls-0.8.0 lib/mls/models/flyer.rb
mls-0.7.2 lib/mls/models/flyer.rb
mls-0.7.1 lib/mls/models/flyer.rb
mls-0.7.0 lib/mls/models/flyer.rb
mls-0.6.7 lib/mls/models/flyer.rb