lib/http/securenative_http_client.rb in securenative-0.1.18 vs lib/http/securenative_http_client.rb in securenative-0.1.20
- old
+ new
@@ -1,20 +1,21 @@
# frozen_string_literal: true
-require 'httpclient'
+require 'net/http'
+require 'uri'
+require 'json'
class SecureNativeHttpClient
AUTHORIZATION_HEADER = 'Authorization'
VERSION_HEADER = 'SN-Version'
USER_AGENT_HEADER = 'User-Agent'
- USER_AGENT_HEADER_VALUE = 'SecureNative-python'
+ USER_AGENT_HEADER_VALUE = 'SecureNative-ruby'
CONTENT_TYPE_HEADER = 'Content-Type'
CONTENT_TYPE_HEADER_VALUE = 'application/json'
def initialize(securenative_options)
@options = securenative_options
- @client = HTTPClient.new
end
def _headers
{
CONTENT_TYPE_HEADER => CONTENT_TYPE_HEADER_VALUE,
@@ -23,10 +24,15 @@
AUTHORIZATION_HEADER => @options.api_key
}
end
def post(path, body)
- url = "#{@options.api_url}/#{path}"
+ uri = URI.parse("#{@options.api_url}/#{path}")
headers = _headers
- @client.post(url, body, headers)
+
+ client = Net::HTTP.new(uri.host, uri.port)
+ request = Net::HTTP::Post.new(uri.request_uri, headers)
+ request.body = body.to_json
+
+ client.request(request)
end
end