troo 0.0.11 → 0.0.12

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 (44) hide show
  1. checksums.yaml +4 -4
  2. data/.simplecov +3 -0
  3. data/Gemfile.lock +4 -1
  4. data/README.md +7 -7
  5. data/Rakefile +2 -2
  6. data/config/en.yml +2 -0
  7. data/features/support/env.rb +0 -4
  8. data/lib/troo.rb +14 -26
  9. data/lib/troo/api/client.rb +28 -6
  10. data/lib/troo/api/endpoints.rb +42 -30
  11. data/lib/troo/api/response.rb +5 -0
  12. data/lib/troo/cli/main.rb +3 -0
  13. data/lib/troo/cli/wizard.rb +71 -0
  14. data/lib/troo/configuration.rb +29 -15
  15. data/lib/troo/debug.rb +9 -0
  16. data/lib/troo/decorators/resource.rb +8 -4
  17. data/lib/troo/launcher.rb +22 -12
  18. data/lib/troo/models/board.rb +2 -2
  19. data/lib/troo/models/card.rb +2 -2
  20. data/lib/troo/models/member.rb +1 -1
  21. data/lib/troo/models/refresh.rb +2 -2
  22. data/lib/troo/remote/list.rb +1 -1
  23. data/lib/troo/remote/member.rb +1 -1
  24. data/lib/troo/remote/persistence/board.rb +6 -10
  25. data/lib/troo/remote/persistence/card.rb +6 -10
  26. data/lib/troo/remote/persistence/comment.rb +6 -10
  27. data/lib/troo/remote/persistence/list.rb +6 -10
  28. data/lib/troo/remote/persistence/move_card.rb +6 -10
  29. data/lib/troo/troo.rb +3 -2
  30. data/lib/troo/version.rb +1 -1
  31. data/test/lib/troo/api/endpoints_test.rb +12 -22
  32. data/test/lib/troo/cli/commands/status_test.rb +1 -1
  33. data/test/lib/troo/cli/wizard_test.rb +44 -0
  34. data/test/lib/troo/configuration_test.rb +39 -0
  35. data/test/lib/troo/decorators/resource_test.rb +2 -1
  36. data/test/lib/troo/models/member_test.rb +1 -1
  37. data/test/support/fake_trello/fake_response.rb +1 -2
  38. data/test/support/fake_trello/server.rb +22 -14
  39. data/test/test_helper.rb +0 -5
  40. data/troo.gemspec +1 -0
  41. metadata +20 -6
  42. data/config/trello_api.yml +0 -19
  43. data/lib/troo/decorators/member.rb +0 -12
  44. data/test/lib/troo/decorators/member_test.rb +0 -8
data/lib/troo/debug.rb CHANGED
@@ -18,4 +18,13 @@ module Troo
18
18
  RubyProf::CallStackPrinter.new(result).print(file)
19
19
  end
20
20
  end
21
+
22
+ def self.trace
23
+ trace = TracePoint.new(:call) do |tp|
24
+ if tp.defined_class.to_s.match(/Troo/)
25
+ Troo.logger.debug [tp.defined_class.to_s, tp.method_id.to_s].join(' ')
26
+ end
27
+ end
28
+ trace.enable
29
+ end
21
30
  end
@@ -39,7 +39,7 @@ module Troo
39
39
  end
40
40
  end
41
41
 
42
- # @return []
42
+ # @return [String]
43
43
  def id
44
44
  (klass.type == :card) ? klass.short_id : klass.id
45
45
  end
@@ -61,12 +61,12 @@ module Troo
61
61
  (klass.name && klass.name.chomp) || 'N/A'
62
62
  end
63
63
 
64
- # @return []
64
+ # @return [Troo::Decorators::Resource]
65
65
  def board
66
66
  klass.board.decorator
67
67
  end
68
68
 
69
- # @return []
69
+ # @return [Troo::Decorators::Resource]
70
70
  def list
71
71
  klass.list.decorator
72
72
  end
@@ -104,7 +104,11 @@ module Troo
104
104
 
105
105
  # @return [String]
106
106
  def username
107
- ['@', klass.member.username].join
107
+ if klass.type == :member
108
+ ['@', klass.username].join
109
+ else
110
+ ['@', klass.member.username].join
111
+ end
108
112
  end
109
113
 
110
114
  # @return [String]
