Created
April 4, 2012 09:06
-
-
Save jlebrech/2299836 to your computer and use it in GitHub Desktop.
Ruby callbacks
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 self.login(game, &block) | |
set_game(game) | |
logger = Rails.logger | |
logger.debug "Logging in" | |
@game = game | |
curl = Curl::Easy.perform(@login_url) | |
resp = JSON.parse(curl.body_str) | |
@authToken = resp["authToken"] | |
#@authToken = "nope" | |
logger.debug curl.body_str | |
if resp.key?(:authToken) then | |
@authToken = resp["authToken"] | |
yield | |
#logger.debug "Logged in (" + @authToken + ")" | |
else | |
# this just raises the net/http response that was raised | |
return | |
end | |
end | |
def get_profiles(search={}) | |
# curl profile data | |
... | |
# if response is success | |
... | |
# else | |
login(@game) { get_profiles(search) } # want this line to rerun get_profiles after another login, and limit to one retry | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment