simplyrets 1.0.7 → 2.0.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/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
@@ -1,156 +0,0 @@
|
|
1
|
-
module SimplyRetsClient
|
2
|
-
module SimplyRets
|
3
|
-
class Response
|
4
|
-
require 'json'
|
5
|
-
require 'date'
|
6
|
-
require 'tempfile'
|
7
|
-
|
8
|
-
attr_accessor :raw
|
9
|
-
|
10
|
-
def initialize(raw)
|
11
|
-
self.raw = raw
|
12
|
-
end
|
13
|
-
|
14
|
-
def code
|
15
|
-
raw.code
|
16
|
-
end
|
17
|
-
|
18
|
-
def status_message
|
19
|
-
raw.status_message
|
20
|
-
end
|
21
|
-
|
22
|
-
def body
|
23
|
-
raw.body
|
24
|
-
end
|
25
|
-
|
26
|
-
def success?
|
27
|
-
raw.success?
|
28
|
-
end
|
29
|
-
|
30
|
-
# Deserialize the raw response body to the given return type.
|
31
|
-
#
|
32
|
-
# @param [String] return_type some examples: "User", "Array[User]", "Hash[String,Integer]"
|
33
|
-
def deserialize(return_type)
|
34
|
-
return nil if body.nil? || body.empty?
|
35
|
-
|
36
|
-
# handle file downloading - save response body into a tmp file and return the File instance
|
37
|
-
return download_file if return_type == 'File'
|
38
|
-
|
39
|
-
# ensuring a default content type
|
40
|
-
content_type = raw.headers['Content-Type'] || 'application/json'
|
41
|
-
|
42
|
-
unless content_type.start_with?('application/json')
|
43
|
-
fail "Content-Type is not supported: #{content_type}"
|
44
|
-
end
|
45
|
-
|
46
|
-
begin
|
47
|
-
data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
|
48
|
-
rescue JSON::ParserError => e
|
49
|
-
if %w(String Date DateTime).include?(return_type)
|
50
|
-
data = body
|
51
|
-
else
|
52
|
-
raise e
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
convert_to_type data, return_type
|
57
|
-
end
|
58
|
-
|
59
|
-
# Convert data to the given return type.
|
60
|
-
def convert_to_type(data, return_type)
|
61
|
-
return nil if data.nil?
|
62
|
-
case return_type
|
63
|
-
when 'String'
|
64
|
-
data.to_s
|
65
|
-
when 'Integer'
|
66
|
-
data.to_i
|
67
|
-
when 'Float'
|
68
|
-
data.to_f
|
69
|
-
when 'BOOLEAN'
|
70
|
-
data == true
|
71
|
-
when 'DateTime'
|
72
|
-
# parse date time (expecting ISO 8601 format)
|
73
|
-
DateTime.parse data
|
74
|
-
when 'Date'
|
75
|
-
# parse date time (expecting ISO 8601 format)
|
76
|
-
Date.parse data
|
77
|
-
when 'Object'
|
78
|
-
# generic object, return directly
|
79
|
-
data
|
80
|
-
when /\AArray<(.+)>\z/
|
81
|
-
# e.g. Array<Pet>
|
82
|
-
sub_type = $1
|
83
|
-
data.map {|item| convert_to_type(item, sub_type) }
|
84
|
-
when /\AHash\<String, (.+)\>\z/
|
85
|
-
# e.g. Hash<String, Integer>
|
86
|
-
sub_type = $1
|
87
|
-
{}.tap do |hash|
|
88
|
-
data.each {|k, v| hash[k] = convert_to_type(v, sub_type) }
|
89
|
-
end
|
90
|
-
else
|
91
|
-
# models, e.g. Pet
|
92
|
-
SimplyRetsClient.const_get(return_type).new.tap do |model|
|
93
|
-
model.build_from_hash data
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
# Save response body into a file in (the defined) temporary folder, using the filename
|
99
|
-
# from the "Content-Disposition" header if provided, otherwise a random filename.
|
100
|
-
#
|
101
|
-
# @see Configuration#temp_folder_path
|
102
|
-
# @return [File] the file downloaded
|
103
|
-
def download_file
|
104
|
-
tmp_file = Tempfile.new '', SimplyRets.configuration.temp_folder_path
|
105
|
-
content_disposition = raw.headers['Content-Disposition']
|
106
|
-
if content_disposition
|
107
|
-
filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
|
108
|
-
path = File.join File.dirname(tmp_file), filename
|
109
|
-
else
|
110
|
-
path = tmp_file.path
|
111
|
-
end
|
112
|
-
# close and delete temp file
|
113
|
-
tmp_file.close!
|
114
|
-
|
115
|
-
File.open(path, 'w') { |file| file.write(raw.body) }
|
116
|
-
SimplyRets.logger.info "File written to #{path}. Please move the file to a proper folder for further processing and delete the temp afterwards"
|
117
|
-
return File.new(path)
|
118
|
-
end
|
119
|
-
|
120
|
-
# `headers_hash` is a Typhoeus-specific extension of Hash,
|
121
|
-
# so simplify it back into a regular old Hash.
|
122
|
-
def headers
|
123
|
-
h = {}
|
124
|
-
raw.headers_hash.each {|k,v| h[k] = v }
|
125
|
-
h
|
126
|
-
end
|
127
|
-
|
128
|
-
# Extract the response format from the header hash
|
129
|
-
# e.g. {'Content-Type' => 'application/json'}
|
130
|
-
def format
|
131
|
-
headers['Content-Type'].split("/").last.downcase
|
132
|
-
end
|
133
|
-
|
134
|
-
def json?
|
135
|
-
format == 'json'
|
136
|
-
end
|
137
|
-
|
138
|
-
def xml?
|
139
|
-
format == 'xml'
|
140
|
-
end
|
141
|
-
|
142
|
-
def pretty_body
|
143
|
-
return unless body
|
144
|
-
if format == 'json'
|
145
|
-
JSON.pretty_generate(JSON.parse(body)).gsub(/\n/, '<br/>')
|
146
|
-
else
|
147
|
-
body
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
def pretty_headers
|
152
|
-
JSON.pretty_generate(headers).gsub(/\n/, '<br/>')
|
153
|
-
end
|
154
|
-
end
|
155
|
-
end
|
156
|
-
end
|
data/simplyrets-1.0.6.gem
DELETED
Binary file
|