Sha256: 7da9f9458fb226c28ae4698bb0648a816cdd43d21e1a43ef8cdf90574f988e4c

Contents?: true

Size: 552 Bytes

Versions: 1

Compression:

Stored size: 552 Bytes

Contents

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
share-link-2.3 lib/link_generator.rb