embed_workflow 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/embed_workflow/actions.rb +19 -0
- data/lib/embed_workflow/base.rb +11 -0
- data/lib/embed_workflow/client.rb +130 -0
- data/lib/embed_workflow/errors.rb +17 -0
- data/lib/embed_workflow/executions.rb +28 -0
- data/lib/embed_workflow/trigger.rb +31 -0
- data/lib/embed_workflow/users.rb +33 -0
- data/lib/embed_workflow/version.rb +5 -0
- data/lib/embed_workflow/workflows.rb +101 -0
- data/lib/embed_workflow.rb +35 -0
- metadata +96 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 50470d806c76f8fec49b69641c744584af88283540280c638f66852466765672
|
4
|
+
data.tar.gz: 9851ef47251788644528ab4c61f8f499b8e0e2a107ac2a80a87f0a6ca7e517c9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fb89462e3bf6ccd86625e79350aed45111e2bed6715b21acc8d26380ce4277a5e18be3c6320db043bb5b0cce20225183f318ecd21598fada159cb33a4b11b366
|
7
|
+
data.tar.gz: 32533f7fb689caf90ad62a4c8ccaae900a47d25c20407923f144d83595b17766e7ead4b24559e9447732a8504ea970d14cd368e5b375a2fac5a154c762d26490
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "net/http"
|
4
|
+
require "uri"
|
5
|
+
|
6
|
+
module EmbedWorkflow
|
7
|
+
module Actions
|
8
|
+
class << self
|
9
|
+
include Base
|
10
|
+
include Client
|
11
|
+
|
12
|
+
RESOURCE_BASE_PATH = "#{BASE_API_PATH}/actions".freeze
|
13
|
+
|
14
|
+
def activities(hashid:)
|
15
|
+
get_request(path: "#{RESOURCE_BASE_PATH}/activities")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,130 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EmbedWorkflow
|
4
|
+
module Client
|
5
|
+
include Kernel
|
6
|
+
BASE_API_PATH = "/api/v1".freeze
|
7
|
+
BASE_API_URL = "https://embedworkflow.com/".freeze
|
8
|
+
|
9
|
+
def client
|
10
|
+
return @client if defined?(@client)
|
11
|
+
@client = create_connection(URI.parse(BASE_API_URL))
|
12
|
+
@client.use_ssl = true
|
13
|
+
|
14
|
+
@client
|
15
|
+
end
|
16
|
+
|
17
|
+
def get_request(path:, auth: true, params: {})
|
18
|
+
request = build_get_request(path: path, auth: auth, params: params)
|
19
|
+
execute_request(request)
|
20
|
+
end
|
21
|
+
|
22
|
+
def post_request(path:, auth: true, body: nil)
|
23
|
+
request = build_post_request(path: path, auth: auth, body: body)
|
24
|
+
execute_request(request)
|
25
|
+
end
|
26
|
+
|
27
|
+
def delete_request(path:, auth: true, params: {})
|
28
|
+
request = build_delete_request(path: path, auth: auth, params: params)
|
29
|
+
execute_request(request)
|
30
|
+
end
|
31
|
+
|
32
|
+
def put_request(path:, auth: true, body: nil)
|
33
|
+
request = build_put_request(path: path, auth: auth, body: body)
|
34
|
+
execute_request(request)
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def execute_request(request)
|
40
|
+
response = client.request(request)
|
41
|
+
check_errors!(response)
|
42
|
+
|
43
|
+
JSON.parse(response.body) if response.body && (response.body != "")
|
44
|
+
end
|
45
|
+
|
46
|
+
def check_errors!(response)
|
47
|
+
case response.code.to_i
|
48
|
+
when 400
|
49
|
+
raise InvalidRequestError.new(
|
50
|
+
http_status: 400,
|
51
|
+
request_id: response["x-request-id"]
|
52
|
+
)
|
53
|
+
when 401
|
54
|
+
raise AuthenticationError.new(
|
55
|
+
http_status: 401,
|
56
|
+
request_id: response["x-request-id"]
|
57
|
+
)
|
58
|
+
when 404
|
59
|
+
raise APIError.new(
|
60
|
+
http_status: 404,
|
61
|
+
request_id: response["x-request-id"]
|
62
|
+
)
|
63
|
+
when 422
|
64
|
+
raise InvalidRequestError.new(
|
65
|
+
http_status: 422,
|
66
|
+
request_id: response["x-request-id"]
|
67
|
+
)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def create_connection(uri)
|
72
|
+
Net::HTTP.new(uri.host, uri.port)
|
73
|
+
end
|
74
|
+
|
75
|
+
def build_get_request(path:, auth: false, params: {})
|
76
|
+
uri = URI(path)
|
77
|
+
uri.query = URI.encode_www_form(params) if params
|
78
|
+
|
79
|
+
request = Net::HTTP::Get.new(
|
80
|
+
uri.to_s,
|
81
|
+
"Content-Type" => "application/json"
|
82
|
+
)
|
83
|
+
|
84
|
+
add_request_auth_headers(request) if auth
|
85
|
+
add_request_headers(request)
|
86
|
+
request
|
87
|
+
end
|
88
|
+
|
89
|
+
def build_post_request(path:, auth: false, body: nil)
|
90
|
+
request = Net::HTTP::Post.new(path, "Content-Type" => "application/json")
|
91
|
+
request.body = body.to_json if body
|
92
|
+
|
93
|
+
add_request_auth_headers(request) if auth
|
94
|
+
add_request_headers(request)
|
95
|
+
request
|
96
|
+
end
|
97
|
+
|
98
|
+
def build_delete_request(path:, auth: false, params: {})
|
99
|
+
uri = URI(path)
|
100
|
+
uri.query = URI.encode_www_form(params) if params
|
101
|
+
|
102
|
+
request = Net::HTTP::Delete.new(
|
103
|
+
uri.to_s,
|
104
|
+
"Content-Type" => "application/json"
|
105
|
+
)
|
106
|
+
|
107
|
+
add_request_auth_headers(request) if auth
|
108
|
+
add_request_headers(request)
|
109
|
+
request
|
110
|
+
end
|
111
|
+
|
112
|
+
def build_put_request(path:, auth: false, body: nil)
|
113
|
+
request = Net::HTTP::Put.new(path, "Content-Type" => "application/json")
|
114
|
+
request.body = body.to_json if body
|
115
|
+
add_request_auth_headers(request) if auth
|
116
|
+
add_request_headers(request)
|
117
|
+
request
|
118
|
+
end
|
119
|
+
|
120
|
+
def add_request_auth_headers(request)
|
121
|
+
request["Authorization"] = "Bearer #{EmbedWorkflow.skey!}"
|
122
|
+
request
|
123
|
+
end
|
124
|
+
|
125
|
+
def add_request_headers(request)
|
126
|
+
request["User-Agent"] = "Embed Workflow Ruby - v#{EmbedWorkflow::VERSION}"
|
127
|
+
request
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EmbedWorkflow
|
4
|
+
class BaseError < StandardError
|
5
|
+
attr_reader :http_status, :request_id
|
6
|
+
|
7
|
+
def initialize(http_status: nil, request_id: nil)
|
8
|
+
super
|
9
|
+
@http_status = http_status
|
10
|
+
@request_id = request_id
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class APIError < BaseError; end
|
15
|
+
class AuthenticationError < BaseError; end
|
16
|
+
class InvalidRequestError < BaseError; end
|
17
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "net/http"
|
4
|
+
require "uri"
|
5
|
+
|
6
|
+
module EmbedWorkflow
|
7
|
+
module Executions
|
8
|
+
class << self
|
9
|
+
include Base
|
10
|
+
include Client
|
11
|
+
|
12
|
+
RESOURCE_BASE_PATH = "#{BASE_API_PATH}/executions".freeze
|
13
|
+
|
14
|
+
def stop(stop_event:, user_key: nil, filters: nil)
|
15
|
+
attrs = {
|
16
|
+
stop_event: stop_event,
|
17
|
+
user_key: user_key,
|
18
|
+
filters: filters
|
19
|
+
}
|
20
|
+
|
21
|
+
post_request(
|
22
|
+
path: "#{RESOURCE_BASE_PATH}/stop",
|
23
|
+
body: attrs
|
24
|
+
)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "net/http"
|
4
|
+
require "uri"
|
5
|
+
|
6
|
+
module EmbedWorkflow
|
7
|
+
module Trigger
|
8
|
+
class << self
|
9
|
+
include Base
|
10
|
+
include Client
|
11
|
+
|
12
|
+
RESOURCE_BASE_PATH = "#{BASE_API_PATH}/trigger".freeze
|
13
|
+
|
14
|
+
def create(event:, all_workflows: false, workflow_hashids: nil, workflow_keys: nil, user_key: nil, execution_data: nil)
|
15
|
+
attrs = {
|
16
|
+
event: event,
|
17
|
+
all_workflows: all_workflows,
|
18
|
+
workflow_hashids: workflow_hashids,
|
19
|
+
workflow_keys: workflow_keys,
|
20
|
+
user_key: user_key,
|
21
|
+
execution_data: execution_data
|
22
|
+
}.compact
|
23
|
+
|
24
|
+
post_request(
|
25
|
+
path: RESOURCE_BASE_PATH,
|
26
|
+
body: attrs
|
27
|
+
)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "net/http"
|
4
|
+
require "uri"
|
5
|
+
|
6
|
+
module EmbedWorkflow
|
7
|
+
module Users
|
8
|
+
class << self
|
9
|
+
include Base
|
10
|
+
include Client
|
11
|
+
|
12
|
+
RESOURCE_BASE_PATH = "#{BASE_API_PATH}/users".freeze
|
13
|
+
|
14
|
+
def upsert(key:, name: nil, email: nil, config: nil)
|
15
|
+
attrs = {
|
16
|
+
key: key,
|
17
|
+
name: name,
|
18
|
+
email: email,
|
19
|
+
config: config
|
20
|
+
}.compact
|
21
|
+
|
22
|
+
put_request(
|
23
|
+
path: "#{RESOURCE_BASE_PATH}/#{key}",
|
24
|
+
body: attrs
|
25
|
+
)
|
26
|
+
end
|
27
|
+
|
28
|
+
def fetch(key:)
|
29
|
+
get_request(path: "#{RESOURCE_BASE_PATH}/#{key}")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "net/http"
|
4
|
+
require "uri"
|
5
|
+
|
6
|
+
module EmbedWorkflow
|
7
|
+
module Workflows
|
8
|
+
class << self
|
9
|
+
include Base
|
10
|
+
include Client
|
11
|
+
|
12
|
+
RESOURCE_BASE_PATH = "#{BASE_API_PATH}/workflows"
|
13
|
+
|
14
|
+
def create(name:, template: nil, context: nil, auto_start: nil, tenant_key: nil)
|
15
|
+
attrs = {
|
16
|
+
name: name,
|
17
|
+
template: template,
|
18
|
+
auto_start: auto_start,
|
19
|
+
tenant_key: tenant_key,
|
20
|
+
context: context
|
21
|
+
}
|
22
|
+
|
23
|
+
post_request(
|
24
|
+
path: RESOURCE_BASE_PATH,
|
25
|
+
body: attrs
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
def fetch(hashid: nil, key: nil)
|
30
|
+
get_request(
|
31
|
+
path: "#{RESOURCE_BASE_PATH}/#{hashid}"
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
def update(hashid:, name: nil, template: nil, tenant_key: nil, context: nil, auto_start: nil)
|
36
|
+
attrs = {
|
37
|
+
name: name,
|
38
|
+
template: template,
|
39
|
+
tenant_key: tenant_key,
|
40
|
+
context: context
|
41
|
+
}.compact
|
42
|
+
|
43
|
+
put_request(
|
44
|
+
path: "#{RESOURCE_BASE_PATH}/#{hashid}",
|
45
|
+
body: attrs
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
def list(user_key: nil, starting_after: nil, ending_before: nil)
|
50
|
+
get_request(
|
51
|
+
path: RESOURCE_BASE_PATH,
|
52
|
+
params: { user_key: user_key, starting_after: starting_after, ending_before: ending_before }.compact
|
53
|
+
)
|
54
|
+
end
|
55
|
+
|
56
|
+
def execute(hashid: nil, key: nil, user_key: nil, execution_data: {})
|
57
|
+
raise ArgumentError, "Hashid or Key is required" if hashid.nil? && key.nil?
|
58
|
+
|
59
|
+
attrs = {
|
60
|
+
user_key: user_key,
|
61
|
+
id_type: hashid.nil? ? "key" : "hashid",
|
62
|
+
execution_data: execution_data,
|
63
|
+
}.compact
|
64
|
+
|
65
|
+
post_request(
|
66
|
+
path: "#{RESOURCE_BASE_PATH}/#{hashid || key}/execute",
|
67
|
+
body: attrs
|
68
|
+
)
|
69
|
+
end
|
70
|
+
|
71
|
+
def clone(hashid:, user_key: nil)
|
72
|
+
attrs = { user_key: user_key }.compact
|
73
|
+
|
74
|
+
post_request(
|
75
|
+
path: "#{RESOURCE_BASE_PATH}/#{hashid}/clone",
|
76
|
+
body: attrs
|
77
|
+
)
|
78
|
+
end
|
79
|
+
|
80
|
+
def activities(hashid:)
|
81
|
+
get_request(
|
82
|
+
path: "#{RESOURCE_BASE_PATH}/#{hashid}/activities"
|
83
|
+
)
|
84
|
+
end
|
85
|
+
|
86
|
+
def delete(hashid: nil, key: nil, user_key: nil)
|
87
|
+
raise ArgumentError, "Hashid or Key is required" if hashid.nil? && key.nil?
|
88
|
+
|
89
|
+
attrs = {
|
90
|
+
user_key: user_key,
|
91
|
+
id_type: hashid.nil? ? "key" : "hashid"
|
92
|
+
}.compact
|
93
|
+
|
94
|
+
delete_request(
|
95
|
+
path: "#{RESOURCE_BASE_PATH}/#{hashid || key}",
|
96
|
+
params: attrs
|
97
|
+
)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "embed_workflow/version"
|
4
|
+
require "json"
|
5
|
+
|
6
|
+
module EmbedWorkflow
|
7
|
+
def self.skey=(value)
|
8
|
+
Base.skey = value
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.skey
|
12
|
+
Base.skey
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.skey!
|
16
|
+
skey || raise("EmbedWorkflow.skey not set")
|
17
|
+
end
|
18
|
+
|
19
|
+
autoload :Base, "embed_workflow/base"
|
20
|
+
autoload :Client, "embed_workflow/client"
|
21
|
+
|
22
|
+
autoload :Actions, "embed_workflow/actions"
|
23
|
+
autoload :Executions, "embed_workflow/executions"
|
24
|
+
autoload :Trigger, "embed_workflow/trigger"
|
25
|
+
autoload :Users, "embed_workflow/users"
|
26
|
+
autoload :Workflows, "embed_workflow/workflows"
|
27
|
+
|
28
|
+
autoload :APIError, "embed_workflow/errors"
|
29
|
+
autoload :AuthenticationError, "embed_workflow/errors"
|
30
|
+
autoload :InvalidRequestError, "embed_workflow/errors"
|
31
|
+
|
32
|
+
def self.trigger(**args)
|
33
|
+
Trigger.create(**args)
|
34
|
+
end
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: embed_workflow
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Embed Workflow
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-02-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.0.1
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.0.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: standard
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: API client for Embed Workflow
|
56
|
+
email:
|
57
|
+
- devsupport@embedworkflow.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- lib/embed_workflow.rb
|
63
|
+
- lib/embed_workflow/actions.rb
|
64
|
+
- lib/embed_workflow/base.rb
|
65
|
+
- lib/embed_workflow/client.rb
|
66
|
+
- lib/embed_workflow/errors.rb
|
67
|
+
- lib/embed_workflow/executions.rb
|
68
|
+
- lib/embed_workflow/trigger.rb
|
69
|
+
- lib/embed_workflow/users.rb
|
70
|
+
- lib/embed_workflow/version.rb
|
71
|
+
- lib/embed_workflow/workflows.rb
|
72
|
+
homepage: https://github.com/embedworkflow/embed-workflow-ruby
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
metadata:
|
76
|
+
documentation_uri: https://api-docs.embedworkflow.com
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '2.5'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubygems_version: 3.1.4
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: API client for Embed Workflow
|
96
|
+
test_files: []
|