Class: ComplyanceSDK::HTTP::Client
- Inherits:
-
Object
- Object
- ComplyanceSDK::HTTP::Client
- Defined in:
- lib/complyance_sdk/http/client.rb
Overview
HTTP client for making requests to the Complyance API
Constant Summary collapse
- DEFAULT_TIMEOUT =
Default timeout in seconds
30
Instance Method Summary collapse
-
#get(path, params = {}, headers = {}) ⇒ Hash
Make a GET request to the API.
-
#initialize(config) ⇒ Client
constructor
Initialize a new HTTP client.
-
#post(path, payload = {}, headers = {}) ⇒ Hash
Make a POST request to the API.
Constructor Details
#initialize(config) ⇒ Client
Initialize a new HTTP client
19 20 21 22 |
# File 'lib/complyance_sdk/http/client.rb', line 19 def initialize(config) @config = config @connection = build_connection end |
Instance Method Details
#get(path, params = {}, headers = {}) ⇒ Hash
Make a GET request to the API
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/complyance_sdk/http/client.rb', line 72 def get(path, params = {}, headers = {}) response = @connection.get(path) do |req| req.headers.merge!(headers) req.params.merge!(params) end handle_response(response) rescue Faraday::Error => e handle_faraday_error(e) end |
#post(path, payload = {}, headers = {}) ⇒ Hash
Make a POST request to the API
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/complyance_sdk/http/client.rb', line 30 def post(path, payload = {}, headers = {}) # Get the full URL base_url = ComplyanceSDK::Models::Environment.base_url(@config.environment) full_url = "#{base_url}#{path}" # Log request details puts "\nš === API REQUEST ===" puts "š URL: #{full_url}" puts "š Headers: #{headers.merge('Content-Type' => 'application/json')}" puts "š¦ Payload:" puts JSON.pretty_generate(payload) puts "========================\n" response = @connection.post(path) do |req| req.headers.merge!(headers) req.headers["Content-Type"] = "application/json" req.body = payload.to_json end # Log response details puts "\nš„ === API RESPONSE ===" puts "š Status: #{response.status}" puts "š Headers: #{response.headers}" puts "š¦ Body:" puts JSON.pretty_generate(response.body) if response.body puts "========================\n" handle_response(response) rescue Faraday::Error => e puts "\nā === API ERROR ===" puts "šØ Error: #{e.class.name}" puts "š Message: #{e.}" puts "===================\n" handle_faraday_error(e) end |