mls 0.13.0 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/mls/models/account.rb +0 -5
- data/lib/mls/models/brokerage.rb +5 -7
- data/lib/mls/models/floorplan.rb +1 -1
- data/lib/mls/models/flyer.rb +1 -1
- data/lib/mls/models/photo.rb +1 -1
- data/lib/mls.rb +19 -15
- data/mls.gemspec +1 -1
- data/test/test_helper.rb +1 -1
- data/test/units/test_mls.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 49407504285320c314076642711aa51cbcffb1ea
|
4
|
+
data.tar.gz: 1f01d0b23a0b9e5d89744a3020615ff59c420a6f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96d45047e9069909a6e05f80fa8335188da8e81dd99e9c6d1aa0c7c898b1a84372aaac30320884f5b11233fec7d0f9f1b68fb34579bff6ae2be3bd6bb0faf0b1
|
7
|
+
data.tar.gz: d3fc967552d7105a79cd845ce8024b91e0f78a903ad87d300c63831d8f28bc2497eb50445e0e61e251cef952f02a24595aa99d395f5b5e062d6ceb75f6c4817f
|
data/lib/mls/models/account.rb
CHANGED
@@ -29,7 +29,6 @@ class MLS::Account < MLS::Resource
|
|
29
29
|
attribute :updated_at, DateTime, :serialize => :false
|
30
30
|
|
31
31
|
attribute :email_token, String, :serialize => false
|
32
|
-
attribute :auth_cookie, String, :serialize => false
|
33
32
|
attribute :start_hours_of_operation, Fixnum, :serialize => :if_present
|
34
33
|
attribute :end_hours_of_operation, Fixnum, :serialize => :if_present
|
35
34
|
attribute :days_of_operation, String, :serialize => :if_present
|
@@ -129,12 +128,8 @@ class MLS::Account < MLS::Resource
|
|
129
128
|
def authenticate(attrs_or_email, password=nil)
|
130
129
|
email = attrs_or_email.is_a?(Hash) ? attrs_or_email[:email] : attrs_or_email
|
131
130
|
password = attrs_or_email.is_a?(Hash) ? attrs_or_email[:password] : password
|
132
|
-
|
133
131
|
response = MLS.post('/login', {:email => email, :password => password})
|
134
|
-
MLS.auth_cookie = response['set-cookie']
|
135
|
-
|
136
132
|
account = MLS::Account::Parser.parse(response.body)
|
137
|
-
account.auth_cookie = MLS.auth_cookie
|
138
133
|
account
|
139
134
|
rescue MLS::Exception::Unauthorized => response
|
140
135
|
nil
|
data/lib/mls/models/brokerage.rb
CHANGED
@@ -1,19 +1,14 @@
|
|
1
1
|
class MLS::Brokerage < MLS::Resource
|
2
2
|
|
3
|
+
attr_accessor :avatar
|
4
|
+
|
3
5
|
attribute :id, Fixnum, :serialize => :if_present
|
4
6
|
attribute :name, String, :serialize => :if_present
|
5
7
|
attribute :admin_id, Fixnum, :serialize => :if_present
|
6
8
|
attribute :slug, String, :serialize => false
|
7
9
|
attribute :palette, Hash, :serialize => :if_present
|
8
|
-
attribute :avatar_digest, String, :serialize => false
|
9
10
|
|
10
11
|
class << self
|
11
|
-
|
12
|
-
def avatar(format='png', protocol='http')
|
13
|
-
if avatar_digest
|
14
|
-
"#{protocol}://assets.42floors.com/photos/original/#{avatar_digest}.png"
|
15
|
-
end
|
16
|
-
end
|
17
12
|
|
18
13
|
def find(id)
|
19
14
|
response = MLS.get("/brokerages/#{id}")
|
@@ -30,4 +25,7 @@ class MLS::Brokerage < MLS::Resource
|
|
30
25
|
end
|
31
26
|
|
32
27
|
class MLS::Brokerage::Parser < MLS::Parser
|
28
|
+
def avatar=(avatar)
|
29
|
+
@object.avatar = MLS::Photo::Parser.build(avatar)
|
30
|
+
end
|
33
31
|
end
|
data/lib/mls/models/floorplan.rb
CHANGED
data/lib/mls/models/flyer.rb
CHANGED
data/lib/mls/models/photo.rb
CHANGED
@@ -26,7 +26,7 @@ class MLS::Photo < MLS::Resource
|
|
26
26
|
attrs[:file].rewind
|
27
27
|
url = MLS.url.dup
|
28
28
|
url.user = nil
|
29
|
-
url.path = "/
|
29
|
+
url.path = "/photos"
|
30
30
|
response = RestClient.post(url.to_s, {:photo => attrs}, MLS.headers)
|
31
31
|
attrs[:file].close unless attrs[:file].closed?
|
32
32
|
|
data/lib/mls.rb
CHANGED
@@ -6,6 +6,7 @@ require 'singleton'
|
|
6
6
|
require 'yajl'
|
7
7
|
require 'bigdecimal'
|
8
8
|
require 'bigdecimal/util'
|
9
|
+
require 'active_support'
|
9
10
|
require 'active_support/core_ext'
|
10
11
|
require 'date'
|
11
12
|
require 'time'
|
@@ -25,7 +26,7 @@ class MLS
|
|
25
26
|
|
26
27
|
attr_reader :url, :user_agent
|
27
28
|
attr_writer :asset_host, :image_host, :agent_profile
|
28
|
-
attr_accessor :api_key, :
|
29
|
+
attr_accessor :api_key, :cookie_jar, :logger, :branch, :server, :forwarded_for
|
29
30
|
|
30
31
|
# Sets the API Token and Host of the MLS Server
|
31
32
|
#
|
@@ -77,17 +78,21 @@ class MLS
|
|
77
78
|
end
|
78
79
|
|
79
80
|
def headers # TODO: testme
|
80
|
-
{
|
81
|
+
headers = {
|
81
82
|
'Content-Type' => 'application/json',
|
82
83
|
'User-Agent' => @user_agent,
|
83
84
|
'X-42Floors-API-Version' => API_VERSION,
|
84
85
|
'X-42Floors-API-Key' => api_key
|
85
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
|
86
91
|
end
|
87
92
|
|
88
93
|
def prepare_request(req) # TODO: testme
|
89
94
|
headers.each { |k, v| req[k] = v }
|
90
|
-
req['Cookie'] =
|
95
|
+
req['Cookie'] = cookie_jar[:api_session] if cookie_jar[:api_session]
|
91
96
|
end
|
92
97
|
|
93
98
|
# Gets to +url+ on the MLS Server. Automatically includes any headers returned
|
@@ -95,8 +100,7 @@ class MLS
|
|
95
100
|
#
|
96
101
|
# Paramaters::
|
97
102
|
#
|
98
|
-
# * +url+ - The +url+ on the server to Get to.
|
99
|
-
# be prefixed with <tt>"/api"</tt>. To get to <tt>"/api/accounts"</tt>
|
103
|
+
# * +url+ - The +url+ on the server to Get to. To get to <tt>"/accounts"</tt>
|
100
104
|
# pass <tt>"/accounts"</tt> as +url+
|
101
105
|
# * +params+ - A Hash or Ruby Object that responds to #to_param. The result
|
102
106
|
# of this method is appended on the URL as query params
|
@@ -135,7 +139,7 @@ class MLS
|
|
135
139
|
def get(url, params={}, *valid_response_codes, &block)
|
136
140
|
params ||= {}
|
137
141
|
|
138
|
-
req = Net::HTTP::Get.new(
|
142
|
+
req = Net::HTTP::Get.new(url + '?' + params.to_param)
|
139
143
|
prepare_request(req)
|
140
144
|
|
141
145
|
response = connection.request(req)
|
@@ -154,8 +158,7 @@ class MLS
|
|
154
158
|
#
|
155
159
|
# Paramaters::
|
156
160
|
#
|
157
|
-
# * +url+ - The +url+ on the server to Put to.
|
158
|
-
# be prefixed with <tt>"/api"</tt>. To put to <tt>"/api/accounts"</tt>
|
161
|
+
# * +url+ - The +url+ on the server to Put to. To put to <tt>"/accounts"</tt>
|
159
162
|
# pass <tt>"/accounts"</tt> as +url+
|
160
163
|
# * +body+ - A Ruby object which is converted into JSON and added in the request
|
161
164
|
# Body.
|
@@ -194,7 +197,7 @@ class MLS
|
|
194
197
|
def put(url, body={}, *valid_response_codes, &block)
|
195
198
|
body ||= {}
|
196
199
|
|
197
|
-
req = Net::HTTP::Put.new(
|
200
|
+
req = Net::HTTP::Put.new(url)
|
198
201
|
req.body = Yajl::Encoder.encode(body)
|
199
202
|
prepare_request(req)
|
200
203
|
|
@@ -213,8 +216,7 @@ class MLS
|
|
213
216
|
#
|
214
217
|
# Paramaters::
|
215
218
|
#
|
216
|
-
# * +url+ - The +url+ on the server to Post to.
|
217
|
-
# be prefixed with <tt>"/api"</tt>. To post to <tt>"/api/accounts"</tt>
|
219
|
+
# * +url+ - The +url+ on the server to Post to. To post to <tt>"/accounts"</tt>
|
218
220
|
# pass <tt>"/accounts"</tt> as +url+
|
219
221
|
# * +body+ - A Ruby object which is converted into JSON and added in the request
|
220
222
|
# Body.
|
@@ -253,7 +255,7 @@ class MLS
|
|
253
255
|
def post(url, body={}, *valid_response_codes, &block)
|
254
256
|
body ||= {}
|
255
257
|
|
256
|
-
req = Net::HTTP::Post.new(
|
258
|
+
req = Net::HTTP::Post.new(url)
|
257
259
|
req.body = Yajl::Encoder.encode(body)
|
258
260
|
prepare_request(req)
|
259
261
|
|
@@ -272,8 +274,7 @@ class MLS
|
|
272
274
|
#
|
273
275
|
# Paramaters::
|
274
276
|
#
|
275
|
-
# * +url+ - The +url+ on the server to Post to.
|
276
|
-
# be prefixed with <tt>"/api"</tt>. To delete to <tt>"/api/accounts"</tt>
|
277
|
+
# * +url+ - The +url+ on the server to Post to. To delete to <tt>"/accounts"</tt>
|
277
278
|
# pass <tt>"/accounts"</tt> as +url+
|
278
279
|
# * +body+ - A Ruby object which is converted into JSON and added in the request
|
279
280
|
# Body.
|
@@ -312,7 +313,7 @@ class MLS
|
|
312
313
|
def delete(url, body={}, *valid_response_codes, &block)
|
313
314
|
body ||= {}
|
314
315
|
|
315
|
-
req = Net::HTTP::Delete.new(
|
316
|
+
req = Net::HTTP::Delete.new(url)
|
316
317
|
req.body = Yajl::Encoder.encode(body)
|
317
318
|
prepare_request(req)
|
318
319
|
|
@@ -384,6 +385,9 @@ class MLS
|
|
384
385
|
end
|
385
386
|
end
|
386
387
|
|
388
|
+
cookie_jar[:api_session] = response['Set-Cookie'] if response['Set-Cookie']
|
389
|
+
cookie_jar[:api_session_id] = response['X-42Floors-API-Session-Id'] if response['X-42Floors-API-Session-Id']
|
390
|
+
|
387
391
|
response
|
388
392
|
end
|
389
393
|
|
data/mls.gemspec
CHANGED
data/test/test_helper.rb
CHANGED
@@ -13,7 +13,7 @@ require 'fakeweb'
|
|
13
13
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__),'../'))
|
14
14
|
require 'lib/mls/factories_helper'
|
15
15
|
|
16
|
-
MLS_HOST = ENV['MLS_URL'] || 'http://localhost:4000
|
16
|
+
MLS_HOST = ENV['MLS_URL'] || 'http://localhost:4000'
|
17
17
|
|
18
18
|
MLS.url = ENV["MLS_TEST_URL"] || 'http://LBJXFC%2BhDiRRCYj6kXtXREfgNXRCJa8ALvPn%2FIeyjSe2QsQyHZ%2F%2BWwN2VZM2cw%3D%3D@localhost:5000'#
|
19
19
|
# MLS.auth_cookie = MLS::Account.authenticate('jonbracy@gmail.com', 'test').auth_cookie
|
data/test/units/test_mls.rb
CHANGED
@@ -40,7 +40,7 @@ class TestMLS < ::Test::Unit::TestCase
|
|
40
40
|
FakeWeb.register_uri(:get, "#{MLS_HOST}/test?key=value", :body => 'get')
|
41
41
|
response = MLS.get('/test', :key => 'value')
|
42
42
|
|
43
|
-
assert_equal '/
|
43
|
+
assert_equal '/test?key=value', FakeWeb.last_request.path
|
44
44
|
end
|
45
45
|
|
46
46
|
test '#get to 404 raises MLS::Exception::NotFound' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mls
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.14.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James R. Bracy
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-08-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -275,7 +275,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
275
275
|
version: '0'
|
276
276
|
requirements: []
|
277
277
|
rubyforge_project: mls
|
278
|
-
rubygems_version: 2.2.
|
278
|
+
rubygems_version: 2.2.2
|
279
279
|
signing_key:
|
280
280
|
specification_version: 4
|
281
281
|
summary: 42Floors MLS Client
|