simplyrets 0.1
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 +7 -0
- data/#example.rb# +29 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +27 -0
- data/LICENSE +21 -0
- data/README.org +109 -0
- data/Rakefile +2 -0
- data/example.rb +26 -0
- data/lib/monkey.rb +90 -0
- data/lib/properties_api.rb +75 -0
- data/lib/simplyrets.rb +57 -0
- data/lib/simplyrets.rb~ +85 -0
- data/lib/simplyrets/configuration.rb +25 -0
- data/lib/simplyrets/request.rb +205 -0
- data/lib/simplyrets/response.rb +70 -0
- data/lib/simplyrets/version.rb +4 -0
- data/models/agent.rb +39 -0
- data/models/contactinformation.rb +36 -0
- data/models/geographicdata.rb +43 -0
- data/models/listing.rb +95 -0
- data/models/mlsinformation.rb +35 -0
- data/models/office.rb +39 -0
- data/models/property.rb +84 -0
- data/models/school.rb +27 -0
- data/models/streetaddress.rb +47 -0
- data/models/tax.rb +28 -0
- data/pkg/simplyrets-0.1.gem +0 -0
- data/simplyrets.gemspec +25 -0
- metadata +144 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b6c9398d25929ede70fc2f027ba8a048b72983fd
|
4
|
+
data.tar.gz: 9b7f142e7814cac26d553800a96505e171ce8ae8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 51d0f11bcc6eecd244d3ce9694396a335e90cbfc71a6a73d777d693be593545dbae2cc1b7baaeaecf1926082e055601560b3967853fcd47f9128e20481110f50
|
7
|
+
data.tar.gz: 432870f3d25ca223aea79c22e60127a015efddba29edf708662815f172158824619b00175eee1b253648d88e7bf03a465949d34e63a24eb5a7c9edfc349c0999
|
data/#example.rb#
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
%w(rubygems simplyrets).each {|lib| require lib}
|
4
|
+
%w(rubygems simplyrets).each {|models| require models}
|
5
|
+
|
6
|
+
require "simplyrets"
|
7
|
+
require "properties_api"
|
8
|
+
require "listing"
|
9
|
+
|
10
|
+
p "SimplyRETS Ruby SDK"
|
11
|
+
|
12
|
+
SimplyRets.configure do |config|
|
13
|
+
config.username = 'simplyrets'
|
14
|
+
config.password = 'simplyrets'
|
15
|
+
end
|
16
|
+
|
17
|
+
# Properties
|
18
|
+
listings = Properties_api.properties({:minbeds => 2,:brokers => [ "COLD09" ]})
|
19
|
+
listings.each do |l|
|
20
|
+
p l.property['bedrooms']
|
21
|
+
p l.office['brokerid']
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
# Single Properties
|
26
|
+
# Single Listing
|
27
|
+
p = Properties_api.property(47638976)
|
28
|
+
Agentlist 47638976
|
29
|
+
p "#{p.geo['lat']}, #{p.geo['lng']}"
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
simplyrets (0.1)
|
5
|
+
addressable (>= 2.3.4)
|
6
|
+
json (>= 1.8)
|
7
|
+
typhoeus (>= 0.2.1)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: http://rubygems.org/
|
11
|
+
specs:
|
12
|
+
addressable (2.3.7)
|
13
|
+
ethon (0.7.3)
|
14
|
+
ffi (>= 1.3.0)
|
15
|
+
ffi (1.9.8)
|
16
|
+
json (1.8.2)
|
17
|
+
rake (10.4.2)
|
18
|
+
typhoeus (0.7.1)
|
19
|
+
ethon (>= 0.7.1)
|
20
|
+
|
21
|
+
PLATFORMS
|
22
|
+
ruby
|
23
|
+
|
24
|
+
DEPENDENCIES
|
25
|
+
bundler
|
26
|
+
rake
|
27
|
+
simplyrets!
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 SimplyRETS Inc. <support@simplyrets.com>
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.org
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
#+AUTHOR: SimplyRETS, Christopher Reichert, Cody Reichert
|
2
|
+
#+TITLE: SimplyRETS Ruby SDK (Beta)
|
3
|
+
|
4
|
+
The official Ruby SDK for the [[https://simplrets.com][SimplyRETS]] Listings API.
|
5
|
+
|
6
|
+
SimplyRETS provides a modern and simple interface for building robust
|
7
|
+
applications and websites with Real Estate data.
|
8
|
+
|
9
|
+
** Installation
|
10
|
+
|
11
|
+
Clone the repo or install the =simplyrets= gem:
|
12
|
+
|
13
|
+
#+BEGIN_SRC bash
|
14
|
+
$ git clone git@github.com/SimplyRETS/simplyrets-ruby-sdk
|
15
|
+
#+END_SRC
|
16
|
+
or
|
17
|
+
#+BEGIN_SRC bash
|
18
|
+
$ gem install simplyrets
|
19
|
+
#+END_SRC
|
20
|
+
|
21
|
+
|
22
|
+
** Quick Start
|
23
|
+
|
24
|
+
Here's a quick example to set up the client and make a request:
|
25
|
+
|
26
|
+
#+BEGIN_SRC ruby
|
27
|
+
%w(rubygems simplyrets).each {|lib| require lib}
|
28
|
+
%w(rubygems simplyrets).each {|models| require models}
|
29
|
+
|
30
|
+
require "simplyrets"
|
31
|
+
require "properties_api"
|
32
|
+
require "listing"
|
33
|
+
|
34
|
+
SimplyRets.configure do |config|
|
35
|
+
config.username = 'simplyrets'
|
36
|
+
config.password = 'simplyrets'
|
37
|
+
end
|
38
|
+
|
39
|
+
# all properties
|
40
|
+
ps = Properties_api.properties()
|
41
|
+
p ps
|
42
|
+
#+END_SRC
|
43
|
+
|
44
|
+
|
45
|
+
** Setup the client
|
46
|
+
|
47
|
+
To start using the SDK, require =simplyrets= in your gemspec and
|
48
|
+
configure a client by setting your API key and API secret (we have
|
49
|
+
demo credentials available you can use for free!). Here's a short
|
50
|
+
example:
|
51
|
+
|
52
|
+
#+BEGIN_SRC ruby
|
53
|
+
require 'simplyrets'
|
54
|
+
|
55
|
+
SimplyRets.configure do |config|
|
56
|
+
config.username = 'simplyrets'
|
57
|
+
config.password = 'simplyrets'
|
58
|
+
end
|
59
|
+
#+END_SRC
|
60
|
+
|
61
|
+
|
62
|
+
** Examples: Making Requests
|
63
|
+
|
64
|
+
Once you have instantiated the API Client, you can use the
|
65
|
+
Properties API to make requests for multiple or single listings.
|
66
|
+
|
67
|
+
Request all listings with no filters:
|
68
|
+
#+BEGIN_SRC ruby
|
69
|
+
require 'properties_api'
|
70
|
+
|
71
|
+
ps = Properties_api.properties()
|
72
|
+
p ps
|
73
|
+
#+END_SRC
|
74
|
+
|
75
|
+
Request a single listing by id:
|
76
|
+
#+BEGIN_SRC ruby
|
77
|
+
l = Properties_api.property(mls_id=19548526)
|
78
|
+
p l.mls
|
79
|
+
#+END_SRC
|
80
|
+
|
81
|
+
|
82
|
+
Multiple query parameters can be sent to the API to request more
|
83
|
+
refined results:
|
84
|
+
#+BEGIN_SRC ruby
|
85
|
+
# listings with minprice of $700,000 and minbeds of 4
|
86
|
+
ps = Properties_api.properties({:minprice => 700000, :minbeds => 4})
|
87
|
+
p ps
|
88
|
+
#+END_SRC
|
89
|
+
|
90
|
+
Sending back points to get listings in a geographical area:
|
91
|
+
#+BEGIN_SRC ruby
|
92
|
+
# listings within geographics points
|
93
|
+
points = ["29.723837146389066,-95.69778442382812" ,"29.938275329718987,-95.778442382812" ,"29.938275329718987,-95.32974243164061","29.723837146389066,-95.32974243164061"]
|
94
|
+
ps = Properties_api.properties({:points => points})
|
95
|
+
p ps
|
96
|
+
#+END_SRC
|
97
|
+
|
98
|
+
|
99
|
+
** Additional Info
|
100
|
+
|
101
|
+
View the complete interactive API on [[https://docs.simplyrets.com/api/index.html][the docs page]]. Here you can
|
102
|
+
find all the available query parameters and the complete response
|
103
|
+
body. You can even see the URL made for that request.
|
104
|
+
|
105
|
+
|
106
|
+
** Support
|
107
|
+
|
108
|
+
For support regarding the API or bugs in the SDK, can contact us at
|
109
|
+
support (at) simplyrets (dot) com - or leave an issue on the [[https://github.com/simplyrets/simplyrets-ruby-sdk][Github page]]!
|
data/Rakefile
ADDED
data/example.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
%w(rubygems simplyrets).each {|lib| require lib}
|
4
|
+
%w(rubygems simplyrets).each {|models| require models}
|
5
|
+
|
6
|
+
require "simplyrets"
|
7
|
+
require "properties_api"
|
8
|
+
require "listing"
|
9
|
+
|
10
|
+
p "SimplyRETS Ruby SDK"
|
11
|
+
|
12
|
+
SimplyRets.configure do |config|
|
13
|
+
config.username = 'simplyrets'
|
14
|
+
config.password = 'simplyrets'
|
15
|
+
end
|
16
|
+
|
17
|
+
# Properties
|
18
|
+
listings = Properties_api.properties({:minbeds => 2,:brokers => [ "SR1234", "ACME12" ]})
|
19
|
+
listings.each do |l|
|
20
|
+
p l.property['bedrooms']
|
21
|
+
p l.office['brokerid']
|
22
|
+
end
|
23
|
+
|
24
|
+
# Single Listing
|
25
|
+
prop = Properties_api.property(47639002)
|
26
|
+
p "#{prop.geo['lat']}, #{prop.geo['lng']}"
|
data/lib/monkey.rb
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
# module SimplyRets
|
2
|
+
class Object
|
3
|
+
|
4
|
+
unless Object.method_defined? :blank?
|
5
|
+
def blank?
|
6
|
+
respond_to?(:empty?) ? empty? : !self
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
unless Object.method_defined? :present?
|
11
|
+
def present?
|
12
|
+
!blank?
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
class String
|
19
|
+
|
20
|
+
unless String.method_defined? :underscore
|
21
|
+
def underscore
|
22
|
+
self.gsub(/::/, '/').
|
23
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
24
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
25
|
+
tr("-", "_").
|
26
|
+
downcase
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
unless String.method_defined? :camelize
|
31
|
+
def camelize(first_letter_in_uppercase = true)
|
32
|
+
if first_letter_in_uppercase != :lower
|
33
|
+
self.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
|
34
|
+
else
|
35
|
+
self.to_s[0].chr.downcase + camelize(self)[1..-1]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
class Hash
|
43
|
+
|
44
|
+
unless Hash.method_defined? :stringify_keys
|
45
|
+
def stringify_keys
|
46
|
+
inject({}) do |options, (key, value)|
|
47
|
+
options[key.to_s] = value
|
48
|
+
options
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
unless Hash.method_defined? :stringify_keys!
|
54
|
+
def stringify_keys!
|
55
|
+
self.replace(self.stringify_keys)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
unless Hash.method_defined? :symbolize_keys
|
60
|
+
def symbolize_keys
|
61
|
+
inject({}) do |options, (key, value)|
|
62
|
+
options[(key.to_sym rescue key) || key] = value
|
63
|
+
options
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
unless Hash.method_defined? :symbolize_keys!
|
69
|
+
def symbolize_keys!
|
70
|
+
self.replace(self.symbolize_keys)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
unless Hash.method_defined? :symbolize_and_underscore_keys
|
75
|
+
def symbolize_and_underscore_keys
|
76
|
+
inject({}) do |options, (key, value)|
|
77
|
+
options[(key.to_s.underscore.to_sym rescue key) || key] = value
|
78
|
+
options
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
unless Hash.method_defined? :symbolize_and_underscore_keys!
|
84
|
+
def symbolize_and_underscore_keys!
|
85
|
+
self.replace(self.symbolize_and_underscore_keys)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
# end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require "uri"
|
2
|
+
|
3
|
+
class Properties_api
|
4
|
+
basePath = "https://api.simplyrets.com"
|
5
|
+
|
6
|
+
def self.escapeString(string)
|
7
|
+
URI.encode(string.to_s)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.properties (opts={})
|
11
|
+
query_param_keys = [:brokers,:features,:amenities,:agent,:maxarea,
|
12
|
+
:minarea,:minprice,:minbaths,:maxbeds,:minbeds,
|
13
|
+
:neighborhoods,:points,:counties,:status,:type,:q]
|
14
|
+
|
15
|
+
# set default values and merge with input
|
16
|
+
options = {
|
17
|
+
:brokers => nil ,
|
18
|
+
:features => nil ,
|
19
|
+
:amenities => nil ,
|
20
|
+
:agent => nil ,
|
21
|
+
:maxarea => nil ,
|
22
|
+
:minarea => nil ,
|
23
|
+
:minprice => nil ,
|
24
|
+
:minbaths => nil ,
|
25
|
+
:maxbeds => nil ,
|
26
|
+
:minbeds => nil ,
|
27
|
+
:neighborhoods => nil ,
|
28
|
+
:points => nil ,
|
29
|
+
:counties => nil ,
|
30
|
+
:status => nil ,
|
31
|
+
:type => nil ,
|
32
|
+
:q => nil }.merge(opts)
|
33
|
+
|
34
|
+
#resource path
|
35
|
+
path = "/properties".sub('{format}','json')
|
36
|
+
|
37
|
+
# pull querystring keys from options
|
38
|
+
queryopts = options.select do |key,value|
|
39
|
+
query_param_keys.include? key
|
40
|
+
end
|
41
|
+
|
42
|
+
headers = nil
|
43
|
+
post_body = nil
|
44
|
+
response = SimplyRets::Request.new(:GET, path,{:params=>queryopts, :headers=>headers, :body=>post_body }).make.body
|
45
|
+
response.map {|response|Listing.new(response)}
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.property (mls_id=nil,opts={})
|
50
|
+
query_param_keys = []
|
51
|
+
|
52
|
+
# verify existence of params
|
53
|
+
raise "mls_id is required" if mls_id.nil?
|
54
|
+
|
55
|
+
# set default values and merge with input
|
56
|
+
options = {
|
57
|
+
:mls_id => nil
|
58
|
+
}.merge(opts)
|
59
|
+
|
60
|
+
#resource path
|
61
|
+
path = "/properties/{mlsId}".sub('{format}','json').sub('{' + 'mlsId' + '}', escapeString(mls_id))
|
62
|
+
|
63
|
+
# pull querystring keys from options
|
64
|
+
queryopts = options.select do |key,value|
|
65
|
+
query_param_keys.include? key
|
66
|
+
end
|
67
|
+
|
68
|
+
headers = nil
|
69
|
+
post_body = nil
|
70
|
+
response = SimplyRets::Request.new(:GET, path, {:params=>queryopts,:headers=>headers, :body=>post_body }).make.body
|
71
|
+
Listing.new(response)
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
data/lib/simplyrets.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
|
2
|
+
require 'monkey'
|
3
|
+
require 'simplyrets/configuration'
|
4
|
+
require 'simplyrets/request'
|
5
|
+
require 'simplyrets/response'
|
6
|
+
require 'simplyrets/version'
|
7
|
+
require 'logger'
|
8
|
+
|
9
|
+
module SimplyRets
|
10
|
+
|
11
|
+
class << self
|
12
|
+
attr_accessor :logger
|
13
|
+
|
14
|
+
# A SimplyRets configuration object. Must act like a hash and
|
15
|
+
# return sensible values for all SimplyRets configuration
|
16
|
+
# options. See SimplyRets::Configuration.
|
17
|
+
attr_accessor :configuration
|
18
|
+
|
19
|
+
attr_accessor :resources
|
20
|
+
|
21
|
+
# Call this method to modify defaults in your initializers.
|
22
|
+
#
|
23
|
+
# @example
|
24
|
+
# SimplyRets.configure do |config|
|
25
|
+
# config.username = 'simplyrets'
|
26
|
+
# config.password = 'simplyrets'
|
27
|
+
# config.format = 'json' # optional, defaults to 'json'
|
28
|
+
# end
|
29
|
+
#
|
30
|
+
def configure
|
31
|
+
self.configuration ||= Configuration.new
|
32
|
+
yield(configuration) if block_given?
|
33
|
+
|
34
|
+
# Configure logger. Default to use Rails
|
35
|
+
self.logger ||= configuration.logger || (defined?(Rails) ? Rails.logger : Logger.new(STDOUT))
|
36
|
+
|
37
|
+
# remove :// from scheme
|
38
|
+
configuration.scheme.sub!(/:\/\//, '')
|
39
|
+
|
40
|
+
# remove http(s):// and anything after a slash
|
41
|
+
configuration.host.sub!(/https?:\/\//, '')
|
42
|
+
configuration.host = configuration.host.split('/').first
|
43
|
+
|
44
|
+
# Add leading and trailing slashes to base_path
|
45
|
+
configuration.base_path = "/#{configuration.base_path}".gsub(/\/+/, '/')
|
46
|
+
configuration.base_path = "" if configuration.base_path == "/"
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
class ServerError < StandardError
|
54
|
+
end
|
55
|
+
|
56
|
+
class ClientError < StandardError
|
57
|
+
end
|