Class: Agents::TodoistQueryAgent

Inherits:
Agent
  • Object
show all
Includes:
FormConfigurable
Defined in:
lib/huginn_todoist_agent/todoist_query_agent.rb

Instance Method Summary collapse

Instance Method Details

#checkObject



52
53
54
55
56
57
58
59
# File 'lib/huginn_todoist_agent/todoist_query_agent.rb', line 52

def check
  todoist = Todoist::Client.new(interpolated["api_token"].present? ? interpolated["api_token"] : credential("todoist_api_token"))
  result = TodoistQuerynaut::Client.new(todoist).run(options["query"])

  result.each do |item|
    create_event payload: item
  end
end

#default_optionsObject



24
25
26
27
28
29
# File 'lib/huginn_todoist_agent/todoist_query_agent.rb', line 24

def default_options
  {
    "api_token" => "",
    "query" => "today | overdue",
  }
end

#validate_optionsObject



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/huginn_todoist_agent/todoist_query_agent.rb', line 38

def validate_options
  errors.add(:base, "you need to specify your Todoist API token or provide a credential named todoist_api_token") unless options["api_token"].present? || credential("todoist_api_token").present?

  if options["query"].present?
    begin
      TodoistQuerynaut::Parser.parse(options["query"])
    rescue Exception
      errors.add(:base, "query cannot be parsed correctly, check against Todoist filter expression manual")
    end
  else
    errors.add(:base, "query must not be empty")
  end
end

#working?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/huginn_todoist_agent/todoist_query_agent.rb', line 34

def working?
  !recent_error_logs?
end