data/lib/troo/launcher.rb CHANGED
@@ -10,27 +10,37 @@ module Troo
10
10
  stdout = STDOUT,
11
11
  stderr = STDERR,
12
12
  kernel = Kernel)
13
- @argv = argv
14
- @stdin = stdin
15
- @stdout = stdout
16
- @stderr = stderr
17
- @kernel = kernel
13
+ @argv = argv
14
+ @stdin = stdin
15
+ @stdout = stdout
16
+ @stderr = stderr
17
+ @kernel = kernel
18
+ @exit_code = 1
18
19
  end
19
20
 
20
- # @return []
21
+ # @return [String, NilClass]
21
22
  def execute!
22
23
  $stdin, $stdout, $stderr = @stdin, @stdout, @stderr
23
24
  pad { Troo::CLI::Main.start(@argv) }
24
- @kernel.exit(0)
25
- rescue Errno::ENOENT
26
- pad { puts "Configuration cannot be found, please run 'troo init'" \
27
- " first." }
28
- @kernel.exit(1)
25
+ @exit_code = 0
26
+ rescue ConfigurationNotFound
27
+ pad do
28
+ puts "Configuration cannot be found, please run " \
29
+ "`troo wizard` for help, or 'troo init' to manually " \
30
+ "configure."
31
+ end
32
+ rescue ConfigurationAborted
33
+ pad { puts 'Configuration wizard aborted.' }
29
34
  rescue Redis::CannotConnectError
30
35
  pad { puts 'Cannot connect to Redis database.' }
31
- @kernel.exit(1)
36
+ rescue ExpiredAccessToken
37
+ pad do
38
+ puts "Your Trello access token has expired, please run " \
39
+ "`troo wizard` for help, or manually renew."
40
+ end
32
41
  ensure
33
42
  $stdin, $stdout, $stderr = STDIN, STDOUT, STDERR
43
+ @kernel.exit(@exit_code)
34
44
  end
35
45
 
36
46
  private
@@ -5,8 +5,8 @@ module Troo
5
5
 
6
6
  attribute :name
7
7
  attribute :description
8
- attribute :default, Type::Boolean
9
- attribute :closed, Type::Boolean
8
+ attribute :default, Type::Boolean
9
+ attribute :closed, Type::Boolean
10
10
  attribute :external_id
11
11
  attribute :short_id
12
12
 
@@ -10,8 +10,8 @@ module Troo
10
10
  attribute :external_member_ids, Type::Array
11
11
  attribute :position
12
12
  attribute :last_activity_date
13
- attribute :default, Type::Boolean
14
- attribute :closed, Type::Boolean
13
+ attribute :default, Type::Boolean
14
+ attribute :closed, Type::Boolean
15
15
  attribute :external_board_id
16
16
  attribute :external_list_id
17
17
  attribute :external_id
@@ -31,7 +31,7 @@ module Troo
31
31
  # @param [Hash]
32
32
  # @return []
33
33
  def decorator(options = {})
34
- Decorators::Member.new(self, options)
34
+ Decorators::Resource.new(self, options)
35
35
  end
36
36
 
37
37
  # @param [Hash]
@@ -8,13 +8,13 @@ module Troo
8
8
  index :last_performed_at
9
9
 
10
10
  class << self
11
- # @return []
11
+ # @return [Troo::Refresh]
12
12
  def completed!
13
13
  all.map { |record| record.delete }
14
14
  create(last_performed_at: Time.now.to_s)
15
15
  end
16
16
 
17
- # @return []
17
+ # @return [String, NilClass]
18
18
  def last_performed_at
19
19
  first ? first.last_performed_at : nil
20
20
  end
@@ -35,7 +35,7 @@ module Troo
35
35
  []
36
36
  end
37
37
 
38
- # @return []
38
+ # @return [Troo::List]
39
39
  def local_model
40
40
  Troo::List
41
41
  end
@@ -58,7 +58,7 @@ module Troo
58
58
  []
59
59
  end
60
60
 
61
- # @return []
61
+ # @return [Troo::Member]
62
62
  def local_model
63
63
  Troo::Member
64
64
  end
@@ -7,33 +7,29 @@ module Troo
7
7
  # @param [String, NilClass]
8
8
  # @return []
9
9
  def with(name, description = nil)
