Class: Agents::TwitterPublishv2Agent

Inherits:
Agent
  • Object
show all
Includes:
FormConfigurable
Defined in:
lib/huginn_twitter_publishv2_agent/twitter_publishv2_agent.rb

Instance Method Summary collapse

Instance Method Details

#checkObject



112
113
114
# File 'lib/huginn_twitter_publishv2_agent/twitter_publishv2_agent.rb', line 112

def check
  publish()
end

#default_optionsObject



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/huginn_twitter_publishv2_agent/twitter_publishv2_agent.rb', line 48

def default_options
  {
    'message' => "{{text}}",
    'debug' => 'false',
    'consumer_key' => '',
    'consumer_secret' => '',
    'access_token' => '',
    'token_secret' => '',
    'emit_events' => 'true',
    'expected_receive_period_in_days' => '2',
  }
end

#receive(incoming_events) ⇒ Object



103
104
105
106
107
108
109
110
# File 'lib/huginn_twitter_publishv2_agent/twitter_publishv2_agent.rb', line 103

def receive(incoming_events)
  incoming_events.each do |event|
    interpolate_with(event) do
      log event
      publish()
    end
  end
end

#validate_optionsObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/huginn_twitter_publishv2_agent/twitter_publishv2_agent.rb', line 69

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

  unless options['consumer_secret'].present?
    errors.add(:base, "consumer_secret must be true or false")
  end

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

  unless options['access_token'].present?
    errors.add(:base, "access_token must be true or false")
  end

  unless options['token_secret'].present?
    errors.add(:base, "token_secret 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)


99
100
101
# File 'lib/huginn_twitter_publishv2_agent/twitter_publishv2_agent.rb', line 99

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