Class: OpenSandbox::HttpClient
- Inherits:
-
Object
- Object
- OpenSandbox::HttpClient
- 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
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
Instance Method Summary collapse
- #delete(path, headers: {}) ⇒ Object
- #get(path, query: {}, headers: {}) ⇒ Object
-
#initialize(base_url:, api_key: nil, timeout: DEFAULT_TIMEOUT) ⇒ HttpClient
constructor
A new instance of HttpClient.
- #post(path, body: {}, headers: {}) ⇒ Object
-
#proxy(method, path, body: nil, headers: {}) ⇒ Object
Proxy raw HTTP request to sandbox internal service Returns the raw HTTParty response.
- #put(path, body: {}, headers: {}) ⇒ Object
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_key ⇒ Object (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_url ⇒ Object (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 |
#timeout ⇒ Object (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 |