Skip to content

Commit f203e4b

Browse files
committed
Initial commit
0 parents  commit f203e4b

23 files changed

+857
-0
lines changed

.github/workflows/main.yml

+18
Original file line numberDiff line numberDiff line change
@@ -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

.gitignore

+43
Original file line numberDiff line numberDiff line change
@@ -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

.rspec

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
--format documentation
2+
--color
3+
--require spec_helper

.rubocop.yml

+25
Original file line numberDiff line numberDiff line change
@@ -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

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## [Unreleased]
2+
3+
## [0.1.0] - 2021-03-25
4+
5+
- Initial release

Gemfile

+10
Original file line numberDiff line numberDiff line change
@@ -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"

Gemfile.lock

+55
Original file line numberDiff line numberDiff line change
@@ -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

LICENSE.txt

+21
Original file line numberDiff line numberDiff line change
@@ -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.

README.md

+29
Original file line numberDiff line numberDiff line change
@@ -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).

Rakefile

+12
Original file line numberDiff line numberDiff line change
@@ -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]

active_workflow_agent.gemspec

+22
Original file line numberDiff line numberDiff line change
@@ -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 = ["[email protected]"]
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

bin/console

+15
Original file line numberDiff line numberDiff line change
@@ -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__)

bin/setup

+8
Original file line numberDiff line numberDiff line change
@@ -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

lib/active_workflow_agent.rb

+11
Original file line numberDiff line numberDiff line change
@@ -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
Original file line numberDiff line numberDiff line change
@@ -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
Original file line numberDiff line numberDiff line change
@@ -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 commit comments

Comments
 (0)