Skip to content

Instantly share code, notes, and snippets.

@dominiek
Created September 26, 2009 05:13
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 dominiek/194033 to your computer and use it in GitHub Desktop.
Save dominiek/194033 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'ezcrypto'
require 'json'
require 'cgi'
require 'base64'
module Uservoice
class Token
attr_accessor :data
def initialize(options = {})
options.merge!(:expires => (Time.now.utc + (5 * 60)).strftime("%Y/%m/%d %H:%M:%S +0000"))
key = EzCrypto::Key.with_password(USERVOICE_ACCOUNT_KEY, USERVOICE_API_KEY)
encrypted = key.encrypt(options.to_json)
@data = CGI.escape(Base64.encode64(encrypted).gsub(/\n/, '')) # Remove line returns where are annoyingly placed every 60 characters
end
def to_s
@data
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment