ruby-todoist-api 0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.kick +18 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +45 -0
- data/Rakefile +2 -0
- data/lib/todoist.rb +27 -0
- data/lib/todoist/client.rb +94 -0
- data/lib/todoist/command.rb +24 -0
- data/lib/todoist/error.rb +0 -0
- data/lib/todoist/filter.rb +16 -0
- data/lib/todoist/item.rb +54 -0
- data/lib/todoist/label.rb +15 -0
- data/lib/todoist/note.rb +19 -0
- data/lib/todoist/project.rb +32 -0
- data/lib/todoist/query.rb +47 -0
- data/lib/todoist/queue.rb +39 -0
- data/lib/todoist/reminder.rb +16 -0
- data/lib/todoist/request.rb +37 -0
- data/lib/todoist/resource.rb +73 -0
- data/lib/todoist/service/base_service.rb +77 -0
- data/lib/todoist/service/filter.rb +9 -0
- data/lib/todoist/service/item.rb +24 -0
- data/lib/todoist/service/label.rb +9 -0
- data/lib/todoist/service/note.rb +9 -0
- data/lib/todoist/service/project.rb +9 -0
- data/lib/todoist/service/reminder.rb +9 -0
- data/lib/todoist/user.rb +10 -0
- data/lib/todoist/version.rb +3 -0
- data/ruby-todoist-api.gemspec +22 -0
- data/spec/lib/todoist/client_spec.rb +58 -0
- data/spec/lib/todoist/filter_spec.rb +19 -0
- data/spec/lib/todoist/item_spec.rb +39 -0
- data/spec/lib/todoist/label_spec.rb +12 -0
- data/spec/lib/todoist/note_spec.rb +12 -0
- data/spec/lib/todoist/project_spec.rb +12 -0
- data/spec/lib/todoist/query_spec.rb +26 -0
- data/spec/lib/todoist/reminder_spec.rb +12 -0
- data/spec/lib/todoist/service/filter_spec.rb +33 -0
- data/spec/lib/todoist/service/item_spec.rb +46 -0
- data/spec/lib/todoist/service/label_spec.rb +33 -0
- data/spec/lib/todoist/service/note_spec.rb +33 -0
- data/spec/lib/todoist/service/project_spec.rb +33 -0
- data/spec/lib/todoist/service/reminder_spec.rb +33 -0
- data/spec/lib/todoist_spec.rb +7 -0
- data/spec/spec_helper.rb +8 -0
- data/spec/support/json_response_helper.rb +17 -0
- data/spec/support/responses/filter.json +9 -0
- data/spec/support/responses/item.json +25 -0
- data/spec/support/responses/label.json +8 -0
- data/spec/support/responses/note.json +18 -0
- data/spec/support/responses/project.json +14 -0
- data/spec/support/responses/query.json +88 -0
- data/spec/support/responses/reminder.json +9 -0
- metadata +153 -0
@@ -0,0 +1,39 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Todoist::Item do
|
4
|
+
let(:instance) { described_class.new(json_response('item'))}
|
5
|
+
|
6
|
+
it "can be built from json" do
|
7
|
+
expect(instance.attributes).to eq({
|
8
|
+
"id"=>33511505,
|
9
|
+
"user_id"=>1855589,
|
10
|
+
"project_id"=>128501470,
|
11
|
+
"content"=>"Task1",
|
12
|
+
"date_added" => "Fri 26 Sep 2014 08:25:05 +0000",
|
13
|
+
"date_string"=>"",
|
14
|
+
"date_lang"=>"en",
|
15
|
+
"priority"=>1,
|
16
|
+
"indent"=>1,
|
17
|
+
"item_order"=>1,
|
18
|
+
"labels" => [],
|
19
|
+
"day_order"=>-1,
|
20
|
+
"collapsed" => 0,
|
21
|
+
"assigned_by_uid"=>1855589,
|
22
|
+
"checked"=>0,
|
23
|
+
"in_history"=>0,
|
24
|
+
"is_deleted"=>0,
|
25
|
+
"is_archived"=>0
|
26
|
+
}
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "can be assigned a project" do
|
31
|
+
instance.project = Todoist::Project.new({'id' => 1})
|
32
|
+
expect(instance.project_id).to eq 1
|
33
|
+
end
|
34
|
+
|
35
|
+
it "can be assigned a user" do
|
36
|
+
instance.user = Todoist::User.new({'id' => 1})
|
37
|
+
expect(instance.user_id).to eq 1
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Todoist::Label do
|
4
|
+
|
5
|
+
|
6
|
+
it "can be built from json" do
|
7
|
+
instance = described_class.new(json_response('label'))
|
8
|
+
|
9
|
+
expect(instance.attributes).to eq({"id"=>790748, "uid"=>1855589, "name"=>"Label1", "color"=>7, "item_order"=>0, "is_deleted"=>0}
|
10
|
+
)
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Todoist::Note do
|
4
|
+
|
5
|
+
|
6
|
+
it "can be built from json" do
|
7
|
+
instance = described_class.new(json_response('note'))
|
8
|
+
|
9
|
+
expect(instance.attributes).to eq({"id"=>17299568, "item_id"=>33548400, "posted_uid"=>1855589, "project_id"=>128501470, "content"=>"Note", "is_deleted"=>0, "is_archived"=>0, "file_attachment"=>{"file_type"=>"text/plain", "file_name"=>"File1.txt", "file_size"=>1234, "file_url"=>"https://example.com/File1.txt", "upload_state"=>"completed"}, "posted"=>"Wed 01 Oct 2014 14:54:55 +0000"}
|
10
|
+
)
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Todoist::Project do
|
4
|
+
|
5
|
+
|
6
|
+
it "can be built from json" do
|
7
|
+
instance = described_class.new(json_response('project'))
|
8
|
+
|
9
|
+
expect(instance.attributes).to eq({"id"=>128501470, "user_id"=>1855589, "name"=>"Project1", "color"=>1, "indent"=>1, "item_order"=>36, "collapsed"=>0, "shared"=>false, "is_deleted"=>0, "is_archived"=>0, "archived_timestamp"=>0}
|
10
|
+
)
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Todoist::Query do
|
4
|
+
|
5
|
+
let(:client) { Todoist::Client.new("api_token") }
|
6
|
+
let(:query) { described_class.new(client) }
|
7
|
+
|
8
|
+
describe "creating a query" do
|
9
|
+
let(:arguments) { resource_without_id('filter') }
|
10
|
+
|
11
|
+
before do
|
12
|
+
stub_request(:post, "https://todoist.com/API/v6/query").
|
13
|
+
with(:body => {"queries"=>"[\"tomorrow\",\"p1\"]", "token"=>"api_token"}).
|
14
|
+
to_return(:status => 200, :body => json_response_raw('query'), :headers => {})
|
15
|
+
end
|
16
|
+
|
17
|
+
it "can create searches" do
|
18
|
+
|
19
|
+
result = query.search(['tomorrow', 'p1'])
|
20
|
+
|
21
|
+
expect(result.keys).to eq ['tomorrow','p1']
|
22
|
+
expect(result['tomorrow'].size).to eq 2
|
23
|
+
expect(result['tomorrow'].first.id).to eq 35825425
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Todoist::Reminder do
|
4
|
+
|
5
|
+
|
6
|
+
it "can be built from json" do
|
7
|
+
instance = described_class.new(json_response('reminder'))
|
8
|
+
|
9
|
+
expect(instance.attributes).to eq({"id"=>4638878, "user_id"=>1855589, "name"=>"Priority 1", "query"=>"priority 1", "color"=>6, "item_order"=>3, "is_deleted"=>0}
|
10
|
+
)
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Todoist::Service::Filter do
|
4
|
+
|
5
|
+
let(:client) { Todoist::Client.new("api_token") }
|
6
|
+
let(:filter_service) { described_class.new(client) }
|
7
|
+
|
8
|
+
describe "creating a filter" do
|
9
|
+
let(:arguments) { resource_without_id('filter') }
|
10
|
+
|
11
|
+
it "can create a filter" do
|
12
|
+
expect{
|
13
|
+
filter_service.create(arguments)
|
14
|
+
}.to change{ client.queue.length}.by(+1)
|
15
|
+
|
16
|
+
expect(client.queue.last.type).to eq 'filter_add'
|
17
|
+
expect(client.queue.last.arguments).to eq arguments
|
18
|
+
end
|
19
|
+
|
20
|
+
it "create a filter with custom tmp id" do
|
21
|
+
expect{
|
22
|
+
filter_service.create(arguments, 'temporary id')
|
23
|
+
}.to change{ client.queue.length}.by(+1)
|
24
|
+
|
25
|
+
expect(client.queue.last.temp_id).to eq 'temporary id'
|
26
|
+
end
|
27
|
+
|
28
|
+
it "returns an filter" do
|
29
|
+
filter = filter_service.create(arguments, 'temporary id')
|
30
|
+
expect(filter.to_submittable_hash).to eq(arguments)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Todoist::Service::Item do
|
4
|
+
|
5
|
+
let(:client) { Todoist::Client.new("api_token") }
|
6
|
+
let(:item_service) { described_class.new(client) }
|
7
|
+
|
8
|
+
describe "creating an item" do
|
9
|
+
let(:arguments) { resource_without_id('item') }
|
10
|
+
|
11
|
+
it "can create an item" do
|
12
|
+
expect{
|
13
|
+
item = item_service.create(arguments)
|
14
|
+
}.to change{ client.queue.length}.by(+1)
|
15
|
+
|
16
|
+
expect(client.queue.last.type).to eq 'item_add'
|
17
|
+
expect(client.queue.last.arguments).to eq arguments
|
18
|
+
end
|
19
|
+
|
20
|
+
it "create an item with custom tmp id" do
|
21
|
+
expect{
|
22
|
+
item_service.create(arguments, 'temporary id')
|
23
|
+
}.to change{ client.queue.length}.by(+1)
|
24
|
+
|
25
|
+
expect(client.queue.last.temp_id).to eq 'temporary id'
|
26
|
+
end
|
27
|
+
|
28
|
+
it "returns an item" do
|
29
|
+
item = item_service.create(arguments, 'temporary id')
|
30
|
+
expect(item.to_submittable_hash).to eq(arguments)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "updating an item" do
|
35
|
+
let(:arguments) { json_response('item') }
|
36
|
+
|
37
|
+
it "can update an item" do
|
38
|
+
expect{
|
39
|
+
item = item_service.create(arguments)
|
40
|
+
}.to change{ client.queue.length}.by(+1)
|
41
|
+
|
42
|
+
expect(client.queue.last.type).to eq 'item_update'
|
43
|
+
expect(client.queue.last.arguments).to eq arguments
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Todoist::Service::Label do
|
4
|
+
|
5
|
+
let(:client) { Todoist::Client.new("api_token") }
|
6
|
+
let(:label_service) { described_class.new(client) }
|
7
|
+
|
8
|
+
describe "creating an item" do
|
9
|
+
let(:arguments) { resource_without_id('label') }
|
10
|
+
|
11
|
+
it "can create an item" do
|
12
|
+
expect{
|
13
|
+
label_service.create(arguments)
|
14
|
+
}.to change{ client.queue.length}.by(+1)
|
15
|
+
|
16
|
+
expect(client.queue.last.type).to eq 'label_add'
|
17
|
+
expect(client.queue.last.arguments).to eq arguments
|
18
|
+
end
|
19
|
+
|
20
|
+
it "create an item with custom tmp id" do
|
21
|
+
expect{
|
22
|
+
label_service.create(arguments, 'temporary id')
|
23
|
+
}.to change{ client.queue.length}.by(+1)
|
24
|
+
|
25
|
+
expect(client.queue.last.temp_id).to eq 'temporary id'
|
26
|
+
end
|
27
|
+
|
28
|
+
it "returns an label" do
|
29
|
+
label = label_service.create(arguments, 'temporary id')
|
30
|
+
expect(label.to_submittable_hash).to eq(arguments)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Todoist::Service::Note do
|
4
|
+
|
5
|
+
let(:client) { Todoist::Client.new("api_token") }
|
6
|
+
let(:note_service) { described_class.new(client) }
|
7
|
+
|
8
|
+
describe "creating a note" do
|
9
|
+
let(:arguments) { resource_without_id('note')}
|
10
|
+
|
11
|
+
it "can create a note" do
|
12
|
+
expect{
|
13
|
+
note_service.create(arguments)
|
14
|
+
}.to change{ client.queue.length}.by(+1)
|
15
|
+
|
16
|
+
expect(client.queue.last.type).to eq 'note_add'
|
17
|
+
expect(client.queue.last.arguments).to eq arguments
|
18
|
+
end
|
19
|
+
|
20
|
+
it "create a note with custom tmp id" do
|
21
|
+
expect{
|
22
|
+
note_service.create(arguments, 'temporary id')
|
23
|
+
}.to change{ client.queue.length}.by(+1)
|
24
|
+
|
25
|
+
expect(client.queue.last.temp_id).to eq 'temporary id'
|
26
|
+
end
|
27
|
+
|
28
|
+
it "returns an note" do
|
29
|
+
note = note_service.create(arguments, 'temporary id')
|
30
|
+
expect(note.to_submittable_hash).to eq(arguments)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Todoist::Service::Project do
|
4
|
+
|
5
|
+
let(:client) { Todoist::Client.new("api_token") }
|
6
|
+
let(:project_service) { described_class.new(client) }
|
7
|
+
|
8
|
+
describe "creating a project" do
|
9
|
+
let(:arguments) { resource_without_id('project') }
|
10
|
+
|
11
|
+
it "can create an project" do
|
12
|
+
expect{
|
13
|
+
project_service.create(arguments)
|
14
|
+
}.to change{ client.queue.length}.by(+1)
|
15
|
+
|
16
|
+
expect(client.queue.last.type).to eq 'project_add'
|
17
|
+
expect(client.queue.last.arguments).to eq arguments
|
18
|
+
end
|
19
|
+
|
20
|
+
it "can create an project with custom tmp id" do
|
21
|
+
expect{
|
22
|
+
project_service.create(arguments, 'temporary id')
|
23
|
+
}.to change{ client.queue.length}.by(+1)
|
24
|
+
|
25
|
+
expect(client.queue.last.temp_id).to eq 'temporary id'
|
26
|
+
end
|
27
|
+
|
28
|
+
it "returns an project" do
|
29
|
+
project = project_service.create(arguments, 'temporary id')
|
30
|
+
expect(project.to_submittable_hash).to eq(arguments)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Todoist::Service::Reminder do
|
4
|
+
|
5
|
+
let(:client) { Todoist::Client.new("api_token") }
|
6
|
+
let(:reminder_service) { described_class.new(client) }
|
7
|
+
|
8
|
+
describe "creating a reminder" do
|
9
|
+
let(:arguments) { resource_without_id('reminder') }
|
10
|
+
|
11
|
+
it "can create a reminder" do
|
12
|
+
expect{
|
13
|
+
reminder_service.create(arguments)
|
14
|
+
}.to change{ client.queue.length}.by(+1)
|
15
|
+
|
16
|
+
expect(client.queue.last.type).to eq 'reminder_add'
|
17
|
+
expect(client.queue.last.arguments).to eq arguments
|
18
|
+
end
|
19
|
+
|
20
|
+
it "create a reminder with custom tmp id" do
|
21
|
+
expect{
|
22
|
+
reminder_service.create(arguments, 'temporary id')
|
23
|
+
}.to change{ client.queue.length}.by(+1)
|
24
|
+
|
25
|
+
expect(client.queue.last.temp_id).to eq 'temporary id'
|
26
|
+
end
|
27
|
+
|
28
|
+
it "returns an reminder" do
|
29
|
+
reminder = reminder_service.create(arguments, 'temporary id')
|
30
|
+
expect(reminder.to_submittable_hash).to eq(arguments)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
module JsonResponseHelper
|
2
|
+
def json_filename(name)
|
3
|
+
File.join('spec/support/responses/', "#{name}.json")
|
4
|
+
end
|
5
|
+
|
6
|
+
def json_response_raw(name)
|
7
|
+
File.read(json_filename(name))
|
8
|
+
end
|
9
|
+
|
10
|
+
def json_response(name)
|
11
|
+
JSON.parse(json_response_raw(name)).delete_if { |k, v| v.nil? }
|
12
|
+
end
|
13
|
+
|
14
|
+
def resource_without_id(name)
|
15
|
+
json_response(name).delete_if { |k, v| k == 'id' }
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
{
|
2
|
+
"id": 33511505,
|
3
|
+
"user_id": 1855589,
|
4
|
+
"project_id": 128501470,
|
5
|
+
"content": "Task1",
|
6
|
+
"date_string": "",
|
7
|
+
"date_lang": "en",
|
8
|
+
"due_date_utc": null,
|
9
|
+
"due_date": null,
|
10
|
+
"indent": 1,
|
11
|
+
"priority": 1,
|
12
|
+
"item_order": 1,
|
13
|
+
"day_order": -1,
|
14
|
+
"collapsed": 0,
|
15
|
+
"children": null,
|
16
|
+
"labels": [],
|
17
|
+
"assigned_by_uid": 1855589,
|
18
|
+
"responsible_uid": null,
|
19
|
+
"checked": 0,
|
20
|
+
"in_history": 0,
|
21
|
+
"is_deleted": 0,
|
22
|
+
"is_archived": 0,
|
23
|
+
"sync_id": null,
|
24
|
+
"date_added": "Fri 26 Sep 2014 08:25:05 +0000"
|
25
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
{
|
2
|
+
"id": 17299568,
|
3
|
+
"posted_uid": 1855589,
|
4
|
+
"project_id": 128501470,
|
5
|
+
"item_id": 33548400,
|
6
|
+
"content": "Note",
|
7
|
+
"file_attachment": {
|
8
|
+
"file_type": "text/plain",
|
9
|
+
"file_name": "File1.txt",
|
10
|
+
"file_size": 1234,
|
11
|
+
"file_url": "https://example.com/File1.txt",
|
12
|
+
"upload_state": "completed"
|
13
|
+
},
|
14
|
+
"uids_to_notify": null,
|
15
|
+
"is_deleted": 0,
|
16
|
+
"is_archived": 0,
|
17
|
+
"posted": "Wed 01 Oct 2014 14:54:55 +0000"
|
18
|
+
}
|