Class: Webhookdb::Shopify

Inherits:
Object
  • Object
show all
Includes:
Appydays::Configurable
Defined in:
lib/webhookdb/shopify.rb

Class Method Summary collapse

Class Method Details

This function is used in the backfill process to parse out the pagination_token from the responses



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/webhookdb/shopify.rb', line 14

def self.parse_link_header(header)
  parts = header.split(",")

  parts.to_h do |part, _|
    section = part.split(";")
    name = section[1][/rel="(.*)"/, 1].to_sym
    url = section[0][/<(.*)>/, 1]
    # results = section[2][/results="(.*)"/, 1] == 'true'

    [name, url]
  end
end

.verify_webhook(data, hmac_header, webhook_secret) ⇒ Object

Compare the computed HMAC digest based on the shared secret and the request contents to the reported HMAC in the headers

see shopify.dev/tutorials/manage-webhooks#verifying-webhooks



31
32
33
34
# File 'lib/webhookdb/shopify.rb', line 31

def self.verify_webhook(data, hmac_header, webhook_secret)
  calculated_hmac = Base64.strict_encode64(OpenSSL::HMAC.digest("sha256", webhook_secret, data))
  return ActiveSupport::SecurityUtils.secure_compare(calculated_hmac, hmac_header)
end