Class: CrystalApi::WebhookRegistration
- Inherits:
-
Object
- Object
- CrystalApi::WebhookRegistration
- Defined in:
- lib/crystal_api/webhook_registration.rb
Instance Attribute Summary collapse
-
#endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
Instance Method Summary collapse
- #deregister(webhook_id) ⇒ Object
-
#initialize(endpoint) ⇒ WebhookRegistration
constructor
A new instance of WebhookRegistration.
- #register(webhook) ⇒ Object
- #registered?(webhook) ⇒ Boolean
- #registered_webhooks ⇒ Object
- #webhook_id(webhook) ⇒ Object
Constructor Details
#initialize(endpoint) ⇒ WebhookRegistration
Returns a new instance of WebhookRegistration.
5 6 7 |
# File 'lib/crystal_api/webhook_registration.rb', line 5 def initialize(endpoint) @endpoint = endpoint end |
Instance Attribute Details
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
3 4 5 |
# File 'lib/crystal_api/webhook_registration.rb', line 3 def endpoint @endpoint end |
Instance Method Details
#deregister(webhook_id) ⇒ Object
19 20 21 |
# File 'lib/crystal_api/webhook_registration.rb', line 19 def deregister(webhook_id) endpoint.delete("/webhooks/#{webhook_id}") end |
#register(webhook) ⇒ Object
9 10 11 |
# File 'lib/crystal_api/webhook_registration.rb', line 9 def register(webhook) endpoint.post('/webhooks', webhook.to_json(:except => [:id])) end |
#registered?(webhook) ⇒ Boolean
13 14 15 16 17 |
# File 'lib/crystal_api/webhook_registration.rb', line 13 def registered?(webhook) registered_webhooks.any? {|wh| wh.address == webhook.address && wh.topic == webhook.topic && wh.resource_id == webhook.resource_id } end |
#registered_webhooks ⇒ Object
23 24 25 |
# File 'lib/crystal_api/webhook_registration.rb', line 23 def registered_webhooks endpoint.get('/webhooks').parsed end |
#webhook_id(webhook) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/crystal_api/webhook_registration.rb', line 27 def webhook_id(webhook) wh = registered_webhooks.detect {|wh| wh.address == webhook.address && wh.topic == webhook.topic && wh.resource_id == webhook.resource_id } wh && wh.id end |