rxfreader 0.3.0 → 0.3.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 439ac6839199c6d53cb40bbf2a56a73666ecd8c3119a141249284c6dd3c4d2d3
4
- data.tar.gz: b67ef02d5fe587838eb6b9647e422b57e4c4528ced5d44b9238a110a26803d7b
3
+ metadata.gz: 443ef83dff7980ec427bbaa057b1a45ce6d0507bb3631576a59e80bcb82e1bb7
4
+ data.tar.gz: cd03d2c6ff8dcc5e2882b68361699c4833df0f55b0a972d183f92691b56f3a5f
5
5
  SHA512:
6
- metadata.gz: 0e5498c3ad23d1afd698c6d72800b505c28ec78ab5643d99b8f0b7d45cd1845289adabe01941c4f5b0cc2c304de51144975f0730e92cedb56593f6feb6776296
7
- data.tar.gz: b087e28234b235fb6110a328a0ed3a752ff4482c58974c8922fa560acd851d98c4426806d5265b10548b26761d85dbfeb889254026a9cf63ec5136a30d1497e8
6
+ metadata.gz: 9e68f745534c95c2e921475ee0f107ac44efb4af08528465158888d8bf1fb92ffcdc44a4f0e1c857ba92dd6e7589899fb3b648054ce128ca57f892b0a00421ab
7
+ data.tar.gz: 8eac991c1f2fbc6554cd91147705852edab98fd594bef0901e34524f0fba02745d2b09a4e30de99380298dc105921f07a08a87df1f3f058a2bb7889f2d825bb3
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/rxfreader.rb CHANGED
@@ -136,7 +136,7 @@ class RXFReader
136
136
  end
137
137
  end
138
138
 
139
- def reveal(uri_str, a=[])
139
+ def self.reveal(uri_str, a=[])
140
140
 
141
141
  response = Net::HTTP.get_response(URI.parse(uri_str))
142
142
  url = case response
@@ -149,6 +149,144 @@ class RXFReader
149
149
  end
150
150
 
151
151
  end
152
+ module RXFRead
153
+
154
+ class FileX
155
+
156
+ def self.exists?(s) RXFReader.exists?(s) end
157
+ def self.filetype(s) RXFReader.filetype(s) end
158
+ def self.read(s) RXFReader.read(s).first end
159
+
160
+ end
161
+
162
+ end
163
+
164
+
165
+ class RXFReaderException < Exception
166
+ end
167
+
168
+ class RXFReader
169
+ using ColouredText
170
+
171
+ def self.exists?(filename)
172
+
173
+ type = self.filetype(filename)
174
+
175
+ filex = case type
176
+ when :file
177
+ File
178
+ when :dfs
179
+ DfsFile
180
+ else
181
+ nil
182
+ end
183
+
184
+ return nil unless filex
185
+
186
+ filex.exists? filename
187
+
188
+ end
189
+
190
+ def self.filetype(x)
191
+
192
+ return :string if x.lines.length > 1
193
+
194
+ case x
195
+ when /^https?:\/\//
196
+ :http
197
+ when /^dfs:\/\//
198
+ :dfs
199
+ when /^file:\/\//
200
+ :file
201
+ else
202
+
203
+ if File.exists?(x) then
204
+ :file
205
+ else
206
+ :text
207
+ end
208
+
209
+ end
210
+ end
211
+
212
+ def self.read(x, h={})
213
+
214
+ opt = {debug: false, auto: false}.merge(h)
215
+
216
+ debug = opt[:debug]
217
+
218
+ raise RXFReaderException, 'nil found, expected a string' if x.nil?
219
+
220
+ if x.class.to_s =~ /Rexle$/ then
221
+
222
+ [x.xml, :rexle]
223
+
224
+ elsif x.strip[/^<(\?xml|[^\?])/] then
225
+
226
+ [x, :xml]
227
+
228
+ elsif x.lines.length == 1 then
229
+
230
+ if x[/^https?:\/\//] then
231
+
232
+ puts 'before GPDRequest'.info if debug
233
+
234
+ r = if opt[:username] and opt[:password] then
235
+ GPDRequest.new(opt[:username], opt[:password]).get(x)
236
+ else
237
+ response = RestClient.get(x)
238
+ end
239
+
240
+ case r.code
241
+ when '404'
242
+ raise(RXFReaderException, "404 %s not found" % x)
243
+ when '401'
244
+ raise(RXFReaderException, "401 %s unauthorized access" % x)
245
+ end
246
+
247
+ [r.body, :url]
248
+
249
+ elsif x[/^dfs:\/\//] then
250
+
251
+ r = DfsFile.read(x).force_encoding('UTF-8')
252
+ [r, :dfs]
253
+
254
+
255
+ elsif x[/^file:\/\//] or File.exists?(x) then
256
+
257
+ puts 'RXFHelper.read before File.read' if debug
258
+ contents = File.read(File.expand_path(x.sub(%r{^file://}, '')))
259
+
260
+ [contents, :file]
261
+
262
+ elsif x =~ /\s/
263
+ [x, :text]
264
+ elsif DfsFile.exists?(x)
265
+ [DfsFile.read(x).force_encoding('UTF-8'), :dfs]
266
+ else
267
+ [x, :unknown]
268
+ end
269
+
270
+ else
271
+
272
+ [x, :unknown]
273
+ end
274
+ end
275
+
276
+ def self.reveal(uri_str, a=[])
277
+
278
+ u = URI.parse(uri_str)
279
+ response = Net::HTTP.get_response(u)
280
+
281
+ url = case response
282
+ when Net::HTTPRedirection then response['location']
283
+ end
284
+
285
+ return a << uri_str if url.nil?
286
+ url.prepend u.origin if not url[/^http/]
287
+
288
+ reveal(url, a << uri_str)
289
+ end
152
290
 
153
291
 
154
292
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rxfreader
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
metadata.gz.sig CHANGED
Binary file