ki_trello 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/bin/ki_trello CHANGED
@@ -17,12 +17,24 @@ require 'rubygems'
17
17
  require 'gli'
18
18
  require 'ki_trello'
19
19
  require 'colored'
20
- include GLI
20
+ include GLI::App
21
21
 
22
22
  program_desc 'A Kiseru client for Trello'
23
23
 
24
24
  version KiTrello::VERSION
25
25
 
26
+ def find_input(filename)
27
+ if filename.nil? || filename.empty?
28
+ if $stdin.tty?
29
+ nil
30
+ else
31
+ $stdin
32
+ end
33
+ else
34
+ File.open(filename,'r')
35
+ end
36
+ end
37
+
26
38
  desc 'Initialise config files'
27
39
  command :init do |c|
28
40
  c.action do |global_options,options,args|
@@ -58,11 +70,21 @@ desc 'Create new card'
58
70
  command :new_card do |c|
59
71
  c.desc "The list ID"
60
72
  c.flag [:list]
73
+ c.desc "Interactive mode"
74
+ c.switch [:i]
75
+ c.arg_name 'file'
61
76
  c.action do |global_options, options, args|
62
- received_json = $stdin.read
63
- unless list_id = options[:list]
64
- list_id = MultiJson.load(received_json)['idList']
77
+ input = find_input(args.first)
78
+ help_now!(nil) unless input
79
+ received_json = input.read
80
+
81
+ list_id = options[:list]
82
+ if options[:i] && list_id.nil?
83
+ board_id = KiTrello::Interactive.new.select_board("Which board?")
84
+ list_id = KiTrello::Interactive.new.select_list(board_id, "Which list?")
65
85
  end
86
+
87
+ list_id ||= MultiJson.load(received_json)['idList']
66
88
  command = KiTrello::Command.new
67
89
  command.create_card(received_json, { :list => list_id })
68
90
  end
@@ -72,12 +94,12 @@ desc 'List lists in board'
72
94
  command :lists do |c|
73
95
  c.desc "The board ID"
74
96
  c.flag [:board]
75
- c.desc "Interactive Mode"
97
+ c.desc "Interactive mode"
76
98
  c.switch [:i]
77
99
  c.action do |global_options, options, args|
78
100
  unless board_id = options[:board]
79
101
  if options[:i]
80
- board_id = KiTrello::Interactive.select_board("\n Which board would you like to view?")
102
+ board_id = KiTrello::Interactive.new.select_item("Which board?")
81
103
  else
82
104
  end
83
105
  end
@@ -86,4 +108,4 @@ command :lists do |c|
86
108
  end
87
109
  end
88
110
 
89
- exit GLI.run(ARGV)
111
+ exit run(ARGV)
data/ki_trello.gemspec CHANGED
@@ -18,9 +18,10 @@ Gem::Specification.new do |gem|
18
18
  gem.add_dependency('colored', '~> 1.2.0')
19
19
  gem.add_dependency('faraday', '~> 0.8.2')
20
20
  gem.add_dependency('faraday_middleware', '~> 0.8.8')
21
- gem.add_dependency('gli', '~> 1.6.0')
21
+ gem.add_dependency('gli', '~> 2.2.1')
22
22
  gem.add_dependency('multi_json', '~> 1.3.6')
23
23
  gem.add_dependency('json_pure', '~> 1.7.4')
24
+ gem.add_dependency('map', '~> 6.2.0')
24
25
 
25
26
  gem.add_development_dependency('debugger', '~> 1.2.0')
26
27
  gem.add_development_dependency('rake', '~> 0.9.2')
@@ -1,18 +1,28 @@
1
- # TODO - this is duplicated in ki_pivotal
1
+ require 'map'
2
+ require 'colored'
3
+
4
+ # TODO - This should move up into Kiseru gem
2
5
 
3
6
  module KiTrello
4
7
 
5
8
  class Interactive
