Sha256: df517df09163d2aa4206cd5176671eec8b47e8ed70cb91a68576a92fe3b952dc

Contents?: true

Size: 1.19 KB

Versions: 8

Compression:

Stored size: 1.19 KB

Contents

=begin
{{> api_info}}
=end

require 'openssl'

module Dropbox
end

module Dropbox::Sign
  class EventCallbackHelper
    EVENT_TYPE_ACCOUNT_CALLBACK = "account_callback"

    EVENT_TYPE_APP_CALLBACK = "app_callback"

    # Verify that a callback came from HelloSign.com
    #
    # @param [String] api_key
    # @param [EventCallbackRequest] event_callback
    # @return bool
    def self.is_valid(api_key, event_callback)
      hash = OpenSSL::HMAC.hexdigest(
        "SHA256",
        api_key,
        "#{event_callback.event.event_time}#{event_callback.event.event_type}",
      )

      return event_callback.event.event_hash === hash
    end

    # Identifies the callback type, one of "account_callback" or "app_callback".
    # "app_callback" will always include a value for "reported_for_app_id"
    #
    # @param [EventCallbackRequest] event_callback
    # @return string
    def self.get_callback_type(event_callback)
      metadata = event_callback.event.event_metadata || EventCallbackRequestEventMetadata.new

      if metadata.reported_for_app_id.nil? || metadata.reported_for_app_id.empty?
        return EVENT_TYPE_ACCOUNT_CALLBACK
      end

      return EVENT_TYPE_APP_CALLBACK
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
dropbox-sign-1.3.0 templates/event_callback_helper.mustache
dropbox-sign-1.2.0 templates/event_callback_helper.mustache
dropbox-sign-1.1.2 templates/event_callback_helper.mustache
dropbox-sign-1.1.1 templates/event_callback_helper.mustache
dropbox-sign-1.1.0 templates/event_callback_helper.mustache
dropbox-sign-1.0.1 templates/event_callback_helper.mustache
dropbox-sign-1.0.0 templates/event_callback_helper.mustache
dropbox-sign-1.0.0.pre.beta2301 templates/event_callback_helper.mustache