Class: SignedUrl::UrlEncoder

Inherits:
Object
  • Object
show all
Defined in:
lib/signed_url.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#hostObject

Returns the value of attribute host.



33
34
35
# File 'lib/signed_url.rb', line 33

def host
  @host
end

#key_idObject

Returns the value of attribute key_id.



33
34
35
# File 'lib/signed_url.rb', line 33

def key_id
  @key_id
end

#secretObject

Returns the value of attribute secret.



33
34
35
# File 'lib/signed_url.rb', line 33

def secret
  @secret
end

Instance Method Details

#encode(path:, expires:) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/signed_url.rb', line 35

def encode(path:, expires:)
  expires = expires.to_i
  digest = OpenSSL::Digest.new('sha256')
  hmac = OpenSSL::HMAC.digest(digest, @secret, "GET\n\n\n#{expires}\n/#{path}")
  signature = CGI.escape(URI.escape(Base64.encode64(hmac).strip))
  generate_url(host: @host, path: path, access_key_id: @key_id, expires: expires, signature: signature)
end