nylas 6.0.3 → 6.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3bd6fdcadf69439f1f8a8549e26e3b43f4df3cfeb8ae0c5a2aef5aca8fb3acce
4
- data.tar.gz: b1f939a98c16ec5bf390791df31bb0f76feb45af07e4e6bcfc32c52e79e3b53f
3
+ metadata.gz: a2876cab1f609fb357369d692fa8ed5b0fa04754d8b95b30b9d483856bbcff2e
4
+ data.tar.gz: 94db4b8a8c253c4737348dcdb2fbdddf0fbdf021ac626ef0318ade71da4bf247
5
5
  SHA512:
6
- metadata.gz: 591735adfae3cfefdbc513762eff603390779f14321a543bf0a2115f3a368f1b674175c6e5cbea9052b4e10db157d74a3cda80b74773b212bbda2e38fc25aea0
7
- data.tar.gz: 17dc68c13af649f533d206a546a72cf45b508864f71d2daae1eb020f686ce5b79c39829d841dd919cc944cd038042f4075116a7a941c2f782b6ae127c35d63a8
6
+ metadata.gz: bade836048e4f19c3a1aebcf03a792bb73d38d850473fe9e60ff116fe6e7ca613f5e48c7f4d4f959f36cf0b361f3b2e7414cc96d5347c60bd7d306961da13e55
7
+ data.tar.gz: 76d8048ed9eb92a1a660e3edc4d04cda08d7a676898c40092739f60c87250b99afefb19cf04ceef79b08a8cc7bf5425b87178d02e019f74c9937694a86d953e7
@@ -16,6 +16,18 @@ module Nylas
16
16
  include ApiOperations::Post
17
17
  include ApiOperations::Get
18
18
 
19
+ # Get info about a specific token based on the identifier you include.
20
+ # Use either the ID Token or Access Token.
21
+ #
22
+ # @param ID of the request.
23
+ # @return [Hash] Token Info.
24
+ def access_token_info(query_params: nil)
25
+ get(
26
+ path: "#{api_uri}/v3/connect/tokeninfo",
27
+ query_params: query_params
28
+ )
29
+ end
30
+
19
31
  # Builds the URL for authenticating users to your application with OAuth 2.0.
20
32
  #
21
33
  # @param config [Hash] Configuration for building the URL.
@@ -40,19 +40,11 @@ module Nylas
40
40
  # @param identifier [String] Grant ID or email account in which to create the draft.
41
41
  # @param request_body [Hash] The values to create the message with.
42
42
  # If you're attaching files, you must pass an array of [File] objects, or
43
- # you can use {FileUtils::attach_file_request_builder} to build each object attach.
43
+ # you can pass in base64 encoded strings if the total attachment size is less than 3mb.
44
+ # You can also use {FileUtils::attach_file_request_builder} to build each object attach.
44
45
  # @return [Array(Hash, String)] The created draft and API Request ID.
45
46
  def create(identifier:, request_body:)
46
- payload = request_body
47
- opened_files = []
48
-
49
- # Use form data only if the attachment size is greater than 3mb
50
- attachments = request_body[:attachments] || request_body["attachments"] || []
51
- attachment_size = attachments&.sum { |attachment| attachment[:size] || 0 } || 0
52
-
53
- if attachment_size >= FileUtils::FORM_DATA_ATTACHMENT_SIZE
54
- payload, opened_files = FileUtils.build_form_request(request_body)
55
- end
47
+ payload, opened_files = FileUtils.handle_message_payload(request_body)
56
48
 
57
49
  response = post(
58
50
  path: "#{api_uri}/v3/grants/#{identifier}/drafts",
@@ -70,19 +62,11 @@ module Nylas
70
62
  # @param draft_id [String] The id of the draft to update.
71
63
  # @param request_body [Hash] The values to create the message with.
72
64
  # If you're attaching files, you must pass an array of [File] objects, or
73
- # you can use {FileUtils::attach_file_request_builder} to build each object attach.
65
+ # you can pass in base64 encoded strings if the total attachment size is less than 3mb.
66
+ # You can also use {FileUtils::attach_file_request_builder} to build each object attach.
74
67
  # @return [Array(Hash, String)] The updated draft and API Request ID.
75
68
  def update(identifier:, draft_id:, request_body:)
76
- payload = request_body
77
- opened_files = []
78
-
79
- # Use form data only if the attachment size is greater than 3mb
80
- attachments = request_body[:attachments] || request_body["attachments"] || []
81
- attachment_size = attachments&.sum { |attachment| attachment[:size] || 0 } || 0
82
-
83
- if attachment_size >= FileUtils::FORM_DATA_ATTACHMENT_SIZE
84
- payload, opened_files = FileUtils.build_form_request(request_body)
85
- end
69
+ payload, opened_files = FileUtils.handle_message_payload(request_body)
86
70
 
87
71
  response = put(
88
72
  path: "#{api_uri}/v3/grants/#{identifier}/drafts/#{draft_id}",
@@ -38,10 +38,12 @@ module Nylas
38
38
  #
39
39
  # @param identifier [String] Grant ID or email account to query.
40
40
  # @param message_id [String] The id of the message to return.
41
+ # @param query_params [Hash, nil] Query params to pass to the request.
41
42
  # @return [Array(Hash, String)] The message and API request ID.
42
- def find(identifier:, message_id:)
43
+ def find(identifier:, message_id:, query_params: nil)
43
44
  get(
44
- path: "#{api_uri}/v3/grants/#{identifier}/messages/#{message_id}"
45
+ path: "#{api_uri}/v3/grants/#{identifier}/messages/#{message_id}",
46
+ query_params: query_params
45
47
  )
46
48
  end
47
49
 
@@ -50,11 +52,13 @@ module Nylas
50
52
  # @param identifier [String] Grant ID or email account in which to update an object.
51
53
  # @param message_id [String] The id of the message to update.
52
54
  # @param request_body [Hash] The values to update the message with
55
+ # @param query_params [Hash, nil] Query params to pass to the request.
53
56
  # @return [Array(Hash, String)] The updated message and API Request ID.
54
- def update(identifier:, message_id:, request_body:)
57
+ def update(identifier:, message_id:, request_body:, query_params: nil)
55
58
  put(
56
59
  path: "#{api_uri}/v3/grants/#{identifier}/messages/#{message_id}",
57
- request_body: request_body
60
+ request_body: request_body,
61
+ query_params: query_params
58
62
  )
59
63
  end
60
64
 
@@ -71,24 +75,28 @@ module Nylas
71
75
  [true, request_id]
72
76
  end
73
77
 
78
+ # Clean a message.
79
+ #
80
+ # @param identifier [String] Grant ID or email account from which to clean a message.
81
+ # @param request_body [Hash] The options to clean a message with
82
+ # @return [Array(Hash)] The list of clean messages.
83
+ def clean_messages(identifier:, request_body:)
84
+ put(
85
+ path: "#{api_uri}/v3/grants/#{identifier}/messages/clean",
86
+ request_body: request_body
87
+ )
88
+ end
89
+
74
90
  # Send a message.
75
91
  #
76
92
  # @param identifier [String] Grant ID or email account from which to delete an object.
77
93
  # @param request_body [Hash] The values to create the message with.
78
94
  # 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.
95
+ # you can pass in base64 encoded strings if the total attachment size is less than 3mb.
96
+ # You can also use {FileUtils::attach_file_request_builder} to build each object attach.
80
97
  # @return [Array(Hash, String)] The sent message and the API Request ID.
81
98
  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
99
+ payload, opened_files = FileUtils.handle_message_payload(request_body)
92
100
 
93
101
  response = post(
94
102
  path: "#{api_uri}/v3/grants/#{identifier}/messages/send",
@@ -19,9 +19,14 @@ module Nylas
19
19
  GRANT_EXPIRED = "grant.expired"
20
20
  MESSAGE_SEND_SUCCESS = "message.send_success"
21
21
  MESSAGE_SEND_FAILED = "message.send_failed"
22
+ MESSAGE_CREATED = "message.created"
23
+ MESSAGE_UPDATED = "message.updated"
22
24
  MESSAGE_OPENED = "message.opened"
23
25
  MESSAGE_LINK_CLICKED = "message.link_clicked"
24
26
  THREAD_REPLIED = "thread.replied"
27
+ FOLDER_CREATED = "folder.created"
28
+ FOLDER_UPDATE = "folder.updated"
29
+ FOLDER_DELETED = "folder.deleted"
25
30
  end
26
31
 
27
32
  # Nylas Webhooks API
@@ -36,6 +36,50 @@ module Nylas
36
36
  [form_data, opened_files]
37
37
  end
38
38
 
39
+ # Build a json attachment request for the API.
40
+ # @param attachments The attachments to send with the message. Can be a file object or a base64 string.
41
+ # @return The properly-formatted json data to send to the API and the opened files.
42
+ # @!visibility private
43
+ def self.build_json_request(attachments)
44
+ opened_files = []
45
+
46
+ attachments.each_with_index do |attachment, _index|
47
+ current_attachment = attachment[:content]
48
+ next unless current_attachment
49
+
50
+ if current_attachment.respond_to?(:read)
51
+ attachment[:content] = Base64.strict_encode64(current_attachment.read)
52
+ opened_files << current_attachment
53
+ else
54
+ attachment[:content] = current_attachment
55
+ end
56
+ end
57
+
58
+ [attachments, opened_files]
59
+ end
60
+
61
+ # Handle encoding the message payload.
62
+ # @param request_body The values to create the message with.
63
+ # @return The encoded message payload and any opened files.
64
+ # @!visibility private
65
+ def self.handle_message_payload(request_body)
66
+ payload = request_body.transform_keys(&:to_sym)
67
+ opened_files = []
68
+
69
+ # Use form data only if the attachment size is greater than 3mb
70
+ attachments = payload[:attachments]
71
+ attachment_size = attachments&.sum { |attachment| attachment[:size] || 0 } || 0
72
+
73
+ # Handle the attachment encoding depending on the size
74
+ if attachment_size >= FORM_DATA_ATTACHMENT_SIZE
75
+ payload, opened_files = build_form_request(request_body)
76
+ else
77
+ payload[:attachments], opened_files = build_json_request(attachments) unless attachments.nil?
78
+ end
79
+
80
+ [payload, opened_files]
81
+ end
82
+
39
83
  # Build the request to attach a file to a message/draft object.
40
84
  # @param file_path [String] The path to the file to attach.
41
85
  # @return [Hash] The request that will attach the file to the message/draft
data/lib/nylas/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nylas
4
- VERSION = "6.0.3"
4
+ VERSION = "6.1.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nylas
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.3
4
+ version: 6.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nylas, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-05 00:00:00.000000000 Z
11
+ date: 2024-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mime-types