6
- # "Resistance is futile!", "We will get an answer!"
7
- def self.repeatedly_ask(question)
9
+
10
+ def initialize(input=$stdin, output=$stderr)
11
+ @input = input
12
+ @output = output
13
+ end
14
+
15
+ # "Resistance is futile!", "We will get an answer!"
16
+ def repeatedly_ask(question)
8
17
  response = ""
9
18
  while response == ""
10
- response = simple_query(question)
19
+ response = simple_query("\n "+question)
11
20
  end
12
21
  response
13
22
  end
14
- # "We have ways of making you talk!"
15
- def self.repeatedly_choose_from(things, question)
23
+
24
+ # "We have ways of making you talk!"
25
+ def repeatedly_choose_from(things, question)
16
26
  index = nil
17
27
  while index.nil?
18
28
  index = choose_from_many(things, question)
@@ -20,77 +30,60 @@ module KiTrello
20
30
  index
21
31
  end
22
32
 
23
- def self.choose_from_many(things, question)
24
- $stderr.puts "\n "+question
33
+ def choose_from_many(things, question)
34
+ @output.puts "\n "+question.to_s
25
35
 
26
- things.each_with_index { |thing, index| $stderr.puts " #{index+1} ".green + " #{thing}" }
36
+ things.each_with_index do |thing, index|
37
+ @output.puts " #{index+1} ".green + " #{thing}"
38
+ end
27
39
 
28
- index = ( (simple_query( "Enter an index (#{(1..things.size)})" ).to_i) - 1 )
40
+ index = ( (simple_query( "(#{(1..things.size)})").to_i) - 1 )
29
41
  index = ( index >= 0 && index < things.size ) ? index : nil
30
42
  end
31
43
 
32
- def self.simple_query(prompt)
44
+ def simple_query(prompt)
33
45
  if prompt.nil?
34
- $stderr.print "\n> "
46
+ @output.print "\n> "
35
47
  else
36
- $stderr.print "\n #{prompt}: "
48
+ @output.print "\n #{prompt}: "
37
49
  end
38
- $stdin.gets.chomp
50
+ @input.gets.chomp
39
51
  end
40
52
 
41
- def self.select_board(prompt)
42
- boards = MultiJson.load(KiTrello::Command.new.boards)
43
- if boards.size > 1
44
- index = repeatedly_choose_from(boards.map { |b| b['name'] }, prompt)
45
- else
46
- index = 0
47
- end
48
- $stderr.puts "\n Chosen board is #{boards[index]['name']}"
49
- boards[index]['id']
53
+ def select_item(items, prompt=nil, input=$stdin, output=$stdout, err=$stderr)
54
+ items = mapify(items)
55
+ index = get_index(items, prompt)
56
+ return index if index.nil?
57
+ items[index]['id']
50
58
  end
51
59
 
52
- def self.select_story(project_id, prompt)
53
- stories = MultiJson.load(KiPivotal::Api.new.stories_in_project(project_id))
54
-
55
- if stories.size > 1
56
- index = repeatedly_choose_from(stories.map { |p| p['name'] }, prompt)
57
- else
58
- index = 0
59
- end
60
+ def select_list(board_id, prompt)
61
+ lists = MultiJson.load(KiTrello::Command.new.lists(board_id))
62
+ select_item(lists, prompt)
63
+ end
60
64
 
61
- $stderr.puts "\n Chosen story is '#{stories[index]['name']}'"
62
- stories[index]['id']
65
+ def select_board(prompt)
66
+ boards = MultiJson.load(KiTrello::Command.new.boards)
67
+ select_item(boards, prompt)
63
68
  end
64
69
 
65
- def self.select_project(prompt)
66
- projects = MultiJson.load(KiPivotal::Api.new.projects)
70
+ private
71
+
72
+ def mapify(items)
73
+ Array(items).map { |x| Map(x) }
74
+ end
67
75
 
68
- if projects.size > 1
69
- index = repeatedly_choose_from(projects.map { |p| p['name'] }, prompt)
76
+ def get_index(items, prompt)
77
+ case items.size
78
+ when 0
79
+ return nil
80
+ when 1
81
+ 0
70
82
  else
