Module: BunBun::URI
- Defined in:
- lib/bunbun/uri.rb
Class Method Summary collapse
- .join(path, params = nil) ⇒ Object
- .sign(path, expires: Time.now + 3600, host: ENV.fetch('BUNNY_CDN_HOST'), security_key: ENV.fetch('BUNNY_CDN_KEY')) ⇒ Object
Class Method Details
.join(path, params = nil) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/bunbun/uri.rb', line 6 def self.join(path, params = nil) return path if params.nil? || params.empty? || params.all? { |_, value| value.nil? } encoded = [] params.each do |name, value| next if value.nil? encoded << ::URI.encode_uri_component(name) + '=' + ::URI.encode_uri_component(value) end path + '?' + encoded.join('&') end |
.sign(path, expires: Time.now + 3600, host: ENV.fetch('BUNNY_CDN_HOST'), security_key: ENV.fetch('BUNNY_CDN_KEY')) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/bunbun/uri.rb', line 20 def self.sign(path, expires: Time.now + 3600, host: ENV.fetch('BUNNY_CDN_HOST'), security_key: ENV.fetch('BUNNY_CDN_KEY')) uri = 'https://' + host + path expires = expires.to_i.to_s string = security_key + path + expires token = BunBun::Base64.encode(Digest::SHA256.digest(string)) uri + "?token=#{token}&expires=#{expires}" end |