active_workflow_agent 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 760bc7e511153b9589591f3a1aaf245519a8bb1df5265987f884c98faefda1ef
4
+ data.tar.gz: 984ffb2222a4de580114b000dcd6dbfea631259f6a8478f7452c51dab5ccf781
5
+ SHA512:
6
+ metadata.gz: 43ba4c7d73088c7b956c630575552c6fc26f60ce6ff1b4f165e4d2ee96cb29388777729b0e0b3a27d71318d77bb5843a34c3becc6db6f14aa9701bc9e7993f54
7
+ data.tar.gz: 5672d6b21f2ca4cf92b32f10ac73e14e74adf749ae8aca3b5f4a6e647eb12c3b43916415de86740ae36c727a2ef5d1d9ceb997ae64835380b86108ff4eee441b
@@ -0,0 +1,18 @@
1
+ name: Ruby
2
+
3
+ on: [push,pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v2
10
+ - name: Set up Ruby
11
+ uses: ruby/setup-ruby@v1
12
+ with:
13
+ ruby-version: 2.7.2
14
+ - name: Run the default task
15
+ run: |
16
+ gem install bundler -v 2.2.14
17
+ bundle install
18
+ bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,43 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ # Ignore Byebug command history file.
17
+ .byebug_history
18
+
19
+ ## Documentation cache and generated files:
20
+ /.yardoc/
21
+ /_yardoc/
22
+ /doc/
23
+ /rdoc/
24
+
25
+ ## Environment normalization:
26
+ /.bundle/
27
+ /vendor/bundle
28
+ /lib/bundler/man/
29
+
30
+ # for a library or gem, you might want to ignore these files since the code is
31
+ # intended to run in multiple environments; otherwise, check them in:
32
+ # Gemfile.lock
33
+ .ruby-version
34
+ .ruby-gemset
35
+
36
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
37
+ .rvmrc
38
+
39
+ # Used by RuboCop. Remote config files pulled in from inherit_from directive.
40
+ .rubocop-https?--*
41
+
42
+ # rspec failure tracking
43
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,25 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.4
3
+ SuggestExtensions: false
4
+ Exclude:
5
+ - 'active_workflow_agent.gemspec'
6
+
7
+ Style/StringLiterals:
8
+ Enabled: true
9
+ EnforcedStyle: double_quotes
10
+
11
+ Style/StringLiteralsInInterpolation:
12
+ Enabled: true
13
+ EnforcedStyle: double_quotes
14
+
15
+ Layout/LineLength:
16
+ Max: 80
17
+
18
+ Metrics/MethodLength:
19
+ Max: 15
20
+
21
+ Metrics/BlockLength:
22
+ IgnoredMethods: ['describe', 'context']
23
+
24
+ Style/CombinableLoops:
25
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2021-03-25
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in active_workflow_agent.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+ gem "rspec", "~> 3.0"
10
+ gem "rubocop", "~> 1.7"
data/Gemfile.lock ADDED
@@ -0,0 +1,55 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ active_workflow_agent (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.2)
10
+ diff-lcs (1.4.4)
11
+ parallel (1.20.1)
12
+ parser (3.0.0.0)
13
+ ast (~> 2.4.1)
14
+ rainbow (3.0.0)
15
+ rake (13.0.3)
16
+ regexp_parser (2.1.1)
17
+ rexml (3.2.4)
18
+ rspec (3.10.0)
19
+ rspec-core (~> 3.10.0)
20
+ rspec-expectations (~> 3.10.0)
21
+ rspec-mocks (~> 3.10.0)
22
+ rspec-core (3.10.1)
23
+ rspec-support (~> 3.10.0)
24
+ rspec-expectations (3.10.1)
25
+ diff-lcs (>= 1.2.0, < 2.0)
26
+ rspec-support (~> 3.10.0)
27
+ rspec-mocks (3.10.2)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.10.0)
30
+ rspec-support (3.10.2)
31
+ rubocop (1.11.0)
32
+ parallel (~> 1.10)
33
+ parser (>= 3.0.0.0)
34
+ rainbow (>= 2.2.2, < 4.0)
35
+ regexp_parser (>= 1.8, < 3.0)
36
+ rexml
37
+ rubocop-ast (>= 1.2.0, < 2.0)
38
+ ruby-progressbar (~> 1.7)
39
+ unicode-display_width (>= 1.4.0, < 3.0)
40
+ rubocop-ast (1.4.1)
41
+ parser (>= 2.7.1.5)
42
+ ruby-progressbar (1.11.0)
43
+ unicode-display_width (2.0.0)
44
+
45
+ PLATFORMS
46
+ ruby
47
+
48
+ DEPENDENCIES
49
+ active_workflow_agent!
50
+ rake (~> 13.0)
51
+ rspec (~> 3.0)
52
+ rubocop (~> 1.7)
53
+
54
+ BUNDLED WITH
55
+ 2.1.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Automatic Mode Labs AG
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # ActiveWorkflowAgent
2
+
3
+ ![GitHub Workflow Status](https://img.shields.io/github/workflow/status/automaticmode/active_workflow_agent/Ruby?label=build&style=flat-square) ![GitHub](https://img.shields.io/github/license/automaticmode/active_workflow_agent?color=27aace&style=flat-square)
4
+
5
+ This library helps you to write your own [ActiveWorkflow](https://docs.activeworkflow.org/) agents in **Ruby** using ActiveWorkflow's [remote agent API](https://docs.activeworkflow.org/remote-agent-api/).
6
+
7
+ ## Installation
8
+
9
+ Add this line to your agent's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'active_workflow_agent'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install active_workflow_agent
22
+
23
+ ## Documentation
24
+
25
+ For full documentation please see [ActiveWorkflow Agent Ruby](https://docs.activeworkflow.org/activeworkflow-agent-ruby) on ActiveWorkflow's documentation website.
26
+
27
+ ## License
28
+
29
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/active_workflow_agent/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "active_workflow_agent"
7
+ spec.version = ActiveWorkflowAgent::VERSION
8
+ spec.authors = ["Automatic Mode Labs"]
9
+ spec.email = ["info@automaticmode.com"]
10
+
11
+ spec.summary = "Helper library for writing ActiveWorkflow agents."
12
+ spec.homepage = "https://github.com/automaticmode/active_workflow_agent"
13
+ spec.license = "MIT"
14
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
20
+ end
21
+ spec.require_paths = ["lib"]
22
+ end
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "active_workflow_agent"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "active_workflow_agent/version"
4
+ require_relative "active_workflow_agent/parsed_request"
5
+ require_relative "active_workflow_agent/response"
6
+ require_relative "active_workflow_agent/register_response"
7
+
8
+ module ActiveWorkflowAgent
9
+ CheckResponse = Response
10
+ ReceiveResponse = Response
11
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveWorkflowAgent
4
+ # Helper class to parse the content of a request from the Agent API.
5
+ class ParsedRequest
6
+ attr_reader :method, :options, :memory, :credentials, :message
7
+
8
+ def initialize(request)
9
+ @method = request["method"].to_sym
10
+ # Set to empty for 'register' method.
11
+ @options = {}
12
+ @memory = {}
13
+ @credentials = []
14
+ @message = {}
15
+
16
+ if %i[check receive].include? @method
17
+ @options = request["params"]["options"]
18
+ @memory = request["params"]["memory"]
19
+ @credentials = request["params"]["credentials"]
20
+ end
21
+ @message = request["params"]["message"]["payload"] if @method == :receive
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+
5
+ module ActiveWorkflowAgent
6
+ # Helper class to construct a response to ActiveWorkflow's register method.
7
+ # https://docs.activeworkflow.org/remote-agent-api#the-register-method
8
+ class RegisterResponse
9
+ def initialize(name:, display_name:, description:, default_options: {})
10
+ @name = name
11
+ @display_name = display_name
12
+ @description = description
13
+ @default_options = default_options
14
+
15
+ validate_args
16
+ end
17
+
18
+ def to_h
19
+ {
20
+ "result" => {
21
+ "name" => @name,
22
+ "display_name" => @display_name,
23
+ "description" => @description,
24
+ "default_options" => @default_options
25
+ }
26
+ }
27
+ end
28
+
29
+ def to_json(*)
30
+ JSON.dump(to_h)
31
+ end
32
+
33
+ private
34
+
35
+ def validate_args
36
+ str_msg = "must be a string"
37
+ empty_msg = "can not be empty"
38
+ whitespace_msg = "can not have whitespace"
39
+ hash_msg = "must be a hash"
40
+
41
+ # name
42
+ raise(ArgumentError, "name #{str_msg}") unless @name.is_a?(String)
43
+ raise(ArgumentError, "name #{empty_msg}") if @name.empty?
44
+ raise(ArgumentError, "name #{whitespace_msg}") if @name.include?(" ")
45
+ # display_name
46
+ # rubocop:disable Layout/LineLength
47
+ raise(ArgumentError, "display_name #{str_msg}") unless @display_name.is_a?(String)
48
+ raise(ArgumentError, "display_name #{empty_msg}") if @display_name.empty?
49
+ # default_options
50
+ raise(ArgumentError, "default_options #{hash_msg}") unless @default_options.is_a?(Hash)
51
+ # rubocop:enable Layout/LineLength
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+
5
+ module ActiveWorkflowAgent
6
+ # Helper class to construct responses to ActiveWorkflow's agent API.
7
+ # https://docs.activeworkflow.org/remote-agent-api#responses
8
+ class Response
9
+ # Create an object for responding to 'receive' or 'check' methods.
10
+ def initialize
11
+ @logs = []
12
+ @errors = []
13
+ @messages = []
14
+ @memory = {}
15
+ end
16
+
17
+ # Add log messages to the response object.
18
+ def add_logs(*logs)
19
+ # Validation.
20
+ must_str = "must be (non-empty) strings"
21
+ not_empty = "can not be empty strings"
22
+ logs.each do |log|
23
+ raise(ArgumentError, "Logs #{must_str}.") unless log.is_a?(String)
24
+ raise(ArgumentError, "Logs #{not_empty}.") if log == ""
25
+ end
26
+
27
+ logs.each { |log| @logs << log }
28
+ end
29
+
30
+ def add_errors(*errors)
31
+ # Validation.
32
+ must_str = "must be (non-empty) strings"
33
+ not_empty = "can not be empty strings"
34
+ errors.each do |err|
35
+ raise(ArgumentError, "Errors #{must_str}.") unless err.is_a?(String)
36
+ raise(ArgumentError, "Errors #{not_empty}.") if err == ""
37
+ end
38
+
39
+ errors.each { |err| @errors << err }
40
+ end
41
+
42
+ def add_messages(*messages)
43
+ # Validation.
44
+ must_hash = "must be (non-empty) hashes"
45
+ not_empty = "can not be empty hashes"
46
+ messages.each do |msg|
47
+ raise(ArgumentError, "Messages #{must_hash}.") unless msg.is_a?(Hash)
48
+ raise(ArgumentError, "Messages #{not_empty}.") if msg == {}
49
+ end
50
+
51
+ messages.each { |msg| @messages << msg }
52
+ end
53
+
54
+ def add_memory(memory)
55
+ must_hash = "must be a hash"
56
+ raise(ArgumentError, "Memory #{must_hash}.") unless memory.is_a?(Hash)
57
+
58
+ @memory = memory
59
+ end
60
+
61
+ def to_h
62
+ {
63
+ "result" => {
64
+ "logs" => @logs,
65
+ "errors" => @errors,
66
+ "messages" => @messages,
67
+ "memory" => @memory
68
+ }
69
+ }
70
+ end
71
+
72
+ def to_json(*)
73
+ JSON.dump(to_h)
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveWorkflowAgent
4
+ VERSION = "0.1.0"
5
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_workflow_agent
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Automatic Mode Labs
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-03-25 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - info@automaticmode.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".github/workflows/main.yml"
21
+ - ".gitignore"
22
+ - ".rspec"
23
+ - ".rubocop.yml"
24
+ - CHANGELOG.md
25
+ - Gemfile
26
+ - Gemfile.lock
27
+ - LICENSE.txt
28
+ - README.md
29
+ - Rakefile
30
+ - active_workflow_agent.gemspec
31
+ - bin/console
32
+ - bin/setup
33
+ - lib/active_workflow_agent.rb
34
+ - lib/active_workflow_agent/parsed_request.rb
35
+ - lib/active_workflow_agent/register_response.rb
36
+ - lib/active_workflow_agent/response.rb
37
+ - lib/active_workflow_agent/version.rb
38
+ homepage: https://github.com/automaticmode/active_workflow_agent
39
+ licenses:
40
+ - MIT
41
+ metadata: {}
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 2.4.0
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubygems_version: 3.1.4
58
+ signing_key:
59
+ specification_version: 4
60
+ summary: Helper library for writing ActiveWorkflow agents.
61
+ test_files: []