Class: Agents::LiveTennisAgent

Inherits:
Agent
  • Object
show all
Defined in:
lib/huginn_live_tennis_agent/live_tennis_agent.rb

Constant Summary collapse

API_BASE =
'https://api.livetennisapi.com/api/public/v1'
MODES =
%w[live_scores fixtures].freeze
TOURS =
%w[atp wta challenger itf juniors].freeze

Instance Method Summary collapse

Instance Method Details

#checkObject



142
143
144
145
146
147
148
# File 'lib/huginn_live_tennis_agent/live_tennis_agent.rb', line 142

def check
  if interpolated['mode'] == 'fixtures'
    check_fixtures
  else
    check_live_scores
  end
end

#default_optionsObject



113
114
115
116
117
118
119
120
# File 'lib/huginn_live_tennis_agent/live_tennis_agent.rb', line 113

def default_options
  {
    'api_key' => '{% credential live_tennis_api_key %}',
    'mode' => 'live_scores',
    'tour' => '',
    'lookup_finished' => 'true'
  }
end

#validate_optionsObject



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/huginn_live_tennis_agent/live_tennis_agent.rb', line 122

def validate_options
  errors.add(:base, 'api_key is required') unless options['api_key'].present?

  unless MODES.include?(options['mode'])
    errors.add(:base, "mode must be one of: #{MODES.join(', ')}")
  end

  if options['tour'].present? && !TOURS.include?(options['tour'])
    errors.add(:base, "tour must be one of: #{TOURS.join(', ')} (or blank for all tours)")
  end

  if options['lookup_finished'].present? && boolify(options['lookup_finished']).nil?
    errors.add(:base, 'lookup_finished must be true or false')
  end
end

#working?Boolean

Returns:

  • (Boolean)


138
139
140
# File 'lib/huginn_live_tennis_agent/live_tennis_agent.rb', line 138

def working?
  !recent_error_logs?
end