tsks 0.0.1

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
+ SHA256:
3
+ metadata.gz: '0915c80ecccdda0fbe03190ba3430ae42fbbd04047c8f5f755746f23279aaaf3'
4
+ data.tar.gz: acb17ef0eb9760ad4f8cb061812fd64e65950f3cba38cb57b03e7b9e965dd2c6
5
+ SHA512:
6
+ metadata.gz: a11d81689354f90811165eb4e24d08c76ee2f8d4c5607b8af6ee88e6f66c23037f6e9142adf41ad829d8aa2bbcb9702eb519aacadcaf91268538ae2ed6923e3b
7
+ data.tar.gz: 31abf6a8ed58a0523472750f763e4b889b4890ca7917b6d6d2ea83bcf26d3eed2d2280591785d2d3087a6d53b4247ea1e133d4a1192a00a71a4e5a3b0227cb78
data/.env.sample ADDED
@@ -0,0 +1,2 @@
1
+ SETUP_FOLDER=~/.tsks_test
2
+ BASE_API_URI=http://localhost:3000/api/v1
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ .env
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.0
6
+ before_install: gem install bundler -v 2.1.4
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in tsks.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
8
+ gem "dotenv"
9
+ gem "thor"
10
+ gem "sqlite3"
11
+ gem "httparty"
data/Gemfile.lock ADDED
@@ -0,0 +1,51 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ tsks (0.1.0)
5
+ httparty
6
+ sqlite3
7
+ thor
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ diff-lcs (1.4.4)
13
+ dotenv (2.7.6)
14
+ httparty (0.18.1)
15
+ mime-types (~> 3.0)
16
+ multi_xml (>= 0.5.2)
17
+ mime-types (3.3.1)
18
+ mime-types-data (~> 3.2015)
19
+ mime-types-data (3.2020.0512)
20
+ multi_xml (0.6.0)
21
+ rake (12.3.3)
22
+ rspec (3.9.0)
23
+ rspec-core (~> 3.9.0)
24
+ rspec-expectations (~> 3.9.0)
25
+ rspec-mocks (~> 3.9.0)
26
+ rspec-core (3.9.2)
27
+ rspec-support (~> 3.9.3)
28
+ rspec-expectations (3.9.2)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (~> 3.9.0)
31
+ rspec-mocks (3.9.1)
32
+ diff-lcs (>= 1.2.0, < 2.0)
33
+ rspec-support (~> 3.9.0)
34
+ rspec-support (3.9.3)
35
+ sqlite3 (1.4.2)
36
+ thor (1.0.1)
37
+
38
+ PLATFORMS
39
+ ruby
40
+
41
+ DEPENDENCIES
42
+ dotenv
43
+ httparty
44
+ rake (~> 12.0)
45
+ rspec (~> 3.0)
46
+ sqlite3
47
+ thor
48
+ tsks!
49
+
50
+ BUNDLED WITH
51
+ 2.1.4
data/README.md ADDED
@@ -0,0 +1,93 @@
1
+ # tsks-cli
2
+
3
+ _Yet another command line interface to handle your daily tsks with contexts._
4
+
5
+ ## Features
6
+
7
+ * Add tsks, check what is already done and list active or archived tsks
8
+ * Synchronize your tsks and access them from all your devices (In develpoment!)
9
+ * Increase your daily tsks with contexts (see `tsks help add` for more info!)
10
+
11
+ ## Installation
12
+
13
+ ```ruby
14
+ gem install tsks
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ After follow the step above you should be able to run `tsks` from your terminal.
20
+
21
+ _It's important to notice that you will need to run `tsks init` before any other
22
+ command to setup stuffs like the storage._
23
+
24
+ ### Adding new tsks
25
+
26
+ ```sh
27
+ tsks add "My first tsk"
28
+ ```
29
+
30
+ **Adding with context**
31
+
32
+ ```sh
33
+ tsks add "Bootstraps my pet project environment --context=Personal"
34
+ ```
35
+
36
+ ### Checking done tsks
37
+
38
+ ```sh
39
+ tsks done 2 # Where 2 is the id
40
+ ```
41
+
42
+ ### Listing your tsks
43
+
44
+ ```sh
45
+ tsks list
46
+ ```
47
+
48
+ **Filtering by context**
49
+
50
+ ```sh
51
+ tsks list --context=Personal
52
+ ```
53
+
54
+ **Or tsks already done**
55
+ ```sh
56
+ tsks list --done
57
+ ```
58
+
59
+ **Tip:** It's possible to combine the flags `--done` and `--context` when
60
+ listing.
61
+
62
+ ### Synchronizing your tsks
63
+
64
+ As easy as running `tsks sync`. This command will fetch your tsks from the API,
65
+ then filter what is not synced yet from local, and then update both remote and
66
+ local tsks with most recent data.
67
+
68
+ #### To be able to sync you will need to login or register an account
69
+
70
+ Run this to login:
71
+
72
+ ```sh
73
+ tsks login --email=sample@mail.com --password=secret
74
+ ```
75
+
76
+ Or this to register an account:
77
+
78
+ ```sh
79
+ tsks register --email=sample@mail.com --password=secret
80
+ ```
81
+
82
+ ## Development
83
+
84
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run
85
+ `rake spec` to run the tests. You can also run `bin/console` for an interactive
86
+ prompt that will allow you to experiment.
87
+
88
+ To install this gem onto your local machine, run `bundle exec rake install`.
89
+
90
+ ## Contributing
91
+
92
+ Bug reports and pull requests are welcome on GitHub at
93
+ https://github.com/luanrvmood/tsks-cli.
data/Rakefile ADDED
@@ -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
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "tsks"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/tsks ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "tsks"
4
+
5
+ Tsks.init
data/lib/tsks/cli.rb ADDED
@@ -0,0 +1,150 @@
1
+ require "thor"
2
+ require "time"
3
+ require "tsks/storage"
4
+ require "tsks/request"
5
+
6
+ module Tsks
7
+ class CLI < Thor
8
+ @setup_folder = File.expand_path ENV["SETUP_FOLDER"] || "~/.tsks"
9
+
10
+ def self.setup_folder
11
+ @setup_folder
12
+ end
13
+
14
+ desc "init", "Setup tsks folder and storage"
15
+ def init
16
+ if File.directory? CLI.setup_folder
17
+ return puts "tsks was already initialized."
18
+ end
19
+
20
+ Dir.mkdir CLI.setup_folder
21
+ Tsks::Storage.init
22
+ end
23
+
24
+ desc "add TSK", "Add a new tsk (Use --context to specify one i.g. Work)"
25
+ option :context
26
+ def add tsk
27
+ if !File.directory? CLI.setup_folder
28
+ return puts "tsks was not initialized yet."
29
+ end
30
+
31
+ if options[:context]
32
+ Tsks::Storage.insert tsk, options[:context]
33
+ else
34
+ Tsks::Storage.insert tsk
35
+ end
36
+ end
37
+
38
+ desc "done ID", "Mark a tsk you have already done"
39
+ def done id
40
+ if !File.directory? CLI.setup_folder
41
+ return puts "tsks was not initialized yet."
42
+ end
43
+
44
+ Tsks::Storage.update id
45
+ end
46
+
47
+ desc "list", "See all active tsks, filter by context or that are done"
48
+ option :done, type: :boolean
49
+ option :context
50
+ def list
51
+ if !File.directory? CLI.setup_folder
52
+ return puts "tsks was not initialized yet."
53
+ end
54
+
55
+ tsks = nil
56
+
57
+ if options[:done] && options[:context]
58
+ tsks = Tsks::Storage.select_by({done: 1, context: options[:context]})
59
+ elsif options[:done]
60
+ tsks = Tsks::Storage.select_by({done: 1})
61
+ elsif options[:context]
62
+ tsks = Tsks::Storage.select_by({context: options[:context]})
63
+ else
64
+ tsks = Tsks::Storage.select_by({done: 0})
65
+ end
66
+
67
+ if tsks.count > 0
68
+ for tsk in tsks
69
+ puts "#{tsk[:id]} @#{tsk[:context]} #{tsk[:tsk]}"
70
+ end
71
+ else
72
+ puts "No tsks found."
73
+ end
74
+ end
75
+
76
+ desc "register", "Register an e-mail to be able to sync your tsks"
77
+ option :email, required: true
78
+ option :password, required: true
79
+ def register
80
+ if !File.directory? CLI.setup_folder
81
+ return puts "tsks was not initialized yet."
82
+ end
83
+
84
+ res = Tsks::Request.post "/register", {email: options[:email],
85
+ password: options[:password]}
86
+
87
+ if res && res[:status_code] == 201
88
+ File.write File.join(CLI.setup_folder, "token"), res[:token]
89
+ puts "Succesfully registered."
90
+ elsif res && res[:status_code] == 409
91
+ puts "This e-mail is already registered."
92
+ end
93
+ end
94
+
95
+ desc "login", "Login to be able to sync your tsks"
96
+ option :email, required: true
97
+ option :password, required: true
98
+ def login
99
+ if !File.directory? CLI.setup_folder
100
+ return puts "tsks was not initialized yet."
101
+ end
102
+
103
+ res = Tsks::Request.post "/login", {email: options[:email],
104
+ password: options[:password]}
105
+
106
+ if res && res[:status_code] == 200
107
+ File.write File.join(CLI.setup_folder, "token"), res[:token]
108
+ puts "Succesfully logged in."
109
+ elsif res && res[:status_code] == 403
110
+ puts "Invalid e-mail or password."
111
+ end
112
+ end
113
+
114
+ desc "sync", "Synchronize your tsks"
115
+ def sync
116
+ if !File.directory? CLI.setup_folder
117
+ return puts "tsks was not initialized yet."
118
+ end
119
+
120
+ if !File.exist? File.join CLI.setup_folder, "token"
121
+ return puts "Please, login before try to sync."
122
+ end
123
+
124
+ token = File.read File.join CLI.setup_folder, "token"
125
+ get_res = Tsks::Request.get "/tsks", token
126
+ local_tsks = Tsks::Storage.select_all
127
+ remote_tsks = []
128
+
129
+ for tsk in get_res[:tsks]
130
+ tsk[:created_at] = Time.parse(tsk[:created_at]).strftime "%F %T"
131
+ tsk[:updated_at] = Time.parse(tsk[:updated_at]).strftime "%F %T"
132
+ remote_tsks.append tsk
133
+ end
134
+
135
+ if get_res && get_res[:status_code] == 200
136
+ local_tsks_to_post = local_tsks - remote_tsks
137
+ if local_tsks_to_post.count > 0
138
+ Tsks::Request.post "/tsks", token, {tsks: local_tsks_to_post}
139
+ end
140
+
141
+ remote_tsks_to_storage = remote_tsks - local_tsks
142
+ if remote_tsks_to_storage.count > 0
143
+ Tsks::Storage.insert_many remote_tsks_to_storage
144
+ end
145
+
146
+ puts "Your tsks were succesfully synchronized."
147
+ end
148
+ end
149
+ end
150
+ end
@@ -0,0 +1,36 @@
1
+ require "httparty"
2
+
3
+ module Tsks
4
+ class Request
5
+ @base_uri = ENV["BASE_API_URI"] || "https://tsks-api.herokuapp.com/v1"
6
+
7
+ def self.base_uri
8
+ @base_uri
9
+ end
10
+
11
+ def self.post endpoint, token=nil, body
12
+ uri = URI "#{Request.base_uri}#{endpoint}"
13
+
14
+ if token
15
+ res = HTTParty.post uri, body: body,
16
+ headers: {authorization: "Bearer #{token}"}
17
+ else
18
+ res = HTTParty.post uri, body: body
19
+ end
20
+
21
+ parsed_res = parse_response res.body
22
+ end
23
+
24
+ def self.get endpoint, token
25
+ uri = URI "#{Request.base_uri}#{endpoint}"
26
+ res = HTTParty.get uri, headers: {authorization: "Bearer #{token}"}
27
+ parsed_res = parse_response res.body
28
+ end
29
+
30
+ private
31
+
32
+ def self.parse_response body
33
+ JSON.parse body, symbolize_names: true
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,110 @@
1
+ require "sqlite3"
2
+
3
+ module Tsks
4
+ class Storage
5
+ def self.init
6
+ storage = get_storage_instance
7
+ storage.execute <<-SQL
8
+ CREATE TABLE tsks (
9
+ id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
10
+ user_id INTEGER DEFAULT 1,
11
+ tsk VARCHAR NOT NULL,
12
+ context VARCHAR DEFAULT Inbox,
13
+ done BOOLEAN DEFAULT false,
14
+ created_at VARCHAR NOT NULL,
15
+ updated_at VARCHAR NOT NULL
16
+ )
17
+ SQL
18
+ end
19
+
20
+ def self.insert tsk, ctx=nil
21
+ storage = get_storage_instance
22
+ now = Time.now.strftime "%Y-%m-%e %H:%M:%S"
23
+
24
+ if ctx
25
+ storage.execute("
26
+ INSERT INTO tsks (tsk, context, created_at, updated_at)
27
+ VALUES (?, ?, ?, ?)",
28
+ [tsk, ctx, now, now]
29
+ )
30
+ else
31
+ storage.execute("
32
+ INSERT INTO tsks (tsk, created_at, updated_at) VALUES (?, ?, ?)",
33
+ [tsk, now, now]
34
+ )
35
+ end
36
+ end
37
+
38
+ def self.insert_many tsks
39
+ storage = get_storage_instance
40
+
41
+ for tsk in tsks
42
+ storage.execute("
43
+ INSERT INTO tsks (id, tsk, context, done, created_at, updated_at)
44
+ VALUES (?, ?, ?, ?, ?, ?)",
45
+ [tsk[:id],
46
+ tsk[:tsk],
47
+ tsk[:context],
48
+ tsk[:done],
49
+ tsk[:created_at],
50
+ tsk[:updated_at]]
51
+ )
52
+ end
53
+ end
54
+
55
+ def self.update id
56
+ storage = get_storage_instance
57
+ storage.execute "UPDATE tsks SET done=true WHERE id=?", id
58
+ end
59
+
60
+ def self.select_by params
61
+ storage = get_storage_instance
62
+
63
+ raw_tsks = nil
64
+
65
+ if params.count == 2
66
+ raw_tsks = storage.execute(
67
+ "SELECT * FROM tsks " \
68
+ "WHERE #{params.keys.first}=? and #{params.keys.last}=?",
69
+ [params.values.first, params.values.last]
70
+ )
71
+ else
72
+ raw_tsks = storage.execute(
73
+ "SELECT * FROM tsks WHERE #{params.keys.first}=?",
74
+ params.values.first)
75
+ end
76
+
77
+ tsks = structure_tsks raw_tsks
78
+ end
79
+
80
+ def self.select_all
81
+ storage = get_storage_instance
82
+ raw_tsks = storage.execute "SELECT * FROM tsks"
83
+ tsks = structure_tsks raw_tsks
84
+ end
85
+
86
+ private
87
+
88
+ def self.get_storage_instance
89
+ SQLite3::Database.new File.join CLI.setup_folder, "tsks.db"
90
+ end
91
+
92
+ def self.structure_tsks tsks
93
+ structured_tsks = []
94
+
95
+ for tsk in tsks
96
+ t = {id: tsk[0],
97
+ user_id: tsk[1],
98
+ tsk: tsk[2],
99
+ context: tsk[3],
100
+ done: tsk[4],
101
+ created_at: tsk[5],
102
+ updated_at: tsk[5]}
103
+
104
+ structured_tsks.append t
105
+ end
106
+
107
+ return structured_tsks
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,3 @@
1
+ module Tsks
2
+ VERSION = "0.0.1"
3
+ end
data/lib/tsks.rb ADDED
@@ -0,0 +1,9 @@
1
+ require "dotenv/load"
2
+ require "tsks/version"
3
+ require "tsks/cli"
4
+
5
+ module Tsks
6
+ def self.init
7
+ Tsks::CLI.start ARGV
8
+ end
9
+ end
data/tsks.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ require_relative 'lib/tsks/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "tsks"
5
+ spec.version = Tsks::VERSION
6
+ spec.authors = ["Luan F. R. Vicente"]
7
+ spec.email = ["luanrvmood@gmail.com"]
8
+ spec.summary = ""
9
+ spec.homepage = "https://github.com/luanrvmood/tsks-cli"
10
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
11
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
12
+ spec.metadata["homepage_uri"] = spec.homepage
13
+ spec.metadata["source_code_uri"] = spec.homepage
14
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
15
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ end
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+ spec.add_development_dependency "rspec"
21
+ spec.add_development_dependency "dotenv"
22
+ spec.add_dependency "thor"
23
+ spec.add_dependency "sqlite3"
24
+ spec.add_dependency "httparty"
25
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tsks
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Luan F. R. Vicente
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-09-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: dotenv
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: thor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sqlite3
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: httparty
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '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'
83
+ description:
84
+ email:
85
+ - luanrvmood@gmail.com
86
+ executables:
87
+ - tsks
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".env.sample"
92
+ - ".gitignore"
93
+ - ".rspec"
94
+ - ".travis.yml"
95
+ - Gemfile
96
+ - Gemfile.lock
97
+ - README.md
98
+ - Rakefile
99
+ - bin/console
100
+ - bin/setup
101
+ - exe/tsks
102
+ - lib/tsks.rb
103
+ - lib/tsks/cli.rb
104
+ - lib/tsks/request.rb
105
+ - lib/tsks/storage.rb
106
+ - lib/tsks/version.rb
107
+ - tsks.gemspec
108
+ homepage: https://github.com/luanrvmood/tsks-cli
109
+ licenses: []
110
+ metadata:
111
+ allowed_push_host: https://rubygems.org
112
+ homepage_uri: https://github.com/luanrvmood/tsks-cli
113
+ source_code_uri: https://github.com/luanrvmood/tsks-cli
114
+ post_install_message:
115
+ rdoc_options: []
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: 2.3.0
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ requirements: []
129
+ rubygems_version: 3.1.2
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: ''
133
+ test_files: []