mls 0.14.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Rakefile +6 -6
- data/lib/mls.rb +73 -427
- data/lib/mls/account.rb +15 -0
- data/lib/mls/address.rb +4 -0
- data/lib/mls/agency.rb +6 -0
- data/lib/mls/brokerage.rb +7 -0
- data/lib/mls/coworking_space.rb +5 -0
- data/lib/mls/floorplan.rb +11 -0
- data/lib/mls/flyer.rb +11 -0
- data/lib/mls/lease.rb +2 -0
- data/lib/mls/listing.rb +135 -0
- data/lib/mls/locality.rb +6 -0
- data/lib/mls/photo.rb +18 -0
- data/lib/mls/property.rb +24 -0
- data/lib/mls/region.rb +13 -0
- data/lib/mls/sale.rb +2 -0
- data/lib/mls/space.rb +3 -0
- data/lib/mls/sublease.rb +2 -0
- data/lib/mls/use.rb +25 -0
- data/mls.gemspec +11 -15
- data/test/mls/attribute_test.rb +55 -0
- data/test/mls/resource_test.rb +31 -0
- data/test/mls_test.rb +27 -0
- data/test/test_helper.rb +26 -27
- metadata +43 -75
- data/lib/mls/attribute.rb +0 -44
- data/lib/mls/attributes/array.rb +0 -11
- data/lib/mls/attributes/boolean.rb +0 -9
- data/lib/mls/attributes/datetime.rb +0 -25
- data/lib/mls/attributes/decimal.rb +0 -21
- data/lib/mls/attributes/fixnum.rb +0 -16
- data/lib/mls/attributes/hash.rb +0 -15
- data/lib/mls/attributes/string.rb +0 -15
- data/lib/mls/errors.rb +0 -29
- data/lib/mls/factories/account.rb +0 -34
- data/lib/mls/factories/address.rb +0 -16
- data/lib/mls/factories/listing.rb +0 -29
- data/lib/mls/factories_helper.rb +0 -7
- data/lib/mls/model.rb +0 -125
- data/lib/mls/models/account.rb +0 -174
- data/lib/mls/models/address.rb +0 -58
- data/lib/mls/models/brokerage.rb +0 -31
- data/lib/mls/models/floorplan.rb +0 -45
- data/lib/mls/models/flyer.rb +0 -45
- data/lib/mls/models/listing.rb +0 -394
- data/lib/mls/models/pdf.rb +0 -15
- data/lib/mls/models/photo.rb +0 -40
- data/lib/mls/models/property.rb +0 -114
- data/lib/mls/models/region.rb +0 -56
- data/lib/mls/models/tour.rb +0 -54
- data/lib/mls/models/video.rb +0 -18
- data/lib/mls/parser.rb +0 -74
- data/lib/mls/resource.rb +0 -99
- data/lib/rdoc/generator/template/42floors/_context.rhtml +0 -209
- data/lib/rdoc/generator/template/42floors/_head.rhtml +0 -7
- data/lib/rdoc/generator/template/42floors/class.rhtml +0 -39
- data/lib/rdoc/generator/template/42floors/file.rhtml +0 -35
- data/lib/rdoc/generator/template/42floors/index.rhtml +0 -13
- data/lib/rdoc/generator/template/42floors/resources/apple-touch-icon.png +0 -0
- data/lib/rdoc/generator/template/42floors/resources/css/github.css +0 -129
- data/lib/rdoc/generator/template/42floors/resources/css/main.css +0 -339
- data/lib/rdoc/generator/template/42floors/resources/css/panel.css +0 -389
- data/lib/rdoc/generator/template/42floors/resources/css/reset.css +0 -48
- data/lib/rdoc/generator/template/42floors/resources/favicon.ico +0 -0
- data/lib/rdoc/generator/template/42floors/resources/i/arrows.png +0 -0
- data/lib/rdoc/generator/template/42floors/resources/i/results_bg.png +0 -0
- data/lib/rdoc/generator/template/42floors/resources/i/tree_bg.png +0 -0
- data/lib/rdoc/generator/template/42floors/resources/js/highlight.pack.js +0 -1
- data/lib/rdoc/generator/template/42floors/resources/js/jquery-1.3.2.min.js +0 -19
- data/lib/rdoc/generator/template/42floors/resources/js/jquery-effect.js +0 -593
- data/lib/rdoc/generator/template/42floors/resources/js/main.js +0 -20
- data/lib/rdoc/generator/template/42floors/resources/js/searchdoc.js +0 -442
- data/lib/rdoc/generator/template/42floors/resources/panel/index.html +0 -73
- data/lib/rdoc/generator/template/42floors/se_index.rhtml +0 -8
- data/test/units/properties/test_boolean.rb +0 -4
- data/test/units/test_errors.rb +0 -32
- data/test/units/test_mls.rb +0 -294
- data/test/units/test_property.rb +0 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 02850148a3e96cfb9ed81d4acf27060f3f38d3b3
|
4
|
+
data.tar.gz: 63f702c4c5c63b7eb05fa6c7e50554cb1ed30e7d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e227236ccc27936b17ea7de888a28e7cbfc0298d6122d8c366042dad72f6b6fc56ab6f1cb5073e9737bda3e29760ed4c2e2d4ff96624f8b69651ec083c862db2
|
7
|
+
data.tar.gz: 9c0275c121db1a4c3d4b12d85c0f939d800d76077fc5d42454920632f650a7238ea9f1d55c4d8dce0e5bb1e93a418fc003aaf88eb1067f8bfda4493c83034f46
|
data/.gitignore
CHANGED
data/Rakefile
CHANGED
@@ -9,10 +9,9 @@ task :console do
|
|
9
9
|
end
|
10
10
|
task :c => :console
|
11
11
|
|
12
|
-
|
13
12
|
Rake::TestTask.new do |t|
|
14
13
|
t.libs << 'lib' << 'test'
|
15
|
-
t.test_files = FileList['test
|
14
|
+
t.test_files = FileList['test/**/*_test.rb']
|
16
15
|
#t.warning = true
|
17
16
|
#t.verbose = true
|
18
17
|
end
|
@@ -24,14 +23,15 @@ Rake::RDocTask.new do |rd|
|
|
24
23
|
|
25
24
|
rd.options << '-f' << 'sdoc' # explictly set shtml generator
|
26
25
|
rd.options << '-T' << '42floors'
|
27
|
-
rd.options << '-
|
28
|
-
rd.options << '-g'
|
29
|
-
rd.options << '--include' << 'lib/rdoc'
|
26
|
+
rd.options << '-g' # Generate github links
|
30
27
|
|
31
28
|
rd.rdoc_files.include('README.rdoc')
|
32
29
|
rd.rdoc_files.include('lib/**/*.rb')
|
33
|
-
rd.rdoc_files.exclude('lib/rdoc/**/*.rb')
|
34
30
|
end
|
35
31
|
|
36
32
|
desc "Run tests"
|
37
33
|
task :default => :test
|
34
|
+
|
35
|
+
namespace :pages do
|
36
|
+
#TODO: https://github.com/defunkt/sdoc-helpers/blob/master/lib/sdoc_helpers/pages.rb
|
37
|
+
end
|
data/lib/mls.rb
CHANGED
@@ -1,456 +1,102 @@
|
|
1
|
-
require '
|
2
|
-
require 'cgi'
|
3
|
-
require 'logger'
|
4
|
-
require 'net/https'
|
5
|
-
require 'singleton'
|
6
|
-
require 'yajl'
|
7
|
-
require 'bigdecimal'
|
8
|
-
require 'bigdecimal/util'
|
9
|
-
require 'active_support'
|
10
|
-
require 'active_support/core_ext'
|
11
|
-
require 'date'
|
12
|
-
require 'time'
|
1
|
+
require 'sunstone'
|
13
2
|
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
class Boolean #:nodoc:
|
18
|
-
end
|
19
|
-
|
20
|
-
# _MLS_ is a low-level API. It provides basic HTTP #get, #post, #put, and #delete
|
21
|
-
# calls to the MLS. It can also provides basic error checking of responses.
|
22
|
-
class MLS
|
23
|
-
include Singleton
|
3
|
+
module MLS
|
24
4
|
|
25
5
|
API_VERSION = '0.1.0'
|
26
6
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
#
|
33
|
-
# #!ruby
|
34
|
-
# MLS.url = "https://mls.42floors.com/API_KEY"
|
35
|
-
def url=(uri) # TODO: testme
|
36
|
-
@url = URI.parse(uri)
|
37
|
-
@api_key = CGI.unescape(@url.user)
|
38
|
-
@host, @port = @url.host, @url.port
|
39
|
-
@ssl = (url.scheme == 'https')
|
40
|
-
end
|
41
|
-
|
42
|
-
# Sets the user agent so that MLS can distinguish between multiple users
|
43
|
-
# with the same auth
|
44
|
-
def user_agent=(user_agent)
|
45
|
-
@user_agent = user_agent
|
46
|
-
end
|
47
|
-
|
48
|
-
def logger # TODO: testme
|
49
|
-
@logger ||= default_logger
|
50
|
-
end
|
51
|
-
|
52
|
-
# Returns the current connection to the MLS or if connection has been made
|
53
|
-
# it returns a new connection
|
54
|
-
def connection # TODO: testme
|
55
|
-
return @connection if @connection
|
56
|
-
@connection = Net::HTTP.new(@host, @port)
|
57
|
-
@connection.use_ssl = @ssl
|
58
|
-
@connection
|
59
|
-
end
|
60
|
-
|
61
|
-
# provides the asset host, if asset_host is set then it is returned,
|
62
|
-
# otherwise it queries the MLS for this configuration.
|
63
|
-
def asset_host # TODO: testme
|
64
|
-
@asset_host ||= get('/asset_host').body
|
7
|
+
def request_headers
|
8
|
+
super
|
9
|
+
super.merge({
|
10
|
+
'Api-Version' => API_VERSION
|
11
|
+
})
|
65
12
|
end
|
66
13
|
|
67
|
-
def
|
68
|
-
|
14
|
+
def self.asset_host
|
15
|
+
MLS::Model.connection.server_config['asset_host']
|
69
16
|
end
|
70
17
|
|
71
|
-
def
|
72
|
-
|
18
|
+
def self.image_host
|
19
|
+
MLS::Model.connection.server_config['image_host']
|
73
20
|
end
|
21
|
+
|
22
|
+
end
|
74
23
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
end
|
79
|
-
|
80
|
-
def headers # TODO: testme
|
81
|
-
headers = {
|
82
|
-
'Content-Type' => 'application/json',
|
83
|
-
'User-Agent' => @user_agent,
|
84
|
-
'X-42Floors-API-Version' => API_VERSION,
|
85
|
-
'X-42Floors-API-Key' => api_key
|
86
|
-
}
|
87
|
-
headers['X-42Floors-Branch'] = branch if branch
|
88
|
-
headers['X-42Floors-Server'] = server if server
|
89
|
-
headers['X-Forwarded-For'] = forwarded_for if forwarded_for
|
90
|
-
headers
|
91
|
-
end
|
92
|
-
|
93
|
-
def prepare_request(req) # TODO: testme
|
94
|
-
headers.each { |k, v| req[k] = v }
|
95
|
-
req['Cookie'] = cookie_jar[:api_session] if cookie_jar[:api_session]
|
96
|
-
end
|
97
|
-
|
98
|
-
# Gets to +url+ on the MLS Server. Automatically includes any headers returned
|
99
|
-
# by the MLS#headers function.
|
100
|
-
#
|
101
|
-
# Paramaters::
|
102
|
-
#
|
103
|
-
# * +url+ - The +url+ on the server to Get to. To get to <tt>"/accounts"</tt>
|
104
|
-
# pass <tt>"/accounts"</tt> as +url+
|
105
|
-
# * +params+ - A Hash or Ruby Object that responds to #to_param. The result
|
106
|
-
# of this method is appended on the URL as query params
|
107
|
-
# * +valid_response_codes+ - An Array of HTTP response codes that should be
|
108
|
-
# considered accepable and not raise exceptions. For example If you don't
|
109
|
-
# want a MLS::Exception::NotFound to be raised when a GET request returns
|
110
|
-
# a 404 pass in 404, and the response body will be returned if the status
|
111
|
-
# code is a 404 as it does if the status code is in the 200..299 rage. Status
|
112
|
-
# codes in the 200..299 range are *always* considred acceptable
|
113
|
-
#
|
114
|
-
# Return Value::
|
115
|
-
#
|
116
|
-
# Returns the return value of the <tt>&block</tt> if given, otherwise the response
|
117
|
-
# object
|
118
|
-
#
|
119
|
-
# Examples:
|
120
|
-
#
|
121
|
-
# #!ruby
|
122
|
-
# MLS.get('/example') # => #<Net::HTTP::Response>
|
123
|
-
#
|
124
|
-
# MLS.get('/example', {:body => 'stuff'}) # => #<Net::HTTP::Response>
|
125
|
-
#
|
126
|
-
# MLS.get('/404') # => raises MLS::Exception::NotFound
|
127
|
-
#
|
128
|
-
# MLS.get('/404', nil, 404, 450..499) # => #<Net::HTTP::Response>
|
129
|
-
#
|
130
|
-
# MLS.get('/404', nil, [404, 450..499]) # => #<Net::HTTP::Response>
|
131
|
-
#
|
132
|
-
# MLS.get('/404', nil, 404) # => #<Net::HTTP::Response>
|
133
|
-
#
|
134
|
-
# # this will still raise an exception if the response_code is not valid
|
135
|
-
# # and the block will not be called
|
136
|
-
# MLS.get('/act') do |response, response_code|
|
137
|
-
# # ...
|
138
|
-
# end
|
139
|
-
def get(url, params={}, *valid_response_codes, &block)
|
140
|
-
params ||= {}
|
141
|
-
|
142
|
-
req = Net::HTTP::Get.new(url + '?' + params.to_param)
|
143
|
-
prepare_request(req)
|
144
|
-
|
145
|
-
response = connection.request(req)
|
146
|
-
handle_response(response, valid_response_codes)
|
147
|
-
|
148
|
-
response.body.force_encoding(Encoding::UTF_8)
|
149
|
-
if block_given?
|
150
|
-
yield(response, response.code.to_i)
|
151
|
-
else
|
152
|
-
response
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
# Puts to +url+ on the MLS Server. Automatically includes any headers returned
|
157
|
-
# by the MLS#headers function.
|
158
|
-
#
|
159
|
-
# Paramaters::
|
160
|
-
#
|
161
|
-
# * +url+ - The +url+ on the server to Put to. To put to <tt>"/accounts"</tt>
|
162
|
-
# pass <tt>"/accounts"</tt> as +url+
|
163
|
-
# * +body+ - A Ruby object which is converted into JSON and added in the request
|
164
|
-
# Body.
|
165
|
-
# * +valid_response_codes+ - An Array of HTTP response codes that should be
|
166
|
-
# considered accepable and not raise exceptions. For example If you don't
|
167
|
-
# want a MLS::Exception::NotFound to be raised when a PUT request returns
|
168
|
-
# a 404 pass in 404, and the response body will be returned if the status
|
169
|
-
# code is a 404 as it does if the status code is in the 200..299 rage. Status
|
170
|
-
# codes in the 200..299 range are *always* considred acceptable
|
171
|
-
#
|
172
|
-
# Return Value::
|
173
|
-
#
|
174
|
-
# Returns the return value of the <tt>&block</tt> if given, otherwise the response
|
175
|
-
# object
|
176
|
-
#
|
177
|
-
# Examples:
|
178
|
-
#
|
179
|
-
# #!ruby
|
180
|
-
# MLS.put('/example') # => #<Net::HTTP::Response>
|
181
|
-
#
|
182
|
-
# MLS.put('/example', {:body => 'stuff'}) # => #<Net::HTTP::Response>
|
183
|
-
#
|
184
|
-
# MLS.put('/404') # => raises MLS::Exception::NotFound
|
185
|
-
#
|
186
|
-
# MLS.put('/404', nil, 404, 450..499) # => #<Net::HTTP::Response>
|
187
|
-
#
|
188
|
-
# MLS.put('/404', nil, [404, 450..499]) # => #<Net::HTTP::Response>
|
189
|
-
#
|
190
|
-
# MLS.put('/404', nil, 404) # => #<Net::HTTP::Response>
|
191
|
-
#
|
192
|
-
# # this will still raise an exception if the response_code is not valid
|
193
|
-
# # and the block will not be called
|
194
|
-
# MLS.put('/act') do |response, response_code|
|
195
|
-
# # ...
|
196
|
-
# end
|
197
|
-
def put(url, body={}, *valid_response_codes, &block)
|
198
|
-
body ||= {}
|
199
|
-
|
200
|
-
req = Net::HTTP::Put.new(url)
|
201
|
-
req.body = Yajl::Encoder.encode(body)
|
202
|
-
prepare_request(req)
|
203
|
-
|
204
|
-
response = connection.request(req)
|
205
|
-
handle_response(response, valid_response_codes)
|
24
|
+
class MLS::Model < ActiveRecord::Base
|
25
|
+
self.abstract_class = true
|
26
|
+
end
|
206
27
|
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
28
|
+
module MLS::Slugger
|
29
|
+
|
30
|
+
extend ActiveSupport::Concern
|
31
|
+
|
32
|
+
module ClassMethods
|
33
|
+
|
34
|
+
def find(*args)
|
35
|
+
friendly = -> (arg) { arg.respond_to?(:to_i) && arg.to_i.to_s != arg.to_s }
|
36
|
+
|
37
|
+
if args.count == 1 && friendly.call(args.first)
|
38
|
+
find_by_slug!(args)
|
39
|
+
else
|
40
|
+
super
|
41
|
+
end
|
211
42
|
end
|
212
|
-
end
|
213
|
-
|
214
|
-
# Posts to +url+ on the MLS Server. Automatically includes any headers returned
|
215
|
-
# by the MLS#headers function.
|
216
|
-
#
|
217
|
-
# Paramaters::
|
218
|
-
#
|
219
|
-
# * +url+ - The +url+ on the server to Post to. To post to <tt>"/accounts"</tt>
|
220
|
-
# pass <tt>"/accounts"</tt> as +url+
|
221
|
-
# * +body+ - A Ruby object which is converted into JSON and added in the request
|
222
|
-
# Body.
|
223
|
-
# * +valid_response_codes+ - An Array of HTTP response codes that should be
|
224
|
-
# considered accepable and not raise exceptions. For example If you don't
|
225
|
-
# want a MLS::Exception::NotFound to be raised when a POST request returns
|
226
|
-
# a 404 pass in 404, and the response body will be returned if the status
|
227
|
-
# code is a 404 as it does if the status code is in the 200..299 rage. Status
|
228
|
-
# codes in the 200..299 range are *always* considred acceptable
|
229
|
-
#
|
230
|
-
# Return Value::
|
231
|
-
#
|
232
|
-
# Returns the return value of the <tt>&block</tt> if given, otherwise the response
|
233
|
-
# object
|
234
|
-
#
|
235
|
-
# Examples:
|
236
|
-
#
|
237
|
-
# #!ruby
|
238
|
-
# MLS.post('/example') # => #<Net::HTTP::Response>
|
239
|
-
#
|
240
|
-
# MLS.post('/example', {:body => 'stuff'}) # => #<Net::HTTP::Response>
|
241
|
-
#
|
242
|
-
# MLS.post('/404') # => raises MLS::Exception::NotFound
|
243
|
-
#
|
244
|
-
# MLS.post('/404', nil, 404, 450..499) # => #<Net::HTTP::Response>
|
245
|
-
#
|
246
|
-
# MLS.post('/404', nil, [404, 450..499]) # => #<Net::HTTP::Response>
|
247
|
-
#
|
248
|
-
# MLS.post('/404', nil, 404) # => #<Net::HTTP::Response>
|
249
|
-
#
|
250
|
-
# # this will still raise an exception if the response_code is not valid
|
251
|
-
# # and the block will not be called
|
252
|
-
# MLS.post('/act') do |response, response_code|
|
253
|
-
# # ...
|
254
|
-
# end
|
255
|
-
def post(url, body={}, *valid_response_codes, &block)
|
256
|
-
body ||= {}
|
257
|
-
|
258
|
-
req = Net::HTTP::Post.new(url)
|
259
|
-
req.body = Yajl::Encoder.encode(body)
|
260
|
-
prepare_request(req)
|
261
43
|
|
262
|
-
response = connection.request(req)
|
263
|
-
handle_response(response, valid_response_codes)
|
264
|
-
|
265
|
-
if block_given?
|
266
|
-
yield(response, response.code.to_i)
|
267
|
-
else
|
268
|
-
response
|
269
|
-
end
|
270
44
|
end
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
#
|
275
|
-
# Paramaters::
|
276
|
-
#
|
277
|
-
# * +url+ - The +url+ on the server to Post to. To delete to <tt>"/accounts"</tt>
|
278
|
-
# pass <tt>"/accounts"</tt> as +url+
|
279
|
-
# * +body+ - A Ruby object which is converted into JSON and added in the request
|
280
|
-
# Body.
|
281
|
-
# * +valid_response_codes+ - An Array of HTTP response codes that should be
|
282
|
-
# considered accepable and not raise exceptions. For example If you don't
|
283
|
-
# want a MLS::Exception::NotFound to be raised when a POST request returns
|
284
|
-
# a 404 pass in 404, and the response body will be returned if the status
|
285
|
-
# code is a 404 as it does if the status code is in the 200..299 rage. Status
|
286
|
-
# codes in the 200..299 range are *always* considred acceptable
|
287
|
-
#
|
288
|
-
# Return Value::
|
289
|
-
#
|
290
|
-
# Returns the return value of the <tt>&block</tt> if given, otherwise the
|
291
|
-
# response object
|
292
|
-
#
|
293
|
-
# Examples:
|
294
|
-
#
|
295
|
-
# #!ruby
|
296
|
-
# MLS.delete('/example') # => #<Net::HTTP::Response>
|
297
|
-
#
|
298
|
-
# MLS.delete('/example', {:body => 'stuff'}) # => #<Net::HTTP::Response>
|
299
|
-
#
|
300
|
-
# MLS.delete('/404') # => raises MLS::Exception::NotFound
|
301
|
-
#
|
302
|
-
# MLS.delete('/404', nil, 404, 450..499) # => #<Net::HTTP::Response>
|
303
|
-
#
|
304
|
-
# MLS.delete('/404', nil, [404, 450..499]) # => #<Net::HTTP::Response>
|
305
|
-
#
|
306
|
-
# MLS.delete('/404', nil, 404) # => #<Net::HTTP::Response>
|
307
|
-
#
|
308
|
-
# # this will still raise an exception if the response_code is not valid
|
309
|
-
# # and the block will not be called
|
310
|
-
# MLS.delete('/act') do |response, response_code|
|
311
|
-
# # ...
|
312
|
-
# end
|
313
|
-
def delete(url, body={}, *valid_response_codes, &block)
|
314
|
-
body ||= {}
|
315
|
-
|
316
|
-
req = Net::HTTP::Delete.new(url)
|
317
|
-
req.body = Yajl::Encoder.encode(body)
|
318
|
-
prepare_request(req)
|
319
|
-
|
320
|
-
response = connection.request(req)
|
321
|
-
handle_response(response, valid_response_codes)
|
322
|
-
if block_given?
|
323
|
-
yield(response, response.code.to_i)
|
324
|
-
else
|
325
|
-
response
|
326
|
-
end
|
45
|
+
|
46
|
+
def to_param
|
47
|
+
slug
|
327
48
|
end
|
328
49
|
|
329
|
-
|
330
|
-
# is include in the valid_response_codes Array
|
331
|
-
#
|
332
|
-
# Paramaters::
|
333
|
-
#
|
334
|
-
# * +response+ - The Net::HTTP::Response object
|
335
|
-
# * +valid_response_codes+ - An Array, Integer, or Range. If it's Array the
|
336
|
-
# Array can include both Integers or Ranges.
|
337
|
-
#
|
338
|
-
# Return Value::
|
339
|
-
#
|
340
|
-
# If an exception is not raised the +response+ is returned
|
341
|
-
#
|
342
|
-
# Examples:
|
343
|
-
#
|
344
|
-
# #!ruby
|
345
|
-
# MLS.handle_response(<Net::HTTP::Response @code=200>) # => <Net::HTTP::Response @code=200>
|
346
|
-
#
|
347
|
-
# MLS.handle_response(<Net::HTTP::Response @code=404>) # => raises MLS::Exception::NotFound
|
348
|
-
#
|
349
|
-
# MLS.handle_response(<Net::HTTP::Response @code=500>) # => raises MLS::Exception
|
350
|
-
#
|
351
|
-
# MLS.handle_response(<Net::HTTP::Response @code=404>, 404) # => <Net::HTTP::Response @code=404>
|
352
|
-
#
|
353
|
-
# MLS.handle_response(<Net::HTTP::Response @code=500>, 404, 500) # => <Net::HTTP::Response @code=500>
|
354
|
-
#
|
355
|
-
# MLS.handle_response(<Net::HTTP::Response @code=405>, 300, 400..499) # => <Net::HTTP::Response @code=405>
|
356
|
-
#
|
357
|
-
# MLS.handle_response(<Net::HTTP::Response @code=405>, [300, 400..499]) # => <Net::HTTP::Response @code=405>
|
358
|
-
def handle_response(response, *valid_response_codes)
|
359
|
-
if response['X-42Floors-API-Version-Deprecated']
|
360
|
-
logger.warn("DEPRECATION WARNING: API v#{API_VERSION} is being phased out")
|
361
|
-
end
|
362
|
-
|
363
|
-
code = response.code.to_i
|
364
|
-
valid_response_codes.flatten!
|
365
|
-
valid_response_codes << (200..299)
|
366
|
-
|
367
|
-
if !valid_response_codes.detect{|i| i.is_a?(Range) ? i.include?(code) : i == code}
|
368
|
-
case code
|
369
|
-
when 400
|
370
|
-
raise MLS::Exception::BadRequest, response.body
|
371
|
-
when 401
|
372
|
-
raise MLS::Exception::Unauthorized, response.body
|
373
|
-
when 404
|
374
|
-
raise MLS::Exception::NotFound
|
375
|
-
when 410
|
376
|
-
raise MLS::Exception::Gone
|
377
|
-
when 422
|
378
|
-
raise MLS::Exception::ApiVersionUnsupported, response.body
|
379
|
-
when 503
|
380
|
-
raise MLS::Exception::ServiceUnavailable, response.body
|
381
|
-
when 301
|
382
|
-
raise MLS::Exception::MovedPermanently, response.body
|
383
|
-
when 300..599
|
384
|
-
raise MLS::Exception, code
|
385
|
-
end
|
386
|
-
end
|
50
|
+
end
|
387
51
|
|
388
|
-
|
389
|
-
cookie_jar[:api_session_id] = response['X-42Floors-API-Session-Id'] if response['X-42Floors-API-Session-Id']
|
390
|
-
|
391
|
-
response
|
392
|
-
end
|
52
|
+
module MLS::Avatar
|
393
53
|
|
394
|
-
|
395
|
-
# will be returned. Otherwise and MLS::Exception should be thrown.
|
396
|
-
#
|
397
|
-
# #!ruby
|
398
|
-
# MLS.ping # => "pong"
|
399
|
-
#
|
400
|
-
# MLS.ping # raises MLS::Exception::ServiceUnavailable if a 503 is returned
|
401
|
-
def ping # TODO: testme
|
402
|
-
get('/ping').body
|
403
|
-
end
|
54
|
+
extend ActiveSupport::Concern
|
404
55
|
|
405
|
-
|
406
|
-
|
56
|
+
included do
|
57
|
+
belongs_to :avatar, :class_name => 'Photo'
|
407
58
|
end
|
408
59
|
|
409
|
-
def
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
60
|
+
def avatar_url(options={})
|
61
|
+
options.reverse_merge!({
|
62
|
+
:style => nil,
|
63
|
+
:protocol => "http",
|
64
|
+
:bg => nil,
|
65
|
+
:format => "jpg"
|
66
|
+
});
|
414
67
|
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
end
|
68
|
+
url_params = {s: options[:style], bg: options[:bg]}.select{ |k, v| v }
|
69
|
+
result = "#{options[:protocol]}://#{MLS.image_host}/#{avatar_digest}.#{options[:format]}"
|
70
|
+
result += "?#{url_params.to_param}" if url_params.size > 1
|
419
71
|
|
420
|
-
|
421
|
-
Yajl::Parser.new(:symbolize_keys => true).parse(json)
|
72
|
+
result
|
422
73
|
end
|
423
74
|
|
424
75
|
end
|
425
76
|
|
426
|
-
require 'mls/
|
427
|
-
require 'mls/
|
428
|
-
require 'mls/
|
429
|
-
|
430
|
-
|
431
|
-
require 'mls/
|
432
|
-
require 'mls/
|
433
|
-
require 'mls/
|
434
|
-
require 'mls/
|
435
|
-
require 'mls/
|
436
|
-
require 'mls/
|
437
|
-
require 'mls/
|
438
|
-
require 'mls/
|
77
|
+
require 'mls/photo'
|
78
|
+
require 'mls/account'
|
79
|
+
require 'mls/brokerage'
|
80
|
+
require 'mls/property'
|
81
|
+
require 'mls/region'
|
82
|
+
require 'mls/listing'
|
83
|
+
require 'mls/lease'
|
84
|
+
require 'mls/sublease'
|
85
|
+
require 'mls/space'
|
86
|
+
require 'mls/sale'
|
87
|
+
require 'mls/coworking_space'
|
88
|
+
require 'mls/address'
|
89
|
+
require 'mls/locality'
|
90
|
+
require 'mls/flyer'
|
91
|
+
require 'mls/agency'
|
92
|
+
require 'mls/floorplan'
|
93
|
+
require 'mls/use'
|
439
94
|
|
440
95
|
# Models
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
require 'mls/models/pdf'
|
449
|
-
require 'mls/models/tour'
|
450
|
-
require 'mls/models/flyer'
|
451
|
-
require 'mls/models/floorplan'
|
452
|
-
require 'mls/models/region'
|
453
|
-
require 'mls/models/brokerage'
|
454
|
-
|
455
|
-
#factories
|
456
|
-
require 'mls/factories_helper'
|
96
|
+
# # Helpers
|
97
|
+
# class MLS
|
98
|
+
#
|
99
|
+
# def current_account
|
100
|
+
# end
|
101
|
+
#
|
102
|
+
# end
|