Class: Nylas::Webhooks

Inherits:
Resource show all
Includes:
ApiOperations::Delete, ApiOperations::Get, ApiOperations::Post, ApiOperations::Put
Defined in:
lib/nylas/resources/webhooks.rb

Overview

Nylas Webhooks API

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

#initialize

Constructor Details

This class inherits a constructor from Nylas::Resource

Class Method Details

.extract_challenge_parameter(url) ⇒ String

Extract the challenge parameter from a URL

Parameters:

  • url (String)

    The URL sent by Nylas containing the challenge parameter

Returns:

  • (String)

    The challenge parameter



109
110
111
112
113
114
115
116
117
118
119
# File 'lib/nylas/resources/webhooks.rb', line 109

def self.extract_challenge_parameter(url)
  url_object = URI.parse(url)
  query = CGI.parse(url_object.query || "")

  challenge_parameter = query["challenge"]
  if challenge_parameter.nil? || challenge_parameter.empty? || challenge_parameter.first.nil?
    raise "Invalid URL or no challenge parameter found."
  end

  challenge_parameter.first
end

Instance Method Details

#create(request_body:) ⇒ Array(Hash, String)

Create a webhook.

Parameters:

  • request_body (Hash)

    The values to create the webhook with.

Returns:

  • (Array(Hash, String))

    The created webhook and API Request ID.



57
58
59
60
61
62
# File 'lib/nylas/resources/webhooks.rb', line 57

def create(request_body:)
  post(
    path: "#{api_uri}/v3/webhooks",
    request_body: request_body
  )
end

#destroy(webhook_id:) ⇒ Array(TrueClass, String)

Delete a webhook.

Parameters:

  • webhook_id (String)

    The id of the webhook to delete.

Returns:

  • (Array(TrueClass, String))

    True and the API Request ID for the delete operation.



80
81
82
83
84
85
86
# File 'lib/nylas/resources/webhooks.rb', line 80

def destroy(webhook_id:)
  _, request_id = delete(
    path: "#{api_uri}/v3/webhooks/#{webhook_id}"
  )

  [true, request_id]
end

#find(webhook_id:) ⇒ Array(Hash, String)

Return a webhook.

Parameters:

  • webhook_id (String)

    The id of the webhook to return.

Returns:

  • (Array(Hash, String))

    The webhook and API request ID.



47
48
49
50
51
# File 'lib/nylas/resources/webhooks.rb', line 47

def find(webhook_id:)
  get(
    path: "#{api_uri}/v3/webhooks/#{webhook_id}"
  )
end

#ip_addressesArray(Hash, String)

Get the current list of IP addresses that Nylas sends webhooks from

Returns:

  • (Array(Hash, String))

    List of IP addresses that Nylas sends webhooks from and API Request ID.



100
101
102
103
104
# File 'lib/nylas/resources/webhooks.rb', line 100

def ip_addresses
  get(
    path: "#{api_uri}/v3/webhooks/ip-addresses"
  )
end

#listArray(Array(Hash), String)

Return all webhooks.

Returns:

  • (Array(Array(Hash), String))

    The list of webhooks and API Request ID.



37
38
39
40
41
# File 'lib/nylas/resources/webhooks.rb', line 37

def list
  get(
    path: "#{api_uri}/v3/webhooks"
  )
end

#rotate_secret(webhook_id:) ⇒ Array(Hash, String)

Update the webhook secret value for a destination.

Parameters:

  • webhook_id (String)

    The ID of the webhook destination to update.

Returns:

  • (Array(Hash, String))

    The updated webhook destination and API Request ID.



91
92
93
94
95
96
# File 'lib/nylas/resources/webhooks.rb', line 91

def rotate_secret(webhook_id:)
  post(
    path: "#{api_uri}/v3/webhooks/rotate-secret/#{webhook_id}",
    request_body: {}
  )
end

#update(webhook_id:, request_body:) ⇒ Array(Hash, String)

Update a webhook.

Parameters:

  • webhook_id (String)

    The id of the webhook to update.

  • request_body (Hash)

    The values to update the webhook with

Returns:

  • (Array(Hash, String))

    The updated webhook and API Request ID.



69
70
71
72
73
74
# File 'lib/nylas/resources/webhooks.rb', line 69

def update(webhook_id:, request_body:)
  put(
    path: "#{api_uri}/v3/webhooks/#{webhook_id}",
    request_body: request_body
  )
end