simplyrets 1.0.7 → 2.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 +23 -21
- data/Makefile +48 -0
- data/README.org +5 -58
- data/example.rb +14 -4
- data/lib/simplyrets.rb +42 -21
- data/lib/simplyrets/api/default_api.rb +292 -59
- data/lib/simplyrets/api_client.rb +370 -0
- data/lib/simplyrets/api_error.rb +36 -0
- data/lib/simplyrets/configuration.rb +170 -0
- data/lib/simplyrets/models/agent.rb +146 -11
- data/lib/simplyrets/models/broker.rb +133 -7
- data/lib/simplyrets/models/contact_information.rb +149 -17
- data/lib/simplyrets/models/error.rb +138 -9
- data/lib/simplyrets/models/geographic_data.rb +150 -12
- data/lib/simplyrets/models/listing.rb +248 -49
- data/lib/simplyrets/models/mls_information.rb +148 -12
- data/lib/simplyrets/models/office.rb +146 -11
- data/lib/simplyrets/models/open_house.rb +215 -12
- data/lib/simplyrets/models/parking.rb +148 -17
- data/lib/simplyrets/models/property.rb +353 -129
- data/lib/simplyrets/models/sales.rb +163 -25
- data/lib/simplyrets/models/school.rb +167 -24
- data/lib/simplyrets/models/street_address.rb +204 -26
- data/lib/simplyrets/models/tax.rb +150 -18
- data/lib/simplyrets/version.rb +15 -0
- data/multi-query-param.patch +44 -0
- data/simplyrets.gemspec +4 -4
- data/spec/api/default_api_spec.rb +172 -0
- data/spec/models/agent_spec.rb +75 -0
- data/spec/models/broker_spec.rb +45 -0
- data/spec/models/contact_information_spec.rb +65 -0
- data/spec/models/error_spec.rb +55 -0
- data/spec/models/geographic_data_spec.rb +85 -0
- data/spec/models/listing_spec.rb +245 -0
- data/spec/models/mls_information_spec.rb +75 -0
- data/spec/models/office_spec.rb +75 -0
- data/spec/models/open_house_spec.rb +115 -0
- data/spec/models/parking_spec.rb +65 -0
- data/spec/models/property_spec.rb +365 -0
- data/spec/models/sales_spec.rb +85 -0
- data/spec/models/school_spec.rb +75 -0
- data/spec/models/street_address_spec.rb +105 -0
- data/spec/models/tax_spec.rb +65 -0
- data/spec/spec_helper.rb +78 -0
- metadata +33 -18
- data/lib/simplyrets.rb~ +0 -34
- data/lib/simplyrets/api/#default_api.rb# +0 -146
- data/lib/simplyrets/simplyrets/api_error.rb +0 -26
- data/lib/simplyrets/simplyrets/configuration.rb +0 -101
- data/lib/simplyrets/simplyrets/request.rb +0 -248
- data/lib/simplyrets/simplyrets/response.rb +0 -156
- data/lib/simplyrets/simplyrets/version.rb +0 -5
- data/simplyrets-1.0.6.gem +0 -0
@@ -0,0 +1,370 @@
|
|
1
|
+
=begin
|
2
|
+
SimplyRETS API
|
3
|
+
|
4
|
+
The SimplyRETS API is an exciting step towards making it easier for\ndevelopers and real estate agents to build something awesome with\nreal estate data!\n\nThe documentation below makes live requests to our API using the\ntrial data. To get set up with the API using live MLS data, you\nmust have RETS credentials from your MLS, which you can then use to\ncreate an app with SimplyRETS. For more information on that\nprocess, please see our [FAQ](https://simplyrets.com/faq), [Getting\nStarted](https://simplyrets.com/blog/getting-set-up.html) page, or\n[contact us](https://simplyrets.com/\\#home-contact).\n\nBelow you'll find the API endpoints, query parameters, response bodies,\nand other information about using the SimplyRETS API. You can run\nqueries by clicking the 'Try it Out' button at the bottom of each\nsection.\n\n### Authentication\nThe SimplyRETS API uses Basic Authentication. When you create an\napp, you'll get a set of API credentials to access your\nlistings. If you're trying out the test data, you can use\n`simplyrets:simplyrets` for connecting to the API.\n\n### Media Types\nThe SimplyRETS API uses the `Accept` header to allow clients to\ncontrol media types (content versions). We maintain backwards\ncompatibility with API clients by allowing them to specify a\ncontent version. We highly recommend setting and explicity media\ntype when your application reaches production. Both the structure\nand content of our API response bodies is subject to change so we\ncan add new features while respecting the stability of applications\nwhich have already been developed.\n\nTo always use the latest SimplyRETS content version, simply use\n`application/json` in your application `Accept` header.\n\nIf you want to pin your clients media type to a specific version,\nyou can use the vendor-specific SimplyRETS media type, e.g.\n`application/vnd.simplyrets-v0.1+json\"`\n\nTo view all valid content-types for making an `OPTIONS`, make a\nrequest to the SimplyRETS api root\n\n`curl -XOPTIONS -u simplyrets:simplyrets https://api.simplyrets.com/`\n\nThe default media types used in our API responses may change in the\nfuture. If you're building an application and care about the\nstability of the API, be sure to request a specific media type in the\nAccept header as shown in the examples below.\n\nThe wordpress plugin automatically sets the `Accept` header for the\ncompatible SimplyRETS media types.\n\n### Pagination\nThere a few pieces of useful information about each request stored\nin the HTTP Headers:\n\n- `X-Total-Count` shows you the total amount of listings that match\n your current query.\n- `Link` contains pre-built pagination links for accessing the next\n'page' of listings that match your query. Read more about that\n[here](https://simplyrets.com/blog/api-pagination.html).\n
|
5
|
+
|
6
|
+
OpenAPI spec version: 1.0.0
|
7
|
+
|
8
|
+
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
9
|
+
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
require 'date'
|
14
|
+
require 'json'
|
15
|
+
require 'logger'
|
16
|
+
require 'tempfile'
|
17
|
+
require 'typhoeus'
|
18
|
+
require 'uri'
|
19
|
+
|
20
|
+
module SimplyRetsClient
|
21
|
+
class ApiClient
|
22
|
+
# The Configuration object holding settings to be used in the API client.
|
23
|
+
attr_accessor :config
|
24
|
+
|
25
|
+
# Defines the headers to be used in HTTP requests of all API calls by default.
|
26
|
+
#
|
27
|
+
# @return [Hash]
|
28
|
+
attr_accessor :default_headers
|
29
|
+
|
30
|
+
def initialize(config = Configuration.default)
|
31
|
+
@config = config
|
32
|
+
@user_agent = "Swagger-Codegen/#{VERSION}/ruby"
|
33
|
+
@default_headers = {
|
34
|
+
'Content-Type' => "application/json",
|
35
|
+
'User-Agent' => @user_agent
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.default
|
40
|
+
@@default ||= ApiClient.new
|
41
|
+
end
|
42
|
+
|
43
|
+
# Call an API with given options.
|
44
|
+
#
|
45
|
+
# @return [Array<(Object, Fixnum, Hash)>] an array of 3 elements:
|
46
|
+
# the data deserialized from response body (could be nil), response status code and response headers.
|
47
|
+
def call_api(http_method, path, opts = {})
|
48
|
+
request = build_request(http_method, path, opts)
|
49
|
+
response = request.run
|
50
|
+
|
51
|
+
if @config.debugging
|
52
|
+
@config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
|
53
|
+
end
|
54
|
+
|
55
|
+
unless response.success?
|
56
|
+
fail ApiError.new(:code => response.code,
|
57
|
+
:response_headers => response.headers,
|
58
|
+
:response_body => response.body),
|
59
|
+
response.status_message
|
60
|
+
end
|
61
|
+
|
62
|
+
if opts[:return_type]
|
63
|
+
data = deserialize(response, opts[:return_type])
|
64
|
+
else
|
65
|
+
data = nil
|
66
|
+
end
|
67
|
+
return data, response.code, response.headers
|
68
|
+
end
|
69
|
+
|
70
|
+
def build_request(http_method, path, opts = {})
|
71
|
+
url = build_request_url(path)
|
72
|
+
http_method = http_method.to_sym.downcase
|
73
|
+
|
74
|
+
header_params = @default_headers.merge(opts[:header_params] || {})
|
75
|
+
query_params = opts[:query_params] || {}
|
76
|
+
form_params = opts[:form_params] || {}
|
77
|
+
|
78
|
+
|
79
|
+
update_params_for_auth! header_params, query_params, opts[:auth_names]
|
80
|
+
|
81
|
+
|
82
|
+
req_opts = {
|
83
|
+
:method => http_method,
|
84
|
+
:headers => header_params,
|
85
|
+
:params => query_params,
|
86
|
+
:timeout => @config.timeout,
|
87
|
+
:ssl_verifypeer => @config.verify_ssl,
|
88
|
+
:sslcert => @config.cert_file,
|
89
|
+
:sslkey => @config.key_file,
|
90
|
+
:verbose => @config.debugging
|
91
|
+
}
|
92
|
+
|
93
|
+
req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert
|
94
|
+
|
95
|
+
if [:post, :patch, :put, :delete].include?(http_method)
|
96
|
+
req_body = build_request_body(header_params, form_params, opts[:body])
|
97
|
+
req_opts.update :body => req_body
|
98
|
+
if @config.debugging
|
99
|
+
@config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
Typhoeus::Request.new(url, req_opts)
|
104
|
+
end
|
105
|
+
|
106
|
+
# Check if the given MIME is a JSON MIME.
|
107
|
+
# JSON MIME examples:
|
108
|
+
# application/json
|
109
|
+
# application/json; charset=UTF8
|
110
|
+
# APPLICATION/JSON
|
111
|
+
def json_mime?(mime)
|
112
|
+
!!(mime =~ /\Aapplication\/json(;.*)?\z/i)
|
113
|
+
end
|
114
|
+
|
115
|
+
# Deserialize the response to the given return type.
|
116
|
+
#
|
117
|
+
# @param [String] return_type some examples: "User", "Array[User]", "Hash[String,Integer]"
|
118
|
+
def deserialize(response, return_type)
|
119
|
+
body = response.body
|
120
|
+
return nil if body.nil? || body.empty?
|
121
|
+
|
122
|
+
# return response body directly for String return type
|
123
|
+
return body if return_type == 'String'
|
124
|
+
|
125
|
+
# handle file downloading - save response body into a tmp file and return the File instance
|
126
|
+
return download_file(response) if return_type == 'File'
|
127
|
+
|
128
|
+
# ensuring a default content type
|
129
|
+
content_type = response.headers['Content-Type'] || 'application/json'
|
130
|
+
|
131
|
+
fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
|
132
|
+
|
133
|
+
begin
|
134
|
+
data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
|
135
|
+
rescue JSON::ParserError => e
|
136
|
+
if %w(String Date DateTime).include?(return_type)
|
137
|
+
data = body
|
138
|
+
else
|
139
|
+
raise e
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
convert_to_type data, return_type
|
144
|
+
end
|
145
|
+
|
146
|
+
# Convert data to the given return type.
|
147
|
+
def convert_to_type(data, return_type)
|
148
|
+
return nil if data.nil?
|
149
|
+
case return_type
|
150
|
+
when 'String'
|
151
|
+
data.to_s
|
152
|
+
when 'Integer'
|
153
|
+
data.to_i
|
154
|
+
when 'Float'
|
155
|
+
data.to_f
|
156
|
+
when 'BOOLEAN'
|
157
|
+
data == true
|
158
|
+
when 'DateTime'
|
159
|
+
# parse date time (expecting ISO 8601 format)
|
160
|
+
DateTime.parse data
|
161
|
+
when 'Date'
|
162
|
+
# parse date time (expecting ISO 8601 format)
|
163
|
+
Date.parse data
|
164
|
+
when 'Object'
|
165
|
+
# generic object (usually a Hash), return directly
|
166
|
+
data
|
167
|
+
when /\AArray<(.+)>\z/
|
168
|
+
# e.g. Array<Pet>
|
169
|
+
sub_type = $1
|
170
|
+
data.map {|item| convert_to_type(item, sub_type) }
|
171
|
+
when /\AHash\<String, (.+)\>\z/
|
172
|
+
# e.g. Hash<String, Integer>
|
173
|
+
sub_type = $1
|
174
|
+
{}.tap do |hash|
|
175
|
+
data.each {|k, v| hash[k] = convert_to_type(v, sub_type) }
|
176
|
+
end
|
177
|
+
else
|
178
|
+
# models, e.g. Pet
|
179
|
+
SimplyRetsClient.const_get(return_type).new.tap do |model|
|
180
|
+
model.build_from_hash data
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
# Save response body into a file in (the defined) temporary folder, using the filename
|
186
|
+
# from the "Content-Disposition" header if provided, otherwise a random filename.
|
187
|
+
#
|
188
|
+
# @see Configuration#temp_folder_path
|
189
|
+
# @return [Tempfile] the file downloaded
|
190
|
+
def download_file(response)
|
191
|
+
content_disposition = response.headers['Content-Disposition']
|
192
|
+
if content_disposition
|
193
|
+
filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
|
194
|
+
prefix = sanitize_filename(filename)
|
195
|
+
else
|
196
|
+
prefix = 'download-'
|
197
|
+
end
|
198
|
+
prefix = prefix + '-' unless prefix.end_with?('-')
|
199
|
+
|
200
|
+
tempfile = nil
|
201
|
+
encoding = response.body.encoding
|
202
|
+
Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding) do |file|
|
203
|
+
file.write(response.body)
|
204
|
+
tempfile = file
|
205
|
+
end
|
206
|
+
@config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
|
207
|
+
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
|
208
|
+
"will be deleted automatically with GC. It's also recommended to delete the temp file "\
|
209
|
+
"explicitly with `tempfile.delete`"
|
210
|
+
tempfile
|
211
|
+
end
|
212
|
+
|
213
|
+
# Sanitize filename by removing path.
|
214
|
+
# e.g. ../../sun.gif becomes sun.gif
|
215
|
+
#
|
216
|
+
# @param [String] filename the filename to be sanitized
|
217
|
+
# @return [String] the sanitized filename
|
218
|
+
def sanitize_filename(filename)
|
219
|
+
filename.gsub /.*[\/\\]/, ''
|
220
|
+
end
|
221
|
+
|
222
|
+
def build_request_url(path)
|
223
|
+
# Add leading and trailing slashes to path
|
224
|
+
path = "/#{path}".gsub(/\/+/, '/')
|
225
|
+
URI.encode(@config.base_url + path)
|
226
|
+
end
|
227
|
+
|
228
|
+
def build_request_body(header_params, form_params, body)
|
229
|
+
# http form
|
230
|
+
if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
|
231
|
+
header_params['Content-Type'] == 'multipart/form-data'
|
232
|
+
data = {}
|
233
|
+
form_params.each do |key, value|
|
234
|
+
case value
|
235
|
+
when File, Array, nil
|
236
|
+
# let typhoeus handle File, Array and nil parameters
|
237
|
+
data[key] = value
|
238
|
+
else
|
239
|
+
data[key] = value.to_s
|
240
|
+
end
|
241
|
+
end
|
242
|
+
elsif body
|
243
|
+
data = body.is_a?(String) ? body : body.to_json
|
244
|
+
else
|
245
|
+
data = nil
|
246
|
+
end
|
247
|
+
data
|
248
|
+
end
|
249
|
+
|
250
|
+
# Update hearder and query params based on authentication settings.
|
251
|
+
def update_params_for_auth!(header_params, query_params, auth_names)
|
252
|
+
Array(auth_names).each do |auth_name|
|
253
|
+
auth_setting = @config.auth_settings[auth_name]
|
254
|
+
next unless auth_setting
|
255
|
+
case auth_setting[:in]
|
256
|
+
when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
|
257
|
+
when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
|
258
|
+
else fail ArgumentError, 'Authentication token must be in `query` of `header`'
|
259
|
+
end
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
def user_agent=(user_agent)
|
264
|
+
@user_agent = user_agent
|
265
|
+
@default_headers['User-Agent'] = @user_agent
|
266
|
+
end
|
267
|
+
|
268
|
+
# Return Accept header based on an array of accepts provided.
|
269
|
+
# @param [Array] accepts array for Accept
|
270
|
+
# @return [String] the Accept header (e.g. application/json)
|
271
|
+
def select_header_accept(accepts)
|
272
|
+
return nil if accepts.nil? || accepts.empty?
|
273
|
+
# use JSON when present, otherwise use all of the provided
|
274
|
+
json_accept = accepts.find { |s| json_mime?(s) }
|
275
|
+
return json_accept || accepts.join(',')
|
276
|
+
end
|
277
|
+
|
278
|
+
# Return Content-Type header based on an array of content types provided.
|
279
|
+
# @param [Array] content_types array for Content-Type
|
280
|
+
# @return [String] the Content-Type header (e.g. application/json)
|
281
|
+
def select_header_content_type(content_types)
|
282
|
+
# use application/json by default
|
283
|
+
return 'application/json' if content_types.nil? || content_types.empty?
|
284
|
+
# use JSON when present, otherwise use the first one
|
285
|
+
json_content_type = content_types.find { |s| json_mime?(s) }
|
286
|
+
return json_content_type || content_types.first
|
287
|
+
end
|
288
|
+
|
289
|
+
# Convert object (array, hash, object, etc) to JSON string.
|
290
|
+
# @param [Object] model object to be converted into JSON string
|
291
|
+
# @return [String] JSON string representation of the object
|
292
|
+
def object_to_http_body(model)
|
293
|
+
return model if model.nil? || model.is_a?(String)
|
294
|
+
_body = nil
|
295
|
+
if model.is_a?(Array)
|
296
|
+
_body = model.map{|m| object_to_hash(m) }
|
297
|
+
else
|
298
|
+
_body = object_to_hash(model)
|
299
|
+
end
|
300
|
+
_body.to_json
|
301
|
+
end
|
302
|
+
|
303
|
+
# Convert object(non-array) to hash.
|
304
|
+
# @param [Object] obj object to be converted into JSON string
|
305
|
+
# @return [String] JSON string representation of the object
|
306
|
+
def object_to_hash(obj)
|
307
|
+
if obj.respond_to?(:to_hash)
|
308
|
+
obj.to_hash
|
309
|
+
else
|
310
|
+
obj
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
314
|
+
# Build parameter value according to the given collection format.
|
315
|
+
# @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
|
316
|
+
def build_collection_param(param, collection_format)
|
317
|
+
case collection_format
|
318
|
+
when :csv
|
319
|
+
param.join(',')
|
320
|
+
when :ssv
|
321
|
+
param.join(' ')
|
322
|
+
when :tsv
|
323
|
+
param.join("\t")
|
324
|
+
when :pipes
|
325
|
+
param.join('|')
|
326
|
+
when :multi
|
327
|
+
# return the array directly as typhoeus will handle it as expected
|
328
|
+
param
|
329
|
+
else
|
330
|
+
fail "unknown collection format: #{collection_format.inspect}"
|
331
|
+
end
|
332
|
+
end
|
333
|
+
end
|
334
|
+
end
|
335
|
+
|
336
|
+
|
337
|
+
# PATCH: array parameter rendering
|
338
|
+
#
|
339
|
+
# Typheous defaults to rendering array query parameters with
|
340
|
+
# an index:
|
341
|
+
#
|
342
|
+
# ?points[0]=23.232,-98.232&points[1]=23.232,-98.232
|
343
|
+
#
|
344
|
+
# The simplyrets api uses the form:
|
345
|
+
#
|
346
|
+
# ?points=23.232,-98.232&points=23.232,-98.232
|
347
|
+
#
|
348
|
+
# this monkey-patch removes the array index when the query
|
349
|
+
# parameter is rendered.
|
350
|
+
module Ethon
|
351
|
+
class Easy
|
352
|
+
module Queryable
|
353
|
+
private
|
354
|
+
def recursively_generate_pairs(h, prefix, pairs)
|
355
|
+
case h
|
356
|
+
when Hash
|
357
|
+
h.each_pair do |k,v|
|
358
|
+
key = prefix.nil? ? k : "#{prefix}"
|
359
|
+
pairs_for(v, key, pairs)
|
360
|
+
end
|
361
|
+
when Array
|
362
|
+
h.each_with_index do |v, i|
|
363
|
+
key = "#{prefix}"
|
364
|
+
pairs_for(v, key, pairs)
|
365
|
+
end
|
366
|
+
end
|
367
|
+
end
|
368
|
+
end
|
369
|
+
end
|
370
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
=begin
|
2
|
+
SimplyRETS API
|
3
|
+
|
4
|
+
The SimplyRETS API is an exciting step towards making it easier for\ndevelopers and real estate agents to build something awesome with\nreal estate data!\n\nThe documentation below makes live requests to our API using the\ntrial data. To get set up with the API using live MLS data, you\nmust have RETS credentials from your MLS, which you can then use to\ncreate an app with SimplyRETS. For more information on that\nprocess, please see our [FAQ](https://simplyrets.com/faq), [Getting\nStarted](https://simplyrets.com/blog/getting-set-up.html) page, or\n[contact us](https://simplyrets.com/\\#home-contact).\n\nBelow you'll find the API endpoints, query parameters, response bodies,\nand other information about using the SimplyRETS API. You can run\nqueries by clicking the 'Try it Out' button at the bottom of each\nsection.\n\n### Authentication\nThe SimplyRETS API uses Basic Authentication. When you create an\napp, you'll get a set of API credentials to access your\nlistings. If you're trying out the test data, you can use\n`simplyrets:simplyrets` for connecting to the API.\n\n### Media Types\nThe SimplyRETS API uses the `Accept` header to allow clients to\ncontrol media types (content versions). We maintain backwards\ncompatibility with API clients by allowing them to specify a\ncontent version. We highly recommend setting and explicity media\ntype when your application reaches production. Both the structure\nand content of our API response bodies is subject to change so we\ncan add new features while respecting the stability of applications\nwhich have already been developed.\n\nTo always use the latest SimplyRETS content version, simply use\n`application/json` in your application `Accept` header.\n\nIf you want to pin your clients media type to a specific version,\nyou can use the vendor-specific SimplyRETS media type, e.g.\n`application/vnd.simplyrets-v0.1+json\"`\n\nTo view all valid content-types for making an `OPTIONS`, make a\nrequest to the SimplyRETS api root\n\n`curl -XOPTIONS -u simplyrets:simplyrets https://api.simplyrets.com/`\n\nThe default media types used in our API responses may change in the\nfuture. If you're building an application and care about the\nstability of the API, be sure to request a specific media type in the\nAccept header as shown in the examples below.\n\nThe wordpress plugin automatically sets the `Accept` header for the\ncompatible SimplyRETS media types.\n\n### Pagination\nThere a few pieces of useful information about each request stored\nin the HTTP Headers:\n\n- `X-Total-Count` shows you the total amount of listings that match\n your current query.\n- `Link` contains pre-built pagination links for accessing the next\n'page' of listings that match your query. Read more about that\n[here](https://simplyrets.com/blog/api-pagination.html).\n
|
5
|
+
|
6
|
+
OpenAPI spec version: 1.0.0
|
7
|
+
|
8
|
+
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
9
|
+
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
module SimplyRetsClient
|
14
|
+
class ApiError < StandardError
|
15
|
+
attr_reader :code, :response_headers, :response_body
|
16
|
+
|
17
|
+
# Usage examples:
|
18
|
+
# ApiError.new
|
19
|
+
# ApiError.new("message")
|
20
|
+
# ApiError.new(:code => 500, :response_headers => {}, :response_body => "")
|
21
|
+
# ApiError.new(:code => 404, :message => "Not Found")
|
22
|
+
def initialize(arg = nil)
|
23
|
+
if arg.is_a? Hash
|
24
|
+
arg.each do |k, v|
|
25
|
+
if k.to_s == 'message'
|
26
|
+
super v
|
27
|
+
else
|
28
|
+
instance_variable_set "@#{k}", v
|
29
|
+
end
|
30
|
+
end
|
31
|
+
else
|
32
|
+
super arg
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,170 @@
|
|
1
|
+
require 'uri'
|
2
|
+
|
3
|
+
module SimplyRetsClient
|
4
|
+
class Configuration
|
5
|
+
# Defines url scheme
|
6
|
+
attr_accessor :scheme
|
7
|
+
|
8
|
+
# Defines url host
|
9
|
+
attr_accessor :host
|
10
|
+
|
11
|
+
# Defines url base path
|
12
|
+
attr_accessor :base_path
|
13
|
+
|
14
|
+
# Defines API keys used with API Key authentications.
|
15
|
+
#
|
16
|
+
# @return [Hash] key: parameter name, value: parameter value (API key)
|
17
|
+
#
|
18
|
+
# @example parameter name is "api_key", API key is "xxx" (e.g. "api_key=xxx" in query string)
|
19
|
+
# config.api_key['api_key'] = 'xxx'
|
20
|
+
attr_accessor :api_key
|
21
|
+
|
22
|
+
# Defines API key prefixes used with API Key authentications.
|
23
|
+
#
|
24
|
+
# @return [Hash] key: parameter name, value: API key prefix
|
25
|
+
#
|
26
|
+
# @example parameter name is "Authorization", API key prefix is "Token" (e.g. "Authorization: Token xxx" in headers)
|
27
|
+
# config.api_key_prefix['api_key'] = 'Token'
|
28
|
+
attr_accessor :api_key_prefix
|
29
|
+
|
30
|
+
# Defines the username used with HTTP basic authentication.
|
31
|
+
#
|
32
|
+
# @return [String]
|
33
|
+
attr_accessor :username
|
34
|
+
|
35
|
+
# Defines the password used with HTTP basic authentication.
|
36
|
+
#
|
37
|
+
# @return [String]
|
38
|
+
attr_accessor :password
|
39
|
+
|
40
|
+
# Defines the access token (Bearer) used with OAuth2.
|
41
|
+
attr_accessor :access_token
|
42
|
+
|
43
|
+
# Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
|
44
|
+
# details will be logged with `logger.debug` (see the `logger` attribute).
|
45
|
+
# Default to false.
|
46
|
+
#
|
47
|
+
# @return [true, false]
|
48
|
+
attr_accessor :debugging
|
49
|
+
|
50
|
+
# Defines the logger used for debugging.
|
51
|
+
# Default to `Rails.logger` (when in Rails) or logging to STDOUT.
|
52
|
+
#
|
53
|
+
# @return [#debug]
|
54
|
+
attr_accessor :logger
|
55
|
+
|
56
|
+
# Defines the temporary folder to store downloaded files
|
57
|
+
# (for API endpoints that have file response).
|
58
|
+
# Default to use `Tempfile`.
|
59
|
+
#
|
60
|
+
# @return [String]
|
61
|
+
attr_accessor :temp_folder_path
|
62
|
+
|
63
|
+
# The time limit for HTTP request in seconds.
|
64
|
+
# Default to 0 (never times out).
|
65
|
+
attr_accessor :timeout
|
66
|
+
|
67
|
+
### TLS/SSL
|
68
|
+
# Set this to false to skip verifying SSL certificate when calling API from https server.
|
69
|
+
# Default to true.
|
70
|
+
#
|
71
|
+
# @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
|
72
|
+
#
|
73
|
+
# @return [true, false]
|
74
|
+
attr_accessor :verify_ssl
|
75
|
+
|
76
|
+
# Set this to customize the certificate file to verify the peer.
|
77
|
+
#
|
78
|
+
# @return [String] the path to the certificate file
|
79
|
+
#
|
80
|
+
# @see The `cainfo` option of Typhoeus, `--cert` option of libcurl. Related source code:
|
81
|
+
# https://github.com/typhoeus/typhoeus/blob/master/lib/typhoeus/easy_factory.rb#L145
|
82
|
+
attr_accessor :ssl_ca_cert
|
83
|
+
|
84
|
+
# Client certificate file (for client certificate)
|
85
|
+
attr_accessor :cert_file
|
86
|
+
|
87
|
+
# Client private key file (for client certificate)
|
88
|
+
attr_accessor :key_file
|
89
|
+
|
90
|
+
attr_accessor :inject_format
|
91
|
+
|
92
|
+
attr_accessor :force_ending_format
|
93
|
+
|
94
|
+
def initialize
|
95
|
+
@scheme = 'https'
|
96
|
+
@host = 'api.simplyrets.com'
|
97
|
+
@base_path = '/'
|
98
|
+
@api_key = {}
|
99
|
+
@api_key_prefix = {}
|
100
|
+
@timeout = 0
|
101
|
+
@verify_ssl = true
|
102
|
+
@cert_file = nil
|
103
|
+
@key_file = nil
|
104
|
+
@debugging = false
|
105
|
+
@inject_format = false
|
106
|
+
@force_ending_format = false
|
107
|
+
@logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
|
108
|
+
|
109
|
+
yield(self) if block_given?
|
110
|
+
end
|
111
|
+
|
112
|
+
# The default Configuration object.
|
113
|
+
def self.default
|
114
|
+
@@default ||= Configuration.new
|
115
|
+
end
|
116
|
+
|
117
|
+
def configure
|
118
|
+
yield(self) if block_given?
|
119
|
+
end
|
120
|
+
|
121
|
+
def scheme=(scheme)
|
122
|
+
# remove :// from scheme
|
123
|
+
@scheme = scheme.sub(/:\/\//, '')
|
124
|
+
end
|
125
|
+
|
126
|
+
def host=(host)
|
127
|
+
# remove http(s):// and anything after a slash
|
128
|
+
@host = host.sub(/https?:\/\//, '').split('/').first
|
129
|
+
end
|
130
|
+
|
131
|
+
def base_path=(base_path)
|
132
|
+
# Add leading and trailing slashes to base_path
|
133
|
+
@base_path = "/#{base_path}".gsub(/\/+/, '/')
|
134
|
+
@base_path = "" if @base_path == "/"
|
135
|
+
end
|
136
|
+
|
137
|
+
def base_url
|
138
|
+
url = "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '')
|
139
|
+
URI.encode(url)
|
140
|
+
end
|
141
|
+
|
142
|
+
# Gets API key (with prefix if set).
|
143
|
+
# @param [String] param_name the parameter name of API key auth
|
144
|
+
def api_key_with_prefix(param_name)
|
145
|
+
if @api_key_prefix[param_name]
|
146
|
+
"#{@api_key_prefix[param_name]} #{@api_key[param_name]}"
|
147
|
+
else
|
148
|
+
@api_key[param_name]
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
# Gets Basic Auth token string
|
153
|
+
def basic_auth_token
|
154
|
+
'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
|
155
|
+
end
|
156
|
+
|
157
|
+
# Returns Auth Settings hash for api client.
|
158
|
+
def auth_settings
|
159
|
+
{
|
160
|
+
'basicAuth' =>
|
161
|
+
{
|
162
|
+
type: 'basic',
|
163
|
+
in: 'header',
|
164
|
+
key: 'Authorization',
|
165
|
+
value: basic_auth_token
|
166
|
+
},
|
167
|
+
}
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|