Skip to content

Instantly share code, notes, and snippets.

@xzyfer
Last active August 29, 2015 14:27
Show Gist options
  • Select an option

  • Save xzyfer/cfe1f94d11261e1d3407 to your computer and use it in GitHub Desktop.

Select an option

Save xzyfer/cfe1f94d11261e1d3407 to your computer and use it in GitHub Desktop.
A simple rake script for triggering Calibre snapshots via the HTTP API
require "net/http"
namespace :calibre do
desc "Trigger a Calibre snapshot to run"
task :create_snapshot => :environment do
res = calibre_api
case res
when Net::HTTPSuccess then
say "<%= color('#{checkmark_icon} triggered Calibre snapshot successfully', GREEN) %>"
else
say "<%= color('#{warning_icon} triggering Calibre snapshot failed with status code #{res.code}', RED) %>"
end
end
end
def calibre_api
uri = URI("https://calibreapp.com/api/sites/#{calibre_app}/snapshots")
res = Net::HTTP.post_form(uri, "api_key" => calibre_apikey)
end
def calibre_apikey
apikey = ENV['CALIBRE_API_KEY']
unless apikey
say "<%= color('#{warning_icon} missing CALIBRE_API_KEY environment variable', RED) %>"
exit 1
end
apikey
end
def calibre_app
app = ENV['CALIBRE_APP']
unless app
say "<%= color('#{warning_icon} missing CALIBRE_APP environment variable', RED) %>"
exit 1
end
app
end
def warning_icon
"\u26A0"
end
def checkmark_icon
"\u2713"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment