class ActiveWorkflowAgent::ReceiveResponse
Helper class to construct responses to ActiveWorkflow's agent API. docs.activeworkflow.org/remote-agent-api#responses
Public Class Methods
new()
click to toggle source
Create an object for responding to 'receive' or 'check' methods.
# File lib/active_workflow_agent/response.rb, line 10 def initialize @logs = [] @errors = [] @messages = [] @memory = {} end
Public Instance Methods
add_errors(*errors)
click to toggle source
# File lib/active_workflow_agent/response.rb, line 30 def add_errors(*errors) # Validation. must_str = "must be (non-empty) strings" not_empty = "can not be empty strings" errors.each do |err| raise(ArgumentError, "Errors #{must_str}.") unless err.is_a?(String) raise(ArgumentError, "Errors #{not_empty}.") if err == "" end errors.each { |err| @errors << err } end
add_logs(*logs)
click to toggle source
Add log messages to the response object.
# File lib/active_workflow_agent/response.rb, line 18 def add_logs(*logs) # Validation. must_str = "must be (non-empty) strings" not_empty = "can not be empty strings" logs.each do |log| raise(ArgumentError, "Logs #{must_str}.") unless log.is_a?(String) raise(ArgumentError, "Logs #{not_empty}.") if log == "" end logs.each { |log| @logs << log } end
add_memory(memory)
click to toggle source
# File lib/active_workflow_agent/response.rb, line 54 def add_memory(memory) must_hash = "must be a hash" raise(ArgumentError, "Memory #{must_hash}.") unless memory.is_a?(Hash) @memory = memory end
add_messages(*messages)
click to toggle source
# File lib/active_workflow_agent/response.rb, line 42 def add_messages(*messages) # Validation. must_hash = "must be (non-empty) hashes" not_empty = "can not be empty hashes" messages.each do |msg| raise(ArgumentError, "Messages #{must_hash}.") unless msg.is_a?(Hash) raise(ArgumentError, "Messages #{not_empty}.") if msg == {} end messages.each { |msg| @messages << msg } end
to_h()
click to toggle source
# File lib/active_workflow_agent/response.rb, line 61 def to_h { "result" => { "logs" => @logs, "errors" => @errors, "messages" => @messages, "memory" => @memory } } end
to_json(*)
click to toggle source
# File lib/active_workflow_agent/response.rb, line 72 def to_json(*) JSON.dump(to_h) end