Class: Contentful::Management::Webhook

Inherits:
Object
  • Object
show all
Includes:
Resource, Resource::Refresher, Resource::SystemProperties
Defined in:
lib/contentful/management/webhook.rb

Overview

Constant Summary

Constants included from Resource::SystemProperties

Resource::SystemProperties::SYS_COERCIONS

Constants included from Resource

Resource::COERCIONS

Instance Attribute Summary

Attributes included from Resource::SystemProperties

#sys

Attributes included from Resource

#client, #default_locale, #properties, #raw_object, #request

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Resource::Refresher

#refresh_data, #reload

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

#destroyObject

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