Class: AssayDepot::Webhook

Inherits:
Object
  • Object
show all
Includes:
SearchModel
Defined in:
lib/assaydepot/event.rb,
lib/assaydepot/endpoints.rb

Class Method Summary collapse

Methods included from SearchModel

#facets, #find, included, #initialize, #internal_results, #where

Class Method Details

.construct_event(payload, signature_header, endpoint_secret) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/assaydepot/event.rb', line 6

def self.construct_event(payload, signature_header, endpoint_secret)
  sig_hash = {}

  # get t=, v0=, v1= components of the signature
  signature_header.split(',').each do |str|
    sig_hash[str.split('=')[0]] = str.split('=')[1]
  end

  mac = OpenSSL::HMAC.hexdigest("SHA256", "#{sig_hash["t"]}0123456789abcdefghijklmnopqrstuvwxyz", payload)
  raise AssayDepot::SignatureVerificationError.new "Event (#{Rails.env}) not properly signed." if Rails.env == 'test' || Rails.env == 'development' && mac != sig_hash["v0"]
  mac = OpenSSL::HMAC.hexdigest("SHA256", "#{sig_hash["t"]}#{endpoint_secret}", payload)
  raise AssayDepot::SignatureVerificationError.new if Rails.env != 'test' && Rails.env != 'development' && mac != sig_hash["v1"]
  raise AssayDepot::SignatureVerificationError.new "Invalid timestamp." if sig_hash["t"].to_i < 5.minutes.ago.to_i
end

.endpoint(id = nil, format = "json") ⇒ Object



171
172
173
# File 'lib/assaydepot/endpoints.rb', line 171

def self.endpoint(id=nil, format="json")
  get_endpoint(id, "webhook_config", format)
end

.ref_nameObject



175
176
177
# File 'lib/assaydepot/endpoints.rb', line 175

def self.ref_name
  "results"
end