tsks 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0915c80ecccdda0fbe03190ba3430ae42fbbd04047c8f5f755746f23279aaaf3'
4
- data.tar.gz: acb17ef0eb9760ad4f8cb061812fd64e65950f3cba38cb57b03e7b9e965dd2c6
3
+ metadata.gz: bf122781e8faff2a45760d9bf8bb6d546d7158c47433ce4dc487ff7faa57b163
4
+ data.tar.gz: cb8ab03aa9f5ad004ac243746d2b3b368ccf522fbc734ea20e9c3081c1092882
5
5
  SHA512:
6
- metadata.gz: a11d81689354f90811165eb4e24d08c76ee2f8d4c5607b8af6ee88e6f66c23037f6e9142adf41ad829d8aa2bbcb9702eb519aacadcaf91268538ae2ed6923e3b
7
- data.tar.gz: 31abf6a8ed58a0523472750f763e4b889b4890ca7917b6d6d2ea83bcf26d3eed2d2280591785d2d3087a6d53b4247ea1e133d4a1192a00a71a4e5a3b0227cb78
6
+ metadata.gz: 738bf65c66226c36d14a56c389e970fb789ac98cff0569f4b58aaf02d178ea6d5542beee6c4204bbb4d26eaf91949118dcc2280fc327c8ff1005d1e55395c2ba
7
+ data.tar.gz: b763cdfa17b2b5e995eb8fab45fa42034167fa5b48ce9a512be8a2d8a8ff6485a1e60c46f7844e71b07dec4f3527a012e22070075c2075808e4ac09882818d9c
@@ -1,2 +1,2 @@
1
1
  SETUP_FOLDER=~/.tsks_test
2
- BASE_API_URI=http://localhost:3000/api/v1
2
+ BASE_API_URI=http://localhost:3000/v1
data/Gemfile CHANGED
@@ -5,7 +5,8 @@ gemspec
5
5
 
6
6
  gem "rake", "~> 12.0"
7
7
  gem "rspec", "~> 3.0"
8
- gem "dotenv"
9
- gem "thor"
10
- gem "sqlite3"
11
- gem "httparty"
8
+ gem "dotenv", "~> 2.7.6"
9
+ gem "thor", "~> 1.0.1"
10
+ gem "sqlite3", "~> 1.4.2"
11
+ gem "httparty", "~> 0.18.1"
12
+ gem "uuid", "~> 2.3.9"
@@ -1,10 +1,11 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tsks (0.1.0)
4
+ tsks (0.0.2)
5
5
  httparty
6
6
  sqlite3
7
7
  thor
8
+ uuid
8
9
 
9
10
  GEM
10
11
  remote: https://rubygems.org/
@@ -14,6 +15,8 @@ GEM
14
15
  httparty (0.18.1)
15
16
  mime-types (~> 3.0)
16
17
  multi_xml (>= 0.5.2)
18
+ macaddr (1.7.2)
19
+ systemu (~> 2.6.5)
17
20
  mime-types (3.3.1)
18
21
  mime-types-data (~> 3.2015)
19
22
  mime-types-data (3.2020.0512)
@@ -23,7 +26,7 @@ GEM
23
26
  rspec-core (~> 3.9.0)
24
27
  rspec-expectations (~> 3.9.0)
25
28
  rspec-mocks (~> 3.9.0)
26
- rspec-core (3.9.2)
29
+ rspec-core (3.9.3)
27
30
  rspec-support (~> 3.9.3)
28
31
  rspec-expectations (3.9.2)
29
32
  diff-lcs (>= 1.2.0, < 2.0)
@@ -33,19 +36,23 @@ GEM
33
36
  rspec-support (~> 3.9.0)
34
37
  rspec-support (3.9.3)
35
38
  sqlite3 (1.4.2)
39
+ systemu (2.6.5)
36
40
  thor (1.0.1)
41
+ uuid (2.3.9)
42
+ macaddr (~> 1.0)
37
43
 
38
44
  PLATFORMS
39
45
  ruby
40
46
 
41
47
  DEPENDENCIES
42
- dotenv
43
- httparty
48
+ dotenv (~> 2.7.6)
49
+ httparty (~> 0.18.1)
44
50
  rake (~> 12.0)
45
51
  rspec (~> 3.0)
46
- sqlite3
47
- thor
52
+ sqlite3 (~> 1.4.2)
53
+ thor (~> 1.0.1)
48
54
  tsks!
55
+ uuid (~> 2.3.9)
49
56
 
50
57
  BUNDLED WITH
51
- 2.1.4
58
+ 2.1.2
data/README.md CHANGED
@@ -1,12 +1,14 @@
1
1
  # tsks-cli
2
2
 
3
- _Yet another command line interface to handle your daily tsks with contexts._
3
+ _A stateful command line interface to help you handle your daily tsks
4
+ (with contexts!)._
4
5
 
5
6
  ## Features
6
7
 
7
8
  * 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!)
9
+ * Synchronize your tsks and access them from all your terminals!)
10
+ * Increase your daily tsks management with contexts `tsks add tsk --context=today`
11
+ (see `tsks help add` for more info!)
10
12
 
11
13
  ## Installation
12
14
 
@@ -0,0 +1,13 @@
1
+ require "tsks/storage"
2
+
3
+ module Tsks
4
+ class Actions
5
+ def self.update_tsks_with_uuid uuid
6
+ current_tsks = Tsks::Storage.select_all
7
+
8
+ for tsk in current_tsks
9
+ Tsks::Storage.update tsk[:local_id], {user_id: uuid}
10
+ end
11
+ end
12
+ end
13
+ end
@@ -2,6 +2,7 @@ require "thor"
2
2
  require "time"
3
3
  require "tsks/storage"
4
4
  require "tsks/request"
5
+ require "tsks/actions"
5
6
 
6
7
  module Tsks
7
8
  class CLI < Thor
@@ -21,7 +22,7 @@ module Tsks
21
22
  Tsks::Storage.init
22
23
  end
23
24
 
24
- desc "add TSK", "Add a new tsk (Use --context to specify one i.g. Work)"
25
+ desc "add TSK", "Add a new tsk (Use --context to specify one e.g. Work)"
25
26
  option :context
26
27
  def add tsk
27
28
  if !File.directory? CLI.setup_folder
@@ -66,7 +67,7 @@ module Tsks
66
67
 
67
68
  if tsks.count > 0
68
69
  for tsk in tsks
69
- puts "#{tsk[:id]} @#{tsk[:context]} #{tsk[:tsk]}"
70
+ puts "#{tsk[:local_id]} @#{tsk[:context]} #{tsk[:tsk]}"
70
71
  end
71
72
  else
72
73
  puts "No tsks found."
@@ -86,6 +87,8 @@ module Tsks
86
87
 
87
88
  if res && res[:status_code] == 201
88
89
  File.write File.join(CLI.setup_folder, "token"), res[:token]
90
+ File.write File.join(CLI.setup_folder, "user_id"), res[:user_id]
91
+ Tsks::Actions.update_tsks_with_uuid res[:user_id]
89
92
  puts "Succesfully registered."
90
93
  elsif res && res[:status_code] == 409
91
94
  puts "This e-mail is already registered."
@@ -105,6 +108,8 @@ module Tsks
105
108
 
106
109
  if res && res[:status_code] == 200
107
110
  File.write File.join(CLI.setup_folder, "token"), res[:token]
111
+ File.write File.join(CLI.setup_folder, "user_id"), res[:user_id]
112
+ Tsks::Actions.update_tsks_with_uuid res[:user_id]
108
113
  puts "Succesfully logged in."
109
114
  elsif res && res[:status_code] == 403
110
115
  puts "Invalid e-mail or password."
@@ -121,11 +126,13 @@ module Tsks
121
126
  return puts "Please, login before try to sync."
122
127
  end
123
128
 
129
+ user_id = File.read File.join CLI.setup_folder, "user_id"
130
+ Tsks::Actions.update_tsks_with_uuid user_id
131
+ local_tsks = Tsks::Storage.select_all local_id=false
132
+
124
133
  token = File.read File.join CLI.setup_folder, "token"
125
134
  get_res = Tsks::Request.get "/tsks", token
126
- local_tsks = Tsks::Storage.select_all
127
135
  remote_tsks = []
128
-
129
136
  for tsk in get_res[:tsks]
130
137
  tsk[:created_at] = Time.parse(tsk[:created_at]).strftime "%F %T"
131
138
  tsk[:updated_at] = Time.parse(tsk[:updated_at]).strftime "%F %T"
@@ -1,4 +1,5 @@
1
1
  require "sqlite3"
2
+ require "uuid"
2
3
 
3
4
  module Tsks
4
5
  class Storage
@@ -6,7 +7,7 @@ module Tsks
6
7
  storage = get_storage_instance
7
8
  storage.execute <<-SQL
8
9
  CREATE TABLE tsks (
9
- id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
10
+ id VARCHAR PRIMARY KEY UNIQUE NOT NULL,
10
11
  user_id INTEGER DEFAULT 1,
11
12
  tsk VARCHAR NOT NULL,
12
13
  context VARCHAR DEFAULT Inbox,
@@ -19,18 +20,20 @@ module Tsks
19
20
 
20
21
  def self.insert tsk, ctx=nil
21
22
  storage = get_storage_instance
22
- now = Time.now.strftime "%Y-%m-%e %H:%M:%S"
23
+ now = Time.now.strftime "%F %T"
24
+ uuid = UUID.new.generate
23
25
 
24
26
  if ctx
25
27
  storage.execute("
26
- INSERT INTO tsks (tsk, context, created_at, updated_at)
27
- VALUES (?, ?, ?, ?)",
28
- [tsk, ctx, now, now]
28
+ INSERT INTO tsks (id, tsk, context, created_at, updated_at)
29
+ VALUES (?, ?, ?, ?, ?)",
30
+ [uuid, tsk, ctx, now, now]
29
31
  )
30
32
  else
31
33
  storage.execute("
32
- INSERT INTO tsks (tsk, created_at, updated_at) VALUES (?, ?, ?)",
33
- [tsk, now, now]
34
+ INSERT INTO tsks (id, tsk, created_at, updated_at)
35
+ VALUES (?, ?, ?, ?)",
36
+ [uuid, tsk, now, now]
34
37
  )
35
38
  end
36
39
  end
@@ -40,9 +43,11 @@ module Tsks
40
43
 
41
44
  for tsk in tsks
42
45
  storage.execute("
43
- INSERT INTO tsks (id, tsk, context, done, created_at, updated_at)
44
- VALUES (?, ?, ?, ?, ?, ?)",
46
+ INSERT INTO tsks
47
+ (id, user_id, tsk, context, done, created_at, updated_at) VALUES
48
+ (?, ?, ?, ?, ?, ?, ?)",
45
49
  [tsk[:id],
50
+ tsk[:user_id],
46
51
  tsk[:tsk],
47
52
  tsk[:context],
48
53
  tsk[:done],
@@ -52,9 +57,22 @@ module Tsks
52
57
  end
53
58
  end
54
59
 
55
- def self.update id
60
+ def self.update local_id, params=nil
56
61
  storage = get_storage_instance
57
- storage.execute "UPDATE tsks SET done=true WHERE id=?", id
62
+
63
+ if params && params.count == 1
64
+ # NOTE
65
+ # there is only a currently in use case covered by this conditional
66
+ # ant that is ok for now, but we should make sure it is updated when
67
+ # Storage.update starting to be called from many different ways.
68
+ storage.execute(
69
+ "UPDATE tsks SET " \
70
+ "#{params.keys.first}=? " \
71
+ "WHERE rowid=?",
72
+ [params.values.first, local_id])
73
+ else
74
+ storage.execute "UPDATE tsks SET done=true WHERE rowid=?", local_id
75
+ end
58
76
  end
59
77
 
60
78
  def self.select_by params
@@ -64,23 +82,25 @@ module Tsks
64
82
 
65
83
  if params.count == 2
66
84
  raw_tsks = storage.execute(
67
- "SELECT * FROM tsks " \
85
+ "SELECT rowid, * FROM tsks " \
68
86
  "WHERE #{params.keys.first}=? and #{params.keys.last}=?",
69
87
  [params.values.first, params.values.last]
70
88
  )
71
89
  else
72
90
  raw_tsks = storage.execute(
73
- "SELECT * FROM tsks WHERE #{params.keys.first}=?",
91
+ "SELECT rowid, * FROM tsks WHERE #{params.keys.first}=?",
74
92
  params.values.first)
75
93
  end
76
94
 
77
95
  tsks = structure_tsks raw_tsks
78
96
  end
79
97
 
80
- def self.select_all
98
+ def self.select_all local_id=true
81
99
  storage = get_storage_instance
82
- raw_tsks = storage.execute "SELECT * FROM tsks"
83
- tsks = structure_tsks raw_tsks
100
+ raw_tsks = local_id ?
101
+ storage.execute("SELECT rowid, * FROM tsks") :
102
+ storage.execute("SELECT * FROM tsks")
103
+ tsks = structure_tsks(raw_tsks, local_id=local_id)
84
104
  end
85
105
 
86
106
  private
@@ -89,17 +109,30 @@ module Tsks
89
109
  SQLite3::Database.new File.join CLI.setup_folder, "tsks.db"
90
110
  end
91
111
 
92
- def self.structure_tsks tsks
112
+ def self.structure_tsks tsks, local_id=true
93
113
  structured_tsks = []
94
114
 
95
115
  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]}
116
+ t = {}
117
+
118
+ if local_id
119
+ t[:local_id] = tsk[0]
120
+ t[:id] = tsk[1]
121
+ t[:user_id] = tsk[2]
122
+ t[:tsk] = tsk[3]
123
+ t[:context] = tsk[4]
124
+ t[:done] = tsk[5]
125
+ t[:created_at] = tsk[6]
126
+ t[:updated_at] = tsk[7]
127
+ else
128
+ t[:id] = tsk[0]
129
+ t[:user_id] = tsk[1]
130
+ t[:tsk] = tsk[2]
131
+ t[:context] = tsk[3]
132
+ t[:done] = tsk[4]
133
+ t[:created_at] = tsk[5]
134
+ t[:updated_at] = tsk[6]
135
+ end
103
136
 
104
137
  structured_tsks.append t
105
138
  end
@@ -1,3 +1,3 @@
1
1
  module Tsks
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -5,8 +5,8 @@ Gem::Specification.new do |spec|
5
5
  spec.version = Tsks::VERSION
6
6
  spec.authors = ["Luan F. R. Vicente"]
7
7
  spec.email = ["luanrvmood@gmail.com"]
8
- spec.summary = ""
9
- spec.homepage = "https://github.com/luanrvmood/tsks-cli"
8
+ spec.summary = "A stateful command line interface to help you handle your daily tsks (with contexts!)"
9
+ spec.homepage = "https://github.com/luanrvmood/tsks"
10
10
  spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
11
11
  spec.metadata["allowed_push_host"] = "https://rubygems.org"
12
12
  spec.metadata["homepage_uri"] = spec.homepage
@@ -22,4 +22,5 @@ Gem::Specification.new do |spec|
22
22
  spec.add_dependency "thor"
23
23
  spec.add_dependency "sqlite3"
24
24
  spec.add_dependency "httparty"
25
+ spec.add_dependency "uuid"
25
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tsks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luan F. R. Vicente
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-09-28 00:00:00.000000000 Z
11
+ date: 2020-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: uuid
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  description:
84
98
  email:
85
99
  - luanrvmood@gmail.com
@@ -100,17 +114,18 @@ files:
100
114
  - bin/setup
101
115
  - exe/tsks
102
116
  - lib/tsks.rb
117
+ - lib/tsks/actions.rb
103
118
  - lib/tsks/cli.rb
104
119
  - lib/tsks/request.rb
105
120
  - lib/tsks/storage.rb
106
121
  - lib/tsks/version.rb
107
122
  - tsks.gemspec
108
- homepage: https://github.com/luanrvmood/tsks-cli
123
+ homepage: https://github.com/luanrvmood/tsks
109
124
  licenses: []
110
125
  metadata:
111
126
  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
127
+ homepage_uri: https://github.com/luanrvmood/tsks
128
+ source_code_uri: https://github.com/luanrvmood/tsks
114
129
  post_install_message:
115
130
  rdoc_options: []
116
131
  require_paths:
@@ -129,5 +144,6 @@ requirements: []
129
144
  rubygems_version: 3.1.2
130
145
  signing_key:
131
146
  specification_version: 4
132
- summary: ''
147
+ summary: A stateful command line interface to help you handle your daily tsks (with
148
+ contexts!)
133
149
  test_files: []