nylas 5.17.0 → 6.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/nylas/client.rb +121 -0
- data/lib/nylas/config.rb +19 -0
- data/lib/nylas/errors.rb +63 -89
- data/lib/nylas/handler/api_operations.rb +162 -0
- data/lib/nylas/handler/http_client.rb +252 -0
- data/lib/nylas/resources/applications.rb +27 -0
- data/lib/nylas/resources/attachments.rb +65 -0
- data/lib/nylas/resources/auth.rb +209 -0
- data/lib/nylas/resources/calendars.rb +101 -0
- data/lib/nylas/resources/connectors.rb +80 -0
- data/lib/nylas/resources/contacts.rb +89 -0
- data/lib/nylas/resources/credentials.rb +75 -0
- data/lib/nylas/resources/drafts.rb +121 -0
- data/lib/nylas/resources/events.rb +98 -0
- data/lib/nylas/resources/folders.rb +73 -0
- data/lib/nylas/resources/grants.rb +59 -0
- data/lib/nylas/resources/messages.rb +135 -0
- data/lib/nylas/resources/redirect_uris.rb +68 -0
- data/lib/nylas/resources/resource.rb +18 -0
- data/lib/nylas/resources/smart_compose.rb +36 -0
- data/lib/nylas/resources/threads.rb +62 -0
- data/lib/nylas/resources/webhooks.rb +121 -0
- data/lib/nylas/utils/file_utils.rb +61 -0
- data/lib/nylas/version.rb +1 -1
- data/lib/nylas.rb +31 -148
- metadata +88 -247
- data/lib/nylas/account.rb +0 -56
- data/lib/nylas/api.rb +0 -246
- data/lib/nylas/application_details.rb +0 -13
- data/lib/nylas/calendar.rb +0 -46
- data/lib/nylas/calendar_collection.rb +0 -144
- data/lib/nylas/categorize.rb +0 -14
- data/lib/nylas/collection.rb +0 -175
- data/lib/nylas/component.rb +0 -35
- data/lib/nylas/component_collection.rb +0 -10
- data/lib/nylas/constraints.rb +0 -56
- data/lib/nylas/contact.rb +0 -53
- data/lib/nylas/contact_group.rb +0 -23
- data/lib/nylas/current_account.rb +0 -23
- data/lib/nylas/delta.rb +0 -56
- data/lib/nylas/deltas.rb +0 -19
- data/lib/nylas/deltas_collection.rb +0 -40
- data/lib/nylas/draft.rb +0 -100
- data/lib/nylas/email_address.rb +0 -12
- data/lib/nylas/event.rb +0 -144
- data/lib/nylas/event_collection.rb +0 -15
- data/lib/nylas/event_conferencing.rb +0 -12
- data/lib/nylas/event_conferencing_autocreate.rb +0 -10
- data/lib/nylas/event_conferencing_details.rb +0 -14
- data/lib/nylas/event_notification.rb +0 -17
- data/lib/nylas/file.rb +0 -75
- data/lib/nylas/filter_attributes.rb +0 -25
- data/lib/nylas/folder.rb +0 -26
- data/lib/nylas/free_busy.rb +0 -13
- data/lib/nylas/free_busy_collection.rb +0 -48
- data/lib/nylas/http_client.rb +0 -279
- data/lib/nylas/im_address.rb +0 -11
- data/lib/nylas/job_status.rb +0 -27
- data/lib/nylas/job_status_collection.rb +0 -21
- data/lib/nylas/label.rb +0 -27
- data/lib/nylas/logging.rb +0 -41
- data/lib/nylas/message.rb +0 -98
- data/lib/nylas/message_headers.rb +0 -27
- data/lib/nylas/message_tracking.rb +0 -13
- data/lib/nylas/model/attributable.rb +0 -89
- data/lib/nylas/model/attribute_definition.rb +0 -24
- data/lib/nylas/model/attributes.rb +0 -97
- data/lib/nylas/model/list_attribute_definition.rb +0 -39
- data/lib/nylas/model/transferable.rb +0 -53
- data/lib/nylas/model.rb +0 -217
- data/lib/nylas/native_authentication.rb +0 -39
- data/lib/nylas/neural.rb +0 -87
- data/lib/nylas/neural_categorizer.rb +0 -29
- data/lib/nylas/neural_clean_conversation.rb +0 -33
- data/lib/nylas/neural_contact_link.rb +0 -11
- data/lib/nylas/neural_contact_name.rb +0 -11
- data/lib/nylas/neural_message_options.rb +0 -35
- data/lib/nylas/neural_ocr.rb +0 -16
- data/lib/nylas/neural_sentiment_analysis.rb +0 -17
- data/lib/nylas/neural_signature_contact.rb +0 -81
- data/lib/nylas/neural_signature_extraction.rb +0 -18
- data/lib/nylas/new_message.rb +0 -39
- data/lib/nylas/nylas_date.rb +0 -25
- data/lib/nylas/open_hours.rb +0 -15
- data/lib/nylas/outbox.rb +0 -116
- data/lib/nylas/outbox_job_status.rb +0 -19
- data/lib/nylas/outbox_message.rb +0 -17
- data/lib/nylas/participant.rb +0 -13
- data/lib/nylas/phone_number.rb +0 -11
- data/lib/nylas/physical_address.rb +0 -17
- data/lib/nylas/raw_message.rb +0 -25
- data/lib/nylas/recurrence.rb +0 -11
- data/lib/nylas/registry.rb +0 -42
- data/lib/nylas/room_resource.rb +0 -19
- data/lib/nylas/rsvp.rb +0 -24
- data/lib/nylas/scheduler.rb +0 -51
- data/lib/nylas/scheduler_booking_confirmation.rb +0 -24
- data/lib/nylas/scheduler_booking_request.rb +0 -17
- data/lib/nylas/scheduler_collection.rb +0 -104
- data/lib/nylas/scheduler_config.rb +0 -20
- data/lib/nylas/scheduler_time_slot.rb +0 -14
- data/lib/nylas/search_collection.rb +0 -10
- data/lib/nylas/send_grid_verified_status.rb +0 -12
- data/lib/nylas/services/tunnel.rb +0 -128
- data/lib/nylas/thread.rb +0 -66
- data/lib/nylas/time_slot.rb +0 -16
- data/lib/nylas/time_slot_capacity.rb +0 -13
- data/lib/nylas/timespan.rb +0 -20
- data/lib/nylas/token_info.rb +0 -20
- data/lib/nylas/types.rb +0 -168
- data/lib/nylas/web_page.rb +0 -11
- data/lib/nylas/webhook.rb +0 -111
- data/lib/nylas/when.rb +0 -75
@@ -0,0 +1,135 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "resource"
|
4
|
+
require_relative "smart_compose"
|
5
|
+
require_relative "../handler/api_operations"
|
6
|
+
require_relative "../utils/file_utils"
|
7
|
+
|
8
|
+
module Nylas
|
9
|
+
# Nylas Messages API
|
10
|
+
class Messages < Resource
|
11
|
+
include ApiOperations::Get
|
12
|
+
include ApiOperations::Post
|
13
|
+
include ApiOperations::Put
|
14
|
+
include ApiOperations::Delete
|
15
|
+
|
16
|
+
attr_reader :smart_compose
|
17
|
+
|
18
|
+
# Initializes the messages resource.
|
19
|
+
# @param sdk_instance [Nylas::API] The API instance to which the resource is bound.
|
20
|
+
def initialize(sdk_instance)
|
21
|
+
super(sdk_instance)
|
22
|
+
@smart_compose = SmartCompose.new(sdk_instance)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Return all messages.
|
26
|
+
#
|
27
|
+
# @param identifier [String] Grant ID or email account to query.
|
28
|
+
# @param query_params [Hash, nil] Query params to pass to the request.
|
29
|
+
# @return [Array(Array(Hash), String, String)] The list of messages, API Request ID, and next cursor.
|
30
|
+
def list(identifier:, query_params: nil)
|
31
|
+
get_list(
|
32
|
+
path: "#{api_uri}/v3/grants/#{identifier}/messages",
|
33
|
+
query_params: query_params
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Return a message.
|
38
|
+
#
|
39
|
+
# @param identifier [String] Grant ID or email account to query.
|
40
|
+
# @param message_id [String] The id of the message to return.
|
41
|
+
# @return [Array(Hash, String)] The message and API request ID.
|
42
|
+
def find(identifier:, message_id:)
|
43
|
+
get(
|
44
|
+
path: "#{api_uri}/v3/grants/#{identifier}/messages/#{message_id}"
|
45
|
+
)
|
46
|
+
end
|
47
|
+
|
48
|
+
# Update a message.
|
49
|
+
#
|
50
|
+
# @param identifier [String] Grant ID or email account in which to update an object.
|
51
|
+
# @param message_id [String] The id of the message to update.
|
52
|
+
# @param request_body [Hash] The values to update the message with
|
53
|
+
# @return [Array(Hash, String)] The updated message and API Request ID.
|
54
|
+
def update(identifier:, message_id:, request_body:)
|
55
|
+
put(
|
56
|
+
path: "#{api_uri}/v3/grants/#{identifier}/messages/#{message_id}",
|
57
|
+
request_body: request_body
|
58
|
+
)
|
59
|
+
end
|
60
|
+
|
61
|
+
# Delete a message.
|
62
|
+
#
|
63
|
+
# @param identifier [String] Grant ID or email account from which to delete an object.
|
64
|
+
# @param message_id [String] The id of the message to delete.
|
65
|
+
# @return [Array(TrueClass, String)] True and the API Request ID for the delete operation.
|
66
|
+
def destroy(identifier:, message_id:)
|
67
|
+
_, request_id = delete(
|
68
|
+
path: "#{api_uri}/v3/grants/#{identifier}/messages/#{message_id}"
|
69
|
+
)
|
70
|
+
|
71
|
+
[true, request_id]
|
72
|
+
end
|
73
|
+
|
74
|
+
# Send a message.
|
75
|
+
#
|
76
|
+
# @param identifier [String] Grant ID or email account from which to delete an object.
|
77
|
+
# @param request_body [Hash] The values to create the message with.
|
78
|
+
# If you're attaching files, you must pass an array of [File] objects, or
|
79
|
+
# you can use {FileUtils::attach_file_request_builder} to build each object attach.
|
80
|
+
# @return [Array(Hash, String)] The sent message and the API Request ID.
|
81
|
+
def send(identifier:, request_body:)
|
82
|
+
payload = request_body
|
83
|
+
opened_files = []
|
84
|
+
|
85
|
+
# Use form data only if the attachment size is greater than 3mb
|
86
|
+
attachments = request_body[:attachments] || request_body["attachments"] || []
|
87
|
+
attachment_size = attachments&.sum { |attachment| attachment[:size] || 0 } || 0
|
88
|
+
|
89
|
+
if attachment_size >= FileUtils::FORM_DATA_ATTACHMENT_SIZE
|
90
|
+
payload, opened_files = FileUtils.build_form_request(request_body)
|
91
|
+
end
|
92
|
+
|
93
|
+
response = post(
|
94
|
+
path: "#{api_uri}/v3/grants/#{identifier}/messages/send",
|
95
|
+
request_body: payload
|
96
|
+
)
|
97
|
+
|
98
|
+
opened_files.each(&:close)
|
99
|
+
|
100
|
+
response
|
101
|
+
end
|
102
|
+
|
103
|
+
# Retrieve your scheduled messages.
|
104
|
+
#
|
105
|
+
# @param identifier [String] Grant ID or email account from which to find the scheduled message from.
|
106
|
+
# @return [Array(Array(Hash), String)] The list of scheduled messages and the API Request ID.
|
107
|
+
def list_scheduled_messages(identifier:)
|
108
|
+
get(
|
109
|
+
path: "#{api_uri}/v3/grants/#{identifier}/messages/schedules"
|
110
|
+
)
|
111
|
+
end
|
112
|
+
|
113
|
+
# Retrieve your scheduled messages.
|
114
|
+
#
|
115
|
+
# @param identifier [String] Grant ID or email account from which to list the scheduled messages from.
|
116
|
+
# @param schedule_id [String] The id of the scheduled message to stop.
|
117
|
+
# @return [Array(Hash, String)] The scheduled message and the API Request ID.
|
118
|
+
def find_scheduled_messages(identifier:, schedule_id:)
|
119
|
+
get(
|
120
|
+
path: "#{api_uri}/v3/grants/#{identifier}/messages/schedules/#{schedule_id}"
|
121
|
+
)
|
122
|
+
end
|
123
|
+
|
124
|
+
# Stop a scheduled message.
|
125
|
+
#
|
126
|
+
# @param identifier [String] Grant ID or email account from which to list the scheduled messages from.
|
127
|
+
# @param schedule_id [String] The id of the scheduled message to stop..
|
128
|
+
# @return [Array(Hash, String)] The scheduled message and the API Request ID.
|
129
|
+
def stop_scheduled_messages(identifier:, schedule_id:)
|
130
|
+
delete(
|
131
|
+
path: "#{api_uri}/v3/grants/#{identifier}/messages/schedules/#{schedule_id}"
|
132
|
+
)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "resource"
|
4
|
+
require_relative "../handler/api_operations"
|
5
|
+
|
6
|
+
module Nylas
|
7
|
+
# A collection of redirect URI related API endpoints.
|
8
|
+
class RedirectUris < Resource
|
9
|
+
include ApiOperations::Get
|
10
|
+
include ApiOperations::Post
|
11
|
+
include ApiOperations::Put
|
12
|
+
include ApiOperations::Delete
|
13
|
+
|
14
|
+
# Return all redirect uris.
|
15
|
+
#
|
16
|
+
# @return [Array(Array(Hash), String)] The list of redirect uris and API Request ID.
|
17
|
+
def list
|
18
|
+
get(
|
19
|
+
path: "#{api_uri}/v3/applications/redirect-uris"
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Return a redirect uri.
|
24
|
+
#
|
25
|
+
# @param redirect_uri_id [String] The id of the redirect uri to return.
|
26
|
+
# @return [Array(Hash, String)] The redirect uri and API request ID.
|
27
|
+
def find(redirect_uri_id:)
|
28
|
+
get(
|
29
|
+
path: "#{api_uri}/v3/applications/redirect-uris/#{redirect_uri_id}"
|
30
|
+
)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Create a redirect uri.
|
34
|
+
#
|
35
|
+
# @param request_body [Hash] The values to create the redirect uri with.
|
36
|
+
# @return [Array(Hash, String)] The created redirect uri and API Request ID.
|
37
|
+
def create(request_body:)
|
38
|
+
post(
|
39
|
+
path: "#{api_uri}/v3/applications/redirect-uris",
|
40
|
+
request_body: request_body
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Update a redirect uri.
|
45
|
+
#
|
46
|
+
# @param redirect_uri_id [String] The id of the redirect uri to update.
|
47
|
+
# @param request_body [Hash] The values to update the redirect uri with
|
48
|
+
# @return [Array(Hash, String)] The updated redirect uri and API Request ID.
|
49
|
+
def update(redirect_uri_id:, request_body:)
|
50
|
+
put(
|
51
|
+
path: "#{api_uri}/v3/applications/redirect-uris/#{redirect_uri_id}",
|
52
|
+
request_body: request_body
|
53
|
+
)
|
54
|
+
end
|
55
|
+
|
56
|
+
# Delete a redirect uri.
|
57
|
+
#
|
58
|
+
# @param redirect_uri_id [String] The id of the redirect uri to delete.
|
59
|
+
# @return [Array(TrueClass, String)] True and the API Request ID for the delete operation.
|
60
|
+
def destroy(redirect_uri_id:)
|
61
|
+
_, request_id = delete(
|
62
|
+
path: "#{api_uri}/v3/applications/redirect-uris/#{redirect_uri_id}"
|
63
|
+
)
|
64
|
+
|
65
|
+
[true, request_id]
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Nylas
|
4
|
+
# NOTE: BaseResource is the base class for all Nylas API resources.
|
5
|
+
# Used by all Nylas API resources
|
6
|
+
class Resource
|
7
|
+
# Initializes a resource.
|
8
|
+
def initialize(sdk_instance)
|
9
|
+
@api_key = sdk_instance.api_key
|
10
|
+
@api_uri = sdk_instance.api_uri
|
11
|
+
@timeout = sdk_instance.timeout
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
attr_reader :resource_name, :api_key, :api_uri, :timeout
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "resource"
|
4
|
+
require_relative "../handler/api_operations"
|
5
|
+
|
6
|
+
module Nylas
|
7
|
+
# Nylas Smart Compose API
|
8
|
+
class SmartCompose < Resource
|
9
|
+
include ApiOperations::Post
|
10
|
+
|
11
|
+
# Compose a message.
|
12
|
+
#
|
13
|
+
# @param identifier [String] Grant ID or email account to generate a message suggestion for.
|
14
|
+
# @param request_body [Hash] The prompt that smart compose will use to generate a message suggestion.
|
15
|
+
# @return [Array(Hash, String)] The generated message and API Request ID.
|
16
|
+
def compose_message(identifier:, request_body:)
|
17
|
+
post(
|
18
|
+
path: "#{api_uri}/v3/grants/#{identifier}/messages/smart-compose",
|
19
|
+
request_body: request_body
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Compose a message reply.
|
24
|
+
#
|
25
|
+
# @param identifier [String] Grant ID or email account to generate a message suggestion for.
|
26
|
+
# @param message_id [String] The id of the message to reply to.
|
27
|
+
# @param request_body [Hash] The prompt that smart compose will use to generate a message reply.
|
28
|
+
# @return [Array(Hash, String)] The generated message reply and API Request ID.
|
29
|
+
def compose_message_reply(identifier:, message_id:, request_body:)
|
30
|
+
post(
|
31
|
+
path: "#{api_uri}/v3/grants/#{identifier}/messages/#{message_id}/smart-compose",
|
32
|
+
request_body: request_body
|
33
|
+
)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "resource"
|
4
|
+
require_relative "../handler/api_operations"
|
5
|
+
|
6
|
+
module Nylas
|
7
|
+
# Nylas Threads API
|
8
|
+
class Threads < Resource
|
9
|
+
include ApiOperations::Get
|
10
|
+
include ApiOperations::Put
|
11
|
+
include ApiOperations::Delete
|
12
|
+
|
13
|
+
# Return all threads.
|
14
|
+
#
|
15
|
+
# @param identifier [String] Grant ID or email account to query.
|
16
|
+
# @param query_params [Hash] Query params to pass to the request.
|
17
|
+
# @return [Array(Array(Hash), String, String)] The list of threads, API Request ID, and next cursor.
|
18
|
+
def list(identifier:, query_params: nil)
|
19
|
+
get_list(
|
20
|
+
path: "#{api_uri}/v3/grants/#{identifier}/threads",
|
21
|
+
query_params: query_params
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Return an thread.
|
26
|
+
#
|
27
|
+
# @param identifier [String] Grant ID or email account to query.
|
28
|
+
# @param thread_id [String] The id of the thread to return.
|
29
|
+
# @return [Array(Hash, String)] The thread and API request ID.
|
30
|
+
def find(identifier:, thread_id:)
|
31
|
+
get(
|
32
|
+
path: "#{api_uri}/v3/grants/#{identifier}/threads/#{thread_id}"
|
33
|
+
)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Update an thread.
|
37
|
+
#
|
38
|
+
# @param identifier [String] Grant ID or email account in which to update the thread.
|
39
|
+
# @param thread_id [String] The id of the thread to update.
|
40
|
+
# @param request_body [Hash] The values to update the thread with
|
41
|
+
# @return [Array(Hash, String)] The updated thread and API Request ID.
|
42
|
+
def update(identifier:, thread_id:, request_body:)
|
43
|
+
put(
|
44
|
+
path: "#{api_uri}/v3/grants/#{identifier}/threads/#{thread_id}",
|
45
|
+
request_body: request_body
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
# Delete an thread.
|
50
|
+
#
|
51
|
+
# @param identifier [String] Grant ID or email account from which to delete the thread.
|
52
|
+
# @param thread_id [String] The id of the thread to delete.
|
53
|
+
# @return [Array(TrueClass, String)] True and the API Request ID for the delete operation.
|
54
|
+
def destroy(identifier:, thread_id:)
|
55
|
+
_, request_id = delete(
|
56
|
+
path: "#{api_uri}/v3/grants/#{identifier}/threads/#{thread_id}"
|
57
|
+
)
|
58
|
+
|
59
|
+
[true, request_id]
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "resource"
|
4
|
+
require_relative "../handler/api_operations"
|
5
|
+
|
6
|
+
module Nylas
|
7
|
+
# Module representing the possible 'trigger' values in a Webhook.
|
8
|
+
# @see https://developer.nylas.com/docs/api#post/a/client_id/webhooks
|
9
|
+
module WebhookTrigger
|
10
|
+
CALENDAR_CREATED = "calendar.created"
|
11
|
+
CALENDAR_UPDATED = "calendar.updated"
|
12
|
+
CALENDAR_DELETED = "calendar.deleted"
|
13
|
+
EVENT_CREATED = "event.created"
|
14
|
+
EVENT_UPDATED = "event.updated"
|
15
|
+
EVENT_DELETED = "event.deleted"
|
16
|
+
GRANT_CREATED = "grant.created"
|
17
|
+
GRANT_UPDATED = "grant.updated"
|
18
|
+
GRANT_DELETED = "grant.deleted"
|
19
|
+
GRANT_EXPIRED = "grant.expired"
|
20
|
+
MESSAGE_SEND_SUCCESS = "message.send_success"
|
21
|
+
MESSAGE_SEND_FAILED = "message.send_failed"
|
22
|
+
MESSAGE_OPENED = "message.opened"
|
23
|
+
MESSAGE_LINK_CLICKED = "message.link_clicked"
|
24
|
+
THREAD_REPLIED = "thread.replied"
|
25
|
+
end
|
26
|
+
|
27
|
+
# Nylas Webhooks API
|
28
|
+
class Webhooks < Resource
|
29
|
+
include ApiOperations::Get
|
30
|
+
include ApiOperations::Post
|
31
|
+
include ApiOperations::Put
|
32
|
+
include ApiOperations::Delete
|
33
|
+
|
34
|
+
# Return all webhooks.
|
35
|
+
#
|
36
|
+
# @return [Array(Array(Hash), String)] The list of webhooks and API Request ID.
|
37
|
+
def list
|
38
|
+
get(
|
39
|
+
path: "#{api_uri}/v3/webhooks"
|
40
|
+
)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Return a webhook.
|
44
|
+
#
|
45
|
+
# @param webhook_id [String] The id of the webhook to return.
|
46
|
+
# @return [Array(Hash, String)] The webhook and API request ID.
|
47
|
+
def find(webhook_id:)
|
48
|
+
get(
|
49
|
+
path: "#{api_uri}/v3/webhooks/#{webhook_id}"
|
50
|
+
)
|
51
|
+
end
|
52
|
+
|
53
|
+
# Create a webhook.
|
54
|
+
#
|
55
|
+
# @param request_body [Hash] The values to create the webhook with.
|
56
|
+
# @return [Array(Hash, String)] The created webhook and API Request ID.
|
57
|
+
def create(request_body:)
|
58
|
+
post(
|
59
|
+
path: "#{api_uri}/v3/webhooks",
|
60
|
+
request_body: request_body
|
61
|
+
)
|
62
|
+
end
|
63
|
+
|
64
|
+
# Update a webhook.
|
65
|
+
#
|
66
|
+
# @param webhook_id [String] The id of the webhook to update.
|
67
|
+
# @param request_body [Hash] The values to update the webhook with
|
68
|
+
# @return [Array(Hash, String)] The updated webhook and API Request ID.
|
69
|
+
def update(webhook_id:, request_body:)
|
70
|
+
put(
|
71
|
+
path: "#{api_uri}/v3/webhooks/#{webhook_id}",
|
72
|
+
request_body: request_body
|
73
|
+
)
|
74
|
+
end
|
75
|
+
|
76
|
+
# Delete a webhook.
|
77
|
+
#
|
78
|
+
# @param webhook_id [String] The id of the webhook to delete.
|
79
|
+
# @return [Array(TrueClass, String)] True and the API Request ID for the delete operation.
|
80
|
+
def destroy(webhook_id:)
|
81
|
+
_, request_id = delete(
|
82
|
+
path: "#{api_uri}/v3/webhooks/#{webhook_id}"
|
83
|
+
)
|
84
|
+
|
85
|
+
[true, request_id]
|
86
|
+
end
|
87
|
+
|
88
|
+
# Update the webhook secret value for a destination.
|
89
|
+
# @param webhook_id [String] The ID of the webhook destination to update.
|
90
|
+
# @return [Array(Hash, String)] The updated webhook destination and API Request ID.
|
91
|
+
def rotate_secret(webhook_id:)
|
92
|
+
post(
|
93
|
+
path: "#{api_uri}/v3/webhooks/rotate-secret/#{webhook_id}",
|
94
|
+
request_body: {}
|
95
|
+
)
|
96
|
+
end
|
97
|
+
|
98
|
+
# Get the current list of IP addresses that Nylas sends webhooks from
|
99
|
+
# @return [Array(Hash, String)] List of IP addresses that Nylas sends webhooks from and API Request ID.
|
100
|
+
def ip_addresses
|
101
|
+
get(
|
102
|
+
path: "#{api_uri}/v3/webhooks/ip-addresses"
|
103
|
+
)
|
104
|
+
end
|
105
|
+
|
106
|
+
# Extract the challenge parameter from a URL
|
107
|
+
# @param url [String] The URL sent by Nylas containing the challenge parameter
|
108
|
+
# @return [String] The challenge parameter
|
109
|
+
def self.extract_challenge_parameter(url)
|
110
|
+
url_object = URI.parse(url)
|
111
|
+
query = CGI.parse(url_object.query || "")
|
112
|
+
|
113
|
+
challenge_parameter = query["challenge"]
|
114
|
+
if challenge_parameter.nil? || challenge_parameter.empty? || challenge_parameter.first.nil?
|
115
|
+
raise "Invalid URL or no challenge parameter found."
|
116
|
+
end
|
117
|
+
|
118
|
+
challenge_parameter.first
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "mime/types"
|
4
|
+
|
5
|
+
module Nylas
|
6
|
+
# A collection of file-related utilities.
|
7
|
+
module FileUtils
|
8
|
+
# The maximum size of an attachment that can be sent using json
|
9
|
+
FORM_DATA_ATTACHMENT_SIZE = 3 * 1024 * 1024
|
10
|
+
|
11
|
+
# Build a form request for the API.
|
12
|
+
# @param request_body The values to create the message with.
|
13
|
+
# @return The form data to send to the API and the opened files.
|
14
|
+
# @!visibility private
|
15
|
+
def self.build_form_request(request_body)
|
16
|
+
attachments = request_body.delete(:attachments) || request_body.delete("attachments") || []
|
17
|
+
|
18
|
+
# RestClient will not send a multipart request if there are no attachments
|
19
|
+
# so we need to return the message payload to be used as a json payload
|
20
|
+
return [request_body, []] if attachments.empty?
|
21
|
+
|
22
|
+
# Prepare the data to return
|
23
|
+
message_payload = request_body.to_json
|
24
|
+
|
25
|
+
form_data = {}
|
26
|
+
opened_files = []
|
27
|
+
|
28
|
+
attachments.each_with_index do |attachment, index|
|
29
|
+
file = attachment[:content] || attachment["content"]
|
30
|
+
form_data.merge!({ "file#{index}" => file })
|
31
|
+
opened_files << file
|
32
|
+
end
|
33
|
+
|
34
|
+
form_data.merge!({ "multipart" => true, "message" => message_payload })
|
35
|
+
|
36
|
+
[form_data, opened_files]
|
37
|
+
end
|
38
|
+
|
39
|
+
# Build the request to attach a file to a message/draft object.
|
40
|
+
# @param file_path [String] The path to the file to attach.
|
41
|
+
# @return [Hash] The request that will attach the file to the message/draft
|
42
|
+
def self.attach_file_request_builder(file_path)
|
43
|
+
filename = File.basename(file_path)
|
44
|
+
content_type = MIME::Types.type_for(file_path)
|
45
|
+
content_type = if !content_type.nil? && !content_type.empty?
|
46
|
+
content_type.first.to_s
|
47
|
+
else
|
48
|
+
"application/octet-stream"
|
49
|
+
end
|
50
|
+
size = File.size(file_path)
|
51
|
+
content = File.new(file_path, "rb")
|
52
|
+
|
53
|
+
{
|
54
|
+
filename: filename,
|
55
|
+
content_type: content_type,
|
56
|
+
size: size,
|
57
|
+
content: content
|
58
|
+
}
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/lib/nylas/version.rb
CHANGED