3llo 0.1.8 → 0.1.9.beta

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 45845f6247206e981300f0213b03d9d5b2e9943b
4
- data.tar.gz: 8c373c8ce27298abdf54a083d7c80fb03ae27e84
3
+ metadata.gz: e6cf3198c2484045d6c27f9e502026dc177b2d61
4
+ data.tar.gz: b542d6aa3e3ffeffac36ce468daa7b9d288bddbb
5
5
  SHA512:
6
- metadata.gz: 3e8e2a1142b5859f1bf699732ae39677375fcda06fc003a296a9c91cfc31067f2d6eb16ccfc0432385843dbd05f5628651319226e3743075b756fd2a181428d8
7
- data.tar.gz: e95778da4d3df83edbcc99b0e07ab1c1858244c95eb5a61a7ad6c0380a3e29d40f21c5b1b0ae9900f8962e6b3074dbf57553ff6bc96cadb367f6b955d75b8c54
6
+ metadata.gz: 72c9bd2a0d678d8073b630fcc37e7924cc23245ad46662b6fc27de9986d32f2d8f485e79e097bcd87f49073be71eccdc17d860a9cbfcce759d951db797d8a51e
7
+ data.tar.gz: 500a740b975c8ea42c5088a374a321876a0863fc8bbe117b190058133d2618851fbdb2a893b020835e840014a72074ee33d9687ef1696d4d1def40c653be2e03
data/3llo.gemspec CHANGED
@@ -26,4 +26,6 @@ Gem::Specification.new do |spec|
26
26
  spec.bindir = "bin"
27
27
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
28
28
  spec.require_paths = ["lib"]
29
+
30
+ spec.add_runtime_dependency 'tty-prompt', '~> 0.11.0'
29
31
  end
data/bin/3llo CHANGED
@@ -3,10 +3,12 @@
3
3
  $:.unshift File.expand_path("../../lib", __FILE__)
4
4
  require "3llo"
5
5
  require 'container'
6
+ require 'tty-prompt'
6
7
 
7
8
  $container = Container.new
8
9
  $container.register(:api_client, Tr3llo::Client)
9
- $container.register(:interface, Tr3llo::Interface.new($stdin, $stdout))
10
+ prompt = TTY::Prompt.new
11
+ $container.register(:interface, Tr3llo::Interface.new(prompt, $stdout))
10
12
 
11
13
  configuration = Tr3llo::Configuration.new
12
14
  configuration.user_id = ENV.fetch('TRELLO_USER') { raise "Have you set TRELLO_USER?" }
data/lib/3llo/api/card.rb CHANGED
@@ -20,6 +20,8 @@ module Tr3llo
20
20
  "/lists/#{list_id}/cards",
21
21
  key: api_key,
22
22
  token: api_token,
23
+ members: 'true',
24
+ member_fields: "id,username"
23
25
  ),
24
26
  symbolize_names: true
25
27
  )
@@ -37,6 +39,20 @@ module Tr3llo
37
39
  )
38
40
  end
39
41
 
42
+ def create(name:, description:, list_id:)
43
+ JSON.parse(
44
+ client.post(
45
+ "/cards",
46
+ key: api_key,
47
+ token: api_token,
48
+ name: name,
49
+ description: description,
50
+ idList: list_id
51
+ ),
52
+ symbolize_names: true
53
+ )
54
+ end
55
+
40
56
  def find(card_id)
41
57
  JSON.parse(
42
58
  client.get(
@@ -75,6 +91,19 @@ module Tr3llo
75
91
  )
76
92
  end
77
93
 
94
+ def find_comments(card_id)
95
+ url = "/cards/#{card_id}/actions"
96
+ JSON.parse(
97
+ client.get(
98
+ url,
99
+ key: api_key,
100
+ token: api_token,
101
+ filter: "commentCard",
102
+ ),
103
+ symbolize_names: true
104
+ )
105
+ end
106
+
78
107
  private
79
108
 
80
109
  def api_key
@@ -15,8 +15,7 @@ module Tr3llo
15
15
  user_id = $container.resolve(:user)[:id]
16
16
  Command::Board::ListCommand.new(user_id)
17
17
  when :select
18
- board_id, _ = args
19
- Command::Board::SelectCommand.new(board_id)
18
+ Command::Board::SelectCommand.new
20
19
  else
21
20
  Command::Board::InvalidCommand.new
22
21
  end
@@ -4,6 +4,8 @@ require '3llo/commands/card/show'
4
4
  require '3llo/commands/card/move'
5
5
  require '3llo/commands/card/self_assign'
6
6
  require '3llo/commands/card/invalid'
7
+ require '3llo/commands/card/comments'
8
+ require '3llo/commands/card/add'
7
9
 
8
10
  module Tr3llo
9
11
  class CardCommandFactory
@@ -24,13 +26,19 @@ module Tr3llo
24
26
  else
25
27
  Command::Card::ListCommand.new(board_id)
26
28
  end
29
+ when 'add'
30
+ board_id = $container.resolve(:board)[:id]
31
+ Command::Card::AddCommand.new(board_id)
27
32
  when 'show'
28
33
  card_id, _ = args
29
34
  Command::Card::ShowCommand.new(card_id)
35
+ when 'comments'
36
+ card_id, _ = args
37
+ Command::Card::CommentsCommand.new(card_id)
30
38
  when 'move'
31
- card_id, list_id = args
39
+ card_id, _ = args
32
40
  board_id = $container.resolve(:board)[:id]
33
- Command::Card::MoveCommand.new(card_id, list_id, board_id)
41
+ Command::Card::MoveCommand.new(card_id, board_id)
34
42
  when 'self-assign'
35
43
  card_id, _ = args
36
44
  user_id = $container.resolve(:user)[:id]
data/lib/3llo/client.rb CHANGED
@@ -37,6 +37,23 @@ module Tr3llo
37
37
  end
38
38
  end
39
39
 
40
+ def post(path, params)
41
+ uri = URI("#{BASE_URL}#{path}")
42
+
43
+ http = Net::HTTP.new(uri.host, uri.port)
44
+ http.use_ssl = true
45
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
46
+ request = Net::HTTP::Post.new(uri.request_uri, 'Content-Type' => 'application/json')
47
+ request.body = params.to_json
48
+
49
+ res = http.request(request)
50
+
51
+ case res
52
+ when Net::HTTPOK then res.body
53
+ else raise(RequestError.new(res.body))
54
+ end
55
+ end
56
+
40
57
  def put(path, params)
41
58
  uri = URI("#{BASE_URL}#{path}?#{query_string(params)}")
42
59
 
@@ -15,8 +15,8 @@ module Tr3llo
15
15
  %q{
16
16
  Available `board` commands
17
17
 
18
- board list - Show list of board
19
- board select <board_id> - Select board
18
+ board list - Show list of board
19
+ board select - Select board
20
20
  }
21
21
  end
22
22
 
@@ -2,12 +2,9 @@ module Tr3llo
2
2
  module Command
3
3
  module Board
4
4
  class SelectCommand
5
- def initialize(board_id)
6
- @board_id = board_id
7
- end
8
-
9
5
  def execute
10
- board = load_board
6
+ board = load_board(select_board)
7
+
11
8
  $container.register(:board, board)
12
9
  interface.print_frame do
13
10
  interface.puts("Board #{board[:name].labelize} selected")
@@ -16,9 +13,19 @@ module Tr3llo
16
13
 
17
14
  private
18
15
 
19
- attr_reader :board_id
16
+ def select_board
17
+ interface.input.select("Board to select: ", board_choices)
18
+ end
19
+
20
+ def board_choices
21
+ user_id = $container.resolve(:user)[:id]
22
+ API::Board
23
+ .find_all_by_user(user_id)
24
+ .map { |board| [board[:name], board[:id]] }
25
+ .to_h
26
+ end
20
27
 
21
- def load_board
28
+ def load_board(board_id)
22
29
  API::Board.find(board_id)
23
30
  end
24
31
 
@@ -0,0 +1,50 @@
1
+ module Tr3llo
2
+ module Command
3
+ module Card
4
+ class AddCommand
5
+ def initialize(board_id)
6
+ @board_id = board_id
7
+ end
8
+
9
+ def execute
10
+ interface.print_frame do
11
+ list_id = interface.input.select(
12
+ "Choose a list:",
13
+ load_lists
14
+ )
15
+ name = interface.input.ask("Name:")
16
+ description = interface.input.ask("Description:")
17
+
18
+ interface.puts(
19
+ create_card!(name, description, list_id) &&
20
+ "Card created"
21
+ )
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ attr_reader :board_id
28
+
29
+ def create_card!(name, description, list_id)
30
+ API::Card.create(
31
+ name: name,
32
+ description: description,
33
+ list_id: list_id
34
+ )
35
+ end
36
+
37
+ def load_lists
38
+ API::List
39
+ .find_all_by_board(board_id)
40
+ .map { |list| [list[:name], list[:id]] }
41
+ .to_h
42
+ end
43
+
44
+ def interface
45
+ $container.resolve(:interface)
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,29 @@
1
+ module Tr3llo
2
+ module Command
3
+ module Card
4
+ class CommentsCommand
5
+ def initialize(card_id)
6
+ @card_id = card_id
7
+ end
8
+
9
+ def execute
10
+ Tr3llo::Presenter::Card::CommentsPresenter
11
+ .new(interface)
12
+ .print!(load_comments)
13
+ end
14
+
15
+ private
16
+
17
+ attr_reader :card_id
18
+
19
+ def load_comments
20
+ API::Card.find_comments(card_id)
21
+ end
22
+
23
+ def interface
24
+ $container.resolve(:interface)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -15,11 +15,13 @@ module Tr3llo
15
15
  %q{
16
16
  Available `card` commands
17
17
 
18
- card list - Show list of cards grouped by list
19
- card list mine - Show list of my cards
20
- card show <card_id> - Show card information
21
- card move <card_id> <list_id> - Move card to a list
22
- card self-assign <card_id> - Self-assign a card
18
+ card list - Show list of cards grouped by list
19
+ card list mine - Show list of my cards
20
+ card add - Create a card
21
+ card show <card_id> - Show card information
22
+ card move <card_id> - Move card to a list
23
+ card self-assign <card_id> - Self-assign a card
24
+ card comments <card_id> - Load recent comments of a card
23
25
  }
24
26
  end
25
27
 
@@ -2,23 +2,22 @@ module Tr3llo
2
2
  module Command
3
3
  module Card
4
4
  class MoveCommand
5
- def initialize(card_id, list_id, board_id)
5
+ def initialize(card_id, board_id)
6
6
  @card_id = card_id
7
- @list_id = list_id
8
7
  @board_id = board_id
9
8
  end
10
9
 
11
10
  def execute
12
11
  interface.print_frame do
13
- prompt_for_list_id!(board_id) unless list_id
14
- move_card!
12
+ list_id = prompt_for_list_id!(board_id)
13
+ move_card!(list_id)
15
14
  interface.puts("Card has been moved.")
16
15
  end
17
16
  end
18
17
 
19
18
  private
20
19
 
21
- attr_reader :list_id, :card_id, :board_id
20
+ attr_reader :card_id, :board_id
22
21
 
23
22
  def prompt_for_list_id!(board_id)
24
23
  board_id = $container.resolve(:board)[:id]
@@ -30,7 +29,7 @@ module Tr3llo
30
29
  .prompt_for_list_id(lists)
31
30
  end
32
31
 
33
- def move_card!
32
+ def move_card!(list_id)
34
33
  API::Card.move_to_list(card_id, list_id)
35
34
  end
36
35
 
@@ -19,7 +19,9 @@ module Tr3llo
19
19
  attr_reader :user_id, :card_id
20
20
 
21
21
  def assign_card
22
- API::Card.assign_members(card_id, [user_id])
22
+ card = API::Card.find(card_id)
23
+ members = card[:idMembers] << user_id
24
+ API::Card.assign_members(card_id, members)
23
25
  end
24
26
 
25
27
  def interface
@@ -3,7 +3,7 @@ module Tr3llo
3
3
  class ErrorCommand
4
4
  def execute
5
5
  interface.print_frame do
6
- command = "board select <board-id>".red
6
+ command = "board select".red
7
7
  interface.puts("You have not selected any board. Run #{command} to select one.")
8
8
  end
9
9
  end
@@ -23,7 +23,7 @@ module Tr3llo
23
23
  end
24
24
  end
25
25
  rescue Interrupt
26
- interface.print_frame { interface.puts('Bye Bye...') }
26
+ Command::ExitCommand.new.execute
27
27
  end
28
28
 
29
29
  private
data/lib/3llo/errors.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Tr3llo
2
2
  class BoardNotSelectedError < RuntimeError
3
3
  def message
4
- "Board has not been selected. Run 'board select <board-id>' to select board"
4
+ "Board has not been selected. Run 'board select' to select board"
5
5
  end
6
6
  end
7
7
  end
@@ -20,11 +20,6 @@ module Tr3llo
20
20
  output.print(str)
21
21
  end
22
22
 
23
- def prompt(message)
24
- print("Enter list ID to be moved to: ")
25
- input.gets.chomp
26
- end
27
-
28
23
  attr_reader :input, :output
29
24
  end
30
25
  end
@@ -0,0 +1,33 @@
1
+ module Tr3llo
2
+ module Presenter
3
+ module Card
4
+ class CommentsPresenter
5
+ def initialize(interface)
6
+ @interface = interface
7
+ end
8
+
9
+ def print!(comments)
10
+ interface.print_frame do
11
+ comments.each do |comment|
12
+ present_comment(comment)
13
+ end
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ attr_reader :interface
20
+
21
+ def present_comment(comment)
22
+ interface.puts(
23
+ "#{decorate_user(comment[:memberCreator])}: #{comment[:data][:text]}"
24
+ )
25
+ end
26
+
27
+ def decorate_user(user)
28
+ "@#{user[:username]}".blue
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -25,13 +25,19 @@ module Tr3llo
25
25
  label_str = ''
26
26
  end
27
27
 
28
+ if card.has_key?(:members)
29
+ members_str = card[:members].map { |member| "@#{member[:username]}".blue }.join(", ")
30
+ else
31
+ members_str = ''
32
+ end
33
+
28
34
  if card[:subscribed]
29
35
  subscribed_str = "[✓]"
30
36
  else
31
37
  subscribed_str = "[ ]"
32
38
  end
33
39
 
34
- interface.puts "#{subscribed_str} #{card[:id].labelize}] - #{card[:name]} (#{label_str})"
40
+ interface.puts "#{subscribed_str} #{card[:id].labelize}] - #{card[:name]} (#{label_str}) [#{members_str}]"
35
41
  end
36
42
 
37
43
  def colorize_label(label)
@@ -7,9 +7,10 @@ module Tr3llo
7
7
  end
8
8
 
9
9
  def prompt_for_list_id(lists)
10
- interface.puts("List of lists in this board")
11
- lists.each(&method(:present_list))
12
- interface.prompt("Select list ID")
10
+ interface.input.select(
11
+ 'Choose the list to be moved to',
12
+ lists.map { |list| [list[:name], list[:id]] }.to_h
13
+ )
13
14
  end
14
15
 
15
16
  private
@@ -20,17 +20,19 @@ module Tr3llo
20
20
  3llo - CLI for Trello
21
21
 
22
22
  Usage:
23
- board list - Show list of board
24
- board select <board_id> - Select board
25
- card list - Show list of cards grouped by list
26
- card list mine - Show list of my cards
27
- card show <card_id> - Show card information
28
- card move <card_id> <list_id> - Move card to a list
29
- card self-assign <card_id> - Self-assign a card
30
- list list - Show all lists
31
- list cards <list_id> - Show all cards in list
32
- help - Show help menu
33
- exit - Exit program
23
+ board list - Show list of board
24
+ board select - Select board
25
+ card list - Show list of cards grouped by list
26
+ card list mine - Show list of my cards
27
+ card add - Create a card
28
+ card show <card_id> - Show card information
29
+ card move <card_id> - Move card to a list
30
+ card self-assign <card_id> - Self-assign a card
31
+ card comments <card_id> - Load recent comments of a card
32
+ list list - Show all lists
33
+ list cards <list_id> - Show all cards in list
34
+ help - Show help menu
35
+ exit - Exit program
34
36
  }
