Class: Agents::TransilienAgent

Inherits:
Agent
  • Object
show all
Includes:
FormConfigurable
Defined in:
lib/huginn_transilien_agent/transilien_agent.rb

Instance Method Summary collapse

Instance Method Details

#checkObject



309
310
311
# File 'lib/huginn_transilien_agent/transilien_agent.rb', line 309

def check
  trigger_action
end

#default_optionsObject



254
255
256
257
258
259
260
261
262
263
264
265
266
# File 'lib/huginn_transilien_agent/transilien_agent.rb', line 254

def default_options
  {
    'type' => 'nextdeparture',
    'token' => '',
    'src' => '',
    'dst' => '',
    'date' => '',
    'time' => '',
    'debug' => 'false',
    'expected_receive_period_in_days' => '2',
    'changes_only' => 'true'
  }
end

#validate_optionsObject



277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
# File 'lib/huginn_transilien_agent/transilien_agent.rb', line 277

def validate_options
  errors.add(:base, "type has invalid value: should be 'itinary' 'nextdeparture' 'traffic_reports'") if interpolated['type'].present? && !%w(itinary nextdeparture traffic_reports).include?(interpolated['type'])

  unless options['src'].present? || !['itinary', 'nextdeparture'].include?(options['type'])
    errors.add(:base, "src is a required field")
  end

  unless options['dst'].present? || !['itinary', 'nextdeparture'].include?(options['type'])
    errors.add(:base, "dst is a required field")
  end

  unless options['token'].present? || !['itinary', 'nextdeparture', 'traffic_reports'].include?(options['type'])
    errors.add(:base, "token is a required field")
  end

  if options.has_key?('changes_only') && boolify(options['changes_only']).nil?
    errors.add(:base, "if provided, changes_only must be true or false")
  end

  if options.has_key?('debug') && boolify(options['debug']).nil?
    errors.add(:base, "if provided, debug must be true or false")
  end

  unless options['expected_receive_period_in_days'].present? && options['expected_receive_period_in_days'].to_i > 0
    errors.add(:base, "Please provide 'expected_receive_period_in_days' to indicate how many days can pass before this Agent is considered to be not working")
  end
end

#working?Boolean

Returns:

  • (Boolean)


305
306
307
# File 'lib/huginn_transilien_agent/transilien_agent.rb', line 305

def working?
  event_created_within?(options['expected_receive_period_in_days']) && !recent_error_logs?
end