huginn_todoist_agent 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d8c15f6621a564f83f036dee3c3e979df08d0ee
|
4
|
+
data.tar.gz: 9f340be304f7ab80ef1aa3ba0b9fa2e41dd5dc49
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bbe20813067886e217031d70d5f88d97bd249231cb00e855dd0c7ec43ed988abda84dd9c6d36be8a4f69b8bbf0c463e0615747172d8443a7013f9fb9390401dd
|
7
|
+
data.tar.gz: 52703f25afebc3f72ffdcb138a1405e7f72a30dcf71321a2209a39632dff156f6372b2fafec81fd1ab2f8a06907a0d48f4c25962520d66407e6c98f2878d0bc5
|
data/lib/huginn_todoist_agent.rb
CHANGED
@@ -10,4 +10,5 @@ end
|
|
10
10
|
|
11
11
|
#HuginnAgent.load 'huginn_todoist_agent/concerns/my_agent_concern'
|
12
12
|
HuginnAgent.register 'huginn_todoist_agent/todoist_agent'
|
13
|
+
HuginnAgent.register 'huginn_todoist_agent/todoist_close_item_agent'
|
13
14
|
HuginnAgent.register 'huginn_todoist_agent/todoist_query_agent'
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module Agents
|
2
|
+
class TodoistCloseItemAgent < Agent
|
3
|
+
include FormConfigurable
|
4
|
+
|
5
|
+
cannot_create_events!
|
6
|
+
|
7
|
+
gem_dependency_check { defined?(Todoist::Client) }
|
8
|
+
|
9
|
+
description do
|
10
|
+
<<-MD
|
11
|
+
The Todoist Close Item Agent closes items on your Todoist.
|
12
|
+
|
13
|
+
To authenticate you need to either set `api_token` or provide a credential named
|
14
|
+
`todoist_api_token` to your Todoist API token. You can find it within the
|
15
|
+
Todoist web frontend from "Gear Menu" > Todoist Settings > Account tab.
|
16
|
+
|
17
|
+
Change `id` to whatever the ID of the item you would want to be closed is. You
|
18
|
+
can also route query results from "Todoist Query Agent" to this agent and
|
19
|
+
interpolate it using `{{ id }}` to close all items included in the search result.
|
20
|
+
MD
|
21
|
+
end
|
22
|
+
|
23
|
+
default_schedule "never"
|
24
|
+
|
25
|
+
def default_options
|
26
|
+
{
|
27
|
+
"api_token" => "",
|
28
|
+
"id" => "",
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
form_configurable :api_token
|
33
|
+
form_configurable :id
|
34
|
+
|
35
|
+
def working?
|
36
|
+
!recent_error_logs?
|
37
|
+
end
|
38
|
+
|
39
|
+
def validate_options
|
40
|
+
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?
|
41
|
+
errors.add(:base, "id must not be empty, use `{{ id }}` if you'd like Huginn to use the id from the incoming event") unless options["id"].present?
|
42
|
+
end
|
43
|
+
|
44
|
+
def check
|
45
|
+
log "closing item: #{interpolated["id"]}"
|
46
|
+
todoist = Todoist::Client.new(interpolated["api_token"].present? ? interpolated["api_token"] : credential("todoist_api_token"))
|
47
|
+
todoist.items.close(interpolated["id"])
|
48
|
+
todoist.queue.process!
|
49
|
+
end
|
50
|
+
|
51
|
+
def receive(incoming_events)
|
52
|
+
incoming_events.each do |event|
|
53
|
+
interpolate_with(event) do
|
54
|
+
|
55
|
+
log "closing item: #{interpolated["id"]}"
|
56
|
+
todoist = Todoist::Client.new(interpolated["api_token"].present? ? interpolated["api_token"] : credential("todoist_api_token"))
|
57
|
+
todoist.items.close(interpolated["id"])
|
58
|
+
todoist.queue.process!
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
|
data/spec/todoist_agent_spec.rb
CHANGED
@@ -25,7 +25,7 @@ describe Agents::TodoistAgent do
|
|
25
25
|
|
26
26
|
@expected_token = "some_token_here"
|
27
27
|
@sent_requests = Array.new
|
28
|
-
stub_request(:post, "https://todoist.com/API/
|
28
|
+
stub_request(:post, "https://todoist.com/API/v7/sync").
|
29
29
|
to_return { |request|
|
30
30
|
expect(request.headers["Content-Type"]).to eq("application/x-www-form-urlencoded")
|
31
31
|
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require "rails_helper"
|
2
|
+
require "huginn_agent/spec_helper"
|
3
|
+
require "uri"
|
4
|
+
|
5
|
+
require_relative "./spec_helper"
|
6
|
+
|
7
|
+
describe Agents::TodoistCloseItemAgent do
|
8
|
+
before(:each) do
|
9
|
+
@valid_options = {
|
10
|
+
"api_token" => "some_token_here",
|
11
|
+
"id" => "1234",
|
12
|
+
}
|
13
|
+
@checker = Agents::TodoistCloseItemAgent.new(:name => "TodoistCloseItemAgent", :options => @valid_options)
|
14
|
+
@checker.user = users(:bob)
|
15
|
+
@checker.save!
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#validate_options" do
|
19
|
+
before do
|
20
|
+
expect(@checker).to be_valid
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should reject an empty api_token" do
|
24
|
+
@checker.options["api_token"] = nil
|
25
|
+
expect(@checker).not_to be_valid
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should allow a credential (instead of api_token)" do
|
29
|
+
@checker.user.user_credentials.create :credential_name => "todoist_api_token", :credential_value => "some_credential_here"
|
30
|
+
@checker.options["api_token"] = nil
|
31
|
+
expect(@checker).to be_valid
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should reject an empty id field" do
|
35
|
+
@checker.options["id"] = nil
|
36
|
+
expect(@checker).not_to be_valid
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def assert_item_close(item_id)
|
41
|
+
expect(WebMock).to have_requested(:post, "https://todoist.com/API/v7/sync").
|
42
|
+
with { |request|
|
43
|
+
expect(request.headers["Content-Type"]).to eq("application/x-www-form-urlencoded")
|
44
|
+
|
45
|
+
form_data = URI.decode_www_form(request.body)
|
46
|
+
expect(form_data.assoc("token").last).to eq("some_token_here")
|
47
|
+
|
48
|
+
json_data = ActiveSupport::JSON.decode(form_data.assoc("commands").last)
|
49
|
+
expect(json_data.length).to eq(1)
|
50
|
+
|
51
|
+
expect(json_data[0]["type"]).to eq("item_close")
|
52
|
+
expect(json_data[0]["args"]["id"]).to eq(item_id)
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "#check" do
|
57
|
+
it "should close the referenced item" do
|
58
|
+
stub_request(:post, "https://todoist.com/API/v7/sync").to_return(:status => 200, :body => '{}')
|
59
|
+
|
60
|
+
@checker.check
|
61
|
+
assert_item_close "1234"
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "#receive" do
|
67
|
+
it "should close the referenced item via interpolation" do
|
68
|
+
stub_request(:post, "https://todoist.com/API/v7/sync").to_return(:status => 200, :body => '{}')
|
69
|
+
|
70
|
+
event = Event.new
|
71
|
+
event.agent = agents(:bob_weather_agent)
|
72
|
+
event.payload = {
|
73
|
+
"id" => "2345",
|
74
|
+
}
|
75
|
+
|
76
|
+
@checker.options["id"] = "{{ id }}"
|
77
|
+
|
78
|
+
@checker.receive([event])
|
79
|
+
assert_item_close "2345"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -45,7 +45,7 @@ describe Agents::TodoistQueryAgent do
|
|
45
45
|
|
46
46
|
describe "#check" do
|
47
47
|
before :each do
|
48
|
-
stub_request(:post, "https://todoist.com/API/
|
48
|
+
stub_request(:post, "https://todoist.com/API/v7/query").
|
49
49
|
with(:body => {"queries" => "[\"overdue\"]", "token" => "some_token_here"}).
|
50
50
|
to_return(:status => 200, :body => json_response_raw("query_overdue"), :headers => {})
|
51
51
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: huginn_todoist_agent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefan Siegl
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -53,19 +53,19 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name: ruby-todoist-api
|
56
|
+
name: ruby-todoist-api-v7
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0
|
61
|
+
version: '1.0'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '0
|
68
|
+
version: '1.0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: todoist_querynaut
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,8 +80,8 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0.1'
|
83
|
-
description: The Todoist
|
84
|
-
|
83
|
+
description: The Todoist Agents allow to create new as well as query and close existing
|
84
|
+
items on your Todoist.
|
85
85
|
email:
|
86
86
|
- stesie@brokenpipe.de
|
87
87
|
executables: []
|
@@ -91,10 +91,12 @@ files:
|
|
91
91
|
- LICENSE.txt
|
92
92
|
- lib/huginn_todoist_agent.rb
|
93
93
|
- lib/huginn_todoist_agent/todoist_agent.rb
|
94
|
+
- lib/huginn_todoist_agent/todoist_close_item_agent.rb
|
94
95
|
- lib/huginn_todoist_agent/todoist_query_agent.rb
|
95
96
|
- spec/fixtures/query_overdue.json
|
96
97
|
- spec/spec_helper.rb
|
97
98
|
- spec/todoist_agent_spec.rb
|
99
|
+
- spec/todoist_close_item_agent_spec.rb
|
98
100
|
- spec/todoist_query_agent_spec.rb
|
99
101
|
homepage: https://github.com/stesie/huginn_todoist_agent
|
100
102
|
licenses:
|
@@ -116,12 +118,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
116
118
|
version: '0'
|
117
119
|
requirements: []
|
118
120
|
rubyforge_project:
|
119
|
-
rubygems_version: 2.5.1
|
121
|
+
rubygems_version: 2.5.2.1
|
120
122
|
signing_key:
|
121
123
|
specification_version: 4
|
122
|
-
summary: Huginn agent to add items
|
124
|
+
summary: Huginn agent to add, query and close items on your Todoist.
|
123
125
|
test_files:
|
124
126
|
- spec/fixtures/query_overdue.json
|
125
|
-
- spec/todoist_agent_spec.rb
|
126
|
-
- spec/todoist_query_agent_spec.rb
|
127
127
|
- spec/spec_helper.rb
|
128
|
+
- spec/todoist_query_agent_spec.rb
|
129
|
+
- spec/todoist_close_item_agent_spec.rb
|
130
|
+
- spec/todoist_agent_spec.rb
|