Class: MLS::Listing

Inherits:
Resource show all
Defined in:
lib/mls/models/listing.rb

Defined Under Namespace

Classes: Parser

Constant Summary collapse

STATES =
%w(processing listed leased expired)
TYPES =
%w(lease sublease coworking_space)
SPACE_TYPES =
%w(unit floor building)
LEASE_TERMS =
['Full Service', 'NNN', 'Modified Gross']
RATE_UNITS =
['/sqft/yr', '/sqft/mo', '/mo', '/yr', '/desk/mo']
USES =
["Office", "Creative", "Loft", "Medical Office", "Flex Space", "R&D", "Office Showroom", "Industrial", "Retail"]
SOURCE_TYPES =
%w(website flyer)
CHANNELS =
%w(excavator mls staircase broker_dashboard)

Instance Attribute Summary collapse

Attributes inherited from Resource

#errors, #persisted

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

#==, #create!, inherited, #initialize, #new_record?, #persisted?, #properties, #properties_excluded_from_comparison, #properties_for_comparison, #save!, #set_default_values, #to_key, #update!, #update_attributes

Constructor Details

This class inherits a constructor from MLS::Resource

Instance Attribute Details

#accountObject

Returns the value of attribute account.



68
69
70
# File 'lib/mls/models/listing.rb', line 68

def 
  @account
end

#addressObject

Returns the value of attribute address.



68
69
70
# File 'lib/mls/models/listing.rb', line 68

def address
  @address
end

#agentsObject

Returns the value of attribute agents.



68
69
70
# File 'lib/mls/models/listing.rb', line 68

def agents
  @agents
end

#amenitiesObject



211
212
213
# File 'lib/mls/models/listing.rb', line 211

def amenities
  MLS.listing_amenities
end

#floorplanObject

Returns the value of attribute floorplan.



68
69
70
# File 'lib/mls/models/listing.rb', line 68

def floorplan
  @floorplan
end

#flyerObject

Returns the value of attribute flyer.



68
69
70
# File 'lib/mls/models/listing.rb', line 68

def flyer
  @flyer
end

#photosObject

Returns the value of attribute photos.



68
69
70
# File 'lib/mls/models/listing.rb', line 68

def photos
  @photos
end

#videosObject

Returns the value of attribute videos.



68
69
70
# File 'lib/mls/models/listing.rb', line 68

def videos
  @videos
end

Class Method Details

.all(filters = {}, limit = nil, order = 'listings.id') ⇒ Object



223
224
225
226
# File 'lib/mls/models/listing.rb', line 223

def all(filters = {}, limit = nil, order = 'listings.id')
  response = MLS.get('/listings', :filters => filters, :limit => limit, :order => order)
  MLS::Listing::Parser.parse_collection(response.body)
end

.calculate(filters = {}, operation = nil, column = nil, group = nil) ⇒ Object



233
234
235
236
# File 'lib/mls/models/listing.rb', line 233

def calculate(filters = {}, operation = nil, column = nil, group = nil)
  response = MLS.get("/listings/calculate", :filters => filters, :operation => operation, :column => column, :group => group)
  MLS::Parser.extract_attributes(response.body)[:listings]
end

.find(id) ⇒ Object



217
218
219
220
221
# File 'lib/mls/models/listing.rb', line 217

def find(id)
  response = MLS.get("/listings/#{id}")
  puts response.body
  MLS::Listing::Parser.parse(response.body)
end

.import(attrs) ⇒ Object



228
229
230
231
# File 'lib/mls/models/listing.rb', line 228

def import(attrs)
  model = self.new(attrs)
  {:status => model.import, :model => model}
end

Instance Method Details

#all_photosObject



203
204
205
# File 'lib/mls/models/listing.rb', line 203

def all_photos
  photos + address.photos
end

#all_videosObject



207
208
209
# File 'lib/mls/models/listing.rb', line 207

def all_videos
  videos + address.videos
end

#avatar(size = '150x100', protocol = 'http') ⇒ Object



71
72
73
74
75
76
77
# File 'lib/mls/models/listing.rb', line 71

def avatar(size='150x100', protocol='http')
  if avatar_digest
    "#{protocol}://#{MLS.asset_host}/photos/#{size}/#{avatar_digest}.jpg"
  else
    address.avatar(size, protocol)
  end
