Sha256: ba9880d932aa36325c0d7f58f0a1ddc1e0332ca688c5ffef37741d48929ede1a

Contents?: true

Size: 1.09 KB

Versions: 33

Compression:

Stored size: 1.09 KB

Contents

require 'restclient'

class MLS::Floorplan < 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}/floorplans/#{digest}/#{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

33 entries across 33 versions & 1 rubygems

Version Path
mls-0.5.3 lib/mls/models/floorplan.rb
mls-0.5.2 lib/mls/models/floorplan.rb
mls-0.5.1 lib/mls/models/floorplan.rb
mls-0.5.0 lib/mls/models/floorplan.rb
mls-0.4.0 lib/mls/models/floorplan.rb
mls-0.3.8 lib/mls/models/floorplan.rb
mls-0.3.7 lib/mls/models/floorplan.rb
mls-0.3.6 lib/mls/models/floorplan.rb
mls-0.3.5 lib/mls/models/floorplan.rb
mls-0.3.4 lib/mls/models/floorplan.rb
mls-0.3.3 lib/mls/models/floorplan.rb
mls-0.3.2 lib/mls/models/floorplan.rb
mls-0.3.1 lib/mls/models/floorplan.rb
mls-0.3.0 lib/mls/models/floorplan.rb
mls-0.2.54 lib/mls/models/floorplan.rb
mls-0.2.53 lib/mls/models/floorplan.rb
mls-0.2.52 lib/mls/models/floorplan.rb
mls-0.2.51 lib/mls/models/floorplan.rb
mls-0.2.50 lib/mls/models/floorplan.rb
mls-0.2.49 lib/mls/models/floorplan.rb