Class: MLS::Listing

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

Defined Under Namespace

Classes: Parser

Constant Summary collapse

WORKFLOW_STATES =
%w(visible processing invisible expired)
LEASE_STATES =
%w(listed leased)
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.



91
92
93
# File 'lib/mls/models/listing.rb', line 91

def 
  @account
end

#addressObject

Returns the value of attribute address.



91
92
93
# File 'lib/mls/models/listing.rb', line 91

def address
  @address
end

#agentsObject

Returns the value of attribute agents.



91
92
93
# File 'lib/mls/models/listing.rb', line 91

def agents
  @agents
end

#floorplanObject

Returns the value of attribute floorplan.



91
92
93
# File 'lib/mls/models/listing.rb', line 91

def floorplan
  @floorplan
end

#flyerObject

Returns the value of attribute flyer.



91
92
93
# File 'lib/mls/models/listing.rb', line 91

def flyer
  @flyer
end

#photosObject

Returns the value of attribute photos.



91
92
93
# File 'lib/mls/models/listing.rb', line 91

def photos
  @photos
end

#primary_agentObject

Returns the value of attribute primary_agent.



91
92
93
# File 'lib/mls/models/listing.rb', line 91

def primary_agent
  @primary_agent
end

#similar_photosObject

Returns the value of attribute similar_photos.



91
92
93
# File 'lib/mls/models/listing.rb', line 91

def similar_photos
  @similar_photos
end

#spacesObject

Returns the value of attribute spaces.



91
92
93
# File 'lib/mls/models/listing.rb', line 91

def spaces
  @spaces
end

#videosObject

Returns the value of attribute videos.



91
92
93
# File 'lib/mls/models/listing.rb', line 91

def videos
  @videos
end

Class Method Details

.all(options = {}) ⇒ Object

currently supported options are filters, page, per_page, offset, order



336
337
338
339
# File 'lib/mls/models/listing.rb', line 336

def all(options={})
  response = MLS.get('/listings', options)
  MLS::Listing::Parser.parse_collection(response.body)
end

.amenitiesObject



346
347
348
# File 'lib/mls/models/listing.rb', line 346

def amenities
  @amenities ||= Yajl::Parser.new.parse(MLS.get('/listings/amenities').body).map(&:to_sym)
end

.find(id) ⇒ Object



330
331
332
333
# File 'lib/mls/models/listing.rb', line 330

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

.import(attrs) ⇒ Object



341
342
343
344
# File 'lib/mls/models/listing.rb', line 341

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

Instance Method Details

#active?Boolean

Returns:



109
110
111
# File 'lib/mls/models/listing.rb', line 109

def active?
  lease_state == 'listed' && workflow_state == 'visible'
end

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



93
94
95
96
97
98
99
# File 'lib/mls/models/listing.rb', line 93

def avatar(size='150x100#', protocol='http')
  if avatar_digest
    "#{protocol}://#{MLS.image_host}/#{avatar_digest}.jpg?s=#{URI.escape(size)}"
  else
    address.avatar(size, protocol)
  end
end

#coworking?Boolean

Returns:



125
126
127
# File 'lib/mls/models/listing.rb', line 125

def coworking?
  type == 'coworking_space'
end

#createObject



271
272
273
274
275
276
# File 'lib/mls/models/listing.rb', line 271

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



304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
# File 'lib/mls/models/listing.rb', line 304

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

#inactive?Boolean

Returns:



113
114
115
# File 'lib/mls/models/listing.rb', line 113

def inactive?
  !self.active?
end

#lease?Boolean

Returns:



117
118
119
# File 'lib/mls/models/listing.rb', line 117

def lease?
  type == 'lease'
end

#leased?Boolean

Returns:



105
106
107
# File 'lib/mls/models/listing.rb', line 105

def leased?
  lease_state == 'leased'
end

#processing?Boolean

Returns:



101
102
103
# File 'lib/mls/models/listing.rb', line 101

def processing?
  workflow_state == 'processing'
end

#rate(units = nil) ⇒ Object

TODO: remove /desk/mo conversions



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# File 'lib/mls/models/listing.rb', line 160

def rate(units=nil)
  return nil if !@rate
  units ||= rate_units
  
  price = if rate_units == '/sqft/mo'
    if units == '/sqft/mo'
      @rate
    elsif units == '/sqft/yr'
      @rate * 12.0
    elsif units == '/mo'
      @rate * @size
    elsif units == '/yr'
      @rate * @size * 12.0
    elsif units == '/desk/mo'
      @rate * 200.0
    else
      raise "Invalid rate conversion (#{rate_units} => #{units})"
    end

  elsif rate_units == '/sqft/yr'
    if units == '/sqft/mo'
      @rate / 12.0
    elsif units == '/sqft/yr'
      @rate
    elsif units == '/mo'
      (@rate * @size) / 12.0
    elsif units == '/yr'
      @rate * @size
    elsif units == '/desk/mo'
      (@rate / 12.0) * 200.0
    else
      raise "Invalid rate conversion (#{rate_units} => #{units})"
    end

  elsif rate_units == '/mo'
    if units == '/sqft/mo'
      @rate / @size.to_f
    elsif units == '/sqft/yr'
      (@rate * 12) / @size.to_f
    elsif units == '/mo'
      @rate
    elsif units == '/yr'
      @rate * 12
    elsif units == '/desk/mo'
      (@rate / @size.to_f) * 200.0
    else
      raise "Invalid rate conversion (#{rate_units} => #{units})"
    end

  elsif rate_units == '/yr'
    if units == '/sqft/mo'
      (@rate / 12.0) / @size.to_f
    elsif units == '/sqft/yr'
      @rate / @size.to_f
    elsif units == '/mo'
      @rate / 12.0
    elsif units == '/yr'
      @rate
    elsif units == '/desk/mo'
      ((@rate / 12.0) / @size.to_f) * 200.0
    else
      raise "Invalid rate conversion (#{rate_units} => #{units})"
    end

  elsif rate_units == '/desk/mo'
    if units == '/sqft/mo'
      @rate / 200.0
    elsif units == '/sqft/yr'
      (@rate * 12) / 200.0
    elsif units == '/mo'
      @rate
    elsif units == '/yr'
      @rate * 12
    elsif units == '/desk/mo'
      @rate
    else
      raise "Invalid rate conversion (#{rate_units} => #{units})"
    end

  end
  
  price.round(2)
end

#rate?Boolean

Returns:



155
156
157
# File 'lib/mls/models/listing.rb', line 155

def rate?
  !!@rate
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::Tour>

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


266
267
268
# File 'lib/mls/models/listing.rb', line 266

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

#saveObject



278
279
280
281
282
283
284
285
286
287
288
# File 'lib/mls/models/listing.rb', line 278

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

#similarObject



324
325
326
# File 'lib/mls/models/listing.rb', line 324

def similar
  [] # Similar Listings not supported for now
end

#space_nameObject



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/mls/models/listing.rb', line 130

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:



121
122
123
# File 'lib/mls/models/listing.rb', line 121

def sublease?
  type == 'sublease'
end

#to_hashObject



290
291
292
293
294
295
296
297
298
# File 'lib/mls/models/listing.rb', line 290

def to_hash
  hash = super
  hash[:address_attributes] = address.to_hash if address
  hash[:spaces_attributes] = spaces.inject([]) { |acc, x| acc << x.to_hash; acc } if spaces
  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) unless videos.blank?
  hash
end

#to_paramObject



300
301
302
# File 'lib/mls/models/listing.rb', line 300

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