Class: Agents::TodoistAgent
- Inherits:
-
Agent
- Object
- Agent
- Agents::TodoistAgent
- Includes:
- FormConfigurable
- Defined in:
- lib/huginn_todoist_agent/todoist_agent.rb
Instance Method Summary collapse
- #default_options ⇒ Object
- #receive(incoming_events) ⇒ Object
- #validate_options ⇒ Object
- #working? ⇒ Boolean
Instance Method Details
#default_options ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/huginn_todoist_agent/todoist_agent.rb', line 35 def { "api_token" => "", "content" => "{{ content }}", "date_string" => "today", "project_id" => "", "labels" => "", "priority" => "", } end |
#receive(incoming_events) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/huginn_todoist_agent/todoist_agent.rb', line 61 def receive(incoming_events) incoming_events.each do |event| interpolate_with(event) do item = { "content" => interpolated["content"] } item["date_string"] = interpolated["date_string"] if interpolated["date_string"].present? item["project_id"] = interpolated["project_id"].to_i if interpolated["project_id"].present? item["priority"] = interpolated["priority"].to_i if interpolated["priority"].present? if interpolated["labels"].present? item["labels"] = interpolated["labels"].split(%r{,\s*}).map(&:to_i) end log "creating item: #{item}" todoist = Todoist::Client.new(interpolated["api_token"].present? ? interpolated["api_token"] : credential("todoist_api_token")) todoist.items.create(item) todoist.process! end end end |
#validate_options ⇒ Object
57 58 59 |
# File 'lib/huginn_todoist_agent/todoist_agent.rb', line 57 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? end |
#working? ⇒ Boolean
53 54 55 |
# File 'lib/huginn_todoist_agent/todoist_agent.rb', line 53 def working? !recent_error_logs? end |