Class: Agents::TwitchAgent

Inherits:
Agent
  • Object
show all
Includes:
FormConfigurable
Defined in:
lib/huginn_twitch_agent/twitch_agent.rb

Instance Method Summary collapse

Instance Method Details

#checkObject



115
116
117
# File 'lib/huginn_twitch_agent/twitch_agent.rb', line 115

def check
  trigger_action
end

#default_optionsObject



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/huginn_twitch_agent/twitch_agent.rb', line 50

def default_options
  {
    'client_id' => '',
    'user_id' => '',
    'client_secret' => '',
    'access_token' => '',
    'debug' => 'false',
    'emit_events' => 'false',
    'expected_receive_period_in_days' => '2',
  }
end

#receive(incoming_events) ⇒ Object



106
107
108
109
110
111
112
113
# File 'lib/huginn_twitch_agent/twitch_agent.rb', line 106

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

#validate_optionsObject



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
98
99
100
# File 'lib/huginn_twitch_agent/twitch_agent.rb', line 70

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

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

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

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

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

  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)


102
103
104
# File 'lib/huginn_twitch_agent/twitch_agent.rb', line 102

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