Class: Pusher::PushNotifications::UseCases::GenerateToken

Inherits:
Object
  • Object
show all
Includes:
Caze
Defined in:
lib/pusher/push_notifications/use_cases/generate_token.rb

Defined Under Namespace

Classes: GenerateTokenError

Instance Method Summary collapse

Constructor Details

#initialize(user:) ⇒ GenerateToken

Returns a new instance of GenerateToken.

Raises:



15
16
17
18
19
20
21
22
23
24
# File 'lib/pusher/push_notifications/use_cases/generate_token.rb', line 15

def initialize(user:)
  @user = user
  @user_id = Pusher::PushNotifications::UserId.new

  raise GenerateTokenError, 'User Id cannot be empty.' if user.empty?
  if user.length > UserId::MAX_USER_ID_LENGTH
    raise GenerateTokenError, 'User id length too long ' \
    "(expected fewer than #{UserId::MAX_USER_ID_LENGTH + 1} characters)"
  end
end

Instance Method Details

#generate_tokenObject

Creates a signed JWT for a user id.



27
28
29
# File 'lib/pusher/push_notifications/use_cases/generate_token.rb', line 27

def generate_token
  { 'token' => jwt_token.generate(user) }
end