Module: Knock::Workflows

Extended by:
Base, Client
Defined in:
lib/knock/workflows.rb

Overview

Methods for interacting with workflows in Knock

Instance Attribute Summary

Attributes included from Base

#key

Class Method Summary collapse

Methods included from Client

client, delete_request, execute_request, get_request, handle_error_response, post_request, put_request, user_agent

Class Method Details

.cancel(key:, cancellation_key:, recipients: nil) ⇒ Hash

Cancels the workflow with the given key and cancellation key

Parameters:

  • key (String)

    The workflow key

  • cancellation_key (String)

    The cancellation key

  • recipients (Array<String, Hash>) (defaults to: nil)

    The recipient identifiers

Returns:

  • (Hash)
    • Cancellation result



47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/knock/workflows.rb', line 47

def cancel(key:, cancellation_key:, recipients: nil)
  attrs = {
    cancellation_key: cancellation_key,
    recipients: recipients
  }

  request = post_request(
    auth: true,
    path: "/v1/workflows/#{key}/cancel",
    body: attrs
  )

  execute_request(request: request)
end

.trigger(key:, actor:, recipients:, data: {}, cancellation_key: nil, tenant: nil) ⇒ Hash

Triggers the workflow with the given key

Parameters:

  • key (String)

    The workflow key

  • actor (String, Hash)

    The actor identifier (optional)

  • recipients (Array<String, Hash>)

    The recipient identifiers

  • data (Hash) (defaults to: {})

    The data to pass to the workflow

  • cancellation_key (String) (defaults to: nil)

    An optional key to identify this workflow invocation for cancelling

  • tenant (String) (defaults to: nil)

    An optional tenant identifier

Returns:

  • (Hash)

    A workflow trigger result



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/knock/workflows.rb', line 22

def trigger(key:, actor:, recipients:, data: {}, cancellation_key: nil, tenant: nil)
  attrs = {
    actor: actor,
    recipients: recipients,
    data: data,
    cancellation_key: cancellation_key,
    tenant: tenant
  }

  request = post_request(
    auth: true,
    path: "/v1/workflows/#{key}/trigger",
    body: attrs
  )

  execute_request(request: request)
end