24
25
26
27
28
29
30
31
32
33
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
63
64
65
66
67
|
# File 'lib/educandus_api/estab.rb', line 24
def sendRequest(options = {})
raise Educandus::Error, "The response must be valid!." unless (!@response.empty? || !@cookie.nil?)
if options.has_key?("url")
url = options[:url]
else
url = @url
end
if options.has_key?("headers") && options[:headers].empty?
= {"Cookies" => @response["set-cookies"]}
else
if !@response.empty?
= {"Cookie" => @response["set-cookie"]}
else
= {}
end
end
if options.has_key?("path")
path = options[:path]
else
path = "/"
end
if options.has_key?("post")
if !options.has_key?("method") || !options[:method] == "post"
raise Educandus::Error, "If you pass POST parameters, you must set the METHOD to POST"
else
post = options[:post]
end
end
@connection = Net::HTTP.new(url,443)
@connection.use_ssl = true
if options.has_key?(:method)
method = options[:method].downcase
else
method = "get"
end
begin
method == "post" ? (rsp, data = @connection.post(path,post,)) : ''
method == "get" ? (rsp, data = @connection.get(path,)) : ''
rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError,
Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e
raise Educandus::Error, "The Host seems to be down (like always)."
end
puts rsp.body
end
|