nylas 6.4.0 → 6.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 275a09b48ad361ba1f441efa8b32a026fa547c0296ea3b681da440e6c7652516
4
- data.tar.gz: 813293f38fabeb6cbfae1a9974a6e27622c68352442982a49890c176c354a2d5
3
+ metadata.gz: f9529fffa30430e822edf113d38aa1a179f0995b29d2bec8c3ac5f9a26d4d8c7
4
+ data.tar.gz: 8710b98962a46bef277461df24f5e64dedd9bdbe7949838b2b3d8aab38b36f10
5
5
  SHA512:
6
- metadata.gz: 3453ab99f8e2ab3bec6abd2f2cad0c8ea0d43e26a328eb3ff318b2c250f3cc4d699396c7638648118f4b2af47d37aca767f4106ad04dc5a0858b2c99f6814d5e
7
- data.tar.gz: 236711014f51f24b29c64fbe578cf0eea851cb44bb486dec3ec39c73a9311cb84a42d1f78d5c29e5eeae8025aef154e9e2ae74789fc50c9b5ebfe39eb9226a93
6
+ metadata.gz: 20e35b192df7f3dfaf0d50065556d3ef0c19e959504dc124ec3bd2a6f657ffebb7a61b4808517494b2d79d4ceccdd8ce88e45d49109c142ad366592481a67b56
7
+ data.tar.gz: d957251f63c3c8aa8b90adde51ba2ea7fe52be3b08ca8017e1b91a22c4e42c4d428a720c1b3a18191d1861d2bf379ebd93e481b30547ffbe4ce8f99578e85fb1
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "rest-client"
3
+ require "httparty"
4
+ require "net/http"
4
5
 
5
6
  require_relative "../errors"
6
7
  require_relative "../version"
@@ -34,18 +35,18 @@ module Nylas
34
35
  request = build_request(method: method, path: path, headers: headers,
35
36
  query: query, payload: payload, api_key: api_key, timeout: timeout)
36
37
  begin
37
- rest_client_execute(**request) do |response, _request, result|
38
+ httparty_execute(**request) do |response, _request, result|
38
39
  content_type = nil
39
- if response.headers && response.headers[:content_type]
40
- content_type = response.headers[:content_type].downcase
40
+ if response.headers && response.headers["content-type"]
41
+ content_type = response.headers["content-type"].downcase
41
42
  end
42
43
 
43
- parsed_response = parse_json_evaluate_error(result.code.to_i, response, path, content_type)
44
+ parsed_response = parse_json_evaluate_error(result.code.to_i, response.body, path, content_type)
44
45
  # Include headers in the response
45
46
  parsed_response[:headers] = response.headers unless parsed_response.nil?
46
47
  parsed_response
47
48
  end
48
- rescue RestClient::Exceptions::OpenTimeout, RestClient::Exceptions::ReadTimeout
49
+ rescue Net::OpenTimeout, Net::ReadTimeout
49
50
  raise Nylas::NylasSdkTimeoutError.new(request[:path], timeout)
50
51
  end
51
52
  end
@@ -97,11 +98,17 @@ module Nylas
97
98
  )
98
99
  url = build_url(path, query)
99
100
  resulting_headers = default_headers.merge(headers).merge(auth_header(api_key))
100
- if !payload.nil? && !payload["multipart"]
101
+
102
+ # Check for multipart flag using both string and symbol keys for backwards compatibility
103
+ is_multipart = !payload.nil? && (payload["multipart"] || payload[:multipart])
104
+
105
+ if !payload.nil? && !is_multipart
101
106
  payload = payload&.to_json
102
107
  resulting_headers["Content-type"] = "application/json"
103
- elsif !payload.nil? && payload["multipart"]
108
+ elsif is_multipart
109
+ # Remove multipart flag from both possible key types
104
110
  payload.delete("multipart")
111
+ payload.delete(:multipart)
105
112
  end
106
113
 
107
114
  { method: method, url: url, payload: payload, headers: resulting_headers, timeout: timeout }
@@ -126,16 +133,52 @@ module Nylas
126
133
 
127
134
  private
128
135
 
129
- # Sends a request to the Nylas REST API.
136
+ # Sends a request to the Nylas REST API using HTTParty.
130
137
  #
131
138
  # @param method [Symbol] HTTP method for the API call. Either :get, :post, :delete, or :patch.
132
139
  # @param url [String] URL for the API call.
133
140
  # @param headers [Hash] HTTP headers to include in the payload.
134
141
  # @param payload [String, Hash] Body to send with the request.
135
142
  # @param timeout [Hash] Timeout value to send with the request.
136
- def rest_client_execute(method:, url:, headers:, payload:, timeout:, &block)
137
- ::RestClient::Request.execute(method: method, url: url, payload: payload,
138
- headers: headers, timeout: timeout, &block)
143
+ def httparty_execute(method:, url:, headers:, payload:, timeout:)
144
+ options = {
145
+ headers: headers,
146
+ timeout: timeout
147
+ }
148
+
149
+ # Handle multipart uploads
150
+ if payload.is_a?(Hash) && file_upload?(payload)
151
+ options[:multipart] = true
152
+ options[:body] = payload
153
+ elsif payload
154
+ options[:body] = payload
155
+ end
156
+
157
+ response = HTTParty.send(method, url, options)
158
+
159
+ # Create a compatible response object that mimics RestClient::Response
160
+ result = create_response_wrapper(response)
161
+
162
+ # Call the block with the response in the same format as rest-client
163
+ if block_given?
164
+ yield response, nil, result
165
+ else
166
+ response
167
+ end
168
+ end
169
+
170
+ # Create a response wrapper that mimics RestClient::Response.code behavior
171
+ def create_response_wrapper(response)
172
+ OpenStruct.new(code: response.code)
173
+ end
174
+
175
+ # Check if payload contains file uploads
176
+ def file_upload?(payload)
177
+ return false unless payload.is_a?(Hash)
178
+
179
+ payload.values.any? do |value|
180
+ value.respond_to?(:read) || (value.is_a?(File) && !value.closed?)
181
+ end
139
182
  end
140
183
 
141
184
  def setup_http(path, timeout, headers, query, api_key)
@@ -6,6 +6,19 @@ require_relative "../handler/api_operations"
6
6
  require_relative "../utils/file_utils"
7
7
 
8
8
  module Nylas
9
+ # Module representing the possible 'fields' values for Messages API requests.
10
+ # @see https://developer.nylas.com/docs/api/messages#get-/v3/grants/-identifier-/messages
11
+ module MessageFields
12
+ # Return the standard message payload (default)
13
+ STANDARD = "standard"
14
+ # Return messages and their custom headers
15
+ INCLUDE_HEADERS = "include_headers"
16
+ # Return messages and their tracking settings
17
+ INCLUDE_TRACKING_OPTIONS = "include_tracking_options"
18
+ # Return the grant_id, object, id, and raw_mime fields only
19
+ RAW_MIME = "raw_mime"
20
+ end
21
+
9
22
  # Nylas Messages API
10
23
  class Messages < Resource
11
24
  include ApiOperations::Get
@@ -26,6 +39,11 @@ module Nylas
26
39
  #
27
40
  # @param identifier [String] Grant ID or email account to query.
28
41
  # @param query_params [Hash, nil] Query params to pass to the request.
42
+ # You can use the fields parameter to specify which data to return:
43
+ # - MessageFields::STANDARD (default): Returns the standard message payload
44
+ # - MessageFields::INCLUDE_HEADERS: Returns messages and their custom headers
45
+ # - MessageFields::INCLUDE_TRACKING_OPTIONS: Returns messages and their tracking settings
46
+ # - MessageFields::RAW_MIME: Returns the grant_id, object, id, and raw_mime fields only
29
47
  # @return [Array(Array(Hash), String, String)] The list of messages, API Request ID, and next cursor.
30
48
  def list(identifier:, query_params: nil)
31
49
  get_list(
@@ -39,6 +57,11 @@ module Nylas
39
57
  # @param identifier [String] Grant ID or email account to query.
40
58
  # @param message_id [String] The id of the message to return.
41
59
  # @param query_params [Hash, nil] Query params to pass to the request.
60
+ # You can use the fields parameter to specify which data to return:
61
+ # - MessageFields::STANDARD (default): Returns the standard message payload
62
+ # - MessageFields::INCLUDE_HEADERS: Returns messages and their custom headers
63
+ # - MessageFields::INCLUDE_TRACKING_OPTIONS: Returns messages and their tracking settings
64
+ # - MessageFields::RAW_MIME: Returns the grant_id, object, id, and raw_mime fields only
42
65
  # @return [Array(Hash, String)] The message and API request ID.
43
66
  def find(identifier:, message_id:, query_params: nil)
44
67
  get(
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.4.0"
4
+ VERSION = "6.5.0"
5
5
  end
data/lib/nylas.rb CHANGED
@@ -1,21 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "json"
4
- require "rest-client"
5
-
6
- # BUGFIX
7
- # See https://github.com/sparklemotion/http-cookie/issues/27
8
- # and https://github.com/sparklemotion/http-cookie/issues/6
9
- #
10
- # CookieJar uses unsafe class caching for dynamically loading cookie jars.
11
- # If two rest-client instances are instantiated at the same time (in threads), non-deterministic
12
- # behaviour can occur whereby the Hash cookie jar isn't properly loaded and cached.
13
- # Forcing an instantiation of the jar onload will force the CookieJar to load before the system has
14
- # a chance to spawn any threads.
15
- # Note that this should technically be fixed in rest-client itself, however that library appears to
16
- # be stagnant so we're forced to fix it here.
17
- # This object should get GC'd as it's not referenced by anything.
18
- HTTP::CookieJar.new
4
+ require "httparty"
19
5
 
20
6
  require "ostruct"
21
7
  require "forwardable"
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.4.0
4
+ version: 6.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nylas, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-04-30 00:00:00.000000000 Z
11
+ date: 2025-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: base64
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: httparty
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.21'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.21'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: mime-types
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -58,26 +72,6 @@ dependencies:
58
72
  - - "~>"
59
73
  - !ruby/object:Gem::Version
60
74
  version: '0.6'
61
- - !ruby/object:Gem::Dependency
62
- name: rest-client
63
- requirement: !ruby/object:Gem::Requirement
64
- requirements:
65
- - - ">="
66
- - !ruby/object:Gem::Version
67
- version: 2.0.0
68
- - - "<"
69
- - !ruby/object:Gem::Version
70
- version: '3.0'
71
- type: :runtime
72
- prerelease: false
73
- version_requirements: !ruby/object:Gem::Requirement
74
- requirements:
75
- - - ">="
76
- - !ruby/object:Gem::Version
77
- version: 2.0.0
78
- - - "<"
79
- - !ruby/object:Gem::Version
80
- version: '3.0'
81
75
  - !ruby/object:Gem::Dependency
82
76
  name: yajl-ruby
83
77
  requirement: !ruby/object:Gem::Requirement