lib/lolcommits/plugin/lolsrv.rb in lolcommits-lolsrv-0.0.2 vs lib/lolcommits/plugin/lolsrv.rb in lolcommits-lolsrv-0.0.3

- old
+ new

@@ -45,11 +45,11 @@ options = super if options['enabled'] print "server: " options.merge!('server' => parse_user_input(gets.strip)) puts '---------------------------------------------------------------' - puts ' Lolsrv - Sync and upload lolcommits to a remote Server' + puts ' Lolsrv - Upload and sync lolcommits to a remote server' puts '' puts ' Handle POST /uplol with these request params' puts '' puts ' `lol` - captured lolcommit image file' puts ' `url` - remote repository URL (with commit SHA appended)' @@ -81,32 +81,46 @@ private ## + # Message to show if syncing fails # + # @return [String] message text + # + def fail_message + "failed :( (try again with --debug)\n" + end + + ## + # # Syncs lolcommmit images to the remote server # # Fetches from /lols and iterates over objects in the JSON array # For each image found in the local loldir folder, check if it has already # been uploaded. If not upload the image with a POST request and # upload_params. # # Upload requests that fail are skipped. # def sync + print "Syncing with lolsrv ... " existing = existing_lols - if existing.nil? - # abort sync when invalid response or error from lols_endpoint - debug "aborting sync, #{lols_endpoint} failed to return a valid JSON response" - return + # abort sync when invalid response or error from lols_endpoint + unless existing + print fail_message; return end Dir[runner.config.loldir + '/*.{jpg,gif}'].each do |image| sha = File.basename(image, '.*') - upload(image, sha) unless existing.include?(sha) || sha == 'tmp_snapshot' + response = upload(image, sha) unless existing.include?(sha) || sha == 'tmp_snapshot' + unless response + print fail_message; return + end end + + print "done!\n" end ## # # Fetch and parse JSON response from `server/lols`, returning an array of