lib/checkcheckit/console.rb in checkcheckit-0.0.6 vs lib/checkcheckit/console.rb in checkcheckit-0.1.0
- old
+ new
@@ -1,6 +1,7 @@
require 'ostruct'
+require 'uri'
class CheckCheckIt::Console
attr_accessor :list_dir
attr_accessor :out_stream, :in_stream, :web_socket
@@ -39,30 +40,25 @@
return
end
list_name = Dir[dir + '/*/*'].find{ |fname| fname.include? target }
if list_name
list = List.new(list_name)
- web_service_url = ENV['CHECKCHECKIT_URL']
- client = nil
if (emails = @options['email']) || @options['live']
-
@list_id = list_id = notify_server_of_start(emails, list)
+ puts "Live at URL: #{URI.join(web_service_url, list_id)}"
- puts "Live at URL: #{web_service_url}/#{list_id}"
-
- if @options['ws']
- begin
- @client = web_socket.connect(web_service_url, sync: true) do
- after_start { emit('register', {list_id: list_id}) }
- end
- rescue Errno::ECONNREFUSED => e
- STDERR.puts "Websocket refused connection"
+ begin
+ @client = web_socket.connect(web_service_url, sync: true) do
+ after_start { emit('register', {list_id: list_id}) }
end
+ rescue Errno::ECONNREFUSED, WebSocket::Error => e
+ STDERR.puts "Websocket refused connection - using POST"
+ @use_post = true
end
end
- return if @options['no-cli'] || @options['n']
+ return if @options['no-cli'] || @options['web']
step_through_list(list)
else
puts "Could not find checklist via: #{target}"
end
end
@@ -112,10 +108,14 @@
list_id: @list_id,
step_id: i
}
end
+ if @use_post
+ post_check(@list_id, i)
+ end
+
results[i] = {
step: i + 1,
name: step.name,
body: step.body,
check: check,
@@ -157,9 +157,19 @@
@out_stream.print text
end
def web_service_url
ENV['CHECKCHECKIT_URL']
+ end
+
+ def post_check(list_id, step_id)
+ begin
+ url = URI.join(web_service_url, "/#{list_id}/check/#{step_id}").to_s
+ STDERR.puts url
+ Excon.post(url)
+ rescue Excon::Errors::SocketError, ArgumentError => e
+ puts "Error POSTing to #{url}"
+ end
end
# Returns id
def notify_server_of_start(emails, list)
begin