20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/argonuts/api.rb', line 20
def self.request(verb, path, options = {})
cli = options[:client] || Argonuts.default_client
url = URI("#{cli.endpoint}#{path}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true if url.instance_of? URI::HTTPS
case verb
when :get
request = Net::HTTP::Get.new(url, 'Content-Type' => 'application/json')
when :post
request = Net::HTTP::Post.new(url, 'Content-Type' => 'application/json')
request.body = options[:json].to_json
end
(cli).map { |k, v| request[k] = v }
resp = http.request(request)
if resp.code.to_i > 399
raise Argonuts::Error, "Server returned HTTP status #{resp.code}."
end
return JSON::parse(resp.body)
end
|