10
- new(name, description).perform
10
+ new(name, description).create_local
11
11
  end
12
12
  end
13
13
 
14
14
  # @param [String]
15
15
  # @param [String, NilClass]
16
- # @return []
16
+ # @return [Troo::Remote::Persistence::Board]
17
17
  def initialize(name, description = nil)
18
18
  @name = name
19
19
  @description = description
20
20
  end
21
21
 
22
22
  # @return []
23
- def perform
24
- create_local
25
- end
26
-
27
- private
28
-
29
- attr_reader :name, :description
30
-
31
23
  def create_local
32
24
  return Troo::Persistence::Local
33
25
  .with_collection(resource).first if any?
34
26
  false
35
27
  end
36
28
 
29
+ private
30
+
31
+ attr_reader :name, :description
32
+
37
33
  def any?
38
34
  resource.any?
39
35
  end
@@ -8,14 +8,14 @@ module Troo
8
8
  # @param [String, NilClass]
9
9
  # @return []
10
10
  def with(external_list_id, name = nil, description = nil)
11
- new(external_list_id, name, description).perform
11
+ new(external_list_id, name, description).create_local
12
12
  end
13
13
  end
14
14
 
15
15
  # @param [String]
16
16
  # @param [String, NilClass]
17
17
  # @param [String, NilClass]
18
- # @return []
18
+ # @return [Troo::Remote::Persistence::Card]
19
19
  def initialize(external_list_id, name = nil, description = nil)
20
20
  @external_list_id = external_list_id
21
21
  @name = name
@@ -23,20 +23,16 @@ module Troo
23
23
  end
24
24
 
25
25
  # @return []
26
- def perform
27
- create_local
28
- end
29
-
30
- private
31
-
32
- attr_reader :external_list_id, :name, :description
33
-
34
26
  def create_local
35
27
  return Troo::Persistence::Local
36
28
  .with_collection(resource).first if any?
37
29
  false
38
30
  end
39
31
 
32
+ private
33
+
34
+ attr_reader :external_list_id, :name, :description
35
+
40
36
  def any?
41
37
  resource.any?
42
38
  end
@@ -7,33 +7,29 @@ module Troo
7
7
  # @param []
8
8
  # @return []
9
9
  def with(external_card_id, comment)
10
- new(external_card_id, comment).perform
10
+ new(external_card_id, comment).create_local
11
11
  end
12
12
  end
13
13
 
14
14
  # @param [String]
15
15
  # @param []
16
- # @return []
16
+ # @return [Troo::Remote::Persistence::Comment]
17
17
  def initialize(external_card_id, comment)
18
18
  @external_card_id = external_card_id
19
19
  @comment = comment
20
20
  end
21
21
 
22
22
  # @return []
23
- def perform
24
- create_local
25
- end
26
-
27
- private
28
-
29
- attr_reader :external_card_id, :comment
30
-
31
23
  def create_local
32
24
  return Troo::Persistence::Local
33
25
  .with_collection(resource).first if any?
34
26
  false
35
27
  end
36
28
 
29
+ private
30
+
31
+ attr_reader :external_card_id, :comment
32
+
37
33
  def any?
38
34
  resource.any?
39
35
  end
@@ -7,33 +7,29 @@ module Troo
7
7
  # @param [String]
8
8
  # @return []
9
9
  def with(external_board_id, name)
10
- new(external_board_id, name).perform
10
+ new(external_board_id, name).create_local
11
11
  end
12
12
  end
13
13
 
14
14
  # @param [String]
15
15
  # @param [String]
16
- # @return []
16
+ # @return [Troo::Remote::Persistence::List]
17
17
  def initialize(external_board_id, name)
18
18
  @external_board_id = external_board_id
19
19
  @name = name
20
20
  end
21
21
 
22
22
  # @return []
23
- def perform
24
- create_local
25
- end
26
-
27
- private
28
-
29
- attr_reader :external_board_id, :name
30
-
31
23
  def create_local
32
24
  return Troo::Persistence::Local
33
25
  .with_collection(resource).first if any?
34
26
  false
35
27
  end
36
28
 
29
+ private
30
+
31
+ attr_reader :external_board_id, :name
32
+
37
33
  def any?
38
34
  resource.any?
39
35
  end
@@ -11,14 +11,14 @@ module Troo
11
11
  external_list_id,
