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.



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

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.



15
16
17
# File 'lib/open_sandbox/http_client.rb', line 15

def api_key
  @api_key
end

#base_urlObject (readonly)

Returns the value of attribute base_url.



15
16
17
# File 'lib/open_sandbox/http_client.rb', line 15

def base_url
  @base_url
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



15
16
17
# File 'lib/open_sandbox/http_client.rb', line 15

def timeout
  @timeout
end

Instance Method Details

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



35
36
37
# File 'lib/open_sandbox/http_client.rb', line 35

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

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



23
24
25
# File 'lib/open_sandbox/http_client.rb', line 23

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

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



27
28
29
# File 'lib/open_sandbox/http_client.rb', line 27

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

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

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



41
42
43
# File 'lib/open_sandbox/http_client.rb', line 41

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

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



31
32
33
# File 'lib/open_sandbox/http_client.rb', line 31

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