71
- index = 0
83
+ repeatedly_choose_from(items.map(&:name), prompt)
72
84
  end
73
-
74
- $stderr.puts "\n Chosen project is '#{projects[index]['name']}'"
75
- projects[index]['id']
76
85
  end
77
86
 
78
- def self.new_story
79
- name = repeatedly_ask("Name of story")
80
-
81
- description = repeatedly_ask("Description of story")
82
-
83
- types = ["bug","feature","release","chore"]
84
- type = types[repeatedly_choose_from(types, "What type of story is this?")]
85
-
86
- {
87
- name: name,
88
- description: description,
89
- story_type: type,
90
- requested_by: 'Kiseru',
91
- ki_type: 'pivotal_story'
92
- }.to_json
93
- end
94
87
  end
95
88
  end
96
89
 
@@ -32,13 +32,12 @@ module KiTrello
32
32
  end
33
33
 
34
34
  def card(card_id)
35
- response = connection.get("/1/cards/#{card_id}", auth_params)
35
+ response = connection.get("/1/cards/#{card_id}", auth_params.merge(:checklists => 'all'))
36
36
 
37
37
  case response.status
38
38
  when 200
39
- response.body
39
+ response.body.merge('ki_type' => 'trello_card')
40
40
  else
41
- debugger
42
41
  raise SessionError, "Unhandled status code #{response.status}: #{response.body}"
43
42
  end
44
43
  end
@@ -1,3 +1,3 @@
1
1
  module KiTrello
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -49,6 +49,7 @@ describe Command do
49
49
 
50
50
  card = as_data(out)
51
51
  card['name'].should == "Test card 001"
52
+ card['ki_type'].should == "trello_card"
52
53
 
53
54
  # Sorry for this test, not sure how to get the short name
54
55
  out, err = with_command do |command|
@@ -66,6 +67,20 @@ describe Command do
66
67
  card['name'].should == "Test card 001"
67
68
  end
68
69
 
70
+ it "gets checklists with card", :vcr do
71
+ out, err = with_command do |command|
72
+ command.get_card("503b9388a2a5a25554bae2e7")
73
+ end
74
+
75
+ card = as_data(out)
76
+ checklists = card['checklists']
77
+ checklists.length.should == 2
78
+ checklists.first['name'].should == 'Checklist 1'
79
+ checklists.first['checkItems'].length.should == 2
80
+ checklists.last['name'].should == 'Checklist 2'
81
+ checklists.last['checkItems'].length.should == 1
82
+ end
83
+
69
84
  it "creates card in board", :vcr do
70
85
  json =<<-JSON
