Class: CDN::Choopa
- Inherits:
-
Object
- Object
- CDN::Choopa
- Defined in:
- lib/cdn/providers/choopa.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.generate_token(path, options = {}) ⇒ Object
3 4 5 |
# File 'lib/cdn/providers/choopa.rb', line 3 def self.generate_token(path, = {}) self.new.generate_token(path, ) end |
.generate_url(options = {}) ⇒ Object
7 8 9 10 11 12 |
# File 'lib/cdn/providers/choopa.rb', line 7 def self.generate_url( = {}) (([:protocol] == :https) ? URI::HTTPS : URI::HTTP).build( host: [:domain], path: [:path], query: [:token]) end |
Instance Method Details
#generate_token(path, options = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/cdn/providers/choopa.rb', line 14 def generate_token(path, = {}) return '' if [:token] && [:token][:cdn_type].to_s == 'small' [:start] ||= 0 [:expires_in] ||= 600 expires_at = ([:expires_in].is_a?(Fixnum)) ? Time.now.to_i + [:expires_in] : [:expires_in].to_i expires_at_hex = expires_at.to_s(16) hash = Digest::MD5.hexdigest(File.join(path, CDN.configuration.http_large_secret, expires_at_hex)) "e=#{expires_at_hex}&h=#{hash}&start=#{[:start]}" end |