Module: LoyverseApi::Endpoints::Webhooks
- Included in:
- Client
- Defined in:
- lib/loyverse_api/endpoints/webhooks.rb
Instance Method Summary collapse
-
#create_webhook(url:, event_types:, description: nil) ⇒ Hash
Create a new webhook Available event types: - ORDER_CREATED - ITEM_UPDATED - INVENTORY_UPDATED.
-
#delete_webhook(webhook_id) ⇒ Hash
Delete a webhook.
-
#get_webhook(webhook_id) ⇒ Hash
Get a specific webhook by ID.
-
#list_webhooks(limit: 250, cursor: nil) ⇒ Hash
List all webhooks.
-
#verify_webhook_signature(payload, signature, secret) ⇒ Boolean
Verify webhook signature (for OAuth 2.0 created webhooks).
Instance Method Details
#create_webhook(url:, event_types:, description: nil) ⇒ Hash
Create a new webhook Available event types:
- ORDER_CREATED
- ITEM_UPDATED
- INVENTORY_UPDATED
34 35 36 37 38 39 40 41 42 |
# File 'lib/loyverse_api/endpoints/webhooks.rb', line 34 def create_webhook(url:, event_types:, description: nil) body = { url: url, event_types: Array(event_types) } body[:description] = description if description post("webhooks", body: body) end |
#delete_webhook(webhook_id) ⇒ Hash
Delete a webhook
47 48 49 |
# File 'lib/loyverse_api/endpoints/webhooks.rb', line 47 def delete_webhook(webhook_id) delete("webhooks/#{webhook_id}") end |
#get_webhook(webhook_id) ⇒ Hash
Get a specific webhook by ID
7 8 9 |
# File 'lib/loyverse_api/endpoints/webhooks.rb', line 7 def get_webhook(webhook_id) get("webhooks/#{webhook_id}") end |
#list_webhooks(limit: 250, cursor: nil) ⇒ Hash
List all webhooks
15 16 17 18 19 20 21 22 |
# File 'lib/loyverse_api/endpoints/webhooks.rb', line 15 def list_webhooks(limit: 250, cursor: nil) params = { limit: limit, cursor: cursor }.compact get("webhooks", params: params) end |
#verify_webhook_signature(payload, signature, secret) ⇒ Boolean
Verify webhook signature (for OAuth 2.0 created webhooks)
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/loyverse_api/endpoints/webhooks.rb', line 56 def verify_webhook_signature(payload, signature, secret) return false if payload.nil? || signature.nil? || secret.nil? require "openssl" computed_signature = OpenSSL::HMAC.hexdigest( OpenSSL::Digest.new("sha256"), secret, payload ) secure_compare(computed_signature, signature) end |