12
12
  external_board_id = nil)
13
13
  new(external_card_id, external_list_id, external_board_id)
14
- .perform
14
+ .update_cards
15
15
  end
16
16
  end
17
17
 
18
18
  # @param [String]
19
19
  # @param [String]
20
20
  # @param [String, NilClass]
21
- # @return []
21
+ # @return [Troo::Remote::Persistence::MoveCard]
22
22
  def initialize(external_card_id,
23
23
  external_list_id,
24
24
  external_board_id = nil)
@@ -28,8 +28,10 @@ module Troo
28
28
  end
29
29
 
30
30
  # @return []
31
- def perform
32
- update_cards
31
+ def update_cards
32
+ return Troo::Persistence::Local
33
+ .with_collection(resource).first if any?
34
+ false
33
35
  end
34
36
 
35
37
  private
@@ -38,12 +40,6 @@ module Troo
38
40
  :external_list_id,
39
41
  :external_board_id
40
42
 
41
- def update_cards
42
- return Troo::Persistence::Local
43
- .with_collection(resource).first if any?
44
- false
45
- end
46
-
47
43
  def any?
48
44
  resource.any?
49
45
  end
data/lib/troo/troo.rb CHANGED
@@ -3,8 +3,9 @@ require 'date'
3
3
  require 'dispel'
4
4
  require 'erb'
5
5
  require 'fileutils'
6
- require 'logger'
7
6
  require 'json'
7
+ require 'launchy'
8
+ require 'logger'
8
9
  require 'net/http'
9
10
  require 'oauth'
10
11
  require 'ohm'
@@ -44,7 +45,6 @@ require_relative 'remote/persistence/list'
44
45
  require_relative 'remote/persistence/move_card'
45
46
 
46
47
  require_relative 'decorators/resource'
47
- require_relative 'decorators/member'
48
48
 
49
49
  require_relative 'presentation/formatter'
50
50
  require_relative 'presentation/sentence'
@@ -87,6 +87,7 @@ require_relative 'cli/add'
87
87
  require_relative 'cli/default'
88
88
  require_relative 'cli/refresh'
89
89
  require_relative 'cli/show'
90
+ require_relative 'cli/wizard'
90
91
  require_relative 'cli/main'
91
92
 
92
93
  require_relative 'launcher'
data/lib/troo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Troo
2
- VERSION = '0.0.11'
2
+ VERSION = '0.0.12'
3
3
  end
@@ -4,42 +4,32 @@ module Troo
4
4
  module API
5
5
  describe Endpoints do
6
6
  let(:described_class) { Endpoints }
7
- let(:file) {}
8
- let(:version) {}
9
- let(:endpoints) { { board_by_id: '/boards/%{id}' } }
10
7
 
11
- before do
12
- YAML.stubs(:load_file).returns(endpoints)
13
- end
14
-
15
- describe '.load' do
16
- subject { described_class.load(file, version) }
17
-
18
- it 'returns a new instance of the class' do
19
- subject.must_be_instance_of(Endpoints)
20
- end
21
- end
22
-
23
- describe '#interpolate!' do
8
+ describe '#interpolate' do
24
9
  let(:endpoint) { :board_by_id }
25
- let(:value) { { id: '20001' } }
10
+ let(:value) { { external_id: '20001' } }
26
11
 
27
- subject do
28
- described_class.new(endpoints)
29
- .interpolate!(endpoint, value)
30
- end
12
+ subject { described_class.interpolate(endpoint, value) }
31
13
 
32
14
  context 'when the endpoint exists' do
33
15
  it 'returns the interpolated endpoint' do
34
16
  subject.must_equal('/boards/20001')
35
17
  end
18
+
19
+ context 'but the endpoint does not need interpolation' do
20
+ let(:endpoint) { :boards_all }
21
+
22
+ it 'returns the normal endpoint' do
23
+ subject.must_equal('/members/me/boards')
24
+ end
25
+ end
36
26
  end
37
27
 
38
28
  context 'when the endpoint does not exist' do
39
29
  let(:endpoint) { :wrong_endpoint }
40
30
 
41
31
  it 'raises an exception' do
42
- proc { subject }.must_raise(EndpointNotFound)
32
+ proc { subject }.must_raise(Troo::EndpointNotFound)
43
33
  end
44
34
  end
45
35
  end