3llo 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.travis.yml +5 -0
  4. data/3llo.gemspec +29 -0
  5. data/CODE_OF_CONDUCT.md +49 -0
  6. data/Gemfile +7 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +58 -0
  9. data/Rakefile +10 -0
  10. data/bin/3llo +29 -0
  11. data/lib/3llo/api/board.rb +47 -0
  12. data/lib/3llo/api/card.rb +93 -0
  13. data/lib/3llo/api/list.rb +37 -0
  14. data/lib/3llo/api/user.rb +34 -0
  15. data/lib/3llo/api.rb +4 -0
  16. data/lib/3llo/board_command_factory.rb +29 -0
  17. data/lib/3llo/card_command_factory.rb +49 -0
  18. data/lib/3llo/client.rb +62 -0
  19. data/lib/3llo/command_factory.rb +40 -0
  20. data/lib/3llo/commands/.gitkeep +0 -0
  21. data/lib/3llo/commands/board/invalid.rb +33 -0
  22. data/lib/3llo/commands/board/list.rb +29 -0
  23. data/lib/3llo/commands/board/select.rb +31 -0
  24. data/lib/3llo/commands/card/invalid.rb +36 -0
  25. data/lib/3llo/commands/card/list.rb +37 -0
  26. data/lib/3llo/commands/card/list_mine.rb +30 -0
  27. data/lib/3llo/commands/card/move.rb +43 -0
  28. data/lib/3llo/commands/card/self_assign.rb +31 -0
  29. data/lib/3llo/commands/card/show.rb +29 -0
  30. data/lib/3llo/commands/error.rb +18 -0
  31. data/lib/3llo/commands/exit.rb +16 -0
  32. data/lib/3llo/commands/help.rb +15 -0
  33. data/lib/3llo/commands/invalid.rb +18 -0
  34. data/lib/3llo/commands/list/cards.rb +29 -0
  35. data/lib/3llo/commands/list/invalid.rb +33 -0
  36. data/lib/3llo/commands/list/list.rb +29 -0
  37. data/lib/3llo/configuration.rb +39 -0
  38. data/lib/3llo/controller.rb +35 -0
  39. data/lib/3llo/errors.rb +7 -0
  40. data/lib/3llo/interface.rb +30 -0
  41. data/lib/3llo/list_command_factory.rb +29 -0
  42. data/lib/3llo/presenter/.gitkeep +0 -0
  43. data/lib/3llo/presenter/board/list.rb +25 -0
  44. data/lib/3llo/presenter/card/list.rb +43 -0
  45. data/lib/3llo/presenter/card/list_mine.rb +25 -0
  46. data/lib/3llo/presenter/card/move.rb +25 -0
  47. data/lib/3llo/presenter/card/show.rb +39 -0
  48. data/lib/3llo/presenter/help.rb +38 -0
  49. data/lib/3llo/presenter/list/cards.rb +41 -0
  50. data/lib/3llo/presenter/list/list.rb +25 -0
  51. data/lib/3llo/presenter.rb +8 -0
  52. data/lib/3llo/version.rb +3 -0
  53. data/lib/3llo.rb +14 -0
  54. data/lib/container.rb +24 -0
  55. data/lib/core_ext.rb +41 -0
  56. metadata +100 -0
@@ -0,0 +1,29 @@
1
+ module Tr3llo
2
+ module Command
3
+ module Board
4
+ class ListCommand
5
+ def initialize(user_id)
6
+ @user_id = user_id
7
+ end
8
+
9
+ def execute
10
+ Tr3llo::Presenter::Board::ListPresenter
11
+ .new(interface)
12
+ .print!(list_boards)
13
+ end
14
+
15
+ private
16
+
17
+ attr_reader :user_id
18
+
19
+ def list_boards
20
+ API::Board.find_all_by_user(user_id)
21
+ end
22
+
23
+ def interface
24
+ $container.resolve(:interface)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,31 @@
1
+ module Tr3llo
2
+ module Command
3
+ module Board
4
+ class SelectCommand
5
+ def initialize(board_id)
6
+ @board_id = board_id
7
+ end
8
+
9
+ def execute
10
+ board = load_board
11
+ $container.register(:board, board)
12
+ interface.print_frame do
13
+ interface.puts("Board #{board[:name].labelize} selected")
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ attr_reader :board_id
20
+
21
+ def load_board
22
+ API::Board.find(board_id)
23
+ end
24
+
25
+ def interface
26
+ $container.resolve(:interface)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,36 @@
1
+ module Tr3llo
2
+ module Command
3
+ module Card
4
+ class InvalidCommand
5
+ def execute
6
+ interface.print_frame do
7
+ interface.puts("Invalid command".red)
8
+ interface.puts(menu_text)
9
+ end
10
+ end
11
+
12
+ private
13
+
14
+ def menu_text
15
+ %q{
16
+ Available `card` commands
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
23
+ }
24
+ end
25
+
26
+ def container
27
+ $container
28
+ end
29
+
30
+ def interface
31
+ container.resolve(:interface)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,37 @@
1
+ module Tr3llo
2
+ module Command
3
+ module Card
4
+ class ListCommand
5
+ def initialize(board_id)
6
+ @board_id = board_id
7
+ end
8
+
9
+ def execute
10
+ lists = load_lists
11
+
12
+ lists.each do |list|
13
+ Tr3llo::Presenter::Card::ListPresenter
14
+ .new(interface)
15
+ .print!(list, load_cards(list[:id]))
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ attr_reader :board_id
22
+
23
+ def load_lists
24
+ API::List.find_all_by_board(board_id)
25
+ end
26
+
27
+ def load_cards(list_id)
28
+ API::Card.find_all_by_list(list_id)
29
+ end
30
+
31
+ def interface
32
+ $container.resolve(:interface)
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,30 @@
1
+ module Tr3llo
2
+ module Command
3
+ module Card
4
+ class ListMineCommand
5
+ def initialize(board_id, user_id)
6
+ @board_id = board_id
7
+ @user_id = user_id
8
+ end
9
+
10
+ def execute
11
+ Tr3llo::Presenter::Card::ListMinePresenter
12
+ .new(interface)
13
+ .print!(load_cards)
14
+ end
15
+
16
+ private
17
+
18
+ attr_reader :board_id, :user_id
19
+
20
+ def load_cards
21
+ API::Card.find_all_by_user(board_id, user_id)
22
+ end
23
+
24
+ def interface
25
+ $container.resolve(:interface)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,43 @@
1
+ module Tr3llo
2
+ module Command
3
+ module Card
4
+ class MoveCommand
5
+ def initialize(card_id, list_id, board_id)
6
+ @card_id = card_id
7
+ @list_id = list_id
8
+ @board_id = board_id
9
+ end
10
+
11
+ def execute
12
+ interface.print_frame do
13
+ prompt_for_list_id!(board_id) unless list_id
14
+ move_card!
15
+ interface.puts("Card has been moved.")
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ attr_reader :list_id, :card_id, :board_id
22
+
23
+ def prompt_for_list_id!(board_id)
24
+ board_id = $container.resolve(:board)[:id]
25
+ lists = Tr3llo::API::List.find_all_by_board(board_id)
26
+
27
+ @list_id =
28
+ Tr3llo::Presenter::Card::MovePresenter
29
+ .new(interface)
30
+ .prompt_for_list_id(lists)
31
+ end
32
+
33
+ def move_card!
34
+ API::Card.move_to_list(card_id, list_id)
35
+ end
36
+
37
+ def interface
38
+ $container.resolve(:interface)
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,31 @@
1
+ module Tr3llo
2
+ module Command
3
+ module Card
4
+ class SelfAssignCommand
5
+ def initialize(card_id, user_id)
6
+ @card_id = card_id
7
+ @user_id = user_id
8
+ end
9
+
10
+ def execute
11
+ card = assign_card
12
+ interface.print_frame do
13
+ interface.puts("Card #{card[:name].labelize} self-assigned")
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ attr_reader :user_id, :card_id
20
+
21
+ def assign_card
22
+ API::Card.assign_members(card_id, [user_id])
23
+ end
24
+
25
+ def interface
26
+ $container.resolve(:interface)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,29 @@
1
+ module Tr3llo
2
+ module Command
3
+ module Card
4
+ class ShowCommand
5
+ def initialize(card_id)
6
+ @card_id = card_id
7
+ end
8
+
9
+ def execute
10
+ Tr3llo::Presenter::Card::ShowPresenter
11
+ .new(interface)
12
+ .print!(load_card)
13
+ end
14
+
15
+ private
16
+
17
+ attr_reader :card_id
18
+
19
+ def load_card
20
+ API::Card.find(card_id)
21
+ end
22
+
23
+ def interface
24
+ $container.resolve(:interface)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,18 @@
1
+ module Tr3llo
2
+ module Command
3
+ class ErrorCommand
4
+ def execute
5
+ interface.print_frame do
6
+ command = "board select <board-id>".red
7
+ interface.puts("You have not selected any board. Run #{command} to select one.")
8
+ end
9
+ end
10
+
11
+ private
12
+
13
+ def interface
14
+ $container.resolve(:interface)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,16 @@
1
+ module Tr3llo
2
+ module Command
3
+ class ExitCommand
4
+ def execute
5
+ interface.puts("Bye bye")
6
+ exit(0)
7
+ end
8
+
9
+ private
10
+
11
+ def interface
12
+ $container.resolve(:interface)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,15 @@
1
+ module Tr3llo
2
+ module Command
3
+ class HelpCommand
4
+ def execute
5
+ Presenter::HelpPresenter.new(interface).print!
6
+ end
7
+
8
+ private
9
+
10
+ def interface
11
+ $container.resolve(:interface)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,18 @@
1
+ module Tr3llo
2
+ module Command
3
+ class InvalidCommand
4
+ def execute
5
+ interface.print_frame do
6
+ interface.puts("Invalid command!".red)
7
+ Presenter::HelpPresenter.new(interface).print!
8
+ end
9
+ end
10
+
11
+ private
12
+
13
+ def interface
14
+ $container.resolve(:interface)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,29 @@
1
+ module Tr3llo
2
+ module Command
3
+ module List
4
+ class CardsCommand
5
+ def initialize(list_id)
6
+ @list_id = list_id
7
+ end
8
+
9
+ def execute
10
+ Tr3llo::Presenter::List::CardsPresenter
11
+ .new(interface)
12
+ .print!(list_cards)
13
+ end
14
+
15
+ private
16
+
17
+ attr_reader :list_id
18
+
19
+ def list_cards
20
+ API::Card.find_all_by_list(list_id)
21
+ end
22
+
23
+ def interface
24
+ $container.resolve(:interface)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,33 @@
1
+ module Tr3llo
2
+ module Command
3
+ module List
4
+ class InvalidCommand
5
+ def execute
6
+ interface.print_frame do
7
+ interface.puts("Invalid command".red)
8
+ interface.puts(menu_text)
9
+ end
10
+ end
11
+
12
+ private
13
+
14
+ def menu_text
15
+ %q{
16
+ Available `list` commands
17
+
18
+ list list - Show all lists
19
+ list cards <list_id> - Show all cards in list
20
+ }
21
+ end
22
+
23
+ def container
24
+ $container
25
+ end
26
+
27
+ def interface
28
+ container.resolve(:interface)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,29 @@
1
+ module Tr3llo
2
+ module Command
3
+ module List
4
+ class ListCommand
5
+ def initialize(board_id)
6
+ @board_id = board_id
7
+ end
8
+
9
+ def execute
10
+ Tr3llo::Presenter::List::ListPresenter
11
+ .new(interface)
12
+ .print!(list_lists)
13
+ end
14
+
15
+ private
16
+
17
+ attr_reader :board_id
18
+
19
+ def list_lists
20
+ API::List.find_all_by_board(board_id)
21
+ end
22
+
23
+ def interface
24
+ $container.resolve(:interface)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,39 @@
1
+ module Tr3llo
2
+ class Configuration
3
+ def initialize
4
+ @container = Container.new
5
+ end
6
+
7
+ def user_id=(value)
8
+ container.register(:user_id, value)
9
+ end
10
+
11
+ def user_id
12
+ container.resolve(:user_id)
13
+ end
14
+
15
+ def api_key=(value)
16
+ container.register(:api_key, value)
17
+ end
18
+
19
+ def api_key
20
+ container.resolve(:api_key)
21
+ end
22
+
23
+ def api_token=(token)
24
+ container.register(:api_token, token)
25
+ end
26
+
27
+ def api_token
28
+ container.resolve(:api_token)
29
+ end
30
+
31
+ def finalize!
32
+ container.freeze
33
+ end
34
+
35
+ private
36
+
37
+ attr_reader :container
38
+ end
39
+ end
@@ -0,0 +1,35 @@
1
+ require 'readline'
2
+
3
+ module Tr3llo
4
+ class Controller
5
+ def initialize
6
+ end
7
+
8
+ def start
9
+ list = %w(board card help list mine move select self-assign show)
10
+ comp = proc { |s| list.grep( /^#{Regexp.escape(s)}/ ) }
11
+
12
+ Readline.completion_append_character = " "
13
+ Readline.completion_proc = comp
14
+ loop do
15
+ command_buffer = Readline.readline("\e[15;48;5;27m 3llo \e[0m > ", true)
16
+ begin
17
+ Tr3llo::CommandFactory
18
+ .new(command_buffer)
19
+ .factory
20
+ .execute
21
+ rescue Tr3llo::Client::RequestError => e
22
+ interface.print_frame { interface.puts(e.message) }
23
+ end
24
+ end
25
+ rescue Interrupt
26
+ interface.print_frame { interface.puts('Bye Bye...') }
27
+ end
28
+
29
+ private
30
+
31
+ def interface
32
+ $container.resolve(:interface)
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,7 @@
1
+ module Tr3llo
2
+ class BoardNotSelectedError < RuntimeError
3
+ def message
4
+ "Board has not been selected. Run 'board select <board-id>' to select board"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,30 @@
1
+ module Tr3llo
2
+ class Interface
3
+ def initialize(input, output)
4
+ @input, @output = input, output
5
+ end
6
+
7
+ def print_frame
8
+ print_line("")
9
+ data = yield
10
+ print_line("")
11
+ data
12
+ end
13
+
14
+ def print_line(str)
15
+ output.puts(str)
16
+ end
17
+ alias :puts :print_line
18
+
19
+ def print(str)
20
+ output.print(str)
21
+ end
22
+
23
+ def prompt(message)
24
+ print("Enter list ID to be moved to: ")
25
+ input.gets.chomp
26
+ end
27
+
28
+ attr_reader :input, :output
29
+ end
30
+ end
@@ -0,0 +1,29 @@
1
+ require '3llo/commands/list/list'
2
+ require '3llo/commands/list/cards'
3
+ require '3llo/commands/list/invalid'
4
+
5
+ module Tr3llo
6
+ class ListCommandFactory
7
+ def initialize(subcommand, args)
8
+ @subcommand = subcommand
9
+ @args = args
10
+ end
11
+
12
+ def factory
13
+ case subcommand.to_sym
14
+ when :list
15
+ board_id = $container.resolve(:board)[:id]
16
+ Command::List::ListCommand.new(board_id)
17
+ when :cards
18
+ list_id, _ = args
19
+ Command::List::CardsCommand.new(list_id)
20
+ else
21
+ Command::List::InvalidCommand.new
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ attr_reader :subcommand, :args
28
+ end
29
+ end
File without changes
@@ -0,0 +1,25 @@
1
+ module Tr3llo
2
+ module Presenter
3
+ module Board
4
+ class ListPresenter
5
+ def initialize(interface)
6
+ @interface = interface
7
+ end
8
+
9
+ def print!(boards)
10
+ interface.print_frame do
11
+ boards.each { |board| present_board(board) }
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ attr_reader :interface
18
+
19
+ def present_board(board)
20
+ interface.puts "[#{board[:id].labelize}] - #{board[:name]}"
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,43 @@
1
+ module Tr3llo
2
+ module Presenter
3
+ module Card
4
+ class ListPresenter
5
+ def initialize(interface)
6
+ @interface = interface
7
+ end
8
+
9
+ def print!(list, cards)
10
+ interface.print_frame do
11
+ interface.puts("##{list[:name]}".purple)
12
+ interface.puts("=" * list[:name].length)
13
+ cards.each { |card| present_card(card) }
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ attr_reader :interface
20
+
21
+ def present_card(card)
22
+ if card.has_key?(:labels)
23
+ label_str = card[:labels].map { |label| colorize_label(label) }.join(", ")
24
+ else
25
+ label_str = ''
26
+ end
27
+
28
+ if card[:subscribed]
29
+ subscribed_str = "[✓]"
30
+ else
31
+ subscribed_str = "[ ]"
32
+ end
33
+
34
+ interface.puts "#{subscribed_str} #{card[:id].labelize}] - #{card[:name]} (#{label_str})"
35
+ end
36
+
37
+ def colorize_label(label)
38
+ "##{label[:name]}".paint(label[:color])
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,25 @@
1
+ module Tr3llo
2
+ module Presenter
3
+ module Card
4
+ class ListMinePresenter
5
+ def initialize(interface)
6
+ @interface = interface
7
+ end
8
+
9
+ def print!(cards)
10
+ interface.print_frame do
11
+ cards.each { |card| present_card(card) }
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ attr_reader :interface
18
+
19
+ def present_card(card)
20
+ interface.puts "[#{card[:id].labelize}] - (#{card[:list][:name].purple}) - #{card[:name]}"
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end