3llo 1.0.0.pre.rc.0 → 1.3.1.pre.rc.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 (55) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +4 -0
  3. data/.rubocop.yml +122 -0
  4. data/3llo.gemspec +11 -11
  5. data/CHANGELOG.md +21 -0
  6. data/Gemfile +3 -3
  7. data/LICENSE +2 -1
  8. data/Rakefile +3 -9
  9. data/bin/3llo +4 -4
  10. data/lib/3llo/api/board.rb +23 -27
  11. data/lib/3llo/api/card.rb +87 -103
  12. data/lib/3llo/api/checklist.rb +26 -48
  13. data/lib/3llo/api/label.rb +64 -0
  14. data/lib/3llo/api/list.rb +22 -23
  15. data/lib/3llo/api/token.rb +2 -2
  16. data/lib/3llo/api/user.rb +8 -32
  17. data/lib/3llo/api.rb +7 -6
  18. data/lib/3llo/application.rb +32 -22
  19. data/lib/3llo/command/board/add.rb +29 -0
  20. data/lib/3llo/command/board.rb +7 -9
  21. data/lib/3llo/command/card/add.rb +12 -8
  22. data/lib/3llo/command/card/add_label.rb +56 -0
  23. data/lib/3llo/command/card/assign.rb +3 -3
  24. data/lib/3llo/command/card/edit.rb +33 -0
  25. data/lib/3llo/command/card/move.rb +3 -7
  26. data/lib/3llo/command/card/self_assign.rb +2 -2
  27. data/lib/3llo/command/card.rb +42 -53
  28. data/lib/3llo/command/label/add.rb +22 -0
  29. data/lib/3llo/command/label/edit.rb +37 -0
  30. data/lib/3llo/command/label/invalid.rb +18 -0
  31. data/lib/3llo/command/label/list.rb +18 -0
  32. data/lib/3llo/command/label/remove.rb +28 -0
  33. data/lib/3llo/command/label.rb +47 -0
  34. data/lib/3llo/command/list/add.rb +21 -0
  35. data/lib/3llo/command/list.rb +10 -9
  36. data/lib/3llo/command.rb +47 -14
  37. data/lib/3llo/controller.rb +28 -13
  38. data/lib/3llo/entities.rb +2 -2
  39. data/lib/3llo/interface.rb +3 -2
  40. data/lib/3llo/registry.rb +3 -4
  41. data/lib/3llo/remote_server.rb +99 -0
  42. data/lib/3llo/utils.rb +18 -0
  43. data/lib/3llo/version.rb +1 -1
  44. data/lib/3llo/view/board/help.rb +1 -0
  45. data/lib/3llo/view/board/list.rb +2 -2
  46. data/lib/3llo/view/card/help.rb +2 -1
  47. data/lib/3llo/view/help.rb +2 -0
  48. data/lib/3llo/view/label/help.rb +20 -0
  49. data/lib/3llo/view/label/list.rb +21 -0
  50. data/lib/3llo/view/list/help.rb +1 -0
  51. data/lib/3llo/view.rb +13 -11
  52. data/lib/3llo.rb +14 -14
  53. metadata +38 -9
  54. data/lib/3llo/http/client.rb +0 -95
  55. data/lib/3llo/http/request_error.rb +0 -18
data/lib/3llo/registry.rb CHANGED
@@ -16,11 +16,10 @@ module Tr3llo
16
16
  shortcut_to_id: {}
17
17
  })
18
18
 
19
- id_to_key = data[:id_to_shortcut]
20
- key_to_id = data[:shortcut_to_id]
19
+ id_to_shortcut = data[:id_to_shortcut]
21
20
 
22
- if id_to_key.key?(id)
23
- id_to_key.fetch(id)
21
+ if id_to_shortcut.has_key?(id)
22
+ id_to_shortcut.fetch(id)
24
23
  else
25
24
  counter = data[:counter] + 1
26
25
  shortcut = counter.to_s
@@ -0,0 +1,99 @@
1
+ require "net/http"
2
+
3
+ module Tr3llo
4
+ class RemoteServer
5
+ attr_reader :endpoint_url
6
+
7
+ EXPECTED_CODES = ["200"].freeze
8
+
9
+ class RequestError < ::StandardError
10
+ attr_reader :response
11
+
12
+ def initialize(response)
13
+ @response = response
14
+ super()
15
+ end
16
+
17
+ def message
18
+ formatted_response = "status: " + response.code.inspect() + ", body: " + response.body.inspect()
19
+
20
+ "Received unexpected response from remote server: " + formatted_response
21
+ end
22
+ end
23
+
24
+ def initialize(endpoint_url)
25
+ @endpoint_url = endpoint_url
26
+ end
27
+
28
+ def get(req_path, req_headers, expected_codes = EXPECTED_CODES)
29
+ req_uri = build_request_uri(req_path)
30
+ req_headers = {"accept" => "application/json"}.merge(req_headers)
31
+
32
+ dispatch(Net::HTTP::Get.new(req_uri, req_headers), expected_codes)
33
+ end
34
+
35
+ def post(req_path, req_headers, payload, expected_codes = EXPECTED_CODES)
36
+ req_uri = build_request_uri(req_path)
37
+
38
+ req_headers = {
39
+ "accept" => "application/json",
40
+ "content-type" => "application/json"
41
+ }.merge(req_headers)
42
+
43
+ request = Net::HTTP::Post.new(req_uri, req_headers)
44
+ request.body = JSON.dump(payload)
45
+
46
+ dispatch(request, expected_codes)
47
+ end
48
+
49
+ def put(req_path, req_headers, payload, expected_codes = EXPECTED_CODES)
50
+ req_uri = build_request_uri(req_path)
51
+
52
+ req_headers = {
53
+ "Accept" => "application/json",
54
+ "Content-Type" => "application/json"
55
+ }.merge(req_headers)
56
+
57
+ request = Net::HTTP::Put.new(req_uri, req_headers)
58
+ request.body = JSON.dump(payload)
59
+
60
+ dispatch(request, expected_codes)
61
+ end
62
+
63
+ def delete(req_path, req_headers, payload, expected_codes = EXPECTED_CODES)
64
+ req_uri = build_request_uri(req_path)
65
+
66
+ req_headers = {
67
+ "Accept" => "application/json",
68
+ "Content-Type" => "application/json"
69
+ }.merge(req_headers)
70
+
71
+ request = Net::HTTP::Delete.new(req_uri, req_headers)
72
+ request.body = JSON.dump(payload)
73
+
74
+ dispatch(request, expected_codes)
75
+ end
76
+
77
+ private
78
+
79
+ def build_request_uri(req_path)
80
+ URI.parse(endpoint_url + req_path)
81
+ rescue URI::Error
82
+ raise InvalidArgumentError.new("invalid command arguments")
83
+ end
84
+
85
+ def dispatch(request, expected_status_codes)
86
+ req_uri = request.uri
87
+
88
+ Net::HTTP.start(req_uri.host, req_uri.port, use_ssl: req_uri.scheme == "https") do |http|
89
+ response = http.request(request)
90
+
91
+ if expected_status_codes.include?(response.code)
92
+ JSON.parse(response.body)
93
+ else
94
+ raise RequestError.new(response)
95
+ end
96
+ end
97
+ end
98
+ end
99
+ end
data/lib/3llo/utils.rb CHANGED
@@ -17,6 +17,8 @@ module Tr3llo
17
17
  "sky" => 36
18
18
  }.freeze()
19
19
 
20
+ TRELLO_LABEL_COLOR = %w[red pink blue green purple yellow orange sky].freeze()
21
+
20
22
  def format_key_tag(id, shortcut)
21
23
  formatted_shortcut = Utils.format_highlight(Entities::SHORTCUT_PREFIX + shortcut)
22
24
  formatted_id = Utils.paint(id, "blue")
@@ -55,5 +57,21 @@ module Tr3llo
55
57
  def format_highlight(string)
56
58
  paint(string, "yellow")
57
59
  end
60
+
61
+ def build_req_path(path, extra_params = {})
62
+ params =
63
+ {
64
+ "key" => Application.fetch_configuration!().api_key,
65
+ "token" => Application.fetch_configuration!().api_token
66
+ }.merge(extra_params)
67
+
68
+ [path, URI.encode_www_form(params)].join("?")
69
+ end
70
+
71
+ def require_directory(glob)
72
+ Dir.glob(glob).each do |file|
73
+ require file
74
+ end
75
+ end
58
76
  end
59
77
  end
data/lib/3llo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Tr3llo
2
- VERSION = "1.0.0-rc.0"
2
+ VERSION = "1.3.1-rc.0".freeze
3
3
  end
@@ -10,6 +10,7 @@ module Tr3llo
10
10
 
11
11
  board list - Show list of boards
12
12
  board select <board_key> - Select board
13
+ board add - Create a board
13
14
  TEMPLATE
14
15
  end
15
16
  end
@@ -6,8 +6,8 @@ module Tr3llo
6
6
 
