lib/stackify/http_client.rb in stackify-api-ruby-1.0.2 vs lib/stackify/http_client.rb in stackify-api-ruby-1.0.3
- old
+ new
@@ -1,8 +1,8 @@
require 'uri'
-require 'net/http'
-require 'net/https'
+require 'faraday'
+
module Stackify
class HttpClient
HEADERS = {
'X-Stackify-PV' => 'V1',
@@ -14,34 +14,23 @@
private
def send_request uri, body, headers = HEADERS
@errors = []
begin
- https = get_https uri
- req = Net::HTTP::Post.new uri.path, initheader = headers
- req.body = body
+ conn = Faraday.new(proxy: Stackify.configuration.proxy)
Stackify.internal_log :debug, "============Request body=========================="
- Stackify.internal_log :debug, req.body
+ Stackify.internal_log :debug, body
Stackify.internal_log :debug, "=================================================="
- @response = https.request req
- rescue => ex
+ @response = conn.post do |req|
+ req.url URI(uri)
+ req.headers = headers
+ req.body = body
+ end
+ rescue => ex
@errors << ex
Stackify.log_internal_error('HttpClient: ' + ex.message+ ' Backtrace: '+ Stackify::Backtrace.backtrace_in_line(ex.backtrace))
false
end
end
- def get_https uri
- if Stackify.configuration.with_proxy
- https = Net::HTTP.new uri.host, uri.port,
- Stackify.configuration.proxy_host,
- Stackify.configuration.proxy_port,
- Stackify.configuration.proxy_user,
- Stackify.configuration.proxy_pass
- else
- https = Net::HTTP.new uri.host, uri.port
- end
- https.use_ssl = true
- https
- end
end
end