huginn_todoist_agent 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/huginn_todoist_agent/todoist_query_agent.rb +16 -2
- data/spec/todoist_query_agent_spec.rb +9 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ca365adb5f28bda8ef577fa8a4017aab9a6172b
|
4
|
+
data.tar.gz: d28f19d9cfb515f1ce60a0f20f012d4856fbeb3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7194225fa429faa9934a4708a7c4195f10c33314535bd7b311020c8b8fcafee621e3c51e9e0a23c7fc5b105a21e9fe9111ea62f7baca1b690bc1ff8cd52a711e
|
7
|
+
data.tar.gz: da84042d9438f59b6b03dbf199b22da6de4b6e185a8f137614e83e5fc877a2840d831b815d09472f0a55f2eee8b79b04440977c8bcd545071b596e69a7c25eb3
|
@@ -16,6 +16,11 @@ module Agents
|
|
16
16
|
|
17
17
|
Change `query` to the [Todoist filter expression](https://support.todoist.com/hc/en-us/articles/205248842-Filters)
|
18
18
|
you'd like to be carried out.
|
19
|
+
|
20
|
+
The `mode` option allows to control what information is emitted. With the default value
|
21
|
+
of `items` an event is emitted for every item that matches the search result. And consequently
|
22
|
+
no event is emitted if no items match the query.
|
23
|
+
With `count` the agent always emits a single event, that just tells the number of matched items.
|
19
24
|
MD
|
20
25
|
end
|
21
26
|
|
@@ -25,11 +30,13 @@ module Agents
|
|
25
30
|
{
|
26
31
|
"api_token" => "",
|
27
32
|
"query" => "today | overdue",
|
33
|
+
"mode" => "items",
|
28
34
|
}
|
29
35
|
end
|
30
36
|
|
31
37
|
form_configurable :api_token
|
32
38
|
form_configurable :query, type: :text
|
39
|
+
form_configurable :mode, type: :array, values: %w(items count)
|
33
40
|
|
34
41
|
def working?
|
35
42
|
!recent_error_logs?
|
@@ -53,8 +60,15 @@ module Agents
|
|
53
60
|
todoist = Todoist::Client.new(interpolated["api_token"].present? ? interpolated["api_token"] : credential("todoist_api_token"))
|
54
61
|
result = TodoistQuerynaut::Client.new(todoist).run(options["query"])
|
55
62
|
|
56
|
-
|
57
|
-
|
63
|
+
case options["mode"]
|
64
|
+
when "items"
|
65
|
+
result.each do |item|
|
66
|
+
create_event payload: item
|
67
|
+
end
|
68
|
+
|
69
|
+
when "count"
|
70
|
+
create_event payload: { "matched_items" => result.size }
|
71
|
+
|
58
72
|
end
|
59
73
|
end
|
60
74
|
end
|
@@ -9,6 +9,7 @@ describe Agents::TodoistQueryAgent do
|
|
9
9
|
@valid_options = {
|
10
10
|
"api_token" => "some_token_here",
|
11
11
|
"query" => "overdue",
|
12
|
+
"mode" => "items",
|
12
13
|
}
|
13
14
|
@checker = Agents::TodoistQueryAgent.new(:name => "TodoistQueryAgent", :options => @valid_options)
|
14
15
|
@checker.user = users(:bob)
|
@@ -52,5 +53,13 @@ describe Agents::TodoistQueryAgent do
|
|
52
53
|
it "should execute the query and emit events for every item" do
|
53
54
|
expect { @checker.check }.to change {Event.count}.by(2)
|
54
55
|
end
|
56
|
+
|
57
|
+
it "should emit the number of matched items with mode=count" do
|
58
|
+
@checker.options["mode"] = "count"
|
59
|
+
expect { @checker.check }.to change {Event.count}.by(1)
|
60
|
+
|
61
|
+
event = Event.last
|
62
|
+
expect(event.payload).to eq({ "matched_items" => 2 })
|
63
|
+
end
|
55
64
|
end
|
56
65
|
end
|