71
86
  {
data/spec/spec_helper.rb CHANGED
@@ -38,3 +38,16 @@ RSpec.configure do |config|
38
38
  # --seed 1234
39
39
  config.order = 'random'
40
40
  end
41
+
42
+ # TODO - should move to Kiseru
43
+ module Helpers
44
+ def with_io(input_string)
45
+ input = StringIO.new(input_string.to_s)
46
+ error = StringIO.new
47
+ output = StringIO.new
48
+ yield input, output, error
49
+ output.rewind
50
+ error.rewind
51
+ [output.read, error.read]
52
+ end
53
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ki_trello
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-20 00:00:00.000000000 Z
12
+ date: 2012-09-30 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: colored
16
- requirement: !ruby/object:Gem::Requirement
16
+ requirement: &70093973076780 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,15 +21,10 @@ dependencies:
21
21
  version: 1.2.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ~>
28
- - !ruby/object:Gem::Version
29
- version: 1.2.0
24
+ version_requirements: *70093973076780
30
25
  - !ruby/object:Gem::Dependency
31
26
  name: faraday
32
- requirement: !ruby/object:Gem::Requirement
27
+ requirement: &70093973076280 !ruby/object:Gem::Requirement
33
28
  none: false
34
29
  requirements:
35
30
  - - ~>
@@ -37,15 +32,10 @@ dependencies:
37
32
  version: 0.8.2
38
33
  type: :runtime
39
34
  prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ~>
44
- - !ruby/object:Gem::Version
45
- version: 0.8.2
35
+ version_requirements: *70093973076280
46
36
  - !ruby/object:Gem::Dependency
47
37
  name: faraday_middleware
48
- requirement: !ruby/object:Gem::Requirement
38
+ requirement: &70093973075700 !ruby/object:Gem::Requirement
49
39
  none: false
50
40
  requirements:
51
41
  - - ~>
@@ -53,31 +43,21 @@ dependencies:
53
43
  version: 0.8.8
54
44
  type: :runtime
55
45
  prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ~>
60
- - !ruby/object:Gem::Version
61
- version: 0.8.8
46
+ version_requirements: *70093973075700
62
47
  - !ruby/object:Gem::Dependency
63
48
  name: gli
64
- requirement: !ruby/object:Gem::Requirement
49
+ requirement: &70093973074960 !ruby/object:Gem::Requirement
65
50
  none: false
66
51
  requirements:
67
52
  - - ~>
68
53
  - !ruby/object:Gem::Version
69
- version: 1.6.0
54
+ version: 2.2.1
70
55
  type: :runtime
71
56
  prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ~>
76
- - !ruby/object:Gem::Version
77
- version: 1.6.0
57
+ version_requirements: *70093973074960
78
58
  - !ruby/object:Gem::Dependency
79
59
  name: multi_json
80
- requirement: !ruby/object:Gem::Requirement
60
+ requirement: &70093973074020 !ruby/object:Gem::Requirement
81
61
  none: false
82
62
  requirements:
83
63
  - - ~>
@@ -85,15 +65,10 @@ dependencies:
85
65
  version: 1.3.6
86
66
  type: :runtime
87
67
  prerelease: false
88
- version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
- requirements:
91
- - - ~>
92
- - !ruby/object:Gem::Version
93
- version: 1.3.6
68
+ version_requirements: *70093973074020
94
69
  - !ruby/object:Gem::Dependency
95
70
  name: json_pure
96
- requirement: !ruby/object:Gem::Requirement
71
+ requirement: &70093973073140 !ruby/object:Gem::Requirement
97
72
  none: false
98
73
  requirements:
99
74
  - - ~>
@@ -101,15 +76,21 @@ dependencies:
101
76
  version: 1.7.4
102
77
  type: :runtime
103
78
  prerelease: false
104
- version_requirements: !ruby/object:Gem::Requirement
79
+ version_requirements: *70093973073140
80
+ - !ruby/object:Gem::Dependency
81
+ name: map
82
+ requirement: &70093973051180 !ruby/object:Gem::Requirement
105
83
  none: false
106
84
  requirements:
107
85
  - - ~>
108
86
  - !ruby/object:Gem::Version
109
- version: 1.7.4
87
+ version: 6.2.0
88
+ type: :runtime
89
+ prerelease: false
90
+ version_requirements: *70093973051180
110
91
  - !ruby/object:Gem::Dependency
111
92
  name: debugger
112
- requirement: !ruby/object:Gem::Requirement
93
+ requirement: &70093973050440 !ruby/object:Gem::Requirement
113
94
  none: false
114
95
  requirements:
115
96
  - - ~>
@@ -117,15 +98,10 @@ dependencies:
117
98
  version: 1.2.0
118
99
  type: :development
119
100
  prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
- requirements:
123
- - - ~>
124
- - !ruby/object:Gem::Version
125
- version: 1.2.0
101
+ version_requirements: *70093973050440
126
102
  - !ruby/object:Gem::Dependency
127
103
  name: rake
128
- requirement: !ruby/object:Gem::Requirement
104
+ requirement: &70093973049960 !ruby/object:Gem::Requirement
129
105
  none: false
130
106
  requirements:
131
107
  - - ~>
@@ -133,15 +109,10 @@ dependencies:
133
109
  version: 0.9.2
134
110
  type: :development
135
111
  prerelease: false
136
- version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
- requirements:
139
- - - ~>
140
- - !ruby/object:Gem::Version
141
- version: 0.9.2
112
+ version_requirements: *70093973049960
142
113
  - !ruby/object:Gem::Dependency
143
114
  name: rspec
144
- requirement: !ruby/object:Gem::Requirement
115
+ requirement: &70093973049360 !ruby/object:Gem::Requirement
145
116
  none: false
146
117
  requirements:
147
118
  - - ~>
@@ -149,15 +120,10 @@ dependencies:
149
120
  version: 2.11.0
150
121
  type: :development
151
122
  prerelease: false
152
- version_requirements: !ruby/object:Gem::Requirement
153
- none: false
154
- requirements:
155
- - - ~>
156
- - !ruby/object:Gem::Version
157
- version: 2.11.0
123
+ version_requirements: *70093973049360
158
124
  - !ruby/object:Gem::Dependency
159
125
  name: simplecov
160
- requirement: !ruby/object:Gem::Requirement
126
+ requirement: &70093973048680 !ruby/object:Gem::Requirement
161
127
  none: false
162
128
  requirements:
163
129
  - - ~>
@@ -165,15 +131,10 @@ dependencies:
165
131
  version: 0.6.4
166
132
  type: :development
167
133
  prerelease: false
168
- version_requirements: !ruby/object:Gem::Requirement
169
- none: false
170
- requirements:
171
- - - ~>
172
- - !ruby/object:Gem::Version
173
- version: 0.6.4
134
+ version_requirements: *70093973048680
174
135
  - !ruby/object:Gem::Dependency
175
136
  name: test-construct
176
- requirement: !ruby/object:Gem::Requirement
137
+ requirement: &70093973047960 !ruby/object:Gem::Requirement
177
138
  none: false
178
139
  requirements:
179
140
  - - ~>
@@ -181,15 +142,10 @@ dependencies:
181
142
  version: 1.2.0
182
143
  type: :development
183
144
  prerelease: false
184
- version_requirements: !ruby/object:Gem::Requirement
185
- none: false
186
- requirements:
187
- - - ~>
188
- - !ruby/object:Gem::Version
189
- version: 1.2.0
145
+ version_requirements: *70093973047960
190
146
  - !ruby/object:Gem::Dependency
191
147
  name: vcr
192
- requirement: !ruby/object:Gem::Requirement
148
+ requirement: &70093973047340 !ruby/object:Gem::Requirement
193
149
  none: false
194
150
  requirements:
195
151
  - - ~>
@@ -197,15 +153,10 @@ dependencies:
197
153
  version: 2.2.4
198
154
  type: :development
199
155
  prerelease: false
200
- version_requirements: !ruby/object:Gem::Requirement
201
- none: false
202
- requirements:
203
- - - ~>
204
- - !ruby/object:Gem::Version
205
- version: 2.2.4
156
+ version_requirements: *70093973047340
206
157
  - !ruby/object:Gem::Dependency
207
158
  name: webmock
208
- requirement: !ruby/object:Gem::Requirement
159
+ requirement: &70093973046800 !ruby/object:Gem::Requirement
209
160
  none: false
210
161
  requirements:
211
162
  - - ~>
@@ -213,12 +164,7 @@ dependencies:
213
164
  version: 1.8.9
214
165
  type: :development
215
166
  prerelease: false
216
- version_requirements: !ruby/object:Gem::Requirement
217
- none: false
218
- requirements:
219
- - - ~>
220
- - !ruby/object:Gem::Version
221
- version: 1.8.9
167
+ version_requirements: *70093973046800
222
168
  description: A Kiseru client for Trello
223
169
  email:
224
170
  - ben@freeagent.com
@@ -263,7 +209,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
263
209
  version: '0'
264
210
  requirements: []
265
211
  rubyforge_project:
266
- rubygems_version: 1.8.24
212
+ rubygems_version: 1.8.10
267
213
  signing_key:
268
214
  specification_version: 3
269
215
  summary: A Kiseru client for Trello