Skip to content

Instantly share code, notes, and snippets.

@luxerama
Created November 29, 2013 12:10
Show Gist options
  • Save luxerama/7704832 to your computer and use it in GitHub Desktop.
Save luxerama/7704832 to your computer and use it in GitHub Desktop.
class Auth
attr_accessible :token
def authorised?
token = self.token if token.valid?
token =|| token.refresh
token ? true : false
end
end
class Profile
def self.fetch
raise UnauthoriseError, 'Un-Authorised attempt to fetch profile' unless Auth.authorised?
# continue fetching profile
end
end
class Token
attr_accessible :token, :expires_in, :refresh_token
def valid?
# return false if expired, true otherwise
end
def refresh_token
# refresh token and expiry
end
end
@luxerama
Copy link
Author

@adtaylor, you could even take this further by abstracting all this fetching stuff into a mixin or something. Then all you need to do is set the endpoint for the resource profile and give it the token instance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment