7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/terasms/http_client/base.rb', line 7
def submit url, params, method = 'GET', type = 'text', body =''
begin
uri = URI.parse(url)
uri.query = URI.encode_www_form(params)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.read_timeout = 10
= case type
when 'json'
{'Content-Type' => 'application/json'}
when 'text'
{'Content-Type' => 'text/html'}
else
raise 'unknown type'
end
response = case method
when 'GET'
http.get(uri.request_uri, )
when 'POST'
http.post(uri.request_uri, body, )
else
raise 'unknown http method'
end
result = case type
when 'json'
JSON.parse(response.body)
when 'text'
response.body
end
{"status"=> "success", "result" => result}
rescue => error
{"status"=> "error", "info" => error.to_s}
end
end
|