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.



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

def 
  @account
end

#addressObject

Returns the value of attribute address.



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

def address
  @address
end

#agentsObject

Returns the value of attribute agents.



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

def agents
  @agents
end

#floorplanObject

Returns the value of attribute floorplan.



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

def floorplan
  @floorplan
end

#flyerObject

Returns the value of attribute flyer.



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

def flyer
  @flyer
end

#photosObject

Returns the value of attribute photos.



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

def photos
  @photos
end

#videosObject

Returns the value of attribute videos.



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

def videos
  @videos
end

Class Method Details

.all(options = {}) ⇒ Object

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



242
243
244
245
# File 'lib/mls/models/listing.rb', line 242

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

.amenitiesObject



257
258
259
# File 'lib/mls/models/listing.rb', line 257

def amenities
  @amenities ||= Yajl::Parser.new(:symbolize_keys => true).parse(MLS.get('/listings/amenities').body)
end

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



252
253
254
255
# File 'lib/mls/models/listing.rb', line 252

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



236
237
238
239
# File 'lib/mls/models/listing.rb', line 236

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

.import(attrs) ⇒ Object



247
248
249
250
# File 'lib/mls/models/listing.rb', line 247

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

Instance Method Details

#all_photosObject

TODO: Remove



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

def all_photos
  warn "Listing#all_photos is deprecated"
  photos + address.photos
end

#all_videosObject

TODO: Remove



225
226
227
228
# File 'lib/mls/models/listing.rb', line 225

def all_videos
  warn "Listing#all_videos is deprecated"
  videos + address.videos
end

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



90
91
92
93
94
95
96
# File 'lib/mls/models/listing.rb', line 90

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:



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

def coworking?
  type == 'coworking_space'
end

#createObject



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

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



198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/mls/models/listing.rb', line 198

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:



98
99
100
# File 'lib/mls/models/listing.rb', line 98

def lease?
  type == 'lease'
end

#leased?Boolean

Returns:



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

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::Tour>

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


161
162
163
# File 'lib/mls/models/listing.rb', line 161

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

#saveObject



173
174
175
176
177
178
179
180
181
182
183
# File 'lib/mls/models/listing.rb', line 173

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



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

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

#space_nameObject



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/mls/models/listing.rb', line 112

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:



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

def sublease?
  type == 'sublease'
end

#to_hashObject



185
186
187
188
189
190
191
192
# File 'lib/mls/models/listing.rb', line 185

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) unless videos.blank?
  hash
end

#to_paramObject



194
195
196
# File 'lib/mls/models/listing.rb', line 194

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