Skip to content

Instantly share code, notes, and snippets.

@ltw
Created January 28, 2016 02:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ltw/8977567e3fd880c475dc to your computer and use it in GitHub Desktop.
Save ltw/8977567e3fd880c475dc to your computer and use it in GitHub Desktop.
A script to check GitHub's status.
require 'json'
require 'net/http'
status = nil
until status == 'good'
url = URI('https://status.github.com/api/status.json')
response = Net::HTTP.get(url)
body = JSON.parse(response)
p body
status = body['status']
sleep 5
end
puts 'GitHub has recovered!'
require 'json'
require 'net/http'
# initialize the status with some harmless value. this lets us check the value the first time without getting an error.
status = nil
# until we modify the `status` variable to equal 'good' (the options are 'good', 'minor' or 'major')
until status == 'good'
# the Net::HTTP get method demands an URI object, that gets initialized by the full URL string
url = URI('https://status.github.com/api/status.json')
# this actually goes and gets the information from the github servers.
response = Net::HTTP.get(url)
# the response is in a format called JSON (or JavaScript Object Notation) - this parses it into a Ruby Hash
body = JSON.parse(response)
# print out the Ruby hash containing the status information
p body
# set the `status` variable to equal the status information from the GitHub servers
status = body['status']
# wait for 5 seconds so that we don't just keep spamming the GitHub servers
sleep 5
end
# this line will not be executed until the loop stops. the loop will only stop until the status == 'good'
puts 'GitHub has recovered!'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment