Class: MLS::Listing
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
#account ⇒ Object
Returns the value of attribute account.
68
69
70
|
# File 'lib/mls/models/listing.rb', line 68
def account
@account
end
|
#address ⇒ Object
Returns the value of attribute address.
68
69
70
|
# File 'lib/mls/models/listing.rb', line 68
def address
@address
end
|
#agents ⇒ Object
Returns the value of attribute agents.
68
69
70
|
# File 'lib/mls/models/listing.rb', line 68
def agents
@agents
end
|
#floorplan ⇒ Object
Returns the value of attribute floorplan.
68
69
70
|
# File 'lib/mls/models/listing.rb', line 68
def floorplan
@floorplan
end
|
#flyer ⇒ Object
Returns the value of attribute flyer.
68
69
70
|
# File 'lib/mls/models/listing.rb', line 68
def flyer
@flyer
end
|
#photos ⇒ Object
Returns the value of attribute photos.
68
69
70
|
# File 'lib/mls/models/listing.rb', line 68
def photos
@photos
end
|
#videos ⇒ Object
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.(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_photos ⇒ Object
203
204
205
|
# File 'lib/mls/models/listing.rb', line 203
def all_photos
photos + address.photos
end
|
#all_videos ⇒ Object
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
|
85
86
87
|
# File 'lib/mls/models/listing.rb', line 85
def coworking?
type == 'coworking_space'
end
|
#import ⇒ Object
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 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
|
79
80
81
|
# File 'lib/mls/models/listing.rb', line 79
def lease?
type == 'lease'
end
|
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
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(account, tour={})
MLS::TourRequest.create(id, account, tour)
end
|
#save ⇒ Object
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_name ⇒ Object
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
|
82
83
84
|
# File 'lib/mls/models/listing.rb', line 82
def sublease?
type == 'sublease'
end
|
#to_hash ⇒ Object
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_param ⇒ Object
175
176
177
|
# File 'lib/mls/models/listing.rb', line 175
def to_param
"#{address.to_param}/#{id}"
end
|
#url ⇒ Object
199
200
201
|
# File 'lib/mls/models/listing.rb', line 199
def url
"#{address.url}/#{id}"
end
|