Class: HMACAuth::Signature
- Inherits:
-
Object
- Object
- HMACAuth::Signature
- Defined in:
- lib/hmac_auth/signature.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(params, options = {}) ⇒ Signature
constructor
A new instance of Signature.
-
#sign ⇒ Hash
Signed parameters.
- #verify ⇒ Object
Constructor Details
#initialize(params, options = {}) ⇒ Signature
Returns a new instance of Signature.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/hmac_auth/signature.rb', line 15 def initialize(params, = {}) @secret = .delete(:secret) || HMACAuth.secret @valid_for = .delete(:valid_for) || HMACAuth.valid_for @reject_keys = .delete(:reject_keys) || HMACAuth.reject_keys @keep_values_type = .delete(:keep_values_type) || HMACAuth.keep_values_type @_params = params raise Error.new 'You *must* tell me a secret!' unless @secret end |
Class Method Details
.sign(params, options = {}) ⇒ Object
10 11 12 |
# File 'lib/hmac_auth/signature.rb', line 10 def sign(params, = {}) self.new(params, ).sign end |
.verify(params, options = {}) ⇒ Object
6 7 8 |
# File 'lib/hmac_auth/signature.rb', line 6 def verify(params, = {}) self.new(params, ).verify end |
Instance Method Details
#sign ⇒ Hash
Returns Signed parameters.
31 32 33 34 |
# File 'lib/hmac_auth/signature.rb', line 31 def sign || params['timestamp'] = Time.now.to_i.to_s params.merge('signature' => calculated_signature) end |
#verify ⇒ Object
26 27 28 |
# File 'lib/hmac_auth/signature.rb', line 26 def verify && signature == calculated_signature end |