tdcli 0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: aad9d19a6ada15ff99a14a7ec21b101a8570ee8d
4
+ data.tar.gz: 0dbd4e42af32eac59db589bc60cfd17de6afae75
5
+ SHA512:
6
+ metadata.gz: bcc7a69b9f0c9591b816357c3ccb14016626922093984bbe9e3ac81bb5cb8fde2386774edc32ef4616429dbcf356273dbcde6e1df101ed1ada0db564074009b5
7
+ data.tar.gz: 9da18d48b9ec68f7a49a7528ca967430fa6fc4a291c602a2bf613c5c168777bcc28771f6526d973b6ed7b19dc3531de75784b29f2dde181c2188b7b879ff7442
data/bin/tdcli ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/tdcli'
4
+
5
+ TDCLI.start(ARGV)
data/lib/tdcli.rb ADDED
@@ -0,0 +1,46 @@
1
+ require "thor"
2
+
3
+ require_relative "todoist/client.rb"
4
+ require_relative "todoist/cache.rb"
5
+
6
+ class TDCLI < Thor
7
+ def initialize(*args)
8
+ super
9
+ @todoistClient = TdCLI::Client.new
10
+ @cache = TdCLI::Cache.new
11
+ end
12
+
13
+ desc 'tasks', 'list all tasks'
14
+ def tasks
15
+ items = @cache.get('Items')
16
+ items.each do |item|
17
+ puts "- #{item['content']}"
18
+ end
19
+
20
+ end
21
+
22
+ desc 'user', 'get all user information'
23
+ def user
24
+ user = @cache.get('User')
25
+ user.each do |key, value|
26
+ puts "#{key}: #{value}"
27
+ end
28
+ end
29
+
30
+ desc 'update', 'update Todoist cache'
31
+ def update
32
+ resource_types = ["all"]
33
+ data = @todoistClient.sync(resource_types)
34
+ @cache.set(data)
35
+ @cache.save()
36
+ end
37
+
38
+ desc 'projects', 'show all users projects'
39
+ def projects
40
+ projects = @cache.get('Projects').sort_by {|hsh| hsh['item_order']}
41
+ projects.each do |project|
42
+ puts ' ' *(project['indent']-1) + "#{project['name']}"
43
+ end
44
+ end
45
+
46
+ end
@@ -0,0 +1,40 @@
1
+ require 'fileutils'
2
+ require "json"
3
+
4
+ module TdCLI
5
+ class Cache
6
+ def initialize
7
+ @_cache = {}
8
+ unless File.directory?(DATA_DIR)
9
+ FileUtils.mkdir(DATA_DIR)
10
+ end
11
+
12
+ @file_path = File.join(DATA_DIR, 'cache.json')
13
+ load()
14
+ end
15
+
16
+ def set(data)
17
+ @_cache = data
18
+ end
19
+
20
+ def get(item)
21
+ return @_cache[item]
22
+ end
23
+
24
+ # load the cache from the data dir
25
+ def load
26
+ if File.exist?(@file_path)
27
+
28
+ @_cache = JSON File.open(@file_path, &:read).strip
29
+ else
30
+ $stderr.puts "#{@file_path} does not exist"
31
+ end
32
+ end
33
+
34
+ # save the cache to the data dir
35
+ def save
36
+ cache_json = JSON.generate @_cache
37
+ File.open(@file_path, 'w') { |file| file.write(cache_json) }
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,56 @@
1
+ require "fileutils"
2
+ require "json"
3
+ require "net/https"
4
+ require "uri"
5
+
6
+ module TdCLI
7
+ TODOIST_API_URL = 'https://todoist.com/API/v6/sync'
8
+ DATA_DIR = File.join(ENV['HOME'], '.tdcli/')
9
+
10
+ class Client
11
+ def initialize(token = nil)
12
+ # initialize the client with a token
13
+ if token.nil?
14
+ @file_path = File.join(DATA_DIR, 'tdcli')
15
+ if File.exist?(@file_path)
16
+ @todoist_token = File.open(@file_path, &:readline).strip
17
+ else
18
+ newAPIToken()
19
+ end
20
+ else
21
+ @todoist_token = token
22
+ end
23
+ end
24
+
25
+ def newAPIToken
26
+ # make sure the data dir exists
27
+ if !File.directory?(DATA_DIR)
28
+ FileUtils.mkdir(DATA_DIR)
29
+ end
30
+ puts 'Enter an API token:'
31
+ token = gets.chomp
32
+ # save token to file for later use
33
+ File.open(@file_path, 'w') { |file| file.write(token) }
34
+ @todoist_token = token
35
+
36
+ end
37
+
38
+ def sync(resource_types)
39
+ options = {}
40
+ options['token'] = @todoist_token
41
+ options['seq_no'] = 0
42
+ options['resource_types'] = JSON.generate resource_types
43
+
44
+ uri = URI.parse(TODOIST_API_URL)
45
+ http = Net::HTTP.new(uri.host, uri.port)
46
+ http.use_ssl = true
47
+ request = Net::HTTP::Post.new(uri.request_uri)
48
+ request.set_form_data(options)
49
+
50
+ response = http.request(request)
51
+
52
+ data = JSON.parse response.body
53
+ return data
54
+ end
55
+ end
56
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tdcli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Aaron Gunderson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-02-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.19.1
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.19.1
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: 0.19.1
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.19.1
33
+ - !ruby/object:Gem::Dependency
34
+ name: json
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: 1.8.3
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 1.8.3
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: 1.8.3
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 1.8.3
53
+ description: A CLI for Todoist
54
+ email: aaron@agundy.com
55
+ executables:
56
+ - tdcli
57
+ extensions: []
58
+ extra_rdoc_files: []
59
+ files:
60
+ - bin/tdcli
61
+ - lib/tdcli.rb
62
+ - lib/todoist/cache.rb
63
+ - lib/todoist/client.rb
64
+ homepage: https://www.agundy.com/tdcli/
65
+ licenses:
66
+ - MIT
67
+ metadata: {}
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubyforge_project:
84
+ rubygems_version: 2.2.2
85
+ signing_key:
86
+ specification_version: 4
87
+ summary: Todoist CLI
88
+ test_files: []