Class: Mailgun::Tracking::Signature

Inherits:
Object
  • Object
show all
Defined in:
lib/mailgun/tracking/signature.rb

Overview

A Mailgun::Tracking::Signature object is used to verify the signature.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(payload) ⇒ Mailgun::Tracking::Signature

Initializes a new Signature object.


25
26
27
28
29
# File 'lib/mailgun/tracking/signature.rb', line 25

def initialize(payload)
  @token = payload.fetch('token')
  @timestamp = payload.fetch('timestamp')
  @signature = payload.fetch('signature')
end

Class Method Details

.verify!(payload) ⇒ Boolean

Verify the signature of the response parameters.

Raises:


14
15
16
17
18
# File 'lib/mailgun/tracking/signature.rb', line 14

def self.verify!(payload)
  signature = new(payload)
  raise InvalidSignature unless signature.valid?
  true
end

Instance Method Details

#valid?Boolean


32
33
34
# File 'lib/mailgun/tracking/signature.rb', line 32

def valid?
  @signature == OpenSSL::HMAC.hexdigest(digest, Mailgun::Tracking.api_key, data)
end