Class: CDN::Cloudfront

Inherits:
Object
  • Object
show all
Defined in:
lib/cdn/providers/cloudfront.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.generate_token(path, options = {}) ⇒ Object



3
4
5
# File 'lib/cdn/providers/cloudfront.rb', line 3

def self.generate_token(path, options = {})
  self.new.generate_token(path, options)
end

.generate_url(options = {}) ⇒ Object



7
8
9
10
11
12
# File 'lib/cdn/providers/cloudfront.rb', line 7

def self.generate_url(options = {})
  ((options[:protocol] == :https) ? URI::HTTPS : URI::HTTP).build(
    host: options[:domain],
    path: options[:path],
    query: options[:token])
end

Instance Method Details

#generate_token(path, options = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/cdn/providers/cloudfront.rb', line 14

def generate_token(path, options = {})
  url = if options[:token] && options[:token][:cdn_type].to_s == 'small'
    AwsCfSigner.new(CDN.configuration.aws_pem_file).sign(
      "http://#{options[:domain]}#{path}",
      { ending: Time.now.utc + 1.year })
  else
    AwsCfSigner.new(CDN.configuration.aws_pem_file).sign(
      "http://#{options[:domain]}#{path}",
      self.normalize_options(options))
  end

  url.split('?').last
end