class SecureNative::HttpClient

Constants

AUTHORIZATION_HEADER
CONTENT_TYPE_HEADER
CONTENT_TYPE_HEADER_VALUE
USER_AGENT_HEADER
USER_AGENT_HEADER_VALUE
VERSION_HEADER

Public Class Methods

new(securenative_options) click to toggle source
# File lib/securenative/http_client.rb, line 12
def initialize(securenative_options)
  @options = securenative_options
end

Public Instance Methods

_headers() click to toggle source
# File lib/securenative/http_client.rb, line 16
def _headers
  {
    CONTENT_TYPE_HEADER => CONTENT_TYPE_HEADER_VALUE,
    USER_AGENT_HEADER => USER_AGENT_HEADER_VALUE,
    VERSION_HEADER => SecureNative::Utils::VersionUtils.version,
    AUTHORIZATION_HEADER => @options.api_key
  }
end
post(path, body) click to toggle source
# File lib/securenative/http_client.rb, line 25
def post(path, body)
  uri = URI.parse("#{@options.api_url}/#{path}")
  headers = _headers

  client = Net::HTTP.new(uri.host, uri.port)
  client.read_timeout = @options.timeout / 1000
  client.use_ssl = true
  client.verify_mode = OpenSSL::SSL::VERIFY_NONE

  request = Net::HTTP::Post.new(uri.request_uri, headers)
  request.body = body

  res = nil
  begin
    res = client.request(request)
  rescue StandardError => e
    SecureNative::Log.error("Failed to send request; #{e}")
    return res
  end
  res
end