Class: Runbox::Client
- Inherits:
-
Object
- Object
- Runbox::Client
- Defined in:
- lib/runbox/client.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #delete_containers(identifier) ⇒ Object
- #health ⇒ Object
-
#initialize(url: nil, api_key: nil, timeout: nil, open_timeout: nil) ⇒ Client
constructor
A new instance of Client.
-
#run(container_id:, files:, run_command:, env: {}, timeout: nil, new_dependencies: nil) ⇒ Result
Run code in a container that was set up via setup().
-
#setup(identifier:, language:, env: {}, timeout: nil, memory: nil, network_allow: nil) ⇒ SetupResult
Set up a container and get environment information.
Constructor Details
#initialize(url: nil, api_key: nil, timeout: nil, open_timeout: nil) ⇒ Client
Returns a new instance of Client.
10 11 12 13 14 15 16 17 18 |
# File 'lib/runbox/client.rb', line 10 def initialize(url: nil, api_key: nil, timeout: nil, open_timeout: nil) config = Runbox.configuration @url = url || config.url @api_key = api_key || config.api_key @timeout = timeout || config.timeout @open_timeout = open_timeout || config.open_timeout validate_configuration! end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
8 9 10 |
# File 'lib/runbox/client.rb', line 8 def api_key @api_key end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
8 9 10 |
# File 'lib/runbox/client.rb', line 8 def url @url end |
Instance Method Details
#delete_containers(identifier) ⇒ Object
68 69 70 71 |
# File 'lib/runbox/client.rb', line 68 def delete_containers(identifier) response = delete("/v1/containers/#{identifier}") response["deleted"] || [] end |
#health ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/runbox/client.rb', line 73 def health response = get("/v1/health", auth: false) { status: response["status"], version: response["version"] } end |
#run(container_id:, files:, run_command:, env: {}, timeout: nil, new_dependencies: nil) ⇒ Result
Run code in a container that was set up via setup()
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/runbox/client.rb', line 53 def run(container_id:, files:, run_command:, env: {}, timeout: nil, new_dependencies: nil) payload = { container_id: container_id, files: normalize_files(files), run_command: run_command, env: env } payload[:timeout] = timeout if timeout payload[:new_dependencies] = new_dependencies if new_dependencies response = post("/v1/run", payload) Result.new(response) end |
#setup(identifier:, language:, env: {}, timeout: nil, memory: nil, network_allow: nil) ⇒ SetupResult
Set up a container and get environment information
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/runbox/client.rb', line 29 def setup(identifier:, language:, env: {}, timeout: nil, memory: nil, network_allow: nil) payload = { identifier: identifier, language: language, env: env } payload[:timeout] = timeout if timeout payload[:memory] = memory if memory payload[:network_allow] = network_allow if network_allow response = post("/v1/setup", payload) SetupResult.new(response) end |