ruby-todoist-api-v7 1.0.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.
Files changed (58) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +14 -0
  3. data/.kick +18 -0
  4. data/.rspec +3 -0
  5. data/.travis.yml +6 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +45 -0
  9. data/Rakefile +2 -0
  10. data/lib/todoist.rb +27 -0
  11. data/lib/todoist/client.rb +94 -0
  12. data/lib/todoist/command.rb +24 -0
  13. data/lib/todoist/error.rb +0 -0
  14. data/lib/todoist/filter.rb +16 -0
  15. data/lib/todoist/item.rb +39 -0
  16. data/lib/todoist/label.rb +15 -0
  17. data/lib/todoist/note.rb +19 -0
  18. data/lib/todoist/project.rb +29 -0
  19. data/lib/todoist/query.rb +47 -0
  20. data/lib/todoist/queue.rb +39 -0
  21. data/lib/todoist/reminder.rb +16 -0
  22. data/lib/todoist/request.rb +37 -0
  23. data/lib/todoist/resource.rb +75 -0
  24. data/lib/todoist/service/base_service.rb +77 -0
  25. data/lib/todoist/service/filter.rb +9 -0
  26. data/lib/todoist/service/item.rb +24 -0
  27. data/lib/todoist/service/label.rb +9 -0
  28. data/lib/todoist/service/note.rb +9 -0
  29. data/lib/todoist/service/project.rb +9 -0
  30. data/lib/todoist/service/reminder.rb +9 -0
  31. data/lib/todoist/user.rb +10 -0
  32. data/lib/todoist/version.rb +3 -0
  33. data/ruby-todoist-api-v7.gemspec +22 -0
  34. data/spec/lib/todoist/client_spec.rb +58 -0
  35. data/spec/lib/todoist/filter_spec.rb +19 -0
  36. data/spec/lib/todoist/item_spec.rb +39 -0
  37. data/spec/lib/todoist/label_spec.rb +12 -0
  38. data/spec/lib/todoist/note_spec.rb +12 -0
  39. data/spec/lib/todoist/project_spec.rb +12 -0
  40. data/spec/lib/todoist/query_spec.rb +26 -0
  41. data/spec/lib/todoist/reminder_spec.rb +12 -0
  42. data/spec/lib/todoist/service/filter_spec.rb +33 -0
  43. data/spec/lib/todoist/service/item_spec.rb +46 -0
  44. data/spec/lib/todoist/service/label_spec.rb +33 -0
  45. data/spec/lib/todoist/service/note_spec.rb +33 -0
  46. data/spec/lib/todoist/service/project_spec.rb +33 -0
  47. data/spec/lib/todoist/service/reminder_spec.rb +33 -0
  48. data/spec/lib/todoist_spec.rb +7 -0
  49. data/spec/spec_helper.rb +8 -0
  50. data/spec/support/json_response_helper.rb +17 -0
  51. data/spec/support/responses/filter.json +9 -0
  52. data/spec/support/responses/item.json +25 -0
  53. data/spec/support/responses/label.json +8 -0
  54. data/spec/support/responses/note.json +18 -0
  55. data/spec/support/responses/project.json +15 -0
  56. data/spec/support/responses/query.json +88 -0
  57. data/spec/support/responses/reminder.json +9 -0
  58. metadata +154 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 45abb6cd62abf952735a4a610dfc27bb5be2b01b
