Class: HttpEnvironment
Overview
Environment accessible over http or https
Instance Attribute Summary
#parent
Instance Method Summary
collapse
#instance, #language, #name, #user
Constructor Details
#initialize(uri, options = {}) ⇒ HttpEnvironment
Returns a new instance of HttpEnvironment.
25
26
27
28
|
# File 'lib/libisi/environment/http.rb', line 25
def initialize(uri, options = {})
@uri = uri
super(nil)
end
|
Instance Method Details
#execute(task, options = {}) ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/libisi/environment/http.rb', line 64
def execute(task, options = {})
url = uri_from_task(task, options)
= nil
request = Net::HTTP::Get.new([url.path,url.query].compact.join("?"), )
response = Net::HTTP.start(url.host, url.port) {|http|
http.request(request)
}
case response
when Net::HTTPSuccess then response
else
raise response.error!
end
if out = task.parameter.options[:output_stream]
out.write(response.body)
out.close_write
else
response.body
end
end
|
#implementation ⇒ Object
31
|
# File 'lib/libisi/environment/http.rb', line 31
def implementation; :ruby; end
|
#type ⇒ Object
30
|
# File 'lib/libisi/environment/http.rb', line 30
def type; :http_access; end
|
#uri ⇒ Object
32
|
# File 'lib/libisi/environment/http.rb', line 32
def uri; @uri; end
|
#uri_from_task(task, options = {}) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/libisi/environment/http.rb', line 34
def uri_from_task(task, options = {})
m_uri = uri.to_s
m_uri = m_uri[0..-2] if m_uri =~ /\/$/
m_uri += "/" + task.function.context
m_uri += "/" + task.function.name
m_uri += "/" + task.parameter.arguments.join("/")
params = task.parameter.options.reject {|name, vals|
[:input_stream,:output_stream].include?(name)
}.map {|name, vals|
case vals
when Array, NilClass
when String
vals = [vals]
else
raise "Dont know how to parametrize class #{vals.class}"
end
vals.map {|val|
p [name, val]
if val
"#{name}=#{CGI.escape(val)}"
else
name
end
}
}.join("&")
URI.parse(m_uri + "?" + params)
end
|