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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/gfspark/connection.rb', line 31
def send_request(url, json = {}, options = {}, params = {}, method = :post)
url = "#{url}"
uri = URI.parse(url)
if @debug
puts '-' * 80
puts url
pp json
puts '-' * 80
end
https = connection(uri.host, uri.port)
https.use_ssl = true if uri.scheme == 'https'
https.verify_mode = @ssl_options[:ssl_verify_mode] || OpenSSL::SSL::VERIFY_NONE
store = OpenSSL::X509::Store.new
unless @ssl_options[:ssl_ca_cert].nil?
if File.directory? @ssl_options[:ssl_ca_cert]
store.add_path @ssl_options[:ssl_ca_cert]
else
store.add_file @ssl_options[:ssl_ca_cert]
end
http.cert_store = store
else
store.set_default_paths
end
https.cert_store = store
https.set_debug_output $stderr if @debug && https.respond_to?(:set_debug_output)
https.start{|http|
path = "#{uri.path}"
path += "?" + params.map{|k,v| "#{k}=#{v}"}.join("&") unless params.empty?
request = case method
when :post then Net::HTTP::Post.new(path)
when :put then Net::HTTP::Put.new(path)
when :get then Net::HTTP::Get.new(path)
else raise "unknown method #{method}"
end
if @options[:username] && @options[:password]
request.basic_auth @options[:username], @options[:password]
end
request.set_content_type("application/json")
request.body = json.to_json unless json.nil?
response = http.request(request)
if @debug
puts "#{response.code}: #{response.msg}"
puts response.body
end
response
}
end
|