Class: SecureNative::SecureNativeHttpClient
- Inherits:
-
Object
- Object
- SecureNative::SecureNativeHttpClient
- Defined in:
- lib/securenative/http/securenative_http_client.rb
Constant Summary collapse
- AUTHORIZATION_HEADER =
'Authorization'- VERSION_HEADER =
'SN-Version'- USER_AGENT_HEADER =
'User-Agent'- USER_AGENT_HEADER_VALUE =
'SecureNative-ruby'- CONTENT_TYPE_HEADER =
'Content-Type'- CONTENT_TYPE_HEADER_VALUE =
'application/json'
Instance Method Summary collapse
- #_headers ⇒ Object
-
#initialize(securenative_options) ⇒ SecureNativeHttpClient
constructor
A new instance of SecureNativeHttpClient.
- #post(path, body) ⇒ Object
Constructor Details
#initialize(securenative_options) ⇒ SecureNativeHttpClient
Returns a new instance of SecureNativeHttpClient.
18 19 20 |
# File 'lib/securenative/http/securenative_http_client.rb', line 18 def initialize() @options = end |
Instance Method Details
#_headers ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/securenative/http/securenative_http_client.rb', line 22 def _headers { CONTENT_TYPE_HEADER => CONTENT_TYPE_HEADER_VALUE, USER_AGENT_HEADER => USER_AGENT_HEADER_VALUE, VERSION_HEADER => VersionUtils.version, AUTHORIZATION_HEADER => @options.api_key } end |
#post(path, body) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/securenative/http/securenative_http_client.rb', line 31 def post(path, body) uri = URI.parse("#{@options.api_url}/#{path}") headers = _headers client = Net::HTTP.new(uri.host, uri.port) 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 SecureNativeLogger.error("Failed to send request; #{e}") return res end res end |