end

#coworking?Boolean

Returns:



85
86
87
# File 'lib/mls/models/listing.rb', line 85

def coworking?
  type == 'coworking_space'
end

#createObject



147
148
149
150
151
152
# File 'lib/mls/models/listing.rb', line 147

def create
  MLS.post('/listings', {:listing => to_hash}, 201, 400) do |response, code|
    raise MLS::Exception::UnexpectedResponse if ![201, 400].include?(code)
    MLS::Listing::Parser.update(self, response.body)
  end
end

#importObject

TODO test me



179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/mls/models/listing.rb', line 179

def import #TODO test me
  result = :failure
  MLS.post('/import', {:listing => to_hash}, 400) do |response, code|
    case code
    when 200
      result = :duplicate
    when 201
      result = :created
    when 202
      result = :updated
    when 400
      result = :failure
    else
      raise MLS::Exception::UnexpectedResponse, code
    end
    MLS::Listing::Parser.update(self, response.body)
  end
  result
end

#lease?Boolean

Returns:



79
80
81
# File 'lib/mls/models/listing.rb', line 79

def lease?
  type == 'lease'
end

#leased?Boolean

Returns:



89
90
91
# File 'lib/mls/models/listing.rb', line 89

def leased?
  state == 'leased'
end

#request_tour(account, tour = {}) ⇒ Object

Creates a tour request for the listing.

Paramaters
  • account - A Hash of the user account. Valid keys are:

    • :name - Name of the User requesting the tour (Required)

    • :email - Email of the User requesting the tour (Required)

    • :phone - Phone of the User requesting the tour

  • info - A optional Hash of company info. Valid keys are:

    • :message - Overrides the default message on the email sent to the broker

    • :company - The name of the company that is interested in the space

    • :population - The current number of employees at the company

    • :growing - A boolean of weather or not the company is expecting to grow

Examples:

#!ruby
listing = MLS::Listing.find(@id)
info => {:company => 'name', :population => 10, :funding => 'string', :move_id => '2012-09-12'}
listing.request_tour('name', '[email protected]', info) # => #<MLS::TourRequest>

listing.request_tour('', 'emai', info) # => #<MLS::TourRequest> will have errors on account


142
143
144
# File 'lib/mls/models/listing.rb', line 142

def request_tour(, tour={})
  MLS::TourRequest.create(id, , tour)
end

#saveObject



154
155
156
157
158
159
160
161
162
163
164
# File 'lib/mls/models/listing.rb', line 154

def save
  return create unless id
  MLS.put("/listings/#{id}", {:listing => to_hash}, 400) do |response, code|
    if code == 200 || code == 400
      MLS::Listing::Parser.update(self, response.body)
      code == 200      
    else
      raise MLS::Exception::UnexpectedResponse, code
    end
  end
end

#space_nameObject



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/mls/models/listing.rb', line 93

def space_name
  return name if !name.nil?
  
  case space_type
  when 'unit'
    if unit 
      "Unit #{unit}"
    elsif floor
      "#{floor.ordinalize} Floor"
    else
      "Unit Lease"
    end
  when 'building'
    "Entire Building"
  when 'floor'
    if floor
      "#{floor.ordinalize} Floor"
    elsif unit 
      "Unit #{unit}"
    else
      "Floor Lease"
    end
  end
end

#sublease?Boolean

Returns:



82
83
84
# File 'lib/mls/models/listing.rb', line 82

def sublease?
  type == 'sublease'
end

#to_hashObject



166
167
168
169
170
171
172
173
# File 'lib/mls/models/listing.rb', line 166

def to_hash
  hash = super
  hash[:address_attributes] = address.to_hash if address
  hash[:agents_attributes] = agents.inject([]) { |acc, x| acc << x.to_hash; acc } if agents
  hash[:photo_ids] = photos.map(&:id) if photos
  hash[:videos_attributes] = videos.map(&:to_hash) if videos
  hash
end

#to_paramObject



175
176
177
# File 'lib/mls/models/listing.rb', line 175

def to_param
  "#{address.to_param}/#{id}"
end

#urlObject



199
200
201
# File 'lib/mls/models/listing.rb', line 199

def url
  "#{address.url}/#{id}"
end