Skip to content

Instantly share code, notes, and snippets.

@ryana
Created January 26, 2016 19:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryana/b620908f965e4066f846 to your computer and use it in GitHub Desktop.
Save ryana/b620908f965e4066f846 to your computer and use it in GitHub Desktop.
Example of creating a signed image chart URL for ChartURL.com
# This is a working example.
require 'json'
require 'openssl'
require 'base64'
require 'cgi'
ENCRYPT_KEY = "dek-d7a46236eda961a6c3c18ffcc6b077ba87d27e9ae85f7842c6d427c265dd5f69d5131308d93332353d4a55a4b1160fcf516515a4a9f0aa50fbf2d7a2e7d0f1c5"
PROJECT_TOKEN = "dt-RwYN"
def charturl_url(template_slug, options)
json = options.to_json
sig = Base64.encode64(OpenSSL::HMAC.digest('sha256', ENCRYPT_KEY, json))
"https://charturl.com/i/#{PROJECT_TOKEN}/#{template_slug}?d=#{CGI.escape json}&s=#{CGI.escape sig}"
end
# Call our helper
url = charturl_url("weekly-activity",
{options: {data: {columns: [["This Week", 10,12,41,9,14,15,15], ["Last Week", 9,14,21,21,20,3,5]]}}})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment