lib/checkcheckit/console.rb in checkcheckit-0.3.1 vs lib/checkcheckit/console.rb in checkcheckit-0.4.0
- old
+ new
@@ -8,11 +8,10 @@
attr_accessor :out_stream, :in_stream, :web_socket
def initialize(opts = {})
@out_stream = opts[:out_stream] || $stdout
@in_stream = opts[:in_stream] || $stdin
- @web_socket = opts[:web_socket] || SocketIO
end
def dir
File.expand_path(@list_dir)
end
@@ -69,18 +68,11 @@
Process.detach fork{ exec("open #{url}") }
end
return if @options['no-cli'] || @options['web-only']
- 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, RuntimeError => e
- $stderr.puts "Websocket refused connection - using POST"
- @use_post = true
- end
+ @live = true
end
step_through_list(list)
else
puts "Could not find checklist via: #{target}"
@@ -140,11 +132,11 @@
rescue Interrupt => e
puts "\nGoodbye!"
return
end
- if check
+ if check && @live
update_server_with_step(i)
end
results[i] = {
step: i + 1,
@@ -191,19 +183,10 @@
def web_service_url
ENV['CHECKCHECKIT_URL'] || DEFAULT_URL
end
- def post_check(list_id, step_id)
- begin
- url = URI.join(web_service_url, "/#{list_id}/check/#{step_id}").to_s
- 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
response = Excon.post(web_service_url, :body => {
emails: emails,
@@ -217,13 +200,14 @@
rescue Excon::Errors::SocketError => e
puts "Error connecting to #{web_service_url}"
end
end
- def update_server_with_step(i)
- if @client
- @client.emit 'check', {list_id: @list_id, step_id: i}
- elsif @use_post
- post_check(@list_id, i)
+ def update_server_with_step(step_id)
+ begin
+ url = URI.join(web_service_url, "/#{@list_id}/check/#{step_id}").to_s
+ Excon.post(url)
+ rescue Excon::Errors::SocketError, ArgumentError => e
+ puts "Error POSTing to #{url}"
end
end
end