alexa-todoist_filter 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0f18c031fb4f4ab92a8291e18c3a74de26ca532a
4
+ data.tar.gz: eb7c517fcf0a7f9fe7be2f502d4ccf7586507adb
5
+ SHA512:
6
+ metadata.gz: 22f88f66f61cd1b62880bbe6189237995d2ada3f1e7e16296023f2c51a1988437905e46a165b18d31d12693ed64bc3af92f7670af3063ebc5d52d49643d3164b
7
+ data.tar.gz: d4f51ee54963fe9fc985b6bc6532a853fb02a8c60c0094051d57b76fc53a7b1cc024ee015813606c5a8b340f1702163cef232ccea63efd028747596a1b67684c
@@ -0,0 +1,2 @@
1
+ .idea
2
+ *.iml
@@ -0,0 +1 @@
1
+ 2.4.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in todoist-alexa-filter.gemspec
4
+ gemspec
@@ -0,0 +1,41 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ alexa-todoist_filter (0.1.0)
5
+ faraday (~> 0.11.0)
6
+ thor (~> 0.19.4)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ diff-lcs (1.2.5)
12
+ faraday (0.11.0)
13
+ multipart-post (>= 1.2, < 3)
14
+ multipart-post (2.0.0)
15
+ rake (10.5.0)
16
+ rspec (3.5.0)
17
+ rspec-core (~> 3.5.0)
18
+ rspec-expectations (~> 3.5.0)
19
+ rspec-mocks (~> 3.5.0)
20
+ rspec-core (3.5.4)
21
+ rspec-support (~> 3.5.0)
22
+ rspec-expectations (3.5.0)
23
+ diff-lcs (>= 1.2.0, < 2.0)
24
+ rspec-support (~> 3.5.0)
25
+ rspec-mocks (3.5.0)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.5.0)
28
+ rspec-support (3.5.0)
29
+ thor (0.19.4)
30
+
31
+ PLATFORMS
32
+ ruby
33
+
34
+ DEPENDENCIES
35
+ alexa-todoist_filter!
36
+ bundler (~> 1.13)
37
+ rake (~> 10.0)
38
+ rspec (~> 3.0)
39
+
40
+ BUNDLED WITH
41
+ 1.13.7
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Clark Burns
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,56 @@
1
+ # Alexa::TodoistFilter
2
+
3
+ A command line tool for moving Alexa todos in Todoist into a user specified project.
4
+
5
+ This allows for easily sharing between Todoist accounts.
6
+
7
+ * Setup a Todoist account specifically for Alexa.
8
+ * Create a project in that account and share it with each individuals Todoist account.
9
+ * Run this handy bit of code which will move any todo in your Inbox labeled with 'Alexa' (default behavior) to the
10
+ project you specify
11
+ * Now you can say 'Alexa, add [IMPORTANT THING] to my todo list' and everyone subscribed to the Todoist project will
12
+ automatically have access to that todo.
13
+
14
+ ## Installation
15
+
16
+ Add this line to your application's Gemfile:
17
+
18
+ ```ruby
19
+ gem 'alexa-todoist_filter'
20
+ ```
21
+
22
+ And then execute:
23
+
24
+ $ bundle
25
+
26
+ Or install it yourself as:
27
+
28
+ $ gem install alexa-todoist_filter
29
+
30
+ ## Usage
31
+
32
+ Help
33
+ ```
34
+ bundle exec ./bin/alexa-todoist_filter help
35
+ ```
36
+
37
+ Move Alexa added todos
38
+ ```
39
+ bundle exec ./bin/alexa-todoist_filter inbox_todos API_TOKEN PROJECT_NAME
40
+ ```
41
+
42
+ ## Development
43
+
44
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
45
+
46
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
47
+
48
+ ## Contributing
49
+
50
+ Bug reports and pull requests are welcome on GitHub at https://github.com/rclarkburns/alexa-todoist_filter.
51
+
52
+
53
+ ## License
54
+
55
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
56
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'alexa/todoist_filter/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "alexa-todoist_filter"
8
+ spec.version = Alexa::TodoistFilter::VERSION
9
+ spec.authors = ["Clark Burns"]
10
+ spec.email = ["rclarkburns@icloud.com"]
11
+
12
+ spec.summary = %q{A command line tool for moving Alexa todos in Todoist into a user specified project.}
13
+ spec.description = %q{A command line tool for moving Alexa todos in Todoist into a user specified project.}
14
+ spec.homepage = "https://github.com/rclarkburns/alexa-todoist_filter"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "bin"
21
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.13"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+
28
+ spec.add_runtime_dependency "thor", "~> 0.19.4"
29
+ spec.add_runtime_dependency "faraday", "~> 0.11.0"
30
+ end
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require "alexa/todoist_filter"
3
+
4
+ Alexa::TodoistFilter::CLI.start
@@ -0,0 +1,80 @@
1
+ require "logger"
2
+ require "faraday"
3
+ require "alexa/todoist_api/configuration"
4
+
5
+ module Alexa
6
+ module TodoistApi
7
+ class Base
8
+ include Alexa::TodoistApi::Configuration
9
+
10
+ class UnsuccessfulResponseError < StandardError; end
11
+ class MethodNotImplemented < StandardError; end
12
+
13
+ def connection()
14
+ headers = append_auth_headers(headers: custom_headers)
15
+ Faraday.new url: api_endpoint, headers: headers
16
+ end
17
+
18
+ def connection_requires_auth?
19
+ false
20
+ end
21
+
22
+ def custom_headers
23
+ logger_warn('Todoist::BaseApi custom_headers() method not implemented.')
24
+ raise MethodNotImplemented
25
+ end
26
+
27
+ def method_route
28
+ '/API/v7/sync'
29
+ end
30
+
31
+ def method_params
32
+ logger_warn('Todoist::BaseApi method_params() method not implemented.')
33
+ raise MethodNotImplemented
34
+ end
35
+
36
+ def response_success(response:)
37
+ logger_warn("Todoist::BaseApi response_success(response: #{response}) method not implemented.")
38
+ raise MethodNotImplemented
39
+ end
40
+
41
+ def response_fail(response:)
42
+ logger_warn("Todoist::BaseApi response_fail(response: #{response}) method not implemented.")
43
+ raise MethodNotImplemented
44
+ end
45
+
46
+ def get_route(url:)
47
+ url.sub(api_endpoint, '')
48
+ end
49
+
50
+ def do_request
51
+ @connection = connection
52
+ retries ||= 0
53
+ response = @connection.post method_route, method_params
54
+ if response.status == 200
55
+ response_success(response: response)
56
+ else
57
+ logger_warn("[Todoist::BaseApi] Route: #{method_route} Response code: #{response.status} Response body: #{response.body}")
58
+ response_fail(response: response)
59
+ end
60
+ rescue Faraday::TimeoutError
61
+ logger_warn("[Todoist::BaseApi] Route: #{method_route} Retrying...") && retry if (retries += 1) < 2
62
+ rescue Faraday::ClientError => e
63
+ logger_warn("[Todoist::BaseApi] Route: #{method_route}, Error: #{e.class}, #{e.message}")
64
+ end
65
+
66
+ private
67
+
68
+ def append_auth_headers(headers: {})
69
+ default_headers = {}
70
+ headers.merge(default_headers)
71
+ end
72
+
73
+ def logger_warn(message)
74
+ logger = Logger.new(STDOUT)
75
+ logger.level = Logger::WARN
76
+ logger.warn(message)
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,9 @@
1
+ module Alexa
2
+ module TodoistApi
3
+ module Configuration
4
+ def api_endpoint
5
+ 'https://todoist.com'
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,51 @@
1
+ require "securerandom"
2
+ require "alexa/todoist_api/base"
3
+
4
+ module Alexa
5
+ module TodoistApi
6
+ class ItemMove < Base
7
+ attr_accessor :request_params
8
+
9
+ def custom_headers
10
+ {}
11
+ end
12
+
13
+ def method_params
14
+ validate_request_params
15
+ {
16
+ token: request_params[:api_token],
17
+ commands: [
18
+ {
19
+ type: "item_move",
20
+ uuid: "#{SecureRandom.uuid}",
21
+ args: {
22
+ project_items: request_params[:project_items],
23
+ to_project: request_params[:new_project]
24
+ }
25
+ }
26
+ ].to_json
27
+ }
28
+ end
29
+
30
+ def response_success(response:)
31
+ {
32
+ error: false,
33
+ message: response.body
34
+ }
35
+ end
36
+
37
+ def response_fail(response:)
38
+ {
39
+ error: true,
40
+ message: response.body
41
+ }
42
+ end
43
+
44
+ private
45
+
46
+ def validate_request_params
47
+ true
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,42 @@
1
+ require "alexa/todoist_api/base"
2
+
3
+ module Alexa
4
+ module TodoistApi
5
+ class Sync < Base
6
+ attr_accessor :request_params
7
+
8
+ def custom_headers
9
+ {}
10
+ end
11
+
12
+ def method_params
13
+ validate_request_params
14
+ {
15
+ token: request_params[:api_token],
16
+ sync_token: '*',
17
+ resource_types: '["projects", "items", "labels"]'
18
+ }
19
+ end
20
+
21
+ def response_success(response:)
22
+ {
23
+ error: false,
24
+ message: response.body
25
+ }
26
+ end
27
+
28
+ def response_fail(response:)
29
+ {
30
+ error: true,
31
+ message: response.body
32
+ }
33
+ end
34
+
35
+ private
36
+
37
+ def validate_request_params
38
+ true
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,83 @@
1
+ require "alexa/todoist_filter/version"
2
+ require "alexa/todoist_api/sync"
3
+ require "alexa/todoist_api/item_move"
4
+ require "thor"
5
+ require "json"
6
+
7
+ module Alexa
8
+ module TodoistFilter
9
+ class CLI < Thor
10
+ desc "inbox_todos API_TOKEN PROJECT_NAME", "Check Inbox for items with 'Alexa' label and move to PROJECT_NAME"
11
+ def inbox_todos(api_token, project_name)
12
+ @api_token = api_token
13
+ @project_name = project_name
14
+ todoist_response = todoist_api_sync
15
+ project_ids = project_ids(todoist_response['projects'])
16
+ alexa_label_id = label_id(todoist_response['labels'])
17
+ if alexa_label_id.nil?
18
+ puts "Label 'Alexa' not found in account."
19
+ exit 1
20
+ end
21
+ inbox_items = item_ids(todoist_response['items'], project_ids[:inbox], alexa_label_id)
22
+ if inbox_items.empty?
23
+ puts "No Alexa todos found in the inbox."
24
+ exit 1
25
+ end
26
+ todoist_api_item_move(inbox_items, project_ids)
27
+ end
28
+
29
+ private
30
+
31
+ def todoist_api_sync
32
+ sync = Alexa::TodoistApi::Sync.new
33
+ sync.request_params = {
34
+ api_token: @api_token
35
+ }
36
+ response = sync.do_request
37
+ response = response.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
38
+ if response[:error]
39
+ puts "Halting due to error response. #{response[:message]}"
40
+ exit 1
41
+ end
42
+ JSON.parse(response[:message])
43
+ end
44
+
45
+ def todoist_api_item_move(inbox_items, project_ids)
46
+ item_move = Alexa::TodoistApi::ItemMove.new
47
+ item_move.request_params = {
48
+ api_token: @api_token,
49
+ project_items: {},
50
+ new_project: project_ids[@project_name.to_sym]
51
+ }
52
+ item_move.request_params[:project_items][project_ids[:inbox].to_s.to_sym] = inbox_items
53
+ item_move.do_request
54
+ end
55
+
56
+ def project_ids(projects)
57
+ pids = {inbox: nil}
58
+ pids[@project_name.to_sym] = nil
59
+ projects.each do |project|
60
+ pids[:inbox] = project['id'] if project['name'].downcase == 'inbox'
61
+ pids[@project_name.to_sym] = project['id'] if project['name'].downcase == @project_name.downcase
62
+ end
63
+ pids
64
+ end
65
+
66
+ def label_id(labels)
67
+ labels.each do |label|
68
+ return label['id'] if label['name'].downcase == 'alexa'
69
+ end
70
+ nil
71
+ end
72
+
73
+ def item_ids(items, project_id, label_id)
74
+ item_ids = []
75
+ items.each do |item|
76
+ item_ids << item['id'] if item['project_id'] == project_id && item['labels'].include?(label_id)
77
+ end
78
+ item_ids
79
+ end
80
+
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,5 @@
1
+ module Alexa
2
+ module TodoistFilter
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: alexa-todoist_filter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Clark Burns
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-01-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: thor
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.19.4
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.19.4
69
+ - !ruby/object:Gem::Dependency
70
+ name: faraday
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.11.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.11.0
83
+ description: A command line tool for moving Alexa todos in Todoist into a user specified
84
+ project.
85
+ email:
86
+ - rclarkburns@icloud.com
87
+ executables:
88
+ - alexa-todoist_filter
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - ".gitignore"
93
+ - ".ruby-version"
94
+ - Gemfile
95
+ - Gemfile.lock
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - alexa-todoist_filter.gemspec
100
+ - bin/alexa-todoist_filter
101
+ - lib/alexa/todoist_api/base.rb
102
+ - lib/alexa/todoist_api/configuration.rb
103
+ - lib/alexa/todoist_api/item_move.rb
104
+ - lib/alexa/todoist_api/sync.rb
105
+ - lib/alexa/todoist_filter.rb
106
+ - lib/alexa/todoist_filter/version.rb
107
+ homepage: https://github.com/rclarkburns/alexa-todoist_filter
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.6.8
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: A command line tool for moving Alexa todos in Todoist into a user specified
131
+ project.
132
+ test_files: []