require 'token_storage.rb' require 'securerandom' require 'jwt_manager' class LinkGenerator attr_reader :payload, :base_url, :token_store def initialize(params) @base_url = params[:base_url] @payload = params[:payload] @token_store = TokenStorage.new end def generate_link save_jwt "www.#{base_url}/#{link_token}" end private def link_token @link_token ||= SecureRandom.hex(5) end def save_jwt token_store.save(link_token, jwt_token) end def jwt_token JWTManager.encode(payload) end end