-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathworkflows.rb
More file actions
107 lines (88 loc) · 2.55 KB
/
workflows.rb
File metadata and controls
107 lines (88 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# frozen_string_literal: true
require "net/http"
require "uri"
module EmbedWorkflow
module Workflows
class << self
include Base
include Client
RESOURCE_BASE_PATH = "#{BASE_API_PATH}/workflows"
def create(name:, template: nil, user_key: nil, event_trigger: nil, trigger_conditions: nil)
attrs = {
name: name,
template: template,
event_trigger: event_trigger,
trigger_conditions: trigger_conditions,
user_key: user_key
}
post_request(
path: RESOURCE_BASE_PATH,
body: attrs
)
end
def fetch(hashid: nil, key: nil)
get_request(
path: "#{RESOURCE_BASE_PATH}/#{hashid}"
)
end
def update(hashid:, name: nil, template: nil, user_key: nil)
attrs = {
name: name,
template: template,
user_key: user_key
}.compact
put_request(
path: "#{RESOURCE_BASE_PATH}/#{hashid}",
body: attrs
)
end
def list(user_key: nil, starting_after: nil, ending_before: nil, limit: nil)
params = {
user_key: user_key,
starting_after: starting_after,
ending_before: ending_before,
limit: limit
}.compact
get_request(
path: RESOURCE_BASE_PATH,
params: params
)
end
def execute(hashid: nil, key: nil, user_key: nil, execution_data: {})
raise ArgumentError, "Hashid or Key is required" if hashid.nil? && key.nil?
attrs = {
user_key: user_key,
id_type: hashid.nil? ? "key" : "hashid",
execution_data: execution_data,
}.compact
post_request(
path: "#{RESOURCE_BASE_PATH}/#{hashid || key}/execute",
body: attrs
)
end
def clone(hashid:, user_key: nil)
attrs = { user_key: user_key }.compact
post_request(
path: "#{RESOURCE_BASE_PATH}/#{hashid}/clone",
body: attrs
)
end
def activities(hashid:)
get_request(
path: "#{RESOURCE_BASE_PATH}/#{hashid}/activities"
)
end
def delete(hashid: nil, key: nil, user_key: nil)
raise ArgumentError, "Hashid or Key is required" if hashid.nil? && key.nil?
attrs = {
user_key: user_key,
id_type: hashid.nil? ? "key" : "hashid"
}.compact
delete_request(
path: "#{RESOURCE_BASE_PATH}/#{hashid || key}",
params: attrs
)
end
end
end
end