35
37
  end
36
38
  end
@@ -4,5 +4,6 @@ require '3llo/presenter/card/list'
4
4
  require '3llo/presenter/card/list_mine'
5
5
  require '3llo/presenter/card/move'
6
6
  require '3llo/presenter/card/show'
7
+ require '3llo/presenter/card/comments'
7
8
  require '3llo/presenter/list/list'
8
9
  require '3llo/presenter/list/cards'
data/lib/3llo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Tr3llo
2
- VERSION = "0.1.8"
2
+ VERSION = "0.1.9.beta"
3
3
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: 3llo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9.beta
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cẩm Huỳnh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-02 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2017-03-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: tty-prompt
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.11.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.11.0
13
27
  description: CLI for Trello
14
28
  email:
15
29
  - huynhquancam@gmail.com
@@ -41,6 +55,8 @@ files:
41
55
  - lib/3llo/commands/board/invalid.rb
42
56
  - lib/3llo/commands/board/list.rb
43
57
  - lib/3llo/commands/board/select.rb
58
+ - lib/3llo/commands/card/add.rb
59
+ - lib/3llo/commands/card/comments.rb
44
60
  - lib/3llo/commands/card/invalid.rb
45
61
  - lib/3llo/commands/card/list.rb
46
62
  - lib/3llo/commands/card/list_mine.rb
@@ -62,6 +78,7 @@ files:
62
78
  - lib/3llo/presenter.rb
63
79
  - lib/3llo/presenter/.gitkeep
64
80
  - lib/3llo/presenter/board/list.rb
81
+ - lib/3llo/presenter/card/comments.rb
65
82
  - lib/3llo/presenter/card/list.rb
66
83
  - lib/3llo/presenter/card/list_mine.rb
67
84
  - lib/3llo/presenter/card/move.rb
@@ -88,9 +105,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
88
105
  version: '0'
89
106
  required_rubygems_version: !ruby/object:Gem::Requirement
90
107
  requirements:
91
- - - ">="
108
+ - - ">"
92
109
  - !ruby/object:Gem::Version
93
- version: '0'
110
+ version: 1.3.1
94
111
  requirements: []
95
112
  rubyforge_project:
96
113
  rubygems_version: 2.4.5