Class: Atalanda::Signature::Request
- Inherits:
-
Object
- Object
- Atalanda::Signature::Request
- Defined in:
- lib/atalanda/signature.rb
Instance Method Summary collapse
- #authenticate(token, timestamp_grace = 600) ⇒ Object
-
#initialize(method, path, parameters, time = Time.now) ⇒ Request
constructor
A new instance of Request.
- #sign(token) ⇒ Object
Constructor Details
#initialize(method, path, parameters, time = Time.now) ⇒ Request
Returns a new instance of Request.
16 17 18 19 20 21 |
# File 'lib/atalanda/signature.rb', line 16 def initialize(method, path, parameters, time=Time.now) @method = method.upcase @path = path @parameters = parameters @time = time.to_i end |
Instance Method Details
#authenticate(token, timestamp_grace = 600) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/atalanda/signature.rb', line 33 def authenticate token, =600 if get_auth_hash.nil? return { "authenticated" => false, "reason" => "Auth hash is missing" } end if (@time - get_auth_hash["auth_timestamp"].to_i).abs > return { "authenticated" => false, "reason" => "Auth timestamp is older than #{} seconds" } end recalculated_signature = calculateSignature(token, buildParameterString(), get_auth_hash["auth_timestamp"]) if recalculated_signature != get_auth_hash["auth_signature"] return { "authenticated" => false, "reason" => "Signature does not match" } end { "authenticated" => true } end |
#sign(token) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/atalanda/signature.rb', line 23 def sign(token) param_string = buildParameterString() signature = calculateSignature(token, param_string, @time) @parameters.merge!({ "auth_timestamp" => @time, "auth_key" => token.api_key, "auth_signature" => signature }) end |