caboose-rets 0.0.57 → 0.0.58
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 +9 -9
- data/app/models/caboose_rets/rets_importer.rb +102 -33
- data/app/models/caboose_rets/schema.rb +5 -2
- data/lib/caboose_rets/version.rb +1 -1
- data/lib/rets/base/core.rb +290 -0
- data/lib/rets/base/sax_metadata.rb +63 -0
- data/lib/rets/base/sax_search.rb +58 -0
- data/lib/rets/client.rb +70 -0
- data/lib/rets/exceptions.rb +37 -0
- data/lib/rets/http.rb +329 -0
- data/lib/rets/stream_http.rb +159 -0
- data/lib/rets/version.rb +3 -0
- metadata +17 -9
@@ -0,0 +1,159 @@
|
|
1
|
+
# This is a slightly crazy hack, but it's saner if we can just use Net::HTTP and then fallback on the StreamHTTP class when we need to do stream parsing.
|
2
|
+
# If we were to do it ourselves with Sockets, it would be a bigger pain to manage that, and we would have to do roughly the same setup as below anyway.
|
3
|
+
# Essentially, for the hack of using instance_variable_get/instance_variable_set, we get a simple stream parser, without having to write our own HTTP class.
|
4
|
+
module RETS
|
5
|
+
class StreamHTTP
|
6
|
+
ENCODABLE = RUBY_VERSION >= "1.9.0"
|
7
|
+
|
8
|
+
##
|
9
|
+
# Initializes a new HTTP stream which can be passed to Nokogiri for SAX parsing.
|
10
|
+
# @param [Net::HTTPResponse] response
|
11
|
+
# Unused HTTP response, no calls to any of the read_body or other methods can have been called.
|
12
|
+
def initialize(response)
|
13
|
+
@response = response
|
14
|
+
@left_to_read = @response.content_length
|
15
|
+
@content_length = @response.content_length
|
16
|
+
@chunked = @response.chunked?
|
17
|
+
@socket = @response.instance_variable_get(:@socket)
|
18
|
+
|
19
|
+
@digest = Digest::SHA1.new
|
20
|
+
@total_size = 0
|
21
|
+
|
22
|
+
if @response.header.key?("content-type") and @response["content-type"] =~ /.*charset=(.*)/i
|
23
|
+
@encoding = $1.to_s.upcase
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
##
|
28
|
+
# The total size read from the stream, can be called either while reading or at the end.
|
29
|
+
def size
|
30
|
+
@total_size
|
31
|
+
end
|
32
|
+
|
33
|
+
##
|
34
|
+
# SHA1 hash of the data read from the stream
|
35
|
+
def hash
|
36
|
+
@digest.hexdigest
|
37
|
+
end
|
38
|
+
|
39
|
+
##
|
40
|
+
# Detected encoding
|
41
|
+
def encoding
|
42
|
+
@encoding
|
43
|
+
end
|
44
|
+
|
45
|
+
##
|
46
|
+
# Read
|
47
|
+
#
|
48
|
+
# @param [Integer] read_len
|
49
|
+
# How many bytes to read from the HTTP stream
|
50
|
+
def read(read_len)
|
51
|
+
# If we closed the connection, return nil without calling anything again to avoid EOF
|
52
|
+
# or other errors
|
53
|
+
return nil if @closed
|
54
|
+
|
55
|
+
if @left_to_read
|
56
|
+
# We hit the end of what we need to read, if this is a chunked request, then we need to check for the next chunk
|
57
|
+
if @left_to_read <= read_len
|
58
|
+
data = @socket.read(@left_to_read)
|
59
|
+
@total_size += @left_to_read
|
60
|
+
@left_to_read = nil
|
61
|
+
@read_clfr = true
|
62
|
+
# Reading from known buffer still
|
63
|
+
else
|
64
|
+
@left_to_read -= read_len
|
65
|
+
@total_size += read_len
|
66
|
+
data = @socket.read(read_len)
|
67
|
+
end
|
68
|
+
|
69
|
+
elsif @chunked
|
70
|
+
# We finished reading the chunks, read the last 2 to get \r\n out of the way, and then find the next chunk
|
71
|
+
if @read_clfr
|
72
|
+
@read_clfr = nil
|
73
|
+
@socket.read(2)
|
74
|
+
end
|
75
|
+
|
76
|
+
data, chunk_read = "", 0
|
77
|
+
while true
|
78
|
+
# Read first line to get the chunk length
|
79
|
+
line = @socket.readline
|
80
|
+
|
81
|
+
len = line.slice(/[0-9a-fA-F]+/) or raise Net::HTTPBadResponse.new("wrong chunk size line: #{line}")
|
82
|
+
len = len.hex
|
83
|
+
|
84
|
+
# Nothing left, read off the final \r\n
|
85
|
+
if len == 0
|
86
|
+
@socket.read(2)
|
87
|
+
@socket.close
|
88
|
+
@response.instance_variable_set(:@read, true)
|
89
|
+
|
90
|
+
@closed = true
|
91
|
+
break
|
92
|
+
end
|
93
|
+
|
94
|
+
# Reading this chunk will set us over the buffer amount
|
95
|
+
# Read what we can of it (if anything), and send back what we have and queue a read for the rest
|
96
|
+
if ( chunk_read + len ) > read_len
|
97
|
+
can_read = len - ( ( chunk_read + len ) - read_len )
|
98
|
+
|
99
|
+
@left_to_read = len - can_read
|
100
|
+
@total_size += can_read
|
101
|
+
|
102
|
+
data << @socket.read(can_read) if can_read > 0
|
103
|
+
break
|
104
|
+
# We can just return the chunk as-is
|
105
|
+
else
|
106
|
+
@total_size += len
|
107
|
+
chunk_read += len
|
108
|
+
|
109
|
+
data << @socket.read(len)
|
110
|
+
@socket.read(2)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
# If we don't have a content length, then we need to keep reading until we run out of data
|
115
|
+
elsif !@content_length
|
116
|
+
data = @socket.readline
|
117
|
+
|
118
|
+
@total_size += data.length if data
|
119
|
+
end
|
120
|
+
|
121
|
+
# We've finished reading, set this so Net::HTTP doesn't try and read it again
|
122
|
+
if !data or data == ""
|
123
|
+
@response.instance_variable_set(:@read, true)
|
124
|
+
|
125
|
+
nil
|
126
|
+
else
|
127
|
+
if data.length >= @total_size and !@chunked
|
128
|
+
@response.instance_variable_set(:@read, true)
|
129
|
+
end
|
130
|
+
|
131
|
+
if ENCODABLE and @encoding
|
132
|
+
data = data.force_encoding(@encoding) if @encoding
|
133
|
+
data = data.encode("UTF-8")
|
134
|
+
end
|
135
|
+
|
136
|
+
@digest.update(data)
|
137
|
+
data
|
138
|
+
end
|
139
|
+
|
140
|
+
# Mark as read finished, return the last bits of data (if any)
|
141
|
+
rescue EOFError
|
142
|
+
@response.instance_variable_set(:@read, true)
|
143
|
+
@socket.close
|
144
|
+
@closed = true
|
145
|
+
|
146
|
+
if data and data != ""
|
147
|
+
@digest.update(data)
|
148
|
+
data
|
149
|
+
else
|
150
|
+
nil
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
##
|
155
|
+
# Does nothing, only used because Nokogiri requires it in a SAX parser.
|
156
|
+
def close
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
data/lib/rets/version.rb
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: caboose-rets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.58
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- William Barry
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: caboose-cms
|
@@ -31,6 +31,9 @@ executables: []
|
|
31
31
|
extensions: []
|
32
32
|
extra_rdoc_files: []
|
33
33
|
files:
|
34
|
+
- MIT-LICENSE
|
35
|
+
- README.md
|
36
|
+
- Rakefile
|
34
37
|
- app/assets/javascripts/caboose_rets/admin_media.js
|
35
38
|
- app/assets/javascripts/caboose_rets/caboose_rets.js
|
36
39
|
- app/controllers/caboose_rets/agents_controller.rb
|
@@ -98,16 +101,24 @@ files:
|
|
98
101
|
- lib/caboose_rets/caboose_rets_helper.rb
|
99
102
|
- lib/caboose_rets/engine.rb
|
100
103
|
- lib/caboose_rets/version.rb
|
104
|
+
- lib/rets/base/core.rb
|
105
|
+
- lib/rets/base/sax_metadata.rb
|
106
|
+
- lib/rets/base/sax_search.rb
|
107
|
+
- lib/rets/client.rb
|
108
|
+
- lib/rets/exceptions.rb
|
109
|
+
- lib/rets/http.rb
|
110
|
+
- lib/rets/stream_http.rb
|
111
|
+
- lib/rets/version.rb
|
101
112
|
- lib/tasks/caboose_rets.rake
|
102
|
-
- MIT-LICENSE
|
103
|
-
- Rakefile
|
104
|
-
- README.md
|
105
113
|
- test/caboose_test.rb
|
114
|
+
- test/dummy/README.rdoc
|
115
|
+
- test/dummy/Rakefile
|
106
116
|
- test/dummy/app/assets/javascripts/application.js
|
107
117
|
- test/dummy/app/assets/stylesheets/application.css
|
108
118
|
- test/dummy/app/controllers/application_controller.rb
|
109
119
|
- test/dummy/app/helpers/application_helper.rb
|
110
120
|
- test/dummy/app/views/layouts/application.html.erb
|
121
|
+
- test/dummy/config.ru
|
111
122
|
- test/dummy/config/application.rb
|
112
123
|
- test/dummy/config/boot.rb
|
113
124
|
- test/dummy/config/database.yml
|
@@ -123,15 +134,12 @@ files:
|
|
123
134
|
- test/dummy/config/initializers/wrap_parameters.rb
|
124
135
|
- test/dummy/config/locales/en.yml
|
125
136
|
- test/dummy/config/routes.rb
|
126
|
-
- test/dummy/config.ru
|
127
137
|
- test/dummy/db/test.sqlite3
|
128
138
|
- test/dummy/log/test.log
|
129
139
|
- test/dummy/public/404.html
|
130
140
|
- test/dummy/public/422.html
|
131
141
|
- test/dummy/public/500.html
|
132
142
|
- test/dummy/public/favicon.ico
|
133
|
-
- test/dummy/Rakefile
|
134
|
-
- test/dummy/README.rdoc
|
135
143
|
- test/dummy/script/rails
|
136
144
|
- test/integration/navigation_test.rb
|
137
145
|
- test/test_helper.rb
|
@@ -155,7 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
155
163
|
version: '0'
|
156
164
|
requirements: []
|
157
165
|
rubyforge_project:
|
158
|
-
rubygems_version: 2.
|
166
|
+
rubygems_version: 2.2.2
|
159
167
|
signing_key:
|
160
168
|
specification_version: 4
|
161
169
|
summary: Library to download RETS data to a local website.
|