Class: Zenaton::Client
- Inherits:
-
Object
- Object
- Zenaton::Client
- Includes:
- Singleton
- Defined in:
- lib/zenaton/client.rb
Overview
Zenaton Client
Constant Summary collapse
- ZENATON_WORKER_URL =
Default worker url
'http://localhost'
- DEFAULT_WORKER_PORT =
Default worker port
4001
- WORKER_API_VERSION =
Default worker api version
'v_newton'
- APP_ENV =
Parameter name for the application environment
'app_env'
- APP_ID =
Parameter name for the application ID
'app_id'
Instance Attribute Summary collapse
-
#api_token ⇒ Object
writeonly
Sets the attribute api_token.
-
#app_env ⇒ Object
writeonly
Sets the attribute app_env.
-
#app_id ⇒ Object
writeonly
Sets the attribute app_id.
Class Method Summary collapse
-
.init(app_id, api_token, app_env) ⇒ Zenaton::Client
Class method that sets the three tokens needed to interact with the API.
Instance Method Summary collapse
-
#find_workflow(workflow_name, custom_id) ⇒ Zenaton::Interfaces::Workflow?
Finds a workflow.
-
#kill_workflow(name, custom_id) ⇒ NilClass
Stops a workflow.
-
#pause_workflow(name, custom_id) ⇒ NilClass
Pauses a workflow.
-
#resume_workflow(name, custom_id) ⇒ NilClass
Resumes a workflow.
-
#send_event(workflow_name, custom_id, event) ⇒ NilClass
Sends an event to a workflow.
-
#start_scheduled_task(task, cron) ⇒ Object
Schedule a task for repeated execution.
-
#start_scheduled_workflow(flow, cron) ⇒ Object
Schedule a workflow for repeated execution.
-
#start_task(task) ⇒ Object
Start a single task.
-
#start_workflow(flow) ⇒ Object
Start the specified workflow.
-
#worker_url(resource = '', params = {}) ⇒ String
Gets the url for the workers.
Instance Attribute Details
#api_token=(value) ⇒ Object (writeonly)
Sets the attribute api_token
21 22 23 |
# File 'lib/zenaton/client.rb', line 21 def api_token=(value) @api_token = value end |
#app_env=(value) ⇒ Object (writeonly)
Sets the attribute app_env
21 22 23 |
# File 'lib/zenaton/client.rb', line 21 def app_env=(value) @app_env = value end |
#app_id=(value) ⇒ Object (writeonly)
Sets the attribute app_id
21 22 23 |
# File 'lib/zenaton/client.rb', line 21 def app_id=(value) @app_id = value end |
Class Method Details
.init(app_id, api_token, app_env) ⇒ Zenaton::Client
Class method that sets the three tokens needed to interact with the API
28 29 30 31 32 33 34 |
# File 'lib/zenaton/client.rb', line 28 def self.init(app_id, api_token, app_env) instance.tap do |client| client.app_id = app_id client.api_token = api_token client.app_env = app_env end end |
Instance Method Details
#find_workflow(workflow_name, custom_id) ⇒ Zenaton::Interfaces::Workflow?
Finds a workflow
112 113 114 |
# File 'lib/zenaton/client.rb', line 112 def find_workflow(workflow_name, custom_id) @graphql.find_workflow(workflow_name, custom_id, credentials) end |
#kill_workflow(name, custom_id) ⇒ NilClass
Stops a workflow
88 89 90 |
# File 'lib/zenaton/client.rb', line 88 def kill_workflow(name, custom_id) @graphql.kill_workflow(name, custom_id, credentials) end |
#pause_workflow(name, custom_id) ⇒ NilClass
Pauses a workflow
96 97 98 |
# File 'lib/zenaton/client.rb', line 96 def pause_workflow(name, custom_id) @graphql.pause_workflow(name, custom_id, credentials) end |
#resume_workflow(name, custom_id) ⇒ NilClass
Resumes a workflow
104 105 106 |
# File 'lib/zenaton/client.rb', line 104 def resume_workflow(name, custom_id) @graphql.resume_workflow(name, custom_id, credentials) end |
#send_event(workflow_name, custom_id, event) ⇒ NilClass
Sends an event to a workflow
121 122 123 |
# File 'lib/zenaton/client.rb', line 121 def send_event(workflow_name, custom_id, event) @graphql.send_event(workflow_name, custom_id, event, credentials) end |
#start_scheduled_task(task, cron) ⇒ Object
Schedule a task for repeated execution
73 74 75 76 |
# File 'lib/zenaton/client.rb', line 73 def start_scheduled_task(task, cron) res = @graphql.schedule_task(task, cron, credentials) res && res['createTaskSchedule'] end |
#start_scheduled_workflow(flow, cron) ⇒ Object
Schedule a workflow for repeated execution
79 80 81 82 |
# File 'lib/zenaton/client.rb', line 79 def start_scheduled_workflow(flow, cron) res = @graphql.schedule_workflow(flow, cron, credentials) res && res['createWorkflowSchedule'] end |
#start_task(task) ⇒ Object
Start a single task
62 63 64 |
# File 'lib/zenaton/client.rb', line 62 def start_task(task) @graphql.start_task(task, credentials) end |
#start_workflow(flow) ⇒ Object
Start the specified workflow
68 69 70 |
# File 'lib/zenaton/client.rb', line 68 def start_workflow(flow) @graphql.start_workflow(flow, credentials) end |
#worker_url(resource = '', params = {}) ⇒ String
Gets the url for the workers
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/zenaton/client.rb', line 48 def worker_url(resource = '', params = {}) base_url = ENV['ZENATON_WORKER_URL'] || ZENATON_WORKER_URL port = ENV['ZENATON_WORKER_PORT'] || DEFAULT_WORKER_PORT url = "#{base_url}:#{port}/api/#{WORKER_API_VERSION}/#{resource}" if params.is_a?(Hash) append_params_to_url(url, params) else add_app_env("#{url}?", params) end end |