Skip to content

Instantly share code, notes, and snippets.

@jlebrech
Created April 4, 2012 09:06
Show Gist options
  • Save jlebrech/2299836 to your computer and use it in GitHub Desktop.
Save jlebrech/2299836 to your computer and use it in GitHub Desktop.
Ruby callbacks
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