Created
November 29, 2013 12:10
-
-
Save luxerama/7704832 to your computer and use it in GitHub Desktop.
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
class Auth | |
attr_accessible :token | |
def authorised? | |
token = self.token if token.valid? | |
token =|| token.refresh | |
token ? true : false | |
end | |
end |
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
class Profile | |
def self.fetch | |
raise UnauthoriseError, 'Un-Authorised attempt to fetch profile' unless Auth.authorised? | |
# continue fetching profile | |
end | |
end |
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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@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.