7
7
  def render(boards)
8
8
  boards
9
- .map { |board| render_board(board) }
10
- .join("\n")
9
+ .map { |board| render_board(board) }
10
+ .join("\n")
11
11
  end
12
12
 
13
13
  private
@@ -9,7 +9,7 @@ module Tr3llo
9
9
  #{Utils.format_bold("# Available card commands:")}
10
10
 
11
11
  card list - Show list of cards grouped by list
12
- card list mine - Show list of my cards
12
+ card list-mine - Show list of my cards
13
13
  card add - Create a card
14
14
  card show <key> - Show card information
15
15
  card move <key> - Move card to a list
@@ -18,6 +18,7 @@ module Tr3llo
18
18
  card comments <key> - Load recent comments of a card
19
19
  card comment <key> - Add a comment to a card
20
20
  card archive <key> - Archive a card
21
+ card add-label <key> - Label a card
21
22
 
22
23
  #{Utils.format_bold("# Available checklist commands:")}
23
24
 
@@ -14,6 +14,8 @@ module Tr3llo
14
14
 
15
15
  #{View::List::Help.render()}
16
16
 
17
+ #{View::Label::Help.render()}
18
+
17
19
  #{miscellaneous_help()}
18
20
  TEMPLATE
19
21
  end
@@ -0,0 +1,20 @@
1
+ module Tr3llo
2
+ module View
3
+ module Label
4
+ module Help
5
+ extend self
6
+
7
+ def render()
8
+ <<~TEMPLATE.strip
9
+ #{Utils.format_bold("# Available label commands:")}
10
+
11
+ label list - Show all labels
12
+ label add - Create a label
13
+ label edit <key> - Edit a label
14
+ list remove <key> - Remove a label
15
+ TEMPLATE
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,21 @@
1
+ module Tr3llo
2
+ module View
3
+ module Label
4
+ module List
5
+ extend self
6
+
7
+ def render(labels)
8
+ labels
9
+ .map { |label| render_label(label) }
10
+ .join("\n")
11
+ end
12
+
13
+ private
14
+
15
+ def render_label(label)
16
+ "#{Utils.format_key_tag(label.id, label.shortcut)} #{Utils.paint("#" + label.name, label.color)}"
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -9,6 +9,7 @@ module Tr3llo
9
9
  #{Utils.format_bold("# Available list commands:")}
10
10
 
11
11
  list list - Show all lists
12
+ list add - Create a list
12
13
  list cards <key> - Show all cards in list
13
14
  list archive-cards <key> - Archive all cards in list
14
15
  TEMPLATE
data/lib/3llo/view.rb CHANGED
@@ -1,11 +1,13 @@
1
- require '3llo/view/help'
2
- require '3llo/view/board/list'
3
- require '3llo/view/board/help'
4
- require '3llo/view/card/help'
5
- require '3llo/view/card/list'
6
- require '3llo/view/card/list_mine'
7
- require '3llo/view/card/show'
8
- require '3llo/view/card/comments'
9
- require '3llo/view/list/help'
10
- require '3llo/view/list/list'
11
- require '3llo/view/list/cards'
1
+ require "3llo/view/help"
2
+ require "3llo/view/board/list"
3
+ require "3llo/view/board/help"
4
+ require "3llo/view/card/help"
5
+ require "3llo/view/card/list"
6
+ require "3llo/view/card/list_mine"
7
+ require "3llo/view/card/show"
8
+ require "3llo/view/card/comments"
9
+ require "3llo/view/list/help"
10
+ require "3llo/view/list/list"
11
+ require "3llo/view/list/cards"
12
+ require "3llo/view/label/list"
13
+ require "3llo/view/label/help"
data/lib/3llo.rb CHANGED
@@ -1,17 +1,17 @@
1
1
  require "3llo/version"
2
- require "3llo/http/client"
2
+ require "3llo/remote_server"
3
3
  require "3llo/interface"
4
- require 'container'
5
- require 'json'
6
- require 'erb'
4
+ require "container"
5
+ require "json"
6
+ require "date"
7
7
 
8
- require '3llo/application'
9
- require '3llo/configuration'
10
- require '3llo/utils'
11
- require '3llo/controller'
12
- require '3llo/errors'
13
- require '3llo/api'
14
- require '3llo/view'
15
- require '3llo/command'
16
- require '3llo/registry'
17
- require '3llo/entities'
8
+ require "3llo/application"
9
+ require "3llo/configuration"
10
+ require "3llo/utils"
11
+ require "3llo/controller"
12
+ require "3llo/errors"
13
+ require "3llo/api"
14
+ require "3llo/view"
15
+ require "3llo/command"
16
+ require "3llo/registry"
17
+ require "3llo/entities"
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: 3llo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre.rc.0
4
+ version: 1.3.1.pre.rc.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cẩm Huỳnh
8
- autorequire:
8
+ - Diệp Sở Hùng
9
+ autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2020-01-17 00:00:00.000000000 Z
12
+ date: 2022-01-10 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: tty-prompt
@@ -38,9 +39,24 @@ dependencies:
38
39
  - - "~>"
39
40
  - !ruby/object:Gem::Version
40
41
  version: '3.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rubocop
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '0.79'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '0.79'
41
56
  description: Interactive CLI application for Trello
42
57
  email:
43
58
  - huynhquancam@gmail.com
59
+ - diepsohung@gmail.com
44
60
  executables:
45
61
  - 3llo
46
62
  extensions: []
@@ -48,6 +64,7 @@ extra_rdoc_files: []
48
64
  files:
49
65
  - ".github/workflows/ci.yml"
50
66
  - ".gitignore"
67
+ - ".rubocop.yml"
51
68
  - 3llo.gemspec
52
69
  - CHANGELOG.md
53
70
  - Gemfile
@@ -60,6 +77,7 @@ files:
60
77
  - lib/3llo/api/board.rb
61
78
  - lib/3llo/api/card.rb
62
79
  - lib/3llo/api/checklist.rb
80
+ - lib/3llo/api/label.rb
63
81
  - lib/3llo/api/list.rb
64
82
  - lib/3llo/api/token.rb
65
83
  - lib/3llo/api/user.rb
@@ -67,6 +85,7 @@ files:
67
85
  - lib/3llo/command.rb
68
86
  - lib/3llo/command/.gitkeep
69
87
  - lib/3llo/command/board.rb
88
+ - lib/3llo/command/board/add.rb
70
89
  - lib/3llo/command/board/invalid.rb
71
90
  - lib/3llo/command/board/list.rb
72
91
  - lib/3llo/command/board/select.rb
@@ -74,11 +93,13 @@ files:
74
93
  - lib/3llo/command/card/add.rb
75
94
  - lib/3llo/command/card/add_checklist.rb
76
95
  - lib/3llo/command/card/add_item.rb
96
+ - lib/3llo/command/card/add_label.rb
77
97
  - lib/3llo/command/card/archive.rb
78
98
  - lib/3llo/command/card/assign.rb
79
99
  - lib/3llo/command/card/check_item.rb
80
100
  - lib/3llo/command/card/comment.rb
81
101
  - lib/3llo/command/card/comments.rb
102
+ - lib/3llo/command/card/edit.rb
82
103
  - lib/3llo/command/card/edit_checklist.rb
83
104
  - lib/3llo/command/card/edit_item.rb
84
105
  - lib/3llo/command/card/invalid.rb
@@ -93,7 +114,14 @@ files:
93
114
  - lib/3llo/command/exit.rb
94
115
  - lib/3llo/command/help.rb
95
116
  - lib/3llo/command/invalid.rb
117
+ - lib/3llo/command/label.rb
118
+ - lib/3llo/command/label/add.rb
119
+ - lib/3llo/command/label/edit.rb
120
+ - lib/3llo/command/label/invalid.rb
121
+ - lib/3llo/command/label/list.rb
122
+ - lib/3llo/command/label/remove.rb
96
123
  - lib/3llo/command/list.rb
124
+ - lib/3llo/command/list/add.rb
97
125
  - lib/3llo/command/list/archive_cards.rb
98
126
  - lib/3llo/command/list/cards.rb
99
127
  - lib/3llo/command/list/invalid.rb
@@ -102,10 +130,9 @@ files:
102
130
  - lib/3llo/controller.rb
103
131
  - lib/3llo/entities.rb
104
132
  - lib/3llo/errors.rb
105
- - lib/3llo/http/client.rb
106
- - lib/3llo/http/request_error.rb
107
133
  - lib/3llo/interface.rb
108
134
  - lib/3llo/registry.rb
135
+ - lib/3llo/remote_server.rb
109
136
  - lib/3llo/utils.rb
110
137
  - lib/3llo/version.rb
111
138
  - lib/3llo/view.rb
@@ -118,6 +145,8 @@ files:
118
145
  - lib/3llo/view/card/list_mine.rb
119
146
  - lib/3llo/view/card/show.rb
120
147
  - lib/3llo/view/help.rb
148
+ - lib/3llo/view/label/help.rb
149
+ - lib/3llo/view/label/list.rb
121
150
  - lib/3llo/view/list/cards.rb
122
151
  - lib/3llo/view/list/help.rb
123
152
  - lib/3llo/view/list/list.rb
@@ -127,7 +156,7 @@ licenses:
127
156
  - MIT
128
157
  metadata:
129
158
  allowed_push_host: https://rubygems.org
130
- post_install_message:
159
+ post_install_message:
131
160
  rdoc_options: []
132
161
  require_paths:
133
162
  - lib
@@ -135,15 +164,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
135
164
  requirements:
136
165
  - - "~>"
137
166
  - !ruby/object:Gem::Version
138
- version: '2.5'
167
+ version: '3.0'
139
168
  required_rubygems_version: !ruby/object:Gem::Requirement
140
169
  requirements:
141
170
  - - ">"
142
171
  - !ruby/object:Gem::Version
143
172
  version: 1.3.1
144
173
  requirements: []
145
- rubygems_version: 3.1.2
146
- signing_key:
174
+ rubygems_version: 3.3.3
175
+ signing_key:
147
176
  specification_version: 4
148
177
  summary: Trello CLI app
149
178
  test_files: []
@@ -1,95 +0,0 @@
1
- require 'uri'
2
- require 'net/http'
3
- require 'openssl'
4
- require '3llo/http/request_error'
5
-
6
- module Tr3llo
7
- module HTTP
8
- module Client
9
- extend self
10
-
11
- BASE_URL = "https://api.trello.com/1"
12
-
13
- def get(path, params = {})
14
- uri = URI("#{BASE_URL}#{path}?#{query_string(params)}")
15
-
16
- http = Net::HTTP.new(uri.host, uri.port)
17
- http.use_ssl = true
18
- request = Net::HTTP::Get.new(uri.request_uri)
19
-
20
- res = http.request(request)
21
-
22
- case res
23
- when Net::HTTPSuccess then res.body
24
- else raise(RequestError.new(res.body))
25
- end
26
- end
27
-
28
- def post(path, params)
29
- uri = URI("#{BASE_URL}#{path}")
30
-
31
- http = Net::HTTP.new(uri.host, uri.port)
32
- http.use_ssl = true
33
- req_headers = {
34
- 'Accept' => 'application/json',
35
- 'Content-Type' => 'application/json',
36
- }
37
- request = Net::HTTP::Post.new(uri.request_uri, req_headers)
38
- request.body = JSON.dump(params)
39
-
40
- res = http.request(request)
41
-
42
- case res
43
- when Net::HTTPOK then res.body
44
- else raise(RequestError.new(res.body))
45
- end
46
- end
47
-
48
- def put(path, params)
49
- uri = URI("#{BASE_URL}#{path}")
50
-
51
- http = Net::HTTP.new(uri.host, uri.port)
52
- http.use_ssl = true
53
- req_headers = {
54
- 'Accept' => 'application/json',
55
- 'Content-Type' => 'application/json',
56
- }
57
- request = Net::HTTP::Put.new(uri.request_uri, req_headers)
58
- request.body = JSON.dump(params)
59
-
60
- res = http.request(request)
61
-
62
- case res
63
- when Net::HTTPOK then res.body
64
- else raise(RequestError.new(res.body))
65
- end
66
- end
67
-
68
- def delete(path, params)
69
- uri = URI("#{BASE_URL}#{path}")
70
-
71
- http = Net::HTTP.new(uri.host, uri.port)
72
- http.use_ssl = true
73
- req_headers = {
74
- 'Accept' => 'application/json',
75
- 'Content-Type' => 'application/json',
76
- }
77
- request = Net::HTTP::Delete.new(uri.request_uri, req_headers)
78
- request.body = JSON.dump(params)
79
-
80
- res = http.request(request)
81
-
82
- case res
83
- when Net::HTTPOK then res.body
84
- else raise(RequestError.new(res.body))
85
- end
86
- end
87
-
88
- private
89
-
90
- def query_string(params)
91
- URI.encode_www_form(params)
92
- end
93
- end
94
- end
95
- end
@@ -1,18 +0,0 @@
1
- module Tr3llo
2
- module HTTP
3
- module Client
4
- class RequestError < ::StandardError
5
- attr_reader :response
6
-
7
- def initialize(response)
8
- @response = response
9
- super()
10
- end
11
-
12
- def message
13
- "Request error: #{response}"
14
- end
15
- end
16
- end
17
- end
18
- end