Class: E2B::API::HttpClient
- Inherits:
-
Object
- Object
- E2B::API::HttpClient
- Defined in:
- lib/e2b/api/http_client.rb
Overview
HTTP client wrapper for E2B API communication
Handles authentication, request/response processing, and error handling.
Defined Under Namespace
Classes: DetailedResponse
Constant Summary collapse
- DEFAULT_TIMEOUT =
Default request timeout in seconds
120
Instance Attribute Summary collapse
-
#base_url ⇒ String
readonly
Base URL for API requests.
Instance Method Summary collapse
-
#delete(path, body: nil, timeout: DEFAULT_TIMEOUT, detailed: false) ⇒ Hash, ...
Perform a DELETE request.
-
#get(path, params: {}, timeout: DEFAULT_TIMEOUT, detailed: false) ⇒ Hash, ...
Perform a GET request.
-
#initialize(base_url:, api_key: nil, access_token: nil, logger: nil) ⇒ HttpClient
constructor
Initialize a new HTTP client.
-
#post(path, body: nil, timeout: DEFAULT_TIMEOUT, detailed: false) ⇒ Hash, ...
Perform a POST request.
-
#put(path, body: nil, timeout: DEFAULT_TIMEOUT, detailed: false) ⇒ Hash, ...
Perform a PUT request.
Constructor Details
#initialize(base_url:, api_key: nil, access_token: nil, logger: nil) ⇒ HttpClient
Initialize a new HTTP client
27 28 29 30 31 32 33 |
# File 'lib/e2b/api/http_client.rb', line 27 def initialize(base_url:, api_key: nil, access_token: nil, logger: nil) @base_url = base_url.end_with?("/") ? base_url : "#{base_url}/" @api_key = api_key @access_token = access_token @logger = logger @connection = build_connection end |
Instance Attribute Details
#base_url ⇒ String (readonly)
Returns Base URL for API requests.
19 20 21 |
# File 'lib/e2b/api/http_client.rb', line 19 def base_url @base_url end |
Instance Method Details
#delete(path, body: nil, timeout: DEFAULT_TIMEOUT, detailed: false) ⇒ Hash, ...
Perform a DELETE request
86 87 88 89 90 91 92 93 |
# File 'lib/e2b/api/http_client.rb', line 86 def delete(path, body: nil, timeout: DEFAULT_TIMEOUT, detailed: false) handle_response(detailed: detailed) do @connection.delete(normalize_path(path)) do |req| req.body = body.to_json if body req..timeout = timeout end end end |
#get(path, params: {}, timeout: DEFAULT_TIMEOUT, detailed: false) ⇒ Hash, ...
Perform a GET request
41 42 43 44 45 46 47 48 |
# File 'lib/e2b/api/http_client.rb', line 41 def get(path, params: {}, timeout: DEFAULT_TIMEOUT, detailed: false) handle_response(detailed: detailed) do @connection.get(normalize_path(path)) do |req| req.params = params req..timeout = timeout end end end |
#post(path, body: nil, timeout: DEFAULT_TIMEOUT, detailed: false) ⇒ Hash, ...
Perform a POST request
56 57 58 59 60 61 62 63 |
# File 'lib/e2b/api/http_client.rb', line 56 def post(path, body: nil, timeout: DEFAULT_TIMEOUT, detailed: false) handle_response(detailed: detailed) do @connection.post(normalize_path(path)) do |req| req.body = body.to_json if body req..timeout = timeout end end end |
#put(path, body: nil, timeout: DEFAULT_TIMEOUT, detailed: false) ⇒ Hash, ...
Perform a PUT request
71 72 73 74 75 76 77 78 |
# File 'lib/e2b/api/http_client.rb', line 71 def put(path, body: nil, timeout: DEFAULT_TIMEOUT, detailed: false) handle_response(detailed: detailed) do @connection.put(normalize_path(path)) do |req| req.body = body.to_json if body req..timeout = timeout end end end |