Skip to content

Instantly share code, notes, and snippets.

@maier-stefan
Last active August 29, 2015 14:14
Show Gist options
  • Save maier-stefan/a0ab7e1fbe4f9dd8b90b to your computer and use it in GitHub Desktop.
Save maier-stefan/a0ab7e1fbe4f9dd8b90b to your computer and use it in GitHub Desktop.
initalizer to get auth key from third party provider
def initialize(username, password)
auth = {:username => username, :password => password}
begin
begin
response = HTTParty.get("https://security.example.com/login", :basic_auth => auth)
case response.code
when 200
puts "All good!"
data = JSON.parse(response.body)
@token = token = JSON.parse(response.body)['token']
when 404
puts "O noes not found!"
when 500...600
puts "ZOMG ERROR #{response.code}"
end
rescue Exception => e
puts "#{e.message}"
end
end while response.code != 200
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment