Class: Agents::StateCodeAgent

Inherits:
Agent
  • Object
show all
Includes:
Carmen
Defined in:
lib/huginn_state_code_agent/state_code_agent.rb

Instance Method Summary collapse

Instance Method Details

#checkObject



98
99
100
# File 'lib/huginn_state_code_agent/state_code_agent.rb', line 98

def check
    handle interpolated(event.payload)['payload'].presence || {}
end

#default_optionsObject



71
72
73
74
75
76
77
# File 'lib/huginn_state_code_agent/state_code_agent.rb', line 71

def default_options
    {
        'country' => '',
        'region' => '',
        'output_mode' => 'clean',
    }
end

#receive(incoming_events) ⇒ Object



102
103
104
105
106
# File 'lib/huginn_state_code_agent/state_code_agent.rb', line 102

def receive(incoming_events)
     incoming_events.each do |event|
         handle(event)
     end
end

#validate_optionsObject



79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/huginn_state_code_agent/state_code_agent.rb', line 79

def validate_options
    unless options['country'].present?
        errors.add(:base, 'country is a required field')
    end

    unless options['region'].present?
        errors.add(:base, 'region is a required field')
    end

    if options['output_mode'].present? && !options['output_mode'].to_s.include?('{') && !%[clean merge].include?(options['output_mode'].to_s)
      errors.add(:base, "if provided, output_mode must be 'clean' or 'merge'")
    end

end

#working?Boolean



94
95
96
# File 'lib/huginn_state_code_agent/state_code_agent.rb', line 94

def working?
    received_event_without_error?
end