rxfreader 0.3.2 → 0.3.4

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: ccef2cd84451b01e6a205c84440c5c9b908e126cdd7cc0aed9fd66af41f322b3
4
- data.tar.gz: '07381142d5c737ddf85d0878473a0dcade7526e4fcb3defe3672271e1f5acf17'
3
+ metadata.gz: c771adeccd1e72c4ece1074e644fe3ed1d368b415b298a766be843fca0d8199b
4
+ data.tar.gz: 7ce5c6dc0c1e29031e5ae25e4d7ec11c029380425ab0479b725ba7e16c0cb84e
5
5
  SHA512:
6
- metadata.gz: 03ecf416c6cfd885440f56810d5006f6eb886d81a88e18bfb572e9448a9707d7d3ed82413585e428dc95b21fc5d66a86ab797a32f9ec5d270132c0a2f1c9372f
7
- data.tar.gz: 1af95992561bf8ebef6002e196db3f989632428260f14b075a2b2cb4e42b551e5088c710eab53263af32691868f4799032d4acd3af15849ecb78fb6820b430e1
6
+ metadata.gz: 13e8b31cca1a5979e6582490babef00147483ce3a077d6b95c3fa2fd3edb6808b8f19e8a49367cc0a99526726b333db474ad2edf366715a0f08e294ee6bd57aa
7
+ data.tar.gz: 31aeb2a5b65d78364e81893d229003e81e358e9fb71d40c02ea637b9068b6fa0ea971df7f659c031883fded45d4da3025a118764a3911003743a7793c464fdac
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/rxfreader.rb CHANGED
@@ -149,3 +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
290
+
291
+
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.2
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -35,7 +35,7 @@ cert_chain:
35
35
  ZhYGFOGLCyFBzNWg6gwMKjzpzDZB/H0+GTRB2c3+7DVuJWqyC5SbGnVLkT4Q8+B6
36
36
  Ws39Z48SRONdDWtHwAiUtnU+
37
37
  -----END CERTIFICATE-----
38
- date: 2022-03-31 00:00:00.000000000 Z
38
+ date: 2023-01-15 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: gpd-request
@@ -123,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  requirements: []
126
- rubygems_version: 3.2.22
126
+ rubygems_version: 3.4.1
127
127
  signing_key:
128
128
  specification_version: 4
129
129
  summary: Reads a file from an HTTP address, DFS address, or local location.
metadata.gz.sig CHANGED
Binary file