Class: Serel::AccessToken

Inherits:
Base
  • Object
show all
Defined in:
lib/serel/access_token.rb

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

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.

Parameters:

  • token (String)

    The access token you wish to use.



15
16
17
18
# File 'lib/serel/access_token.rb', line 15

def initialize(token)
  @data = {}
  @data[:token] = token
end

Instance Method Details

#inboxSerel::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.

Returns:



26
27
28
# File 'lib/serel/access_token.rb', line 26

def inbox
  type(:inbox).access_token(self.token).url("me/inbox")
end

#invalidateObject

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_inboxSerel::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.

Returns:



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

#userSerel::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.

Returns:

  • (Serel::User)

    The user associated with the access token.



51
52
53
# File 'lib/serel/access_token.rb', line 51

def user
  type(:user, :singular).access_token(self.token).url("me").get
end