Class: Agents::TodoistQueryAgent
- Inherits:
-
Agent
- Object
- Agent
- Agents::TodoistQueryAgent
- Includes:
- FormConfigurable
- Defined in:
- lib/huginn_todoist_agent/todoist_query_agent.rb
Instance Method Summary collapse
Instance Method Details
#check ⇒ Object
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(["query"]) result.each do |item| create_event payload: item end end |
#default_options ⇒ Object
24 25 26 27 28 29 |
# File 'lib/huginn_todoist_agent/todoist_query_agent.rb', line 24 def { "api_token" => "", "query" => "today | overdue", } end |
#validate_options ⇒ Object
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 errors.add(:base, "you need to specify your Todoist API token or provide a credential named todoist_api_token") unless ["api_token"].present? || credential("todoist_api_token").present? if ["query"].present? begin TodoistQuerynaut::Parser.parse(["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
34 35 36 |
# File 'lib/huginn_todoist_agent/todoist_query_agent.rb', line 34 def working? !recent_error_logs? end |