Class: Serel::AccessToken
Overview
AccessToken is a special helper class designed to make it easier to use access tokens.
It doesn’t handle the retrieval of the token, merely provides a way to get it into Serel. Creating a new AccessToken provides a couple of helper methods to access authorized methods and identify who a user is.
Instance Method Summary collapse
-
#inbox ⇒ Serel::Response
Retrieve the users’ inbox items.
-
#initialize(token) ⇒ Serel::AccessToken
constructor
Create a new instance of AccessToken.
-
#invalidate ⇒ Object
Invalidates the access token Serel::AccessToken.new(token).invalidate.
-
#unread_inbox ⇒ Serel::Response
Retrieve the users’ unread inbox items.
-
#user ⇒ Serel::User
Retrieve the user associated with this access token.
Methods inherited from Base
#[], #[]=, #all, associations, attribute, config, #find, finder_methods, #get, #inspect, #meth, method_missing, #network, network_wide, new_relation, request, respond_to?, #type, with_ids
Constructor Details
#initialize(token) ⇒ Serel::AccessToken
Create a new instance of AccessToken.
15 16 17 18 |
# File 'lib/serel/access_token.rb', line 15 def initialize(token) @data = {} @data[:token] = token end |
Instance Method Details
#inbox ⇒ Serel::Response
Retrieve the users’ inbox items.
Serel::AccessToken.new(token).inbox.get
Serel::AccessToken.new(token).scoping_methods.inbox.get
This is a scoping method and can be combined with other scoping methods.
26 27 28 |
# File 'lib/serel/access_token.rb', line 26 def inbox type(:inbox).access_token(self.token).url("me/inbox") end |
#invalidate ⇒ Object
Invalidates the access token
Serel::AccessToken.new(token).invalidate
41 42 43 |
# File 'lib/serel/access_token.rb', line 41 def invalidate network.url("access-tokens/#{token}/invalidate").get end |
#unread_inbox ⇒ Serel::Response
Retrieve the users’ unread inbox items.
Serel::AccessToken.new(token).unread_inbox.get
This is a scoping method and can be combined with other scoping methods.
35 36 37 |
# File 'lib/serel/access_token.rb', line 35 def unread_inbox type(:inbox).access_token(self.token).url("me/inbox/unread") end |
#user ⇒ Serel::User
Retrieve the user associated with this access token.
Serel::AccessToken.new(token).user
This does not return a Response object, rather it directly returns the User.
51 52 53 |
# File 'lib/serel/access_token.rb', line 51 def user type(:user, :singular).access_token(self.token).url("me").get end |