Class: UrlTokenizer::Fastly

Inherits:
Provider show all
Defined in:
lib/url_tokenizer/fastly.rb

Instance Method Summary collapse

Methods inherited from Provider

#initialize

Constructor Details

This class inherits a constructor from UrlTokenizer::Provider

Instance Method Details

#call(input_url, **options) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/url_tokenizer/fastly.rb', line 7

def call(input_url, **options)
  options = global_options.merge options
  uri = URI.parse input_url
  path = remove_old_token(uri.path)

  return if path.empty? || path == '/'

  expiration = expiration_date(options[:expires_in])
  dir = File.dirname(path)

  token = digest [dir, expiration].compact.join
  token = [expiration, token].compact.join '_'

  uri.path = ['/', token, path].join
  uri.to_s
end