Class: OpenSandbox::HttpClient

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/open_sandbox/http_client.rb

Overview

Low-level HTTP client for the OpenSandbox API. Not intended to be used directly – use Client instead.

Constant Summary collapse

DEFAULT_TIMEOUT =
30
DEFAULT_OPEN_TIMEOUT =
10

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_url:, api_key: nil, timeout: DEFAULT_TIMEOUT) ⇒ HttpClient

Returns a new instance of HttpClient.



19
20
21
22
23
# File 'lib/open_sandbox/http_client.rb', line 19

def initialize(base_url:, api_key: nil, timeout: DEFAULT_TIMEOUT)
  @base_url     = base_url.chomp("/")
  @api_key      = api_key
  @timeout      = timeout
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



17
18
19
# File 'lib/open_sandbox/http_client.rb', line 17

def api_key
  @api_key
end

#base_urlObject (readonly)

Returns the value of attribute base_url.



17
18
19
# File 'lib/open_sandbox/http_client.rb', line 17

def base_url
  @base_url
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



17
18
19
# File 'lib/open_sandbox/http_client.rb', line 17

def timeout
  @timeout
end

Instance Method Details

#delete(path, headers: {}) ⇒ Object



37
38
39
# File 'lib/open_sandbox/http_client.rb', line 37

def delete(path, headers: {})
  request(:delete, path, headers: headers)
end

#get(path, query: {}, headers: {}) ⇒ Object



25
26
27
# File 'lib/open_sandbox/http_client.rb', line 25

def get(path, query: {}, headers: {})
  request(:get, path, query: query.compact, headers: headers)
end

#post(path, body: {}, headers: {}) ⇒ Object



29
30
31
# File 'lib/open_sandbox/http_client.rb', line 29

def post(path, body: {}, headers: {})
  request(:post, path, body: body, headers: headers)
end

#proxy(method, path, body: nil, headers: {}, raw_body: nil) ⇒ Object

Proxy raw HTTP request to sandbox internal service Returns the raw HTTParty response



43
44
45
# File 'lib/open_sandbox/http_client.rb', line 43

def proxy(method, path, body: nil, headers: {}, raw_body: nil)
  request(method, path, body: body, headers: headers, raw: true, raw_body: raw_body)
end

#proxy_stream(method, path, body: nil, headers: {}, raw_body: nil, &block) ⇒ Object

Stream raw HTTP response body chunks. Intended for SSE/JSONL execd proxy endpoints.



48
49
50
# File 'lib/open_sandbox/http_client.rb', line 48

def proxy_stream(method, path, body: nil, headers: {}, raw_body: nil, &block)
  stream_request(method, path, body: body, headers: headers, raw_body: raw_body, &block)
end

#put(path, body: {}, headers: {}) ⇒ Object



33
34
35
# File 'lib/open_sandbox/http_client.rb', line 33

def put(path, body: {}, headers: {})
  request(:put, path, body: body, headers: headers)
end