Class: Nylas::Webhook

Inherits:
Object
  • Object
show all
Includes:
Model
Defined in:
lib/nylas/webhook.rb

Overview

Represents a webhook attached to your application.

Constant Summary collapse

STATE =
[:inactive].freeze

Instance Attribute Summary

Attributes included from Model

#api

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Model

#auth_method, #create, #destroy, #execute, included, #model_class, #persisted?, #reload, #resource_path, #resources_path, #to_json

Class Method Details

.resources_path(api:) ⇒ Object



85
86
87
# File 'lib/nylas/webhook.rb', line 85

def self.resources_path(api:)
  "/a/#{api.app_id}/webhooks"
end

Instance Method Details

#saveObject



57
58
59
60
61
62
63
64
65
# File 'lib/nylas/webhook.rb', line 57

def save
  result = if persisted?
             update_call(update_payload)
           else
             create
           end

  attributes.merge(result)
end

#save_all_attributesObject



67
68
69
# File 'lib/nylas/webhook.rb', line 67

def save_all_attributes
  save
end

#update(**data) ⇒ Object

Raises:

  • (ArgumentError)


71
72
73
74
75
76
77
78
79
# File 'lib/nylas/webhook.rb', line 71

def update(**data)
  raise ArgumentError, "Only 'state' is allowed to be updated" if data.length > 1 || !data.key?(:state)

  attributes.merge(**data)
  payload = JSON.dump(data)
  update_call(payload)

  true
end

#update_all_attributes(**data) ⇒ Object



81
82
83
# File 'lib/nylas/webhook.rb', line 81

def update_all_attributes(**data)
  update(**data)
end