Class: Nylas::Webhook
- Inherits:
-
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
91
92
93
|
# File 'lib/nylas/webhook.rb', line 91
def self.resources_path(api:)
"/a/#{api.app_id}/webhooks"
end
|
.verify_webhook_signature(nylas_signature, raw_body, client_secret) ⇒ Boolean
Verify incoming webhook signature came from Nylas
100
101
102
103
|
# File 'lib/nylas/webhook.rb', line 100
def self.verify_webhook_signature(nylas_signature, raw_body, client_secret)
digest = OpenSSL::HMAC.hexdigest("SHA256", client_secret, raw_body)
digest == nylas_signature
end
|
Instance Method Details
#save ⇒ Object
63
64
65
66
67
68
69
70
71
|
# File 'lib/nylas/webhook.rb', line 63
def save
result = if persisted?
update_call(update_payload)
else
create
end
attributes.merge(result)
end
|
#save_all_attributes ⇒ Object
73
74
75
|
# File 'lib/nylas/webhook.rb', line 73
def save_all_attributes
save
end
|
#update(**data) ⇒ Object
77
78
79
80
81
82
83
84
85
|
# File 'lib/nylas/webhook.rb', line 77
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
87
88
89
|
# File 'lib/nylas/webhook.rb', line 87
def update_all_attributes(**data)
update(**data)
end
|