Class: PxModule::PxHttpClient
- Inherits:
-
Object
- Object
- PxModule::PxHttpClient
- Includes:
- Concurrent::Async
- Defined in:
- lib/perimeterx/utils/px_http_client.rb
Instance Attribute Summary collapse
-
#px_client ⇒ Object
Returns the value of attribute px_client.
-
#px_config ⇒ Object
Returns the value of attribute px_config.
Instance Method Summary collapse
-
#initialize(px_config) ⇒ PxHttpClient
constructor
A new instance of PxHttpClient.
-
#post(path, body, headers, api_timeout = 1, connection_timeout = 1) ⇒ Object
- Runs a POST command to Perimeter X servers Params:
path - string containing uri
body - hash object, containing the request body, must be converted to json format
headers - hash object, hold headers
api_timeout - int, sets the timeout for a request
connection_timeout -
int, sets the timeout for opening a connection.
- int, sets the timeout for a request
- hash object, hold headers
- hash object, containing the request body, must be converted to json format
- string containing uri
- Runs a POST command to Perimeter X servers Params:
Constructor Details
#initialize(px_config) ⇒ PxHttpClient
12 13 14 15 16 |
# File 'lib/perimeterx/utils/px_http_client.rb', line 12 def initialize(px_config) @px_config = px_config @logger = px_config[:logger] @logger.debug("PxHttpClient[initialize]: HTTP client is being initilized with base_uri: #{px_config[:perimeterx_server_host]}") end |
Instance Attribute Details
#px_client ⇒ Object
Returns the value of attribute px_client.
10 11 12 |
# File 'lib/perimeterx/utils/px_http_client.rb', line 10 def px_client @px_client end |
#px_config ⇒ Object
Returns the value of attribute px_config.
9 10 11 |
# File 'lib/perimeterx/utils/px_http_client.rb', line 9 def px_config @px_config end |
Instance Method Details
#post(path, body, headers, api_timeout = 1, connection_timeout = 1) ⇒ Object
Runs a POST command to Perimeter X servers Params:
path-
string containing uri
body-
hash object, containing the request body, must be converted to json format
headers-
hash object, hold headers
api_timeout-
int, sets the timeout for a request
connection_timeout-
int, sets the timeout for opening a connection
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/perimeterx/utils/px_http_client.rb', line 26 def post(path, body, headers, api_timeout = 1, connection_timeout = 1) s = Time.now begin @logger.debug("PxHttpClient[post]: posting to #{path} headers {#{headers.to_json()}} body: {#{body.to_json()}} ") response = Typhoeus.post( "#{px_config[:perimeterx_server_host]}#{path}", headers: headers, body: body.to_json, timeout: api_timeout, connecttimeout: connection_timeout ) if response.timed_out? @logger.warn('PerimeterxS2SValidator[verify]: request timed out') return false end ensure e = Time.now @logger.debug("PxHttpClient[post]: runtime: #{(e-s) * 1000.0}") end return response end |