todoist_client 0.0.1 → 0.0.2
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 +4 -4
- data/README.md +54 -2
- data/lib/todoist_client/api_client.rb +15 -3
- data/lib/todoist_client/completed_item.rb +39 -0
- data/lib/todoist_client/errors.rb +1 -0
- data/lib/todoist_client/item.rb +53 -24
- data/lib/todoist_client/project.rb +43 -30
- data/lib/todoist_client/version.rb +1 -1
- data/lib/todoist_client.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2b2d7aee3f1adc50907f02b6e661a49b62a5b52
|
4
|
+
data.tar.gz: d19483330538c142f0c6a4b372e9a9a3bb514760
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b0ec160b53fee8a9d4b61c02bbd279b177f0da891932bd90cdc0f8fd2912ea5425ea9f8a0fb10942aee4cf11771355515858803b3ff9fdc413be5f92d88485c
|
7
|
+
data.tar.gz: d811f07f039f85fc7396182b83dc155804815872cf598d506e9670e76c488cb9aa2adb48167d76d0c95a4651d3d31fb8e2f12aed06cd19c225538d0597b28c58
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# TodoistClient
|
2
2
|
|
3
|
-
|
3
|
+
[](http://badge.fury.io/rb/todoist_client)
|
4
|
+
|
5
|
+
Todoist API Client.
|
4
6
|
|
5
7
|
## Installation
|
6
8
|
|
@@ -18,7 +20,57 @@ Or install it yourself as:
|
|
18
20
|
|
19
21
|
## Usage
|
20
22
|
|
21
|
-
|
23
|
+
#### API Token
|
24
|
+
|
25
|
+
Copy from account setting in Todoist.
|
26
|
+
|
27
|
+
```
|
28
|
+
TodoistClient.api_token = 'some_api_token'
|
29
|
+
```
|
30
|
+
|
31
|
+
#### Project
|
32
|
+
|
33
|
+
```
|
34
|
+
# create project
|
35
|
+
project = TodoistClient::Project.create(name: "SomeProject")
|
36
|
+
puts [project.id, project.name].join(":") # => 123:SomeProject
|
37
|
+
|
38
|
+
project = TodoistClient::Project.find(some_id)
|
39
|
+
project.name = "OtherProject"
|
40
|
+
project.save # => update
|
41
|
+
project.delete # => delete
|
42
|
+
|
43
|
+
TodoistClient::Project.all.each do |project|
|
44
|
+
# number of uncompleted tasks
|
45
|
+
puts project.uncompleted_items.size
|
46
|
+
end
|
47
|
+
```
|
48
|
+
|
49
|
+
#### Item
|
50
|
+
|
51
|
+
```
|
52
|
+
# create item
|
53
|
+
item = TodoistClient::Item.create(content: "SomeTask")
|
54
|
+
puts [item.id, item.content] # => 123:SomeTask
|
55
|
+
|
56
|
+
item = TodoistClient::Item.find(some_id)
|
57
|
+
item.finished? # => false (if incomplete item)
|
58
|
+
item.content = "OtherTask"
|
59
|
+
item.save # => update
|
60
|
+
item.complete # => to complete
|
61
|
+
item.uncomplete # => to uncomplete
|
62
|
+
item.delete # => delete
|
63
|
+
|
64
|
+
project = TodoistClient::Project.find(some_id)
|
65
|
+
TodoistClient::Item.uncompleted(project).each do |item|
|
66
|
+
item.complete
|
67
|
+
end
|
68
|
+
|
69
|
+
# only premium user
|
70
|
+
TodoistClient::Item.completed_items.each do |completed_item|
|
71
|
+
puts [completed_item.completed_date.to_s, completed_item.content].join(":")
|
72
|
+
end
|
73
|
+
```
|
22
74
|
|
23
75
|
## Contributing
|
24
76
|
|
@@ -6,15 +6,27 @@ module TodoistClient
|
|
6
6
|
klass.extend ClassMethods
|
7
7
|
end
|
8
8
|
|
9
|
+
def with_remote_object(&block)
|
10
|
+
if id
|
11
|
+
block.call if block_given?
|
12
|
+
else
|
13
|
+
raise RemoteObjectNotExists
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def set_params(params)
|
18
|
+
params.each do |k,v|
|
19
|
+
self.send "#{k}=", v if self.respond_to? "#{k}="
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
9
23
|
module ClassMethods
|
10
24
|
def request(method, endpoint, params = nil)
|
11
|
-
p "#{BASE_URI}#{endpoint}"
|
12
|
-
p query_string(params)
|
13
25
|
JSON.load RestClient.send(method, "#{BASE_URI}#{endpoint}", query_string(params))
|
14
26
|
end
|
15
27
|
|
16
28
|
def query_string(params = nil)
|
17
|
-
raise NoApiToken
|
29
|
+
raise NoApiToken unless TodoistClient.api_token
|
18
30
|
params ||= {}
|
19
31
|
{
|
20
32
|
params: {
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module TodoistClient
|
2
|
+
# only premium user
|
3
|
+
class CompletedItem
|
4
|
+
include ApiClient
|
5
|
+
|
6
|
+
VALID_PARAMS = [
|
7
|
+
:content,
|
8
|
+
:meta_data,
|
9
|
+
:user_id,
|
10
|
+
:task_id,
|
11
|
+
:note_count,
|
12
|
+
:project_id,
|
13
|
+
:completed_date,
|
14
|
+
:id
|
15
|
+
].freeze
|
16
|
+
|
17
|
+
attr_accessor *VALID_PARAMS
|
18
|
+
|
19
|
+
def initialize(params)
|
20
|
+
raise ArgumentError if params["id"].nil?
|
21
|
+
set_params(params)
|
22
|
+
end
|
23
|
+
|
24
|
+
def completed_date=(date_string)
|
25
|
+
@completed_date = case
|
26
|
+
when date_string.is_a?(String)
|
27
|
+
Time.parse(date_string)
|
28
|
+
when date_string.is_a?(Time)
|
29
|
+
date_string
|
30
|
+
else
|
31
|
+
raise ArgumentError
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def to_item
|
36
|
+
Item.find(@task_id)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/todoist_client/item.rb
CHANGED
@@ -22,6 +22,7 @@ module TodoistClient
|
|
22
22
|
module Paths
|
23
23
|
UNCOMPLETED = [:get, "/API/getUncompletedItems"]
|
24
24
|
COMPLETED = [:get, "/API/getCompletedItems"]
|
25
|
+
ALL_COMPLETED = [:get, "/API/getAllCompletedItems"]
|
25
26
|
FIND = [:get, "/API/getItemsById"]
|
26
27
|
ADD = [:get, "/API/addItem"]
|
27
28
|
UPDATE = [:get, "/API/updateItem"]
|
@@ -31,59 +32,87 @@ module TodoistClient
|
|
31
32
|
end
|
32
33
|
|
33
34
|
def initialize(params = nil)
|
34
|
-
|
35
|
+
case
|
36
|
+
when params.is_a?(String)
|
37
|
+
@content = params
|
38
|
+
when params.is_a?(Hash)
|
39
|
+
set_params(params)
|
40
|
+
end
|
35
41
|
end
|
36
42
|
|
37
43
|
def save
|
38
44
|
if id
|
39
45
|
json = self.class.request *Paths::UPDATE, {
|
40
|
-
id: id,
|
41
|
-
content: content
|
42
|
-
|
46
|
+
id: @id, # required
|
47
|
+
content: @content,
|
48
|
+
priority: @priority,
|
49
|
+
indent: @indent,
|
50
|
+
item_order: @item_order,
|
51
|
+
collapsed: @collapsed
|
52
|
+
}.select {|k,v| !v.nil?}
|
43
53
|
else
|
44
54
|
json = self.class.request *Paths::ADD, {
|
45
|
-
content: content,
|
46
|
-
project_id: project_id
|
47
|
-
|
55
|
+
content: @content, # required
|
56
|
+
project_id: @project_id,
|
57
|
+
date_string: @date_string,
|
58
|
+
priority: @priority,
|
59
|
+
indent: @indent,
|
60
|
+
item_order: @item_order
|
61
|
+
}.select {|k,v| !v.nil?}
|
48
62
|
end
|
49
63
|
set_params(json)
|
64
|
+
self
|
50
65
|
end
|
51
66
|
|
52
67
|
def delete
|
53
|
-
|
68
|
+
with_remote_object do
|
69
|
+
self.class.request *Paths::DELETE, {ids: JSON.generate([id])}
|
70
|
+
end
|
54
71
|
end
|
55
72
|
|
56
73
|
def complete
|
57
|
-
|
74
|
+
with_remote_object do
|
75
|
+
self.class.request *Paths::COMPLETE, {ids: JSON.generate([id])}
|
76
|
+
end
|
58
77
|
end
|
59
78
|
|
60
79
|
def uncomplete
|
61
|
-
|
80
|
+
with_remote_object do
|
81
|
+
self.class.request *Paths::UNCOMPLETE, {ids: JSON.generate([id])}
|
82
|
+
end
|
62
83
|
end
|
63
84
|
|
64
|
-
def
|
65
|
-
|
66
|
-
self.send "#{k}=", v if self.respond_to? "#{k}="
|
67
|
-
end
|
85
|
+
def finished?
|
86
|
+
checked == 1
|
68
87
|
end
|
69
88
|
|
70
89
|
class << self
|
71
|
-
def uncompleted(
|
72
|
-
|
73
|
-
|
74
|
-
|
90
|
+
def uncompleted(project)
|
91
|
+
project_id = project.is_a?(Project) ? project.id : project
|
92
|
+
request(*Paths::UNCOMPLETED, {project_id: project_id}).map {|item| self.new(item)}
|
93
|
+
end
|
94
|
+
|
95
|
+
def completed(project)
|
96
|
+
project_id = project.is_a?(Project) ? project.id : project
|
97
|
+
request(*Paths::COMPLETED, {project_id: project_id}).map {|item| self.new(item)}
|
75
98
|
end
|
76
99
|
|
77
|
-
|
78
|
-
|
79
|
-
|
100
|
+
# only premium user
|
101
|
+
def completed_items(project = nil)
|
102
|
+
project_id = project.is_a?(Project) ? project.id : project
|
103
|
+
request(*Paths::ALL_COMPLETED, {project_id: project_id})["items"].map {|item|
|
104
|
+
CompletedItem.new(item)
|
80
105
|
}
|
81
106
|
end
|
82
107
|
|
83
108
|
def find(ids)
|
84
|
-
request(*Paths::FIND, {ids: json_ids(ids)}).map {
|
85
|
-
|
86
|
-
|
109
|
+
items = request(*Paths::FIND, {ids: json_ids(ids)}).map {|item| self.new(item)}
|
110
|
+
# return nil or Item object if item does not exist multiple.
|
111
|
+
items.size > 1 ? items : items.first
|
112
|
+
end
|
113
|
+
|
114
|
+
def create(params)
|
115
|
+
self.new(params).save
|
87
116
|
end
|
88
117
|
|
89
118
|
def delete_all(ids)
|
@@ -22,57 +22,70 @@ module TodoistClient
|
|
22
22
|
ADD = [:get, "/API/addProject"]
|
23
23
|
UPDATE = [:get, "/API/updateProject"]
|
24
24
|
DELETE = [:get, "/API/deleteProject"]
|
25
|
-
|
26
|
-
|
25
|
+
ARCHIVE = [:get, "/API/archiveProject"]
|
26
|
+
UNARCHIVE = [:get, "/API/unarchiveProject"]
|
27
27
|
end
|
28
28
|
|
29
29
|
def initialize(params = nil)
|
30
|
-
|
30
|
+
case
|
31
|
+
when params.is_a?(String)
|
32
|
+
@name = params
|
33
|
+
when params.is_a?(Hash)
|
34
|
+
set_params(params)
|
35
|
+
end
|
31
36
|
end
|
32
37
|
|
33
38
|
def save
|
34
39
|
if id
|
35
40
|
json = self.class.request *Paths::UPDATE, {
|
36
|
-
project_id: id,
|
37
|
-
name: name,
|
38
|
-
color: color,
|
39
|
-
indent: indent,
|
40
|
-
order: item_order
|
41
|
-
}
|
41
|
+
project_id: @id, # required
|
42
|
+
name: @name,
|
43
|
+
color: @color,
|
44
|
+
indent: @indent,
|
45
|
+
order: @item_order
|
46
|
+
}.select {|k,v| !v.nil?}
|
42
47
|
else
|
43
48
|
json = self.class.request *Paths::ADD, {
|
44
|
-
name: name,
|
45
|
-
color: color,
|
46
|
-
indent: indent,
|
47
|
-
order: item_order
|
48
|
-
}
|
49
|
+
name: @name, # required
|
50
|
+
color: @color,
|
51
|
+
indent: @indent,
|
52
|
+
order: @item_order
|
53
|
+
}.select {|k,v| !v.nil?}
|
49
54
|
end
|
50
55
|
set_params(json)
|
56
|
+
self
|
51
57
|
end
|
52
58
|
|
53
59
|
def delete
|
54
|
-
|
60
|
+
with_remote_object do
|
61
|
+
self.class.request *Paths::DELETE, {project_id: id}
|
62
|
+
end
|
55
63
|
end
|
56
64
|
|
57
|
-
#
|
58
|
-
|
59
|
-
|
65
|
+
# only premium user
|
66
|
+
def archive
|
67
|
+
with_remote_object do
|
68
|
+
self.class.request *Paths::ARCHIVE, {project_id: id}
|
69
|
+
end
|
70
|
+
end
|
60
71
|
|
61
|
-
#
|
62
|
-
|
63
|
-
|
72
|
+
# only premium user
|
73
|
+
def unarchive
|
74
|
+
with_remote_object do
|
75
|
+
self.class.request *Paths::UNARCHIVE, {project_id: id}
|
76
|
+
end
|
77
|
+
end
|
64
78
|
|
65
79
|
def uncompleted_items
|
66
|
-
|
80
|
+
with_remote_object do
|
81
|
+
Item.uncompleted(id)
|
82
|
+
end
|
67
83
|
end
|
68
84
|
|
85
|
+
# only premium user
|
69
86
|
def completed_items
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
def set_params(params)
|
74
|
-
params.each do |k,v|
|
75
|
-
self.send "#{k}=", v if self.respond_to? "#{k}="
|
87
|
+
with_remote_object do
|
88
|
+
Item.completed_items(id)
|
76
89
|
end
|
77
90
|
end
|
78
91
|
|
@@ -85,8 +98,8 @@ module TodoistClient
|
|
85
98
|
self.new(request(*Paths::FIND, {project_id: id}))
|
86
99
|
end
|
87
100
|
|
88
|
-
def create(
|
89
|
-
self.new(
|
101
|
+
def create(params)
|
102
|
+
self.new(params).save
|
90
103
|
end
|
91
104
|
end
|
92
105
|
end
|
data/lib/todoist_client.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: todoist_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- i2bskn
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -81,6 +81,7 @@ files:
|
|
81
81
|
- lib/todoist_client.rb
|
82
82
|
- lib/todoist_client/api_client.rb
|
83
83
|
- lib/todoist_client/base.rb
|
84
|
+
- lib/todoist_client/completed_item.rb
|
84
85
|
- lib/todoist_client/errors.rb
|
85
86
|
- lib/todoist_client/item.rb
|
86
87
|
- lib/todoist_client/project.rb
|