4
+ data.tar.gz: 7498e6b17bbd47e3f1dfe077d10d5f0d780041cb
5
+ SHA512:
6
+ metadata.gz: 5d3e41c717320de4bfeafff25a500c461b54b82b2eaf7404a7f278fd55efc5a5e5e56daa8951c114c26d28931c8e7ddda81902164893b914d110401ce392a497
7
+ data.tar.gz: 2bbba3368706719d80b0cb7822604d0950f218bf3b5616f325d0d4a50c78e0eebb3b41be6f81039824693b663fa7e438160254cec96fb2402b3738171e13c1f6
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.kick ADDED
@@ -0,0 +1,18 @@
1
+ require 'set'
2
+ require 'benchmark'
3
+
4
+ process do |file, flags|
5
+ test_files = Set.new
6
+ case file
7
+ when %r(^spec/.*_spec.rb$)
8
+ test_files << file
9
+ when %r(^lib/(.*).rb)
10
+ test_files << 'spec/lib/' + $1 + '_spec.rb'
11
+ when %r(^spec/helpers/expected)
12
+ test_files.merge Dir['spec/helpers/**/*_spec.rb']
13
+ end
14
+ test_files = test_files.select { |filename| File.exist?(filename) }
15
+ unless test_files.empty?
16
+ watcher.execute("bundle exec rspec --fail-fast #{test_files.to_a.join(' ')}")
17
+ end
18
+ end
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --profile
3
+ --order rand
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ sudo: false
3
+ rvm:
4
+ - 2.1.0
5
+ - 2.2.0
6
+ script: bundle exec rspec
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in todoist-api.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Maarten van Vliet
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ [![Build Status](https://travis-ci.org/stesie/ruby-todoist-api.svg)](https://travis-ci.org/stesie/ruby-todoist-api)
2
+
3
+ # Todoist::Api
4
+
5
+ Gem to wrap the Todoist Api v7 as described on https://developer.todoist.com/
6
+
7
+ *Note:* Until a more complete coverage of the all Todoist features is achieved the api is unstable and no semantic versioning will be applied.
8
+
9
+ ## Goals
10
+
11
+ * To provide an easy to use, well tested, wrapper for the Todoist Api
12
+ * Use a minimal set of dependencies apart from the Ruby standard library (exception for development dependencies, although also bare minimum).
13
+ * Ruby 2.1 and up
14
+
15
+
16
+ ## Installation
17
+
18
+ Add this line to your application's Gemfile:
19
+
20
+ ```ruby
21
+ gem 'todoist-api', git: 'https://github.com/stesie/ruby-todoist-api', branch: 'master', require: 'todoist'
22
+
23
+ ```
24
+
25
+ And then execute:
26
+
27
+ $ bundle install
28
+
29
+ ## Usage
30
+
31
+ todoist = Todoist::Client.new(todoist_token)
32
+ todoist.items.create(content: 'Some new todo')
33
+ todoist.process!
34
+
35
+ ## Future
36
+
37
+ Possible spinoff would be a gem to do provide a CLI interface to Todoist.
38
+
39
+ ## Contributing
40
+
41
+ 1. Fork it ( https://github.com/stesie/ruby-todoist-api/fork )
42
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
43
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
44
+ 4. Push to the branch (`git push origin my-new-feature`)
45
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/lib/todoist.rb ADDED
@@ -0,0 +1,27 @@
1
+ require "net/http"
2
+ require 'securerandom'
3
+
4
+ module Todoist; end
5
+
6
+ require 'todoist/client'
7
+ require 'todoist/command'
8
+ require 'todoist/resource'
9
+ require 'todoist/error'
10
+ require 'todoist/filter'
11
+ require 'todoist/item'
12
+ require 'todoist/label'
13
+ require 'todoist/note'
14
+ require 'todoist/project'
15
+ require 'todoist/query'
16
+ require 'todoist/queue'
17
+ require 'todoist/user'
18
+ require 'todoist/reminder'
19
+ require 'todoist/request'
20
+ require 'todoist/service/base_service'
21
+ require 'todoist/service/filter'
22
+ require 'todoist/service/item'
23
+ require 'todoist/service/label'
24
+ require 'todoist/service/note'
25
+ require 'todoist/service/project'
26
+ require 'todoist/service/reminder'
27
+ require 'todoist/version'
@@ -0,0 +1,94 @@
1
+ module Todoist
2
+ class Client
3
+ attr_reader :token, :queue, :_last_response
4
+ attr_writer :seq_no, :seq_no_global
5
+ attr_accessor :errors
6
+
7
+ SUCCES_STATUS_CODE = 200
8
+
9
+ def initialize(token)
10
+ @token = token
11
+ end
12
+
13
+ def base_url
14
+ "https://todoist.com"
15
+ end
16
+
17
+ def filters
18
+ @filters ||= Service::Filter.new(self)
19
+ end
20
+
21
+ def items
22
+ @items ||= Service::Item.new(self)
23
+ end
24
+
25
+ def labels
26
+ @labels ||= Service::Label.new(self)
27
+ end
28
+
29
+ def notes
30
+ @notes ||= Service::Note.new(self)
31
+ end
32
+
33
+ def projects
34
+ @projects ||= Service::Project.new(self)
35
+ end
36
+
37
+ def reminders
38
+ @reminders ||= Service::Reminder.new(self)
39
+ end
40
+
41
+ def query
42
+ @query ||= Query.new(self)
43
+ end
44
+
45
+ def queue
46
+ @queue ||= Queue.new(self)
47
+ end
48
+
49
+ def seq_no
50
+ @seq_no ||= 0
51
+ end
52
+
53
+ def seq_no_global
54
+ @seq_no_global ||= 0
55
+ end
56
+
57
+ def logger
58
+ @logger ||= Logger.new($stdout).tap do |log|
59
+ log.progname = 'todoist-api'
60
+ end
61
+ end
62
+
63
+ def post(path, payload)
64
+ post_request = Request.post(path, payload.merge(token: token))
65
+
66
+ response = @_last_response = post_request.execute(base_url)
67
+
68
+ if response.code.to_i != SUCCES_STATUS_CODE
69
+ self.errors = JSON.parse(@_last_response.body.to_s)
70
+ return false
71
+ else
72
+ parsed_response = JSON.parse(response.body)
73
+
74
+ self.seq_no_global = parsed_response['seq_no_global'] if parsed_response.is_a?(Hash) && parsed_response['seq_no_global']
75
+
76
+ parsed_response
77
+ end
78
+ end
79
+
80
+ def process!
81
+ queue.process!
82
+ end
83
+
84
+ def process_queue
85
+ logger.warn 'Deprecated process_queue'
86
+ queue.process!
87
+ end
88
+
89
+ def add_to_queue(command)
90
+ logger.warn 'Deprecated process_queue'
91
+ queue.add(command)
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,24 @@
1
+ module Todoist
2
+ class Command
3
+ attr_accessor :type, :object, :temp_id, :uuid
4
+
5
+ def initialize(type, object, temp_id = nil, uuid = nil)
6
+ @type = type
7
+ @object = object
8
+ @temp_id = object.temp_id
9
+ @uuid = uuid || SecureRandom.uuid
10
+ end
11
+
12
+ def arguments
13
+ object.to_submittable_hash
14
+ end
15
+
16
+ def to_hash
17
+ {
18
+ type: type,
19
+ uuid: uuid,
20
+ args: object.to_submittable_hash
21
+ }.merge(temp_id ? { temp_id: temp_id} : {})
22
+ end
23
+ end
24
+ end
File without changes
@@ -0,0 +1,16 @@
1
+ module Todoist
2
+ class Filter
3
+ include Todoist::Resource
4
+ extend Todoist::Resource::ClassMethods
5
+
6
+ define_attributes %w(
7
+ id
8
+ name
9
+ query
10
+ color
11
+ item_order
12
+ is_deleted
13
+ is_favorite
14
+ )
15
+ end
16
+ end
@@ -0,0 +1,39 @@
1
+ module Todoist
2
+ class Item
3
+ include Todoist::Resource
4
+ extend Todoist::Resource::ClassMethods
5
+
6
+ define_attributes %w(
7
+ id
8
+ user_id
9
+ project_id
10
+ content
11
+ date_string
12
+ date_lang
13
+ due_date_utc
14
+ priority
15
+ indent
16
+ item_order
17
+ day_order
18
+ collapsed
19
+ labels
20
+ assigned_by_uid
21
+ responsible_uid
22
+ checked
23
+ in_history
24
+ is_deleted
25
+ is_archived
26
+ sync_id
27
+ date_added
28
+ )
29
+
30
+ def project=(project)
31
+ self.project_id = project.to_hash['id']
32
+ end
33
+
34
+ def user=(user)
35
+ self.user_id = user.to_hash['id']
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,15 @@
1
+ module Todoist
2
+ class Label
3
+ include Todoist::Resource
4
+ extend Todoist::Resource::ClassMethods
5
+
6
+ define_attributes %w(
7
+ id
8
+ name
9
+ color
10
+ item_order
11
+ is_deleted
12
+ is_favorite
13
+ )
14
+ end
15
+ end
@@ -0,0 +1,19 @@
1
+ module Todoist
2
+ class Note
3
+ include Todoist::Resource
4
+ extend Todoist::Resource::ClassMethods
5
+
6
+ define_attributes %w(
7
+ id
8
+ posted_uid
9
+ item_id
10
+ project_id
11
+ content
12
+ file_attachment
13
+ uids_to_notify
14
+ is_deleted
15
+ is_archived
16
+ posted
17
+ )
18
+ end
19
+ end
@@ -0,0 +1,29 @@
1
+ module Todoist
2
+ class Project
3
+ include Todoist::Resource
4
+ extend Todoist::Resource::ClassMethods
5
+
6
+ define_attributes %w(
7
+ id
8
+ name
9
+ color
10
+ indent
11
+ item_order
12
+ collapsed
13
+ shared
14
+ is_deleted
15
+ is_archived
16
+ is_favorite
17
+ inbox_project
18
+ team_inbox
19
+
20
+ has_more_notes
21
+ )
22
+
23
+ def items
24
+ @items ||= Service::Item.new(client)
25
+ end
26
+
27
+
28
+ end
29
+ end
@@ -0,0 +1,47 @@
1
+ module Todoist
2
+ class Result
3
+ include Enumerable
4
+
5
+ attr_reader :data
6
+
7
+ def initialize(result)
8
+ @query = result['query']
9
+ @data = result['data']
10
+ end
11
+
12
+ def each(&block)
13
+ data.each do |object|
14
+ block.call(Todoist::Item.new(object))
15
+ end
16
+ end
17
+
18
+ def size
19
+ data.size
20
+ end
21
+
22
+ end
23
+
24
+ class Query
25
+ def initialize(client)
26
+ @client = client
27
+ end
28
+
29
+ def query_path
30
+ '/API/v7/query'
31
+ end
32
+
33
+ def search(queries)
34
+ if queries.is_a?(String)
35
+ queries = [queries]
36
+ end
37
+
38
+ parsed_response = @client.post(query_path, { queries: queries.to_json})
39
+
40
+ result_set = parsed_response.inject({}) do |results, query|
41
+ results[query['query']] = Todoist::Result.new(query)
42
+ results
43
+ end
44
+ result_set
45
+ end
46
+ end
47
+ end