Class: OSTSdk::Saas::Webhooks
- Defined in:
- lib/ost-sdk-ruby/saas/webhooks.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#create(params = {}) ⇒ Object
Create a Webhook.
-
#delete(params = {}) ⇒ Object
Delete a Webhook.
-
#get(params = {}) ⇒ Object
Get webhook details.
-
#get_list(params = {}) ⇒ Object
List Webhooks.
-
#initialize(params) ⇒ Webhooks
constructor
Initialize.
-
#update(params = {}) ⇒ Object
Update a Webhook.
-
#verify_signature(params = {}) ⇒ Object
Verify webhook request signature.
Methods included from Util::ServicesHelper
#current_time, #current_timestamp, #perform_and_handle_exceptions
Constructor Details
#initialize(params) ⇒ Webhooks
Initialize
Arguments:
api_base_url: (String)
api_key: (String)
api_secret: (String)
api_spec: (Boolean)
config: (Hash)
16 17 18 19 |
# File 'lib/ost-sdk-ruby/saas/webhooks.rb', line 16 def initialize(params) super @url_prefix = '/webhooks' end |
Instance Method Details
#create(params = {}) ⇒ Object
Create a Webhook
Returns:
response: (Hash)
26 27 28 |
# File 'lib/ost-sdk-ruby/saas/webhooks.rb', line 26 def create(params = {}) http_helper.send_post_request("#{@url_prefix}/", params) end |
#delete(params = {}) ⇒ Object
Delete a Webhook
Returns:
response: (Hash)
62 63 64 |
# File 'lib/ost-sdk-ruby/saas/webhooks.rb', line 62 def delete(params = {}) http_helper.send_delete_request("#{@url_prefix}/#{get_webhook_id!(params)}", params) end |
#get(params = {}) ⇒ Object
Get webhook details
Returns:
response: (Hash)
44 45 46 |
# File 'lib/ost-sdk-ruby/saas/webhooks.rb', line 44 def get(params = {}) http_helper.send_get_request("#{@url_prefix}/#{get_webhook_id!(params)}", params) end |
#get_list(params = {}) ⇒ Object
List Webhooks
Returns:
response: (Hash)
53 54 55 |
# File 'lib/ost-sdk-ruby/saas/webhooks.rb', line 53 def get_list(params = {}) http_helper.send_get_request("#{@url_prefix}/", params) end |
#update(params = {}) ⇒ Object
Update a Webhook
Returns:
response: (Hash)
35 36 37 |
# File 'lib/ost-sdk-ruby/saas/webhooks.rb', line 35 def update(params = {}) http_helper.send_post_request("#{@url_prefix}/#{get_webhook_id!(params)}", params) end |
#verify_signature(params = {}) ⇒ Object
Verify webhook request signature
Returns:
response: (Boolean)
71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/ost-sdk-ruby/saas/webhooks.rb', line 71 def verify_signature(params = {}) version = params[:version] webhook_secret = params[:webhook_secret] stringified_data = params[:stringified_data] = params[:request_timestamp] signature = params[:signature] signature_params = "#{}.#{version}.#{stringified_data}" digest = OpenSSL::Digest.new('sha256') signature_to_be_verified = OpenSSL::HMAC.hexdigest(digest, webhook_secret, signature_params) signature == signature_to_be_verified end |