simplyrets 0.1 → 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/Gemfile.lock +46 -13
- data/README.org +6 -6
- data/example.rb +9 -9
- data/lib/simplyrets.rb +33 -56
- data/lib/simplyrets/#listing.rb# +199 -0
- data/lib/simplyrets/api/default_api.rb +154 -0
- data/lib/simplyrets/listing.rb~ +199 -0
- data/lib/simplyrets/models/agent.rb +61 -0
- data/lib/simplyrets/models/base_object.rb +87 -0
- data/lib/simplyrets/models/broker.rb +37 -0
- data/lib/simplyrets/models/contact_information.rb +53 -0
- data/lib/simplyrets/models/error.rb +45 -0
- data/lib/simplyrets/models/geographic_data.rb +69 -0
- data/lib/simplyrets/models/listing.rb +199 -0
- data/lib/simplyrets/models/listing.rb~ +199 -0
- data/lib/simplyrets/models/mls_information.rb +69 -0
- data/lib/simplyrets/models/office.rb +61 -0
- data/lib/simplyrets/models/open_house.rb +37 -0
- data/lib/simplyrets/models/parking.rb +53 -0
- data/lib/simplyrets/models/property.rb +277 -0
- data/lib/simplyrets/models/sales.rb +69 -0
- data/lib/simplyrets/models/school.rb +61 -0
- data/lib/simplyrets/models/street_address.rb +85 -0
- data/lib/simplyrets/models/tax.rb +53 -0
- data/lib/simplyrets/simplyrets.rb +76 -0
- data/lib/simplyrets/simplyrets/api_error.rb +26 -0
- data/lib/simplyrets/simplyrets/configuration.rb +101 -0
- data/lib/simplyrets/simplyrets/request.rb +213 -0
- data/lib/simplyrets/simplyrets/response.rb +156 -0
- data/lib/simplyrets/simplyrets/version.rb +5 -0
- data/simplyrets.gemspec +16 -9
- metadata +153 -36
- data/#example.rb# +0 -29
- data/lib/monkey.rb +0 -90
- data/lib/properties_api.rb +0 -75
- data/lib/simplyrets.rb~ +0 -85
- data/lib/simplyrets/configuration.rb +0 -25
- data/lib/simplyrets/request.rb +0 -205
- data/lib/simplyrets/response.rb +0 -70
- data/lib/simplyrets/version.rb +0 -4
- data/models/agent.rb +0 -39
- data/models/contactinformation.rb +0 -36
- data/models/geographicdata.rb +0 -43
- data/models/listing.rb +0 -95
- data/models/mlsinformation.rb +0 -35
- data/models/office.rb +0 -39
- data/models/property.rb +0 -84
- data/models/school.rb +0 -27
- data/models/streetaddress.rb +0 -47
- data/models/tax.rb +0 -28
- data/pkg/simplyrets-0.1.gem +0 -0
@@ -0,0 +1,154 @@
|
|
1
|
+
require "uri"
|
2
|
+
|
3
|
+
module SimplyRetsClient
|
4
|
+
class Properties_api
|
5
|
+
|
6
|
+
# The SimplyRets Listings API
|
7
|
+
# This is the main endpoint for accessing your properties. View\nall of the available query parameters and make requests below!\nThe API uses Basic Authorization, which most HTTP libraries\nwill handle for you. To use the test test data (which is what\nthis pages uses), you can use the api key `simplyrets` and\nsecret `simplyrets`. Note that the test listings are not live\nMLS listings but the data, query parameters, and response\nbodies will all work the same.\n
|
8
|
+
# @param [Hash] opts the optional parameters
|
9
|
+
# @option opts [String] :q A fuzzy keyword search.\n
|
10
|
+
# @option opts [Integer] :minprice Filter listings by a minimum price.\n
|
11
|
+
# @option opts [Integer] :maxprice Filter listings by a maximum price\n
|
12
|
+
# @option opts [String] :agent Filter the listings returned by an agent ID. Note, the\nAgent ID is provided by your MLS.\n
|
13
|
+
# @option opts [Integer] :minarea Filter listings by a minimum area size in Sq Ft.\n
|
14
|
+
# @option opts [Integer] :maxarea Filter listings by a maximum area size in Sq Ft.\n
|
15
|
+
# @option opts [Integer] :minbaths Filter listings by a minimum number of bathrooms.\n
|
16
|
+
# @option opts [Integer] :maxbaths Filter listings by a maximum number of bathrooms.\n
|
17
|
+
# @option opts [Integer] :mineds Filter listings by a minimum number of bedrooms.\n
|
18
|
+
# @option opts [Integer] :maxbeds Filter listings by a maximum number of bedrooms.\n
|
19
|
+
# @option opts [Integer] :limit Set the number of listings to return in the response.\nThis defaults to 20 listings, and can be a maximum of 50.\nTo paginate through to the next page of listings, take a\nlook at the `offset` parameter, or the Link in the HTTP\nHeader.\n
|
20
|
+
# @option opts [Integer] :offset Used as a cursor for pagination. Increase the offset parameter\nby the limit to go to the next \"page\" of listings. Also take\na look at the Link HTTP Header for pre-built pagination.\n
|
21
|
+
# @option opts [Array<String>] :brokers Filter the listings returned by brokerage with a Broker ID.\nYou can specific multiple broker parameters. Note, the Broker\nID is provided by your MLS.\n
|
22
|
+
# @option opts [Array<String>] :features Filter the listings returned by specific features. You\ncan specify multiple.\n
|
23
|
+
# @option opts [Array<String>] :amenities Filter the listings returned by specific amenities. You\ncan specify multiple amenities.\n
|
24
|
+
# @option opts [Array<String>] :neighborhoods Filter the listings returned by specific neighborhoods and\nsubdivisions. You can specify multiple.\n
|
25
|
+
# @option opts [Array<String>] :points A list of latitude longitude coordinates which contain\nthe property. Our documentation generator does not yet\nsupport using a list of parameters.\n
|
26
|
+
# @option opts [Array<String>] :counties Filter the listings returned by specific counties. You can\nspecify multiple.\n
|
27
|
+
# @option opts [String] :status Request listings by a specific status. This defaults to\nactive and you can only specify one status in a single\nquery.\n
|
28
|
+
# @option opts [String] :type Request listings by a specific property type. This\ndefaults to Residential, and you can only specify one type\nin a single query.\n
|
29
|
+
# @option opts [String] :sort Sort the response by a specific field. Values starting\nwith a minus (-) denote descending order, while the others\nare ascending.\n
|
30
|
+
# @option opts [String] :include Include a limited set of extra fields which are not found\nin the default response body\n- 'rooms' include parameter will include\n any additional rooms as a list.\n- 'pool' includes an additional pool description\n- 'association' includes additional home owners association data\n
|
31
|
+
# @return [Array<Listing>]
|
32
|
+
def self.properties(opts = {})
|
33
|
+
if SimplyRets.configuration.debug
|
34
|
+
SimplyRets.logger.debug "Calling API: DefaultApi#properties ..."
|
35
|
+
end
|
36
|
+
|
37
|
+
if opts[:'status'] && !['Active', 'Pending', 'Closed'].include?(opts[:'status'])
|
38
|
+
fail 'invalid value for "status", must be one of Active, Pending, Closed'
|
39
|
+
end
|
40
|
+
|
41
|
+
if opts[:'type'] && !['Residential', 'Rential', 'Multifamily', 'Condominium', 'Commercial', 'Land'].include?(opts[:'type'])
|
42
|
+
fail 'invalid value for "type", must be one of Residential, Rential, Multifamily, Condominium, Commercial, Land'
|
43
|
+
end
|
44
|
+
|
45
|
+
if opts[:'sort'] && !['listprice', '-listprice', 'listdate', '-listdate', 'beds', '-beds', 'baths', '-baths'].include?(opts[:'sort'])
|
46
|
+
fail 'invalid value for "sort", must be one of listprice, -listprice, listdate, -listdate, beds, -beds, baths, -baths'
|
47
|
+
end
|
48
|
+
|
49
|
+
if opts[:'include'] && !['pool', 'rooms', 'association'].include?(opts[:'include'])
|
50
|
+
fail 'invalid value for "include", must be one of pool, rooms, association'
|
51
|
+
end
|
52
|
+
|
53
|
+
# resource path
|
54
|
+
path = "/properties".sub('{format}','json')
|
55
|
+
|
56
|
+
# query parameters
|
57
|
+
query_params = {}
|
58
|
+
query_params[:'q'] = opts[:'q'] if opts[:'q']
|
59
|
+
query_params[:'minprice'] = opts[:'minprice'] if opts[:'minprice']
|
60
|
+
query_params[:'maxprice'] = opts[:'maxprice'] if opts[:'maxprice']
|
61
|
+
query_params[:'agent'] = opts[:'agent'] if opts[:'agent']
|
62
|
+
query_params[:'minarea'] = opts[:'minarea'] if opts[:'minarea']
|
63
|
+
query_params[:'maxarea'] = opts[:'maxarea'] if opts[:'maxarea']
|
64
|
+
query_params[:'minbaths'] = opts[:'minbaths'] if opts[:'minbaths']
|
65
|
+
query_params[:'maxbaths'] = opts[:'maxbaths'] if opts[:'maxbaths']
|
66
|
+
query_params[:'mineds'] = opts[:'mineds'] if opts[:'mineds']
|
67
|
+
query_params[:'maxbeds'] = opts[:'maxbeds'] if opts[:'maxbeds']
|
68
|
+
query_params[:'limit'] = opts[:'limit'] if opts[:'limit']
|
69
|
+
query_params[:'offset'] = opts[:'offset'] if opts[:'offset']
|
70
|
+
query_params[:'brokers'] = opts[:'brokers'] if opts[:'brokers']
|
71
|
+
query_params[:'features'] = opts[:'features'] if opts[:'features']
|
72
|
+
query_params[:'amenities'] = opts[:'amenities'] if opts[:'amenities']
|
73
|
+
query_params[:'neighborhoods'] = opts[:'neighborhoods'] if opts[:'neighborhoods']
|
74
|
+
query_params[:'points'] = opts[:'points'] if opts[:'points']
|
75
|
+
query_params[:'counties'] = opts[:'counties'] if opts[:'counties']
|
76
|
+
query_params[:'status'] = opts[:'status'] if opts[:'status']
|
77
|
+
query_params[:'type'] = opts[:'type'] if opts[:'type']
|
78
|
+
query_params[:'sort'] = opts[:'sort'] if opts[:'sort']
|
79
|
+
query_params[:'include'] = opts[:'include'] if opts[:'include']
|
80
|
+
|
81
|
+
# header parameters
|
82
|
+
header_params = {}
|
83
|
+
|
84
|
+
# HTTP header 'Accept' (if needed)
|
85
|
+
_header_accept = []
|
86
|
+
_header_accept_result = SimplyRets::Request.select_header_accept(_header_accept) and header_params['Accept'] = _header_accept_result
|
87
|
+
|
88
|
+
# HTTP header 'Content-Type'
|
89
|
+
_header_content_type = []
|
90
|
+
header_params['Content-Type'] = SimplyRets::Request.select_header_content_type(_header_content_type)
|
91
|
+
|
92
|
+
# form parameters
|
93
|
+
form_params = {}
|
94
|
+
|
95
|
+
# http body (model)
|
96
|
+
post_body = nil
|
97
|
+
|
98
|
+
|
99
|
+
auth_names = ['basicAuth']
|
100
|
+
response = SimplyRets::Request.new(:GET, path, {:params => query_params, :headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make
|
101
|
+
result = response.deserialize('Array<Listing>')
|
102
|
+
if SimplyRets.configuration.debug
|
103
|
+
SimplyRets.logger.debug "API called: DefaultApi#properties. Result: #{result.inspect}"
|
104
|
+
end
|
105
|
+
result
|
106
|
+
end
|
107
|
+
|
108
|
+
# Single Listing Endpoint
|
109
|
+
# Use this endpoint for accessing a single listing.\n
|
110
|
+
# @param listing_id A listings listingId (unique indentifier).
|
111
|
+
# @param [Hash] opts the optional parameters
|
112
|
+
# @return [Listing]
|
113
|
+
def self.property(listing_id, opts = {})
|
114
|
+
if SimplyRets.configuration.debug
|
115
|
+
SimplyRets.logger.debug "Calling API: DefaultApi#property ..."
|
116
|
+
end
|
117
|
+
|
118
|
+
# verify the required parameter 'listing_id' is set
|
119
|
+
fail "Missing the required parameter 'listing_id' when calling property" if listing_id.nil?
|
120
|
+
|
121
|
+
# resource path
|
122
|
+
path = "/properties/{listingId}".sub('{format}','json').sub('{' + 'listingId' + '}', listing_id.to_s)
|
123
|
+
|
124
|
+
# query parameters
|
125
|
+
query_params = {}
|
126
|
+
|
127
|
+
# header parameters
|
128
|
+
header_params = {}
|
129
|
+
|
130
|
+
# HTTP header 'Accept' (if needed)
|
131
|
+
_header_accept = []
|
132
|
+
_header_accept_result = SimplyRets::Request.select_header_accept(_header_accept) and header_params['Accept'] = _header_accept_result
|
133
|
+
|
134
|
+
# HTTP header 'Content-Type'
|
135
|
+
_header_content_type = []
|
136
|
+
header_params['Content-Type'] = SimplyRets::Request.select_header_content_type(_header_content_type)
|
137
|
+
|
138
|
+
# form parameters
|
139
|
+
form_params = {}
|
140
|
+
|
141
|
+
# http body (model)
|
142
|
+
post_body = nil
|
143
|
+
|
144
|
+
|
145
|
+
auth_names = ['basicAuth']
|
146
|
+
response = SimplyRets::Request.new(:GET, path, {:params => query_params, :headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make
|
147
|
+
result = response.deserialize('Listing')
|
148
|
+
if SimplyRets.configuration.debug
|
149
|
+
SimplyRets.logger.debug "API called: DefaultApi#property. Result: #{result.inspect}"
|
150
|
+
end
|
151
|
+
result
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
@@ -0,0 +1,199 @@
|
|
1
|
+
module SwaggerClient
|
2
|
+
#
|
3
|
+
class Listing < BaseObject
|
4
|
+
attr_accessor :property, :mls_id, :showing_instructions, :office, :disclaimer, :address, :list_date, :agent, :modified, :school, :sales, :photos, :list_price, :listing_id, :mls, :geo, :tax, :remarks, :private_remarks, :lease_term, :lease_type
|
5
|
+
# attribute mapping from ruby-style variable name to JSON key
|
6
|
+
def self.attribute_map
|
7
|
+
{
|
8
|
+
|
9
|
+
# Specific property data associated with listing.
|
10
|
+
:'property' => :'property',
|
11
|
+
|
12
|
+
# A unique identifier for this listing specific to the SimplyRETS API.\n
|
13
|
+
:'mls_id' => :'mlsId',
|
14
|
+
|
15
|
+
# Public instructions for showing the property.
|
16
|
+
:'showing_instructions' => :'showingInstructions',
|
17
|
+
|
18
|
+
# Listing office or brokerage.
|
19
|
+
:'office' => :'office',
|
20
|
+
|
21
|
+
# Data accuracy disclaimer. The value in the disclaimer may\nchange depending on your MLS vendors rules.\n
|
22
|
+
:'disclaimer' => :'disclaimer',
|
23
|
+
|
24
|
+
# Comprehensive property address information
|
25
|
+
:'address' => :'address',
|
26
|
+
|
27
|
+
# Date and time the listing became Active
|
28
|
+
:'list_date' => :'listDate',
|
29
|
+
|
30
|
+
# Comprehensive listing agent information
|
31
|
+
:'agent' => :'agent',
|
32
|
+
|
33
|
+
# Date and time of the last modification
|
34
|
+
:'modified' => :'modified',
|
35
|
+
|
36
|
+
# Comprehensive school zone data
|
37
|
+
:'school' => :'school',
|
38
|
+
|
39
|
+
# Sales data
|
40
|
+
:'sales' => :'sales',
|
41
|
+
|
42
|
+
# Photos of the property. Images are served over https and are\nsuitable for production use on secure websites\n
|
43
|
+
:'photos' => :'photos',
|
44
|
+
|
45
|
+
# Price of the listing
|
46
|
+
:'list_price' => :'listPrice',
|
47
|
+
|
48
|
+
# Data Dictionary v1.3 ListingId. The well known identifier\nfor the listing. The value may be identical to\nmlsId. However, listingId is intended to be the value used\nby a human to retrieve the information about a specific\nlisting.\n
|
49
|
+
:'listing_id' => :'listingId',
|
50
|
+
|
51
|
+
# MLS vendor information and data
|
52
|
+
:'mls' => :'mls',
|
53
|
+
|
54
|
+
# Geographic data for the listing
|
55
|
+
:'geo' => :'geo',
|
56
|
+
|
57
|
+
# Associate tax data
|
58
|
+
:'tax' => :'tax',
|
59
|
+
|
60
|
+
# Description or remarks
|
61
|
+
:'remarks' => :'remarks',
|
62
|
+
|
63
|
+
# Agent only remarks
|
64
|
+
:'private_remarks' => :'privateRemarks',
|
65
|
+
|
66
|
+
#
|
67
|
+
:'lease_term' => :'leaseTerm',
|
68
|
+
|
69
|
+
#
|
70
|
+
:'lease_type' => :'leaseType'
|
71
|
+
|
72
|
+
}
|
73
|
+
end
|
74
|
+
|
75
|
+
# attribute type
|
76
|
+
def self.swagger_types
|
77
|
+
{
|
78
|
+
:'property' => :'Property',
|
79
|
+
:'mls_id' => :'Integer',
|
80
|
+
:'showing_instructions' => :'String',
|
81
|
+
:'office' => :'Office',
|
82
|
+
:'disclaimer' => :'String',
|
83
|
+
:'address' => :'StreetAddress',
|
84
|
+
:'list_date' => :'DateTime',
|
85
|
+
:'agent' => :'Agent',
|
86
|
+
:'modified' => :'DateTime',
|
87
|
+
:'school' => :'School',
|
88
|
+
:'sales' => :'Sales',
|
89
|
+
:'photos' => :'Array<String>',
|
90
|
+
:'list_price' => :'Float',
|
91
|
+
:'listing_id' => :'String',
|
92
|
+
:'mls' => :'MlsInformation',
|
93
|
+
:'geo' => :'GeographicData',
|
94
|
+
:'tax' => :'Tax',
|
95
|
+
:'remarks' => :'String',
|
96
|
+
:'private_remarks' => :'String',
|
97
|
+
:'lease_term' => :'String',
|
98
|
+
:'lease_type' => :'String'
|
99
|
+
|
100
|
+
}
|
101
|
+
end
|
102
|
+
|
103
|
+
def initialize(attributes = {})
|
104
|
+
return if !attributes.is_a?(Hash) || attributes.empty?
|
105
|
+
|
106
|
+
# convert string to symbol for hash key
|
107
|
+
attributes = attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
|
108
|
+
|
109
|
+
|
110
|
+
if attributes[:'property']
|
111
|
+
self.property = attributes[:'property']
|
112
|
+
end
|
113
|
+
|
114
|
+
if attributes[:'mlsId']
|
115
|
+
self.mls_id = attributes[:'mlsId']
|
116
|
+
end
|
117
|
+
|
118
|
+
if attributes[:'showingInstructions']
|
119
|
+
self.showing_instructions = attributes[:'showingInstructions']
|
120
|
+
end
|
121
|
+
|
122
|
+
if attributes[:'office']
|
123
|
+
self.office = attributes[:'office']
|
124
|
+
end
|
125
|
+
|
126
|
+
if attributes[:'disclaimer']
|
127
|
+
self.disclaimer = attributes[:'disclaimer']
|
128
|
+
end
|
129
|
+
|
130
|
+
if attributes[:'address']
|
131
|
+
self.address = attributes[:'address']
|
132
|
+
end
|
133
|
+
|
134
|
+
if attributes[:'listDate']
|
135
|
+
self.list_date = attributes[:'listDate']
|
136
|
+
end
|
137
|
+
|
138
|
+
if attributes[:'agent']
|
139
|
+
self.agent = attributes[:'agent']
|
140
|
+
end
|
141
|
+
|
142
|
+
if attributes[:'modified']
|
143
|
+
self.modified = attributes[:'modified']
|
144
|
+
end
|
145
|
+
|
146
|
+
if attributes[:'school']
|
147
|
+
self.school = attributes[:'school']
|
148
|
+
end
|
149
|
+
|
150
|
+
if attributes[:'sales']
|
151
|
+
self.sales = attributes[:'sales']
|
152
|
+
end
|
153
|
+
|
154
|
+
if attributes[:'photos']
|
155
|
+
if (value = attributes[:'photos']).is_a?(Array)
|
156
|
+
self.photos = value
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
if attributes[:'listPrice']
|
161
|
+
self.list_price = attributes[:'listPrice']
|
162
|
+
end
|
163
|
+
|
164
|
+
if attributes[:'listingId']
|
165
|
+
self.listing_id = attributes[:'listingId']
|
166
|
+
end
|
167
|
+
|
168
|
+
if attributes[:'mls']
|
169
|
+
self.mls = attributes[:'mls']
|
170
|
+
end
|
171
|
+
|
172
|
+
if attributes[:'geo']
|
173
|
+
self.geo = attributes[:'geo']
|
174
|
+
end
|
175
|
+
|
176
|
+
if attributes[:'tax']
|
177
|
+
self.tax = attributes[:'tax']
|
178
|
+
end
|
179
|
+
|
180
|
+
if attributes[:'remarks']
|
181
|
+
self.remarks = attributes[:'remarks']
|
182
|
+
end
|
183
|
+
|
184
|
+
if attributes[:'privateRemarks']
|
185
|
+
self.private_remarks = attributes[:'privateRemarks']
|
186
|
+
end
|
187
|
+
|
188
|
+
if attributes[:'leaseTerm']
|
189
|
+
self.lease_term = attributes[:'leaseTerm']
|
190
|
+
end
|
191
|
+
|
192
|
+
if attributes[:'leaseType']
|
193
|
+
self.lease_type = attributes[:'leaseType']
|
194
|
+
end
|
195
|
+
|
196
|
+
end
|
197
|
+
|
198
|
+
end
|
199
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module SimplyRetsClient
|
2
|
+
#
|
3
|
+
class Agent < BaseObject
|
4
|
+
attr_accessor :last_name, :contact, :first_name, :id
|
5
|
+
# attribute mapping from ruby-style variable name to JSON key
|
6
|
+
def self.attribute_map
|
7
|
+
{
|
8
|
+
|
9
|
+
# Agent last name
|
10
|
+
:'last_name' => :'lastName',
|
11
|
+
|
12
|
+
# Agent contact info. This information is only present when\nyour RETS feed specifies the agent wishes to show their\ncontact information publicly.\n
|
13
|
+
:'contact' => :'contact',
|
14
|
+
|
15
|
+
# Agent first name
|
16
|
+
:'first_name' => :'firstName',
|
17
|
+
|
18
|
+
# Well known Agent MLS number or id.
|
19
|
+
:'id' => :'id'
|
20
|
+
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
# attribute type
|
25
|
+
def self.simplyrets_types
|
26
|
+
{
|
27
|
+
:'last_name' => :'String',
|
28
|
+
:'contact' => :'ContactInformation',
|
29
|
+
:'first_name' => :'String',
|
30
|
+
:'id' => :'String'
|
31
|
+
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
def initialize(attributes = {})
|
36
|
+
return if !attributes.is_a?(Hash) || attributes.empty?
|
37
|
+
|
38
|
+
# convert string to symbol for hash key
|
39
|
+
attributes = attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
|
40
|
+
|
41
|
+
|
42
|
+
if attributes[:'lastName']
|
43
|
+
self.last_name = attributes[:'lastName']
|
44
|
+
end
|
45
|
+
|
46
|
+
if attributes[:'contact']
|
47
|
+
self.contact = attributes[:'contact']
|
48
|
+
end
|
49
|
+
|
50
|
+
if attributes[:'firstName']
|
51
|
+
self.first_name = attributes[:'firstName']
|
52
|
+
end
|
53
|
+
|
54
|
+
if attributes[:'id']
|
55
|
+
self.id = attributes[:'id']
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'date'
|
2
|
+
|
3
|
+
module SimplyRetsClient
|
4
|
+
# base class containing fundamental method such as to_hash, build_from_hash and more
|
5
|
+
class BaseObject
|
6
|
+
|
7
|
+
# build the object from hash
|
8
|
+
def build_from_hash(attributes)
|
9
|
+
return nil unless attributes.is_a?(Hash)
|
10
|
+
self.class.simplyrets_types.each_pair do |key, type|
|
11
|
+
if type =~ /^Array<(.*)>/i
|
12
|
+
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
13
|
+
self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
|
14
|
+
else
|
15
|
+
#TODO show warning in debug mode
|
16
|
+
end
|
17
|
+
elsif !attributes[self.class.attribute_map[key]].nil?
|
18
|
+
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
19
|
+
else
|
20
|
+
# data not found in attributes(hash), not an issue as the data can be optional
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
self
|
25
|
+
end
|
26
|
+
|
27
|
+
def _deserialize(type, value)
|
28
|
+
case type.to_sym
|
29
|
+
when :DateTime
|
30
|
+
DateTime.parse(value)
|
31
|
+
when :Date
|
32
|
+
Date.parse(value)
|
33
|
+
when :String
|
34
|
+
value.to_s
|
35
|
+
when :Integer
|
36
|
+
value.to_i
|
37
|
+
when :Float
|
38
|
+
value.to_f
|
39
|
+
when :BOOLEAN
|
40
|
+
if value =~ /^(true|t|yes|y|1)$/i
|
41
|
+
true
|
42
|
+
else
|
43
|
+
false
|
44
|
+
end
|
45
|
+
else # model
|
46
|
+
_model = SimplyRetsClient.const_get(type).new
|
47
|
+
_model.build_from_hash(value)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def to_s
|
52
|
+
to_hash.to_s
|
53
|
+
end
|
54
|
+
|
55
|
+
# to_body is an alias to to_body (backward compatibility))
|
56
|
+
def to_body
|
57
|
+
to_hash
|
58
|
+
end
|
59
|
+
|
60
|
+
# return the object in the form of hash
|
61
|
+
def to_hash
|
62
|
+
hash = {}
|
63
|
+
self.class.attribute_map.each_pair do |key, value|
|
64
|
+
if self.send(key).is_a?(Array)
|
65
|
+
next if self.send(key).empty?
|
66
|
+
hash[value] = self.send(key).select{|v| !v.nil?}.map{ |v| _to_hash v} unless self.send(key).nil?
|
67
|
+
else
|
68
|
+
unless (_tmp_value = _to_hash self.send(key)).nil?
|
69
|
+
hash[value] = _tmp_value
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
hash
|
74
|
+
end
|
75
|
+
|
76
|
+
# Method to output non-array value in the form of hash
|
77
|
+
# For object, use to_hash. Otherwise, just return the value
|
78
|
+
def _to_hash(value)
|
79
|
+
if value.respond_to? :to_hash
|
80
|
+
value.to_hash
|
81
|
+
else
|
82
|
+
value
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
end
|