Class: Zenaton::Client

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#api_token=(value) ⇒ Object (writeonly)

Sets the attribute api_token

Parameters:

  • value

    the value to set the attribute api_token to.



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

Parameters:

  • value

    the value to set the attribute app_env to.



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

Parameters:

  • value

    the value to set the attribute app_id to.



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

Parameters:

  • app_id (String)

    the ID of your Zenaton application

  • api_token (String)

    your Zenaton account API token

  • app_env (String)

    the environment (dev, staging, prod) to run under

Returns:



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

Parameters:

  • workflow_name (String)

    the class name of the workflow

  • custom_id (String)

    the custom ID of the workflow

Returns:



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

Parameters:

  • name (String)

    the class name of the workflow

  • custom_id (String)

    the custom ID of the workflow

Returns:

  • (NilClass)


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

Parameters:

  • name (String)

    the class name of the workflow

  • custom_id (String)

    the custom ID of the workflow

Returns:

  • (NilClass)


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

Parameters:

  • name (String)

    the class name of the workflow

  • custom_id (String)

    the custom ID of the workflow

Returns:

  • (NilClass)


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

Parameters:

  • workflow_name (String)

    the class name of the workflow

  • custom_id (String)

    the custom ID of the workflow

  • event (Zenaton::Interfaces::Event)

    the event to send

Returns:

  • (NilClass)


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

Parameters:



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

Parameters:



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

Parameters:

  • resource (String) (defaults to: '')

    the endpoint for the worker

  • params (Hash|String) (defaults to: {})

    query params to be url encoded

Returns:

  • (String)

    the workers url with parameters



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