class ChartCandy::Authentication

Public Class Methods

compact_params(original_params) click to toggle source
# File lib/chart-candy/authentication.rb, line 5
def self.compact_params(original_params)
  compacted_params = ''

  original_params.each { |k,v| compacted_params << (k.to_s + v.to_s) if not self.reserved_params.include?(k.to_s) }

  return compacted_params
end
new(request_url, params={}) click to toggle source
# File lib/chart-candy/authentication.rb, line 21
def initialize(request_url, params={})
  @request_url = request_url
  @params = params
end
reserved_params() click to toggle source
# File lib/chart-candy/authentication.rb, line 13
def self.reserved_params
  ['action', 'class', 'controller', 'format', 'from', 'nature', 'step', 'to', 'token', 'tools', 'update_every', 'version']
end
tokenize(str) click to toggle source
# File lib/chart-candy/authentication.rb, line 17
def self.tokenize(str)
  OpenSSL::HMAC.hexdigest(OpenSSL::Digest::SHA1.new, Rails.configuration.secret_token, str.chars.sort.join.gsub('/', ''))
end

Public Instance Methods

expired?() click to toggle source
# File lib/chart-candy/authentication.rb, line 26
def expired?
  @params[:timestamp] and Time.parse(@params[:timestamp]) + 12.hours < Time.now
end
valid_token?() click to toggle source
# File lib/chart-candy/authentication.rb, line 30
def valid_token?
  @params[:token] == tokenize(filter_url)
end

Private Instance Methods

filter_url() click to toggle source
# File lib/chart-candy/authentication.rb, line 36
def filter_url
  filtered_url = @request_url.split('?').first.rpartition('/').first

  return filtered_url + ChartCandy::Authentication.compact_params(@params)
end
tokenize(str) click to toggle source
# File lib/chart-candy/authentication.rb, line 42
def tokenize(str)
  ChartCandy::Authentication.tokenize(str)
end