Added by admin, last edited by admin on Feb 24, 2010  (view change)

Labels:

Enter labels to add to this page:
Wait Image 
Looking for a label? Just start typing.
require 'rubygems'require 'rubygems'
require 'ezcrypto'
require 'json'
require 'cgi'
require 'base64'

class ApiToken
  attr_accessor :data

  BOOKINGBUG_AFFILIATE_ID = "xxxxxxxx"
  BOOKINGBUG_API_KEY = "xxxxxxxxxxxxxxxxxxxx"

  def initialize(options = {})
    options.merge!({:expires => (Time.now + 60 * 60).to_s})

    key = EzCrypto::Key.with_password BOOKINGBUG_AFFILIATE_ID, BOOKINGBUG_API_KEY
    encrypted = key.encrypt(options.to_json)
    @data = Base64.encode64(encrypted).gsub(/\n/,'')
    @data = CGI.escape(@data)
  end

  def to_s
    @data
  end

  def token
    "sso=#{@data}&affiliate_id=#{BOOKINGBUG_AFFILIATE_ID}"
  end

end