todoist-ruby 0.1.3 → 0.2.5
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 +5 -5
- data/README.md +95 -51
- data/lib/todoist.rb +4 -2
- data/lib/todoist/client.rb +119 -0
- data/lib/todoist/config.rb +64 -0
- data/lib/todoist/misc/activity.rb +14 -24
- data/lib/todoist/misc/backups.rb +2 -2
- data/lib/todoist/misc/completed.rb +5 -5
- data/lib/todoist/misc/items.rb +4 -4
- data/lib/todoist/misc/projects.rb +4 -4
- data/lib/todoist/misc/quick.rb +2 -2
- data/lib/todoist/misc/templates.rb +5 -5
- data/lib/todoist/misc/uploads.rb +5 -5
- data/lib/todoist/service.rb +10 -0
- data/lib/todoist/sync/filters.rb +6 -6
- data/lib/todoist/sync/items.rb +44 -48
- data/lib/todoist/sync/labels.rb +6 -6
- data/lib/todoist/sync/notes.rb +5 -5
- data/lib/todoist/sync/projects.rb +8 -8
- data/lib/todoist/sync/reminders.rb +6 -6
- data/lib/todoist/util/api_helper.rb +39 -26
- data/lib/todoist/util/network_helper.rb +55 -19
- data/lib/todoist/util/parse_helper.rb +5 -5
- data/lib/todoist/version.rb +1 -1
- data/todoist.gemspec +12 -11
- metadata +44 -32
- data/lib/todoist/misc/query.rb +0 -30
- data/lib/todoist/misc/user.rb +0 -16
- data/lib/todoist/util/command_synchronizer.rb +0 -54
- data/lib/todoist/util/config.rb +0 -78
@@ -1,50 +1,40 @@
|
|
1
1
|
module Todoist
|
2
2
|
module Misc
|
3
|
-
class Activity
|
4
|
-
include Todoist::Util
|
5
|
-
|
6
|
-
# Returns the activity logs for a user.
|
7
|
-
|
8
|
-
# The following objects are converted into parameters as appropriate:
|
9
|
-
#
|
10
|
-
# * object
|
11
|
-
# * parent_project
|
12
|
-
# * parent_item
|
13
|
-
# * initiator
|
14
|
-
# * until
|
15
|
-
# * since
|
16
|
-
|
3
|
+
class Activity < Todoist::Service
|
4
|
+
include Todoist::Util
|
5
|
+
|
6
|
+
# Returns the activity logs for a user.
|
7
|
+
|
17
8
|
def get(params={})
|
18
9
|
if params["until"]
|
19
|
-
params["until"] = ParseHelper.
|
10
|
+
params["until"] = ParseHelper.format_time(params["until"])
|
20
11
|
end
|
21
|
-
|
12
|
+
|
22
13
|
if params["since"]
|
23
|
-
params["since"] = ParseHelper.
|
14
|
+
params["since"] = ParseHelper.format_time(params["since"])
|
24
15
|
end
|
25
|
-
|
16
|
+
|
26
17
|
if params["object"]
|
27
18
|
params["object_id"] = params["object"].id
|
28
19
|
params.delete("object")
|
29
20
|
end
|
30
|
-
|
21
|
+
|
31
22
|
if params["parent_object"]
|
32
23
|
params["parent_object_id"] = params["parent_object"].id
|
33
24
|
params.delete("parent_object")
|
34
25
|
end
|
35
|
-
|
26
|
+
|
36
27
|
if params["parent_item"]
|
37
28
|
params["parent_item_id"] = params["parent_item"].id
|
38
29
|
params.delete("parent_item")
|
39
30
|
end
|
40
|
-
|
31
|
+
|
41
32
|
if params["initiator"]
|
42
33
|
params["initiator_id"] = params["initiator"].id
|
43
34
|
params.delete("initiator")
|
44
35
|
end
|
45
|
-
|
46
|
-
result =
|
47
|
-
ParseHelper.make_objects_as_hash(result)
|
36
|
+
|
37
|
+
result = @client.api_helper.get_response(Config::TODOIST_ACTIVITY_GET_COMMAND, params)
|
48
38
|
end
|
49
39
|
end
|
50
40
|
end
|
data/lib/todoist/misc/backups.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
module Todoist
|
2
2
|
module Misc
|
3
|
-
class Backups
|
3
|
+
class Backups < Todoist::Service
|
4
4
|
include Todoist::Util
|
5
5
|
|
6
6
|
# Returns the backups for a user.
|
7
7
|
def get()
|
8
|
-
result =
|
8
|
+
result = @client.api_helper.get_response(Config::TODOIST_BACKUPS_GET_COMMAND, {})
|
9
9
|
ParseHelper.make_objects_as_hash(result)
|
10
10
|
end
|
11
11
|
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
module Todoist
|
2
2
|
module Misc
|
3
|
-
class Completed
|
3
|
+
class Completed < Todoist::Service
|
4
4
|
include Todoist::Util
|
5
5
|
|
6
6
|
# Get productivity stats. Returns a hash of statistics as documented
|
7
7
|
# at https://developer.todoist.com/#get-productivity-stats
|
8
8
|
def get_productivity_stats()
|
9
|
-
|
9
|
+
@client.api_helper.get_response(Config::TODOIST_COMPLETED_GET_STATS_COMMAND, {})
|
10
10
|
end
|
11
11
|
|
12
12
|
# Retrieves all completed items as documented at
|
@@ -17,13 +17,13 @@ module Todoist
|
|
17
17
|
|
18
18
|
def get_all_completed_items(params = {})
|
19
19
|
if params["until"]
|
20
|
-
params["until"] = ParseHelper.
|
20
|
+
params["until"] = ParseHelper.format_time(params["until"])
|
21
21
|
end
|
22
22
|
if params["since"]
|
23
|
-
params["since"] = ParseHelper.
|
23
|
+
params["since"] = ParseHelper.format_time(params["since"])
|
24
24
|
end
|
25
25
|
|
26
|
-
result =
|
26
|
+
result = @client.api_helper.get_response(Config::TODOIST_COMPLETED_GET_ALL_COMMAND, params)
|
27
27
|
items = ParseHelper.make_objects_as_array(result["items"])
|
28
28
|
projects = ParseHelper.make_objects_as_array(result["projects"])
|
29
29
|
return {"items" => items, "projects" => projects}
|
data/lib/todoist/misc/items.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Todoist
|
2
2
|
module Misc
|
3
|
-
class Items
|
3
|
+
class Items < Todoist::Service
|
4
4
|
include Todoist::Util
|
5
5
|
|
6
6
|
# Add a new task to a project. Note, that this is provided as a
|
@@ -29,8 +29,8 @@ module Todoist
|
|
29
29
|
optional_params.delete("labels")
|
30
30
|
end
|
31
31
|
|
32
|
-
params.merge(optional_params)
|
33
|
-
result =
|
32
|
+
params.merge!(optional_params)
|
33
|
+
result = @client.api_helper.get_response(Config::TODOIST_ITEMS_ADD_COMMAND, params)
|
34
34
|
item = ParseHelper.make_object(result)
|
35
35
|
return item
|
36
36
|
end
|
@@ -43,7 +43,7 @@ module Todoist
|
|
43
43
|
def get_item(item, all_data = true)
|
44
44
|
params = {item_id: item.id, all_data: all_data}
|
45
45
|
|
46
|
-
result =
|
46
|
+
result = @client.api_helper.get_response(Config::TODOIST_ITEMS_GET_COMMAND, params)
|
47
47
|
item = ParseHelper.make_object(result["item"])
|
48
48
|
project = ParseHelper.make_object(result["project"])
|
49
49
|
notes = result["notes"] ? ParseHelper.make_objects_as_hash(result["notes"]) : nil
|
@@ -1,18 +1,18 @@
|
|
1
1
|
module Todoist
|
2
2
|
module Misc
|
3
|
-
class Projects
|
3
|
+
class Projects < Todoist::Service
|
4
4
|
include Todoist::Util
|
5
5
|
|
6
6
|
# Get archived projects. Returns projects as documented here.
|
7
7
|
def get_archived_projects()
|
8
|
-
result =
|
8
|
+
result = @client.api_helper.get_response(Config::TODOIST_PROJECTS_GET_ARCHIVED_COMMAND)
|
9
9
|
return ParseHelper.make_objects_as_hash(result)
|
10
10
|
end
|
11
11
|
|
12
12
|
# Gets project information including all notes.
|
13
13
|
|
14
14
|
def get_project_info(project, all_data = true)
|
15
|
-
result =
|
15
|
+
result = @client.api_helper.get_response(Config::TODOIST_PROJECTS_GET_COMMAND, {project_id: project.id, all_data: true})
|
16
16
|
|
17
17
|
project = result["project"] ? ParseHelper.make_object(result["project"]) : nil
|
18
18
|
notes = result["notes"] ? ParseHelper.make_objects_as_hash(result["notes"]) : nil
|
@@ -21,7 +21,7 @@ module Todoist
|
|
21
21
|
|
22
22
|
# Gets a project's uncompleted items
|
23
23
|
def get_project_data(project)
|
24
|
-
result =
|
24
|
+
result = @client.api_helper.get_response(Config::TODOIST_PROJECTS_GET_DATA_COMMAND, {project_id: project.id})
|
25
25
|
project = result["project"] ? ParseHelper.make_object(result["project"]) : nil
|
26
26
|
items = result["items"] ? ParseHelper.make_objects_as_hash(result["items"]) : nil
|
27
27
|
return {"project" => project, "items" => items}
|
data/lib/todoist/misc/quick.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
module Todoist
|
2
2
|
module Misc
|
3
|
-
class Quick
|
3
|
+
class Quick < Todoist::Service
|
4
4
|
include Todoist::Util
|
5
5
|
|
6
6
|
# Implementation of the Quick Add Task available in the official
|
7
7
|
# clients.
|
8
8
|
def add_item(text)
|
9
|
-
result =
|
9
|
+
result = @client.api_helper.get_response(Config::TODOIST_QUICK_ADD_COMMAND, {text: text})
|
10
10
|
return ParseHelper.make_object(result)
|
11
11
|
end
|
12
12
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Todoist
|
2
2
|
module Misc
|
3
|
-
class Templates
|
3
|
+
class Templates < Todoist::Service
|
4
4
|
include Todoist::Util
|
5
5
|
|
6
6
|
# Given a project and a File object (Ruby) imports the content onto the
|
@@ -8,21 +8,21 @@ module Todoist
|
|
8
8
|
# suffix is CSV. Otherwise, the file will be parsed as one item per line
|
9
9
|
# and ignore the formatting altogether.
|
10
10
|
def import_into_project(project, file)
|
11
|
-
multipart_file =
|
11
|
+
multipart_file = @client.api_helper.multipart_file(file)
|
12
12
|
params = {project_id: project.id, file: multipart_file}
|
13
|
-
|
13
|
+
@client.api_helper.get_multipart_response(Config::TODOIST_TEMPLATES_IMPORT_INTO_PROJECT_COMMAND, params)
|
14
14
|
end
|
15
15
|
|
16
16
|
# Export the project as a CSV string
|
17
17
|
def export_as_file(project)
|
18
18
|
params = {project_id: project.id}
|
19
|
-
|
19
|
+
@client.api_helper.get_response(Config::TODOIST_TEMPLATES_EXPORT_AS_FILE_COMMAND, params)
|
20
20
|
end
|
21
21
|
|
22
22
|
# Export the project as a url that can be accessed over HTTP
|
23
23
|
def export_as_url(project)
|
24
24
|
params = {project_id: project.id}
|
25
|
-
|
25
|
+
@client.api_helper.get_response(Config::TODOIST_TEMPLATES_EXPORT_AS_URL_COMMAND, params)
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
data/lib/todoist/misc/uploads.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
module Todoist
|
2
2
|
module Misc
|
3
|
-
class Uploads
|
3
|
+
class Uploads < Todoist::Service
|
4
4
|
include Todoist::Util
|
5
5
|
|
6
6
|
# Uploads a file given a Ruby File.
|
7
7
|
def add(file)
|
8
|
-
multipart_file =
|
8
|
+
multipart_file = @client.api_helper.multipart_file(file)
|
9
9
|
params = {file_name: File.basename(file), file: multipart_file}
|
10
|
-
|
10
|
+
@client.api_helper.get_multipart_response(Config::TODOIST_UPLOADS_ADD_COMMAND, params)
|
11
11
|
end
|
12
12
|
|
13
13
|
# Get uploads up to limit. If last_id is entered, then the results list
|
@@ -15,13 +15,13 @@ module Todoist
|
|
15
15
|
def get(limit = 30, last_id = 0)
|
16
16
|
params = {limit: limit}
|
17
17
|
params["last_id"] = last_id if last_id
|
18
|
-
|
18
|
+
@client.api_helper.get_response(Config::TODOIST_UPLOADS_GET_COMMAND, params)
|
19
19
|
end
|
20
20
|
|
21
21
|
# Deletes an upload given a file URL.
|
22
22
|
def delete(file_url)
|
23
23
|
params = {file_url: file_url}
|
24
|
-
|
24
|
+
@client.api_helper.get_response(Config::TODOIST_UPLOADS_DELETE_COMMAND, params)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
data/lib/todoist/sync/filters.rb
CHANGED
@@ -2,30 +2,30 @@
|
|
2
2
|
|
3
3
|
module Todoist
|
4
4
|
module Sync
|
5
|
-
class Filters
|
5
|
+
class Filters < Todoist::Service
|
6
6
|
include Todoist::Util
|
7
7
|
|
8
8
|
# Return a Hash of filters where key is the id of a filter and value is a filter
|
9
9
|
def collection
|
10
|
-
return
|
10
|
+
return @client.api_helper.collection("filters")
|
11
11
|
end
|
12
12
|
|
13
13
|
# Add a filter with a given hash of attributes and returns the filter id.
|
14
14
|
# Please note that item_id is required as is a date as specific in the
|
15
15
|
# documentation. This method can be tricky to all.
|
16
16
|
def add(args)
|
17
|
-
return
|
17
|
+
return @client.api_helper.add(args, "filter_add")
|
18
18
|
end
|
19
19
|
|
20
20
|
# Update a filter given a hash of attributes
|
21
21
|
def update(args)
|
22
|
-
return
|
22
|
+
return @client.api_helper.command(args, "filter_update")
|
23
23
|
end
|
24
24
|
|
25
25
|
# Delete filter given an array of filters
|
26
26
|
def delete(filter)
|
27
27
|
args = {id: filter.id}
|
28
|
-
return
|
28
|
+
return @client.api_helper.command(args, "filter_delete")
|
29
29
|
end
|
30
30
|
|
31
31
|
# Update orders for an array of filters
|
@@ -35,7 +35,7 @@ module Todoist
|
|
35
35
|
args[filter.id] = filter.item_order
|
36
36
|
end
|
37
37
|
args = {id_order_mapping: args.to_json}
|
38
|
-
return
|
38
|
+
return @client.api_helper.command(args, "filter_update_orders")
|
39
39
|
end
|
40
40
|
|
41
41
|
|
data/lib/todoist/sync/items.rb
CHANGED
@@ -1,87 +1,83 @@
|
|
1
1
|
module Todoist
|
2
2
|
module Sync
|
3
|
-
class Items
|
4
|
-
include Todoist::Util
|
3
|
+
class Items < Todoist::Service
|
4
|
+
include Todoist::Util
|
5
5
|
|
6
6
|
# Return a Hash of items where key is the id of a item and value is a item
|
7
7
|
def collection
|
8
|
-
return
|
8
|
+
return @client.api_helper.collection("items")
|
9
9
|
end
|
10
10
|
|
11
11
|
# Add a item with a given hash of attributes and returns the item id
|
12
12
|
def add(args)
|
13
|
-
return
|
13
|
+
return @client.api_helper.add(args, "item_add")
|
14
14
|
end
|
15
15
|
|
16
16
|
# Update item given a hash of attributes
|
17
17
|
def update(args)
|
18
|
-
return
|
18
|
+
return @client.api_helper.command(args, "item_update")
|
19
19
|
end
|
20
20
|
|
21
21
|
# Delete items given an array of items
|
22
22
|
def delete(items)
|
23
|
-
item_ids = items.collect { |item| item.id }
|
23
|
+
item_ids = items.collect { |item| item.id }
|
24
24
|
args = {ids: item_ids.to_json}
|
25
|
-
return
|
25
|
+
return @client.api_helper.command(args, "item_delete")
|
26
26
|
end
|
27
27
|
|
28
28
|
# Move an item from one project to another project given an item and a project.
|
29
29
|
# Note that move requires a fully inflated item object because it uses
|
30
30
|
# the project id in the item object.
|
31
31
|
def move(item, project)
|
32
|
-
|
33
|
-
args
|
34
|
-
return ApiHelper.command(args, "item_move")
|
32
|
+
args = {id: item.id, project_id: project.id}
|
33
|
+
return @client.api_helper.command(args, "item_move")
|
35
34
|
end
|
36
|
-
|
37
|
-
# Complete
|
38
|
-
|
39
|
-
def complete(
|
40
|
-
|
41
|
-
|
42
|
-
return ApiHelper.command(args, "item_complete")
|
35
|
+
|
36
|
+
# Complete an item and optionally move them to history. When force_history = 1, items should be moved to history (where 1 is true and 0 is false, and the default is 1) This is useful when checking off sub items.
|
37
|
+
|
38
|
+
def complete(item, force_history=1)
|
39
|
+
args = {id: item.id, force_history: force_history}
|
40
|
+
return @client.api_helper.command(args, "item_complete")
|
43
41
|
end
|
44
|
-
|
45
|
-
# Uncomplete
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
args = {ids: item_ids.to_json}
|
51
|
-
return ApiHelper.command(args, "item_uncomplete")
|
42
|
+
|
43
|
+
# Uncomplete item and move them to the active projects
|
44
|
+
|
45
|
+
def uncomplete(item)
|
46
|
+
args = {id: item.id}
|
47
|
+
return @client.api_helper.command(args, "item_uncomplete")
|
52
48
|
end
|
53
|
-
|
54
|
-
# Complete a recurring item given the id of the recurring item.
|
55
|
-
# This method also accepts as optional a new DateTime in UTC, a date
|
56
|
-
# string to reset the object to, and whether or not the item is to
|
57
|
-
# be completed or not using the is_forward flag.
|
58
49
|
|
59
|
-
|
50
|
+
# Complete a recurring item given the id of the recurring item.
|
51
|
+
# This method also accepts as optional a new DateTime in UTC, a date
|
52
|
+
# string to reset the object to, and whether or not the item is to
|
53
|
+
# be completed or not using the is_forward flag.
|
54
|
+
|
55
|
+
def complete_recurring(item, new_date_utc = nil, date_string = nil,
|
60
56
|
is_forward = 1)
|
61
|
-
|
57
|
+
|
62
58
|
args = {id: item.id, is_forward: is_forward}
|
63
59
|
if new_date_utc
|
64
60
|
# Reformat DateTime to the following string: YYYY-MM-DDTHH:MM
|
65
|
-
args["
|
61
|
+
args["due"] = {date: ParseHelper.format_time(new_date_utc)}
|
66
62
|
end
|
67
|
-
|
63
|
+
|
68
64
|
if date_string
|
69
|
-
args["
|
65
|
+
args["due"] = {string: date_string}
|
70
66
|
end
|
71
|
-
|
72
|
-
return
|
67
|
+
|
68
|
+
return @client.api_helper.command(args, "item_update_date_complete")
|
73
69
|
end
|
74
|
-
|
75
|
-
# A simplified version of item_complete / item_update_date_complete.
|
76
|
-
# The command does exactly what official clients do when you close a item
|
70
|
+
|
71
|
+
# A simplified version of item_complete / item_update_date_complete.
|
72
|
+
# The command does exactly what official clients do when you close a item
|
77
73
|
# given an item.
|
78
|
-
|
74
|
+
|
79
75
|
def close(item)
|
80
76
|
args = {id: item.id}
|
81
|
-
return
|
77
|
+
return @client.api_helper.command(args, "item_close")
|
82
78
|
end
|
83
|
-
|
84
|
-
# Update the day orders of multiple items at once given an array of
|
79
|
+
|
80
|
+
# Update the day orders of multiple items at once given an array of
|
85
81
|
# items
|
86
82
|
def update_day_orders(items)
|
87
83
|
ids_to_orders = {}
|
@@ -89,9 +85,9 @@ module Todoist
|
|
89
85
|
ids_to_orders[item.id] = item.day_order
|
90
86
|
end
|
91
87
|
args = {ids_to_orders: ids_to_orders.to_json}
|
92
|
-
return
|
88
|
+
return @client.api_helper.command(args, "item_update_day_orders")
|
93
89
|
end
|
94
|
-
|
90
|
+
|
95
91
|
# Update orders and indents for an array of items
|
96
92
|
def update_multiple_orders_and_indents(items)
|
97
93
|
tuples = {}
|
@@ -99,9 +95,9 @@ module Todoist
|
|
99
95
|
tuples[item.id] = [item.item_order, item.indent]
|
100
96
|
end
|
101
97
|
args = {ids_to_orders_indents: tuples.to_json}
|
102
|
-
return
|
98
|
+
return @client.api_helper.command(args, "item_update_orders_indents")
|
103
99
|
end
|
104
|
-
|
100
|
+
|
105
101
|
end
|
106
102
|
end
|
107
103
|
end
|