Class: Rallio::AccessToken

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

Overview

Represents an access token object as it comes from Rallio.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

app_credentials

Instance Attribute Details

#access_tokenString

Returns actual access token string.

Returns:

  • (String)

    actual access token string



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rallio/access_token.rb', line 12

class AccessToken < Base
  attribute :access_token, String
  attribute :user_id, Integer
  attribute :expires_at, DateTime
  attribute :scopes, String

  # Creates new access token for user_id.
  #
  # NOTE: These tokens do not expire so it is suggested (recommended) that the
  # token be cached and reused whenever possible.
  #
  # @param user_id [Integer]
  # @return [Rallio::AccessToken]
  def self.create(user_id:)
    response = self.post("/users/#{user_id}/access_tokens", headers: app_credentials)
    new response.parsed_response
  end

  # Destroys access_token
  #
  # @return [true, nil] true if successful or nil
  def destroy
    headers = { 'Authorization' => "Bearer #{access_token}" }
    self.class.delete('/access_token', headers: headers)
    true
  end
end

#expires_atDateTime?

Returns expiration DateTime or nil if access token never expires.

Returns:

  • (DateTime, nil)

    expiration DateTime or nil if access token never expires



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rallio/access_token.rb', line 12

class AccessToken < Base
  attribute :access_token, String
  attribute :user_id, Integer
  attribute :expires_at, DateTime
  attribute :scopes, String

  # Creates new access token for user_id.
  #
  # NOTE: These tokens do not expire so it is suggested (recommended) that the
  # token be cached and reused whenever possible.
  #
  # @param user_id [Integer]
  # @return [Rallio::AccessToken]
  def self.create(user_id:)
    response = self.post("/users/#{user_id}/access_tokens", headers: app_credentials)
    new response.parsed_response
  end

  # Destroys access_token
  #
  # @return [true, nil] true if successful or nil
  def destroy
    headers = { 'Authorization' => "Bearer #{access_token}" }
    self.class.delete('/access_token', headers: headers)
    true
  end
end

#scopesString

Returns list of oauth scopes for the access token.

Returns:

  • (String)

    list of oauth scopes for the access token



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rallio/access_token.rb', line 12

class AccessToken < Base
  attribute :access_token, String
  attribute :user_id, Integer
  attribute :expires_at, DateTime
  attribute :scopes, String

  # Creates new access token for user_id.
  #
  # NOTE: These tokens do not expire so it is suggested (recommended) that the
  # token be cached and reused whenever possible.
  #
  # @param user_id [Integer]
  # @return [Rallio::AccessToken]
  def self.create(user_id:)
    response = self.post("/users/#{user_id}/access_tokens", headers: app_credentials)
    new response.parsed_response
  end

  # Destroys access_token
  #
  # @return [true, nil] true if successful or nil
  def destroy
    headers = { 'Authorization' => "Bearer #{access_token}" }
    self.class.delete('/access_token', headers: headers)
    true
  end
end

#user_idInteger

Returns unique id for user.

Returns:

  • (Integer)

    unique id for user



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rallio/access_token.rb', line 12

class AccessToken < Base
  attribute :access_token, String
  attribute :user_id, Integer
  attribute :expires_at, DateTime
  attribute :scopes, String

  # Creates new access token for user_id.
  #
  # NOTE: These tokens do not expire so it is suggested (recommended) that the
  # token be cached and reused whenever possible.
  #
  # @param user_id [Integer]
  # @return [Rallio::AccessToken]
  def self.create(user_id:)
    response = self.post("/users/#{user_id}/access_tokens", headers: app_credentials)
    new response.parsed_response
  end

  # Destroys access_token
  #
  # @return [true, nil] true if successful or nil
  def destroy
    headers = { 'Authorization' => "Bearer #{access_token}" }
    self.class.delete('/access_token', headers: headers)
    true
  end
end

Class Method Details

.create(user_id:) ⇒ Rallio::AccessToken

Creates new access token for user_id.

NOTE: These tokens do not expire so it is suggested (recommended) that the token be cached and reused whenever possible.

Parameters:

  • user_id (Integer)

Returns:



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

def self.create(user_id:)
  response = self.post("/users/#{user_id}/access_tokens", headers: app_credentials)
  new response.parsed_response
end

Instance Method Details

#destroytrue?

Destroys access_token

Returns:

  • (true, nil)

    true if successful or nil



33
34
35
36
37
# File 'lib/rallio/access_token.rb', line 33

def destroy
  headers = { 'Authorization' => "Bearer #{access_token}" }
  self.class.delete('/access_token', headers: headers)
  true
end