Class: ChartCandy::Authentication
- Inherits:
-
Object
- Object
- ChartCandy::Authentication
- Defined in:
- lib/chart-candy/authentication.rb
Class Method Summary collapse
Instance Method Summary collapse
- #expired? ⇒ Boolean
-
#initialize(request_url, params = {}) ⇒ Authentication
constructor
A new instance of Authentication.
- #valid_token? ⇒ Boolean
Constructor Details
#initialize(request_url, params = {}) ⇒ Authentication
Returns a new instance of Authentication.
21 22 23 24 |
# File 'lib/chart-candy/authentication.rb', line 21 def initialize(request_url, params={}) @request_url = request_url @params = params end |
Class Method Details
.compact_params(original_params) ⇒ Object
5 6 7 8 9 10 11 |
# 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 |
.reserved_params ⇒ Object
13 14 15 |
# 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) ⇒ Object
17 18 19 |
# 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 |
Instance Method Details
#expired? ⇒ Boolean
26 27 28 |
# File 'lib/chart-candy/authentication.rb', line 26 def expired? @params[:timestamp] and Time.parse(@params[:timestamp]) + 12.hours < Time.now end |
#valid_token? ⇒ Boolean
30 31 32 |
# File 'lib/chart-candy/authentication.rb', line 30 def valid_token? @params[:token] == tokenize(filter_url) end |