Class: Webhookdb::Increase
- Inherits:
-
Object
- Object
- Webhookdb::Increase
- Extended by:
- MethodUtilities
- Includes:
- Appydays::Configurable, Appydays::Loggable
- Defined in:
- lib/webhookdb/increase.rb
Class Method Summary collapse
-
.contains_desired_object(webhook_body, desired_object_name) ⇒ Object
this function interprets webhook contents to assist with filtering webhooks by object type in our increase services.
-
.find_desired_object_data(body) ⇒ Object
this helper function finds the relevant object data and helps us avoid repeated code.
- .webhook_response(request, webhook_secret) ⇒ Object
Methods included from MethodUtilities
attr_predicate, attr_predicate_accessor, singleton_attr_accessor, singleton_attr_reader, singleton_attr_writer, singleton_method_alias, singleton_predicate_accessor, singleton_predicate_reader
Class Method Details
.contains_desired_object(webhook_body, desired_object_name) ⇒ Object
this function interprets webhook contents to assist with filtering webhooks by object type in our increase services
37 38 39 40 41 |
# File 'lib/webhookdb/increase.rb', line 37 def self.contains_desired_object(webhook_body, desired_object_name) object_of_interest = self.find_desired_object_data(webhook_body) object_id = object_of_interest["id"] return object_id.include?(desired_object_name) end |
.find_desired_object_data(body) ⇒ Object
this helper function finds the relevant object data and helps us avoid repeated code
32 33 34 |
# File 'lib/webhookdb/increase.rb', line 32 def self.find_desired_object_data(body) return body.fetch("data", body) end |
.webhook_response(request, webhook_secret) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/webhookdb/increase.rb', line 12 def self.webhook_response(request, webhook_secret) http_signature = request.env["HTTP_X_BANK_WEBHOOK_SIGNATURE"] return Webhookdb::WebhookResponse.error("missing hmac") if http_signature.nil? request.body.rewind request_data = request.body.read computed_signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new("sha256"), webhook_secret, request_data) if http_signature != "sha256=" + computed_signature # Invalid signature self.logger.warn "increase signature verification error" return Webhookdb::WebhookResponse.error("invalid hmac") end return Webhookdb::WebhookResponse.ok end |