Permalink
Browse files

Merge pull request #471 from jerboaa/api_helper_fix

Fix Ruby API helper to handle HTTPS appropriately.
  • Loading branch information...
2 parents 9ef353d + a341383 commit 3aa38d006d6ac88ed152bb6dc2774fbf2bb69ad1 @benjaminvialle benjaminvialle committed Sep 8, 2011
Showing with 19 additions and 6 deletions.
  1. +19 −6 lib/tools/api_helper.rb
View
@@ -160,13 +160,26 @@ def submit_request(params, uri, param_data)
headers['Authorization'] = auth_header
headers['Content-type'] = "application/x-www-form-urlencoded"
- Net::HTTP.start(uri.host, uri.port) do |http|
- response = http.send_request(params[:request_type], uri.request_uri, param_data, headers)
- if params[:verbose]
- puts "#{response.body}\n#{response.code} #{response.message}"
- else
- puts "#{response.code} #{response.message}"
+ http = Net::HTTP.new(uri.host, uri.port)
+
+ # Enable SSL if uri.scheme indicates so
+ if (uri.scheme == "https")
+ begin
+ # in order to perform https requests
+ require 'net/https'
+ rescue LoadError => e
+ $stderr.puts("Required library not found: '#{e.message}'.")
+ exit(1)
end
+ http.use_ssl = true
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
+ end
+
+ response = http.send_request(params[:request_type], uri.request_uri, param_data, headers)
+ if params[:verbose]
+ puts "#{response.body}\n#{response.code} #{response.message}"
+ else
+ puts "#{response.code} #{response.message}"
end
end

0 comments on commit 3aa38d0

Please sign in to comment.