class Datadome::Client
Constants
- OPEN_TIMEOUT
- TIMEOUT
Public Class Methods
base_url()
click to toggle source
# File lib/datadome/client.rb, line 14 def base_url "https://#{Datadome.configuration.api_server}/" end
default_params()
click to toggle source
# File lib/datadome/client.rb, line 18 def default_params { "Key" => Datadome.configuration.api_key, "RequestModuleName" => "DataDome Ruby Gem", "ModuleVersion" => ::Datadome::VERSION, "ServerName" => hostname, } end
hostname()
click to toggle source
# File lib/datadome/client.rb, line 27 def hostname Socket.gethostname end
Public Instance Methods
check()
click to toggle source
# File lib/datadome/client.rb, line 33 def check response = connection.get do |req| req.url("check") end response end
validate_request(data)
click to toggle source
# File lib/datadome/client.rb, line 42 def validate_request(data) data = data.merge(self.class.default_params) response = connection.post do |req| req.url("validate-request") req.headers["User-Agent"] = "DataDome" req.body = data end ValidationResponse.from_faraday_response(response) rescue Faraday::Error::ConnectionFailed, Faraday::Error::TimeoutError => e Datadome.logger.warn("Datadome: Timeout #{e}") ValidationResponse.pass end
Private Instance Methods
connection()
click to toggle source
# File lib/datadome/client.rb, line 61 def connection @connection ||= Faraday.new(url: self.class.base_url) do |faraday| faraday.request(:url_encoded) faraday.adapter(Faraday.default_adapter) faraday.options[:open_timeout] = OPEN_TIMEOUT faraday.options[:timeout] = TIMEOUT end end