rxfreader 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ccef2cd84451b01e6a205c84440c5c9b908e126cdd7cc0aed9fd66af41f322b3
4
- data.tar.gz: '07381142d5c737ddf85d0878473a0dcade7526e4fcb3defe3672271e1f5acf17'
3
+ metadata.gz: 443ef83dff7980ec427bbaa057b1a45ce6d0507bb3631576a59e80bcb82e1bb7
4
+ data.tar.gz: cd03d2c6ff8dcc5e2882b68361699c4833df0f55b0a972d183f92691b56f3a5f
5
5
  SHA512:
6
- metadata.gz: 03ecf416c6cfd885440f56810d5006f6eb886d81a88e18bfb572e9448a9707d7d3ed82413585e428dc95b21fc5d66a86ab797a32f9ec5d270132c0a2f1c9372f
7
- data.tar.gz: 1af95992561bf8ebef6002e196db3f989632428260f14b075a2b2cb4e42b551e5088c710eab53263af32691868f4799032d4acd3af15849ecb78fb6820b430e1
6
+ metadata.gz: 9e68f745534c95c2e921475ee0f107ac44efb4af08528465158888d8bf1fb92ffcdc44a4f0e1c857ba92dd6e7589899fb3b648054ce128ca57f892b0a00421ab
7
+ data.tar.gz: 8eac991c1f2fbc6554cd91147705852edab98fd594bef0901e34524f0fba02745d2b09a4e30de99380298dc105921f07a08a87df1f3f058a2bb7889f2d825bb3
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.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
metadata.gz.sig CHANGED
Binary file