Last active
August 29, 2015 14:14
-
-
Save maier-stefan/a0ab7e1fbe4f9dd8b90b to your computer and use it in GitHub Desktop.
initalizer to get auth key from third party provider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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