Module: Camo::Helper

Included in:
Camo
Defined in:
lib/camo/helper.rb

Instance Method Summary collapse

Instance Method Details

#camo(image_url, key: nil) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/camo/helper.rb', line 3

def camo(image_url, key: nil)
  key ||= Camo.key
  host = Camo.host

  raise "No CAMO_KEY" unless key
  raise "No CAMO_HOST" unless host

  # TODO support base64 encoding
  hexdigest = OpenSSL::HMAC.hexdigest("sha1", key, image_url)
  encoded_image_url = image_url.unpack1("H*")
  "#{host}/#{hexdigest}/#{encoded_image_url}"
end