requestor 0.1.2 → 0.1.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.
- data/lib/requestor.rb +35 -3
- metadata +1 -1
data/lib/requestor.rb
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
# file: requestor.rb
|
|
4
4
|
|
|
5
5
|
require 'open-uri'
|
|
6
|
+
require 'net/http'
|
|
7
|
+
require 'dynarex'
|
|
6
8
|
|
|
7
9
|
class Requestor
|
|
8
10
|
|
|
@@ -10,17 +12,47 @@ class Requestor
|
|
|
10
12
|
|
|
11
13
|
attr_reader :code
|
|
12
14
|
|
|
13
|
-
def initialize(url)
|
|
15
|
+
def initialize(url)
|
|
14
16
|
@url = url.sub(/[^\/]$/,'\0/')
|
|
17
|
+
@file_list = false
|
|
18
|
+
|
|
19
|
+
def url.file_list?()
|
|
20
|
+
pattern = "<type>ruby_files</type>"
|
|
21
|
+
|
|
22
|
+
@file_list = false
|
|
23
|
+
|
|
24
|
+
url = URI.parse(self)
|
|
25
|
+
code = Net::HTTP.start(url.host, url.port) do |http|
|
|
26
|
+
http.head(url.request_uri).code
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
if code == '200' then
|
|
30
|
+
buffer = open(url, 'UserAgent' => 'Ruby-Requestor').read
|
|
31
|
+
@file_list = true if buffer[/#{pattern}/i]
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
end
|
|
35
|
+
|
|
15
36
|
@names = []
|
|
16
37
|
@code = []
|
|
38
|
+
|
|
39
|
+
if url.file_list? then
|
|
40
|
+
@file_list = true
|
|
41
|
+
@dynarex = Dynarex.new(url)
|
|
42
|
+
end
|
|
17
43
|
end
|
|
18
44
|
|
|
19
45
|
def require(file)
|
|
20
|
-
|
|
46
|
+
|
|
21
47
|
unless @names.include? file then
|
|
48
|
+
if @file_list then
|
|
49
|
+
url = @dynarex.records[file][:body][:url]
|
|
50
|
+
else
|
|
51
|
+
file += '.rb' unless file[/\.rb$/]
|
|
52
|
+
url = @url + file
|
|
53
|
+
end
|
|
22
54
|
@names << file
|
|
23
|
-
@code << open(
|
|
55
|
+
@code << open(url, 'UserAgent' => 'Ruby-Requestor v0.1').read
|
|
24
56
|
end
|
|
25
57
|
end
|
|
26
58
|
|