Class: Incoming::Strategies::HTTPPost

Inherits:
Object
  • Object
show all
Includes:
Incoming::Strategy
Defined in:
lib/incoming/strategies/http_post.rb

Instance Attribute Summary collapse

Attributes included from Incoming::Strategy

#message

Instance Method Summary collapse

Methods included from Incoming::Strategy

included, #receive

Constructor Details

#initialize(request) ⇒ HTTPPost

Returns a new instance of HTTPPost.



10
11
12
13
14
15
16
17
# File 'lib/incoming/strategies/http_post.rb', line 10

def initialize(request)
  params = request.params

  @signature = params['signature']
  @token = params['token']
  @timestamp = params['timestamp']
  @message = Mail.new(params['message'])
end

Instance Attribute Details

#signatureObject

Returns the value of attribute signature.



8
9
10
# File 'lib/incoming/strategies/http_post.rb', line 8

def signature
  @signature
end

#timestampObject

Returns the value of attribute timestamp.



8
9
10
# File 'lib/incoming/strategies/http_post.rb', line 8

def timestamp
  @timestamp
end

#tokenObject

Returns the value of attribute token.



8
9
10
# File 'lib/incoming/strategies/http_post.rb', line 8

def token
  @token
end

Instance Method Details

#authenticateObject



19
20
21
22
# File 'lib/incoming/strategies/http_post.rb', line 19

def authenticate
  hexdigest = OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new('SHA256'), self.class.default_options[:secret], [timestamp, token].join)
  hexdigest.eql?(signature) or false
end