Class: PxModule::PxHttpClient
- Inherits:
-
Object
- Object
- PxModule::PxHttpClient
- Defined in:
- lib/perimeterx/utils/px_http_client.rb
Instance Attribute Summary collapse
-
#BASE_URL ⇒ Object
Returns the value of attribute BASE_URL.
-
#http_client ⇒ Object
Returns the value of attribute http_client.
-
#px_config ⇒ Object
Returns the value of attribute px_config.
Instance Method Summary collapse
- #async_post(path, body, headers, api_timeout = 0, timeoute = 0) ⇒ Object
-
#initialize(px_config) ⇒ PxHttpClient
constructor
A new instance of PxHttpClient.
- #post(path, body, headers, api_timeout = 0, timeoute = 0) ⇒ Object
Constructor Details
#initialize(px_config) ⇒ PxHttpClient
Returns a new instance of PxHttpClient.
10 11 12 13 14 15 |
# File 'lib/perimeterx/utils/px_http_client.rb', line 10 def initialize(px_config) @px_config = px_config @http_client = HTTPClient.new(:base_url => px_config[:perimeterx_server_host]) @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
#BASE_URL ⇒ Object
Returns the value of attribute BASE_URL.
7 8 9 |
# File 'lib/perimeterx/utils/px_http_client.rb', line 7 def BASE_URL @BASE_URL end |
#http_client ⇒ Object
Returns the value of attribute http_client.
8 9 10 |
# File 'lib/perimeterx/utils/px_http_client.rb', line 8 def http_client @http_client end |
#px_config ⇒ Object
Returns the value of attribute px_config.
6 7 8 |
# File 'lib/perimeterx/utils/px_http_client.rb', line 6 def px_config @px_config end |
Instance Method Details
#async_post(path, body, headers, api_timeout = 0, timeoute = 0) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/perimeterx/utils/px_http_client.rb', line 35 def async_post(path, body, headers, api_timeout = 0, timeoute = 0) @logger.debug("PxHttpClient[async_post]: posting to #{path} headers {#{headers.to_json()}} body: {#{body.to_json()}} ") s = Time.now begin @logger.debug("PxHttpClient[post]: posting to #{path} headers {#{headers.to_json()}} body: {#{body.to_json()}} ") response = @http_client.post_async(path, :header => headers, :body => body.to_json(), :timeout => api_timeout ) rescue Net::OpenTimeout, Net::ReadTimeout => error @logger.warn("PerimeterxS2SValidator[verify]: request timedout") return false end e = Time.now @logger.debug("PxHttpClient[post]: runtime: #{e-s}") return response end |
#post(path, body, headers, api_timeout = 0, timeoute = 0) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/perimeterx/utils/px_http_client.rb', line 17 def post(path, body, headers, api_timeout = 0, timeoute = 0) s = Time.now begin @logger.debug("PxHttpClient[post]: posting to #{path} headers {#{headers.to_json()}} body: {#{body.to_json()}} ") response = @http_client.post(path, :header => headers, :body => body.to_json(), :timeout => api_timeout ) rescue Net::OpenTimeout, Net::ReadTimeout => error @logger.warn("PerimeterxS2SValidator[verify]: request timedout") return false end e = Time.now @logger.debug("PxHttpClient[post]: runtime: #{e-s}") return response end |