Sha256: c9fe379501110b96e43e697cb3b4782be5b8694bb476e0e92aff397b05995c07

Contents?: true

Size: 1.05 KB

Versions: 24

Compression:

Stored size: 1.05 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}/#{file_name}"
  end
  
  def avatar(size='150x100', protocol='http')
    "#{protocol}://#{MLS.asset_host}/photos/#{size}/#{avatar_digest}.jpg"
  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

24 entries across 24 versions & 1 rubygems

Version Path
mls-0.2.35 lib/mls/models/flyer.rb
mls-0.2.34 lib/mls/models/flyer.rb
mls-0.2.33 lib/mls/models/flyer.rb
mls-0.2.32 lib/mls/models/flyer.rb
mls-0.2.31 lib/mls/models/flyer.rb
mls-0.2.29 lib/mls/models/flyer.rb
mls-0.2.28 lib/mls/models/flyer.rb
mls-0.2.26 lib/mls/models/flyer.rb
mls-0.2.25 lib/mls/models/flyer.rb
mls-0.2.24 lib/mls/models/flyer.rb
mls-0.2.23 lib/mls/models/flyer.rb
mls-0.2.21 lib/mls/models/flyer.rb
mls-0.2.20 lib/mls/models/flyer.rb
mls-0.2.19 lib/mls/models/flyer.rb
mls-0.2.18 lib/mls/models/flyer.rb
mls-0.2.17 lib/mls/models/flyer.rb
mls-0.2.16 lib/mls/models/flyer.rb
mls-0.2.15 lib/mls/models/flyer.rb
mls-0.2.14 lib/mls/models/flyer.rb
mls-0.2.13 lib/mls/models/flyer.rb