Sha256: 4fa32ed41f103c74ffdecbda207b8aa9b8d5e09216d78c43aa7d9e6fc9f5646b

Contents?: true

Size: 1.11 KB

Versions: 6

Compression:

Stored size: 1.11 KB

Contents

require 'restclient'

class MLS::Floorplan < MLS::Resource

  attribute :id, Fixnum
  attribute :digest, String
  attribute :avatar_digest, String
  attribute :file_name, String
  attribute :file_size, Fixnum
  
  def url(protocol='http')
    "#{protocol}://#{MLS.asset_host}/floorplans/#{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/floorplans"
    
    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, {:floorplan => attrs}, MLS.headers)
    attrs[:file].close unless attrs[:file].closed?

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

class MLS::Floorplan::Parser < MLS::Parser

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
mls-0.13.0 lib/mls/models/floorplan.rb
mls-0.12.5 lib/mls/models/floorplan.rb
mls-0.12.4 lib/mls/models/floorplan.rb
mls-0.12.2 lib/mls/models/floorplan.rb
mls-0.12.3 lib/mls/models/floorplan.rb
mls-0.12.1 lib/mls/models/floorplan.rb