Class: Nova::API::Resource::Webhook

Inherits:
Base show all
Defined in:
lib/nova/api/resource/webhook.rb

Constant Summary collapse

ALLOWED_ATTRIBUTES =
%i[events url]

Constants inherited from Base

Base::PRODUCTION_HOST, Base::SCHEME, Base::STAGING_HOST

Constants inherited from Utils::BaseStruct

Utils::BaseStruct::DATE_REGEX

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

base_url

Methods inherited from Utils::BaseStruct

#allowed_attributes

Class Method Details

.create(parameters) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/nova/api/resource/webhook.rb', line 15

def self.create(parameters)
  model = new parameters

  model.attributes.delete(:id)

  model.save
end

.destroy(id) ⇒ Object



29
30
31
32
33
# File 'lib/nova/api/resource/webhook.rb', line 29

def self.destroy(id)
  model = initialize_empty_model_with_id(self, id, events: [])

  model.destroy
end

.endpointObject



11
12
13
# File 'lib/nova/api/resource/webhook.rb', line 11

def self.endpoint
  '/api/webhooks'
end

.restore(id) ⇒ Object



35
36
37
38
39
# File 'lib/nova/api/resource/webhook.rb', line 35

def self.restore(id)
  model = initialize_empty_model_with_id(self, id, events: [])

  model.restore
end

.update(id, parameters) ⇒ Object



23
24
25
26
27
# File 'lib/nova/api/resource/webhook.rb', line 23

def self.update(id, parameters)
  model = new parameters.merge(id: id)

  model.update
end

Instance Method Details

#destroyObject



61
62
63
64
65
# File 'lib/nova/api/resource/webhook.rb', line 61

def destroy
  protect_operation_from_missing_value

  do_delete("#{endpoint}")
end

#endpointObject



41
42
43
44
45
# File 'lib/nova/api/resource/webhook.rb', line 41

def endpoint
  protect_operation_from_missing_value

  "/api/webhooks/#{id}"
end

#restoreObject



67
68
69
70
71
# File 'lib/nova/api/resource/webhook.rb', line 67

def restore
  protect_operation_from_missing_value

  do_patch("#{endpoint}/restore", {})
end

#saveObject



47
48
49
50
51
52
53
# File 'lib/nova/api/resource/webhook.rb', line 47

def save
  if id.nil?
    do_post(self.class.endpoint, allowed_attributes)
  else
    do_patch("#{endpoint}", allowed_attributes)
  end
end

#updateObject



55
56
57
58
59
# File 'lib/nova/api/resource/webhook.rb', line 55

def update
  protect_operation_from_missing_value

  do_patch("#{endpoint}", allowed_attributes)
end