lib/hmac_auth/signature.rb in hmac_auth-0.1.2 vs lib/hmac_auth/signature.rb in hmac_auth-0.1.3

- old
+ new

@@ -14,10 +14,12 @@ def initialize(params, options = {}) @secret = options.delete(:secret) || HMACAuth.secret @valid_for = options.delete(:valid_for) || HMACAuth.valid_for @reject_keys = options.delete(:reject_keys) || HMACAuth.reject_keys + @keep_values_type = options.delete(:keep_values_type) || + HMACAuth.keep_values_type @_params = params raise Error.new 'You *must* tell me a secret!' unless @secret end @@ -48,10 +50,16 @@ Hash[hash.map do |k, v| [k.to_s, v.is_a?(Hash) ? deep_stringify(v) : v.to_s] end] end + def deep_stringify_skip_values(hash) + Hash[hash.map do |k, v| + [k.to_s, v.is_a?(Hash) ? deep_stringify_skip_values(v) : v] + end] + end + def valid_timestamp timestamp && timestamp >= valid_for.ago.to_i end def timestamp @@ -67,13 +75,22 @@ def params_without_signature params.reject { |k, v| k == 'signature' } end def params - @params ||= deep_stringify(@_params.reject do |k, v| + reject_keys! + @params ||= if keep_values_type + deep_stringify_skip_values(reject_keys!) + else + deep_stringify(reject_keys!) + end + end + + def reject_keys! + @_params.reject do |k, v| reject_keys.include? k - end) + end end - attr_reader :secret, :valid_for, :reject_keys + attr_reader :secret, :valid_for, :reject_keys, :keep_values_type end end