Class: VcoWorkflows::WorkflowService
- Inherits:
-
Object
- Object
- VcoWorkflows::WorkflowService
- Defined in:
- lib/vcoworkflows/workflowservice.rb
Overview
WorkflowService is the object which acts as the interface to the vCO API, and is loosely modeled from the vCO API documentation.
Instance Attribute Summary collapse
-
#session ⇒ VcoWorkflows::VcoSession
readonly
The VcoSession used by this service.
Instance Method Summary collapse
-
#execute_workflow(id, parameter_json) ⇒ String
Submit the given workflow for execution.
-
#get_execution(workflow_id, execution_id) ⇒ String
Get a WorkflowToken for the requested workflow_id and execution_id.
-
#get_execution_list(workflow_id) ⇒ Hash
Get a list of executions for the given workflow GUID.
-
#get_log(workflow_id, execution_id) ⇒ String
Get the log for a specific execution.
-
#get_presentation(workflow_id) ⇒ String
Get the presentation for the given workflow GUID.
-
#get_workflow_for_id(id) ⇒ String
Get a workflow by GUID.
-
#get_workflow_for_name(name) ⇒ String
Get one workflow with a specified name.
-
#initialize(session) ⇒ VcoWorkflows::WorkflowService
constructor
Create a new WorkflowService.
Constructor Details
#initialize(session) ⇒ VcoWorkflows::WorkflowService
Create a new WorkflowService
21 22 23 |
# File 'lib/vcoworkflows/workflowservice.rb', line 21 def initialize(session) @session = session end |
Instance Attribute Details
#session ⇒ VcoWorkflows::VcoSession (readonly)
The VcoSession used by this service
16 17 18 |
# File 'lib/vcoworkflows/workflowservice.rb', line 16 def session @session end |
Instance Method Details
#execute_workflow(id, parameter_json) ⇒ String
Submit the given workflow for execution
101 102 103 104 105 106 107 |
# File 'lib/vcoworkflows/workflowservice.rb', line 101 def execute_workflow(id, parameter_json) path = "/workflows/#{id}/executions/" response = @session.post(path, parameter_json) # Execution ID is the final component in the Location header URL, so # chop off the front, then pull off any trailing / response.headers[:location].gsub(%r{^.*/executions/}, '').gsub(%r{\/$}, '') end |
#get_execution(workflow_id, execution_id) ⇒ String
Get a WorkflowToken for the requested workflow_id and execution_id
65 66 67 68 |
# File 'lib/vcoworkflows/workflowservice.rb', line 65 def get_execution(workflow_id, execution_id) path = "/workflows/#{workflow_id}/executions/#{execution_id}" @session.get(path).body end |
#get_execution_list(workflow_id) ⇒ Hash
Get a list of executions for the given workflow GUID
73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/vcoworkflows/workflowservice.rb', line 73 def get_execution_list(workflow_id) path = "/workflows/#{workflow_id}/executions/" relations = JSON.parse(@session.get(path).body)['relations'] # The first two elements of the relations['link'] array are URLS, # so scrap them. Everything else is an execution. executions = {} relations['link'].each do |link| next unless link.key?('attributes') attributes = {} link['attributes'].each { |a| attributes[a['name']] = a['value'] } executions[attributes['id']] = attributes end executions end |
#get_log(workflow_id, execution_id) ⇒ String
Get the log for a specific execution
92 93 94 95 |
# File 'lib/vcoworkflows/workflowservice.rb', line 92 def get_log(workflow_id, execution_id) path = "/workflows/#{workflow_id}/executions/#{execution_id}/logs/" @session.get(path).body end |
#get_presentation(workflow_id) ⇒ String
Get the presentation for the given workflow GUID
36 37 38 |
# File 'lib/vcoworkflows/workflowservice.rb', line 36 def get_presentation(workflow_id) @session.get("/workflows/#{workflow_id}/presentation/").body end |
#get_workflow_for_id(id) ⇒ String
Get a workflow by GUID
29 30 31 |
# File 'lib/vcoworkflows/workflowservice.rb', line 29 def get_workflow_for_id(id) @session.get("/workflows/#{id}").body end |
#get_workflow_for_name(name) ⇒ String
Get one workflow with a specified name.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/vcoworkflows/workflowservice.rb', line 43 def get_workflow_for_name(name) path = "/workflows?conditions=name=#{url_encode(name)}" response = JSON.parse(@session.get(path).body) # barf if we got anything other than a single workflow raise(IOError, ERR[:too_many_workflows]) if response['total'] > 1 raise(IOError, ERR[:no_workflow_found]) if response['total'].zero? # yank out the workflow id and name from the result attributes workflow_id = nil response['link'][0]['attributes'].each do |a| workflow_id = a['value'] if a['name'].eql?('id') end # Get the workflow by GUID get_workflow_for_id(workflow_id) end |