Class: Contentful::Management::Webhook
- Inherits:
-
Object
- Object
- Contentful::Management::Webhook
- Includes:
- Resource, Resource::Refresher, Resource::SystemProperties
- Defined in:
- lib/contentful/management/webhook.rb
Overview
Resource class for Webhook. www.contentful.com/developers/documentation/content-management-api/http/#resources-webhooks
Constant Summary
Constants included from Resource::SystemProperties
Resource::SystemProperties::SYS_COERCIONS
Constants included from Resource
Instance Attribute Summary
Attributes included from Resource::SystemProperties
Attributes included from Resource
#client, #default_locale, #properties, #raw_object, #request
Class Method Summary collapse
-
.all(space_id, parameters = {}) ⇒ Object
Gets a collection of webhooks.
-
.create(space_id, attributes) ⇒ Object
Creates a webhook.
- .endpoint_parameters(attributes) ⇒ Object
-
.find(space_id, webhook_id) ⇒ Object
Gets a specific webhook.
Instance Method Summary collapse
-
#destroy ⇒ Object
Destroys an webhook.
-
#update(attributes) ⇒ Object
Updates a webhook.
Methods included from Resource::Refresher
Methods included from Resource::SystemProperties
included, #initialize, #inspect
Methods included from Resource
#array?, #fields, #initialize, #inspect, #nested_locale_fields?, #sys
Class Method Details
.all(space_id, parameters = {}) ⇒ Object
Gets a collection of webhooks. Takes an id of space and hash of parameters. Returns a Contentful::Management::Array of Contentful::Management::Webhook.
18 19 20 21 22 23 24 25 26 |
# File 'lib/contentful/management/webhook.rb', line 18 def self.all(space_id, parameters = {}) request = Request.new( "/#{ space_id }/webhook_definitions", parameters ) response = request.get result = ResourceBuilder.new(response, {}, {}) result.run end |
.create(space_id, attributes) ⇒ Object
Creates a webhook. Takes a space id and hash with attributes (url, httpBasicUsername, httpBasicPassword) Returns a Contentful::Management::Webhook.
41 42 43 44 45 46 47 48 49 |
# File 'lib/contentful/management/webhook.rb', line 41 def self.create(space_id, attributes) id = attributes[:id] request = Request.new( "/#{ space_id }/webhook_definitions/#{ id }", endpoint_parameters(attributes) ) response = id.nil? ? request.post : request.put ResourceBuilder.new(response, {}, {}).run end |
.endpoint_parameters(attributes) ⇒ Object
79 80 81 |
# File 'lib/contentful/management/webhook.rb', line 79 def self.endpoint_parameters(attributes) attributes.select { |key, _value| [:httpBasicUsername, :httpBasicPassword, :url].include? key } end |
.find(space_id, webhook_id) ⇒ Object
Gets a specific webhook. Takes an id of space and webhook. Returns a Contentful::Management::Webhook.
31 32 33 34 35 36 |
# File 'lib/contentful/management/webhook.rb', line 31 def self.find(space_id, webhook_id) request = Request.new("/#{ space_id }/webhook_definitions/#{ webhook_id }") response = request.get result = ResourceBuilder.new(response, {}, {}) result.run end |
Instance Method Details
#destroy ⇒ Object
Destroys an webhook. Returns true if succeed.
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/contentful/management/webhook.rb', line 68 def destroy request = Request.new("/#{ space.id }/webhook_definitions/#{ id }") response = request.delete if response.status == :no_content return true else result = ResourceBuilder.new(response, {}, {}) result.run end end |
#update(attributes) ⇒ Object
Updates a webhook. Takes a hash with attributes. Returns a Contentful::Management::Webhook.
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/contentful/management/webhook.rb', line 54 def update(attributes) request = Request.new( "/#{ space.id }/webhook_definitions/#{ id }", self.class.endpoint_parameters(attributes), id = nil, version: sys[:version] ) response = request.put result = ResourceBuilder.new(response, {}, {}) refresh_data(result.run) end |