Sha256: a48d41486d5c470d001b7a3655116cfa020b5758d7af0aa757a4b3b0afcab25d

Contents?: true

Size: 931 Bytes

Versions: 17

Compression:

Stored size: 931 Bytes

Contents

class DiscoApp::WebhookService

  # Return true iff the provided hmac_to_verify matches that calculated from the
  # give data and secret.
  def self.is_valid_hmac?(body, secret, hmac_to_verify)
    self.calculated_hmac(body, secret) == hmac_to_verify
  end

  # Calculate the HMAC for the given data and secret.
  def self.calculated_hmac(body, secret)
    digest  = OpenSSL::Digest.new('sha256')
    Base64.encode64(OpenSSL::HMAC.digest(digest, secret, body)).strip
  end

  # Try to find a job class for the given webhook topic.
  def self.find_job_class(topic)
    begin
      # First try to find a top-level matching job class.
      "#{topic}_job".gsub('/', '_').classify.constantize
    rescue NameError
      # If that fails, try to find a DiscoApp:: prefixed job class.
      begin
        %Q{DiscoApp::#{"#{topic}_job".gsub('/', '_').classify}}.constantize
      rescue NameError
        nil
      end
    end
  end

end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
disco_app-0.6.0 app/services/disco_app/webhook_service.rb
disco_app-0.6.1 app/services/disco_app/webhook_service.rb
disco_app-0.6.2 app/services/disco_app/webhook_service.rb
disco_app-0.6.3 app/services/disco_app/webhook_service.rb
disco_app-0.6.4 app/services/disco_app/webhook_service.rb
disco_app-0.6.5 app/services/disco_app/webhook_service.rb
disco_app-0.6.6 app/services/disco_app/webhook_service.rb
disco_app-0.6.7 app/services/disco_app/webhook_service.rb
disco_app-0.6.8 app/services/disco_app/webhook_service.rb
disco_app-0.6.9 app/services/disco_app/webhook_service.rb
disco_app-0.7.0 app/services/disco_app/webhook_service.rb
disco_app-0.7.1 app/services/disco_app/webhook_service.rb
disco_app-0.7.2 app/services/disco_app/webhook_service.rb
disco_app-0.8.0 app/services/disco_app/webhook_service.rb
disco_app-0.8.1 app/services/disco_app/webhook_service.rb
disco_app-0.8.2 app/services/disco_app/webhook_service.rb
disco_app-0.8.3 app/services/disco_app/webhook_service.rb