nylas 5.17.0 → 6.0.0.beta.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/lib/nylas/client.rb +107 -0
  3. data/lib/nylas/config.rb +19 -0
  4. data/lib/nylas/errors.rb +63 -89
  5. data/lib/nylas/handler/api_operations.rb +140 -0
  6. data/lib/nylas/handler/http_client.rb +243 -0
  7. data/lib/nylas/resources/applications.rb +27 -0
  8. data/lib/nylas/resources/attachments.rb +65 -0
  9. data/lib/nylas/resources/auth.rb +211 -0
  10. data/lib/nylas/resources/calendars.rb +101 -0
  11. data/lib/nylas/resources/connectors.rb +80 -0
  12. data/lib/nylas/resources/credentials.rb +75 -0
  13. data/lib/nylas/resources/drafts.rb +91 -0
  14. data/lib/nylas/resources/events.rb +83 -0
  15. data/lib/nylas/resources/folders.rb +73 -0
  16. data/lib/nylas/resources/grants.rb +70 -0
  17. data/lib/nylas/resources/messages.rb +126 -0
  18. data/lib/nylas/resources/redirect_uris.rb +68 -0
  19. data/lib/nylas/resources/resource.rb +18 -0
  20. data/lib/nylas/resources/smart_compose.rb +36 -0
  21. data/lib/nylas/resources/threads.rb +62 -0
  22. data/lib/nylas/resources/webhooks.rb +85 -0
  23. data/lib/nylas/utils/file_utils.rb +49 -0
  24. data/lib/nylas/version.rb +1 -1
  25. data/lib/nylas.rb +30 -148
  26. metadata +87 -247
  27. data/lib/nylas/account.rb +0 -56
  28. data/lib/nylas/api.rb +0 -246
  29. data/lib/nylas/application_details.rb +0 -13
  30. data/lib/nylas/calendar.rb +0 -46
  31. data/lib/nylas/calendar_collection.rb +0 -144
  32. data/lib/nylas/categorize.rb +0 -14
  33. data/lib/nylas/collection.rb +0 -175
  34. data/lib/nylas/component.rb +0 -35
  35. data/lib/nylas/component_collection.rb +0 -10
  36. data/lib/nylas/constraints.rb +0 -56
  37. data/lib/nylas/contact.rb +0 -53
  38. data/lib/nylas/contact_group.rb +0 -23
  39. data/lib/nylas/current_account.rb +0 -23
  40. data/lib/nylas/delta.rb +0 -56
  41. data/lib/nylas/deltas.rb +0 -19
  42. data/lib/nylas/deltas_collection.rb +0 -40
  43. data/lib/nylas/draft.rb +0 -100
  44. data/lib/nylas/email_address.rb +0 -12
  45. data/lib/nylas/event.rb +0 -144
  46. data/lib/nylas/event_collection.rb +0 -15
  47. data/lib/nylas/event_conferencing.rb +0 -12
  48. data/lib/nylas/event_conferencing_autocreate.rb +0 -10
  49. data/lib/nylas/event_conferencing_details.rb +0 -14
  50. data/lib/nylas/event_notification.rb +0 -17
  51. data/lib/nylas/file.rb +0 -75
  52. data/lib/nylas/filter_attributes.rb +0 -25
  53. data/lib/nylas/folder.rb +0 -26
  54. data/lib/nylas/free_busy.rb +0 -13
  55. data/lib/nylas/free_busy_collection.rb +0 -48
  56. data/lib/nylas/http_client.rb +0 -279
  57. data/lib/nylas/im_address.rb +0 -11
  58. data/lib/nylas/job_status.rb +0 -27
  59. data/lib/nylas/job_status_collection.rb +0 -21
  60. data/lib/nylas/label.rb +0 -27
  61. data/lib/nylas/logging.rb +0 -41
  62. data/lib/nylas/message.rb +0 -98
  63. data/lib/nylas/message_headers.rb +0 -27
  64. data/lib/nylas/message_tracking.rb +0 -13
  65. data/lib/nylas/model/attributable.rb +0 -89
  66. data/lib/nylas/model/attribute_definition.rb +0 -24
  67. data/lib/nylas/model/attributes.rb +0 -97
  68. data/lib/nylas/model/list_attribute_definition.rb +0 -39
  69. data/lib/nylas/model/transferable.rb +0 -53
  70. data/lib/nylas/model.rb +0 -217
  71. data/lib/nylas/native_authentication.rb +0 -39
  72. data/lib/nylas/neural.rb +0 -87
  73. data/lib/nylas/neural_categorizer.rb +0 -29
  74. data/lib/nylas/neural_clean_conversation.rb +0 -33
  75. data/lib/nylas/neural_contact_link.rb +0 -11
  76. data/lib/nylas/neural_contact_name.rb +0 -11
  77. data/lib/nylas/neural_message_options.rb +0 -35
  78. data/lib/nylas/neural_ocr.rb +0 -16
  79. data/lib/nylas/neural_sentiment_analysis.rb +0 -17
  80. data/lib/nylas/neural_signature_contact.rb +0 -81
  81. data/lib/nylas/neural_signature_extraction.rb +0 -18
  82. data/lib/nylas/new_message.rb +0 -39
  83. data/lib/nylas/nylas_date.rb +0 -25
  84. data/lib/nylas/open_hours.rb +0 -15
  85. data/lib/nylas/outbox.rb +0 -116
  86. data/lib/nylas/outbox_job_status.rb +0 -19
  87. data/lib/nylas/outbox_message.rb +0 -17
  88. data/lib/nylas/participant.rb +0 -13
  89. data/lib/nylas/phone_number.rb +0 -11
  90. data/lib/nylas/physical_address.rb +0 -17
  91. data/lib/nylas/raw_message.rb +0 -25
  92. data/lib/nylas/recurrence.rb +0 -11
  93. data/lib/nylas/registry.rb +0 -42
  94. data/lib/nylas/room_resource.rb +0 -19
  95. data/lib/nylas/rsvp.rb +0 -24
  96. data/lib/nylas/scheduler.rb +0 -51
  97. data/lib/nylas/scheduler_booking_confirmation.rb +0 -24
  98. data/lib/nylas/scheduler_booking_request.rb +0 -17
  99. data/lib/nylas/scheduler_collection.rb +0 -104
  100. data/lib/nylas/scheduler_config.rb +0 -20
  101. data/lib/nylas/scheduler_time_slot.rb +0 -14
  102. data/lib/nylas/search_collection.rb +0 -10
  103. data/lib/nylas/send_grid_verified_status.rb +0 -12
  104. data/lib/nylas/services/tunnel.rb +0 -128
  105. data/lib/nylas/thread.rb +0 -66
  106. data/lib/nylas/time_slot.rb +0 -16
  107. data/lib/nylas/time_slot_capacity.rb +0 -13
  108. data/lib/nylas/timespan.rb +0 -20
  109. data/lib/nylas/token_info.rb +0 -20
  110. data/lib/nylas/types.rb +0 -168
  111. data/lib/nylas/web_page.rb +0 -11
  112. data/lib/nylas/webhook.rb +0 -111
  113. data/lib/nylas/when.rb +0 -75
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0660c04f6656d846a55819153819877b599ed5342d8f2ea9c18a7b19e0799ec3
4
- data.tar.gz: bf1bd6d4382a6705a5146ff86202436512cf0fc5c68817c77a932e846c3150cf
3
+ metadata.gz: 6fa40920f9d190cc73e988935bdd235ad3a4bb342c8762be925fdb81f8c1c45f
4
+ data.tar.gz: 6bf0722aae4e7b9699abeda1e25436ac62256aa7c14a1f9d330eff2d8908c9c6
5
5
  SHA512:
6
- metadata.gz: 076702b69e4ea6a7ef882f3ac65490d54c90bae69cdc8f940aab62a4d29997627d7936b3426158e10935f1aecfad517e17b2d3c5502aa26a636e48319c492fcd
7
- data.tar.gz: 1d7fd956e5676c2b418ed2d0d79ecfd9cf3b6a961f8768ee0dd97952f0ea043810e90499063b1940efc055506a79187f78d4daf04fe386dfbdf64141bd1d9262
6
+ metadata.gz: 3fb796e62d9c6545d5632c0112ac328ee69ce0fbda26e82a31ce4adf790bea75096a172a7252a4b75da850cf6268a864ea6365137e40f8ff6e7682767bc7f3da
7
+ data.tar.gz: 13b91300931cc49f195f1a3ab01d5c72fe7100bf0c83dcfac5acdd965c0da4b2a7c547bc0611482916c3de8a6f7255604f9ca47f3894f94aba09a483da1f8c73
@@ -0,0 +1,107 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "resources/calendars"
4
+ require_relative "resources/connectors"
5
+ require_relative "resources/messages"
6
+ require_relative "resources/events"
7
+ require_relative "resources/auth"
8
+ require_relative "resources/webhooks"
9
+ require_relative "resources/applications"
10
+ require_relative "resources/folders"
11
+
12
+ module Nylas
13
+ # Methods to retrieve data from the Nylas API as Ruby objects.
14
+ class Client
15
+ attr_reader :api_key, :api_uri, :timeout
16
+
17
+ # Initializes a client session.
18
+ #
19
+ # @param api_key [String, nil] API key to use for the client session.
20
+ # @param api_uri [String] Client session's host.
21
+ # @param timeout [String, nil] Timeout value to use for the client session.
22
+ def initialize(api_key:,
23
+ api_uri: Config::DEFAULT_REGION_URL,
24
+ timeout: nil)
25
+ @api_key = api_key
26
+ @api_uri = api_uri
27
+ @timeout = timeout || 30
28
+ end
29
+
30
+ # The application resources for your Nylas application.
31
+ #
32
+ # @return [Nylas::Applications] Application resources for your Nylas application.
33
+ def applications
34
+ Applications.new(self)
35
+ end
36
+
37
+ # The attachments resources for your Nylas application.
38
+ #
39
+ # @return [Nylas::Attachments] Attachment resources for your Nylas application.
40
+ def attachments
41
+ Attachments.new(self)
42
+ end
43
+
44
+ # The auth resources for your Nylas application.
45
+ #
46
+ # @return [Nylas::Auth] Auth resources for your Nylas application.
47
+ def auth
48
+ Auth.new(self)
49
+ end
50
+
51
+ # The calendar resources for your Nylas application.
52
+ #
53
+ # @return [Nylas::Calendars] Calendar resources for your Nylas application.
54
+ def calendars
55
+ Calendars.new(self)
56
+ end
57
+
58
+ # The connector resources for your Nylas application.
59
+ #
60
+ # @return [Nylas::Connectors] Connector resources for your Nylas application.
61
+ def connectors
62
+ Connectors.new(self)
63
+ end
64
+
65
+ # The draft resources for your Nylas application.
66
+ #
67
+ # @return [Nylas::Drafts] Draft resources for your Nylas application.
68
+ def drafts
69
+ Drafts.new(self)
70
+ end
71
+
72
+ # The event resources for your Nylas application.
73
+ #
74
+ # @return [Nylas::Events] Event resources for your Nylas application
75
+ def events
76
+ Events.new(self)
77
+ end
78
+
79
+ # The folder resources for your Nylas application.
80
+ #
81
+ # @return [Nylas::Folder] Folder resources for your Nylas application
82
+ def folders
83
+ Folders.new(self)
84
+ end
85
+
86
+ # The message resources for your Nylas application.
87
+ #
88
+ # @return [Nylas::Messages] Message resources for your Nylas application
89
+ def messages
90
+ Messages.new(self)
91
+ end
92
+
93
+ # The thread resources for your Nylas application.
94
+ #
95
+ # @return [Nylas::Threads] Thread resources for your Nylas application.
96
+ def threads
97
+ Threads.new(self)
98
+ end
99
+
100
+ # The webhook resources for your Nylas application.
101
+ #
102
+ # @return [Nylas::Webhooks] Webhook resources for your Nylas application.
103
+ def webhooks
104
+ Webhooks.new(self)
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nylas
4
+ # Configuration options for the Nylas Ruby SDK.
5
+ module Config
6
+ # The configuration options for supported regions.
7
+ REGION_CONFIG = {
8
+ us: {
9
+ nylas_api_url: "https://api.us.nylas.com"
10
+ },
11
+ eu: {
12
+ nylas_api_url: "https://api.eu.nylas.com"
13
+ }
14
+ }.freeze
15
+
16
+ # The default API endpoint for the Nylas API.
17
+ DEFAULT_REGION_URL = REGION_CONFIG[:us][:nylas_api_url]
18
+ end
19
+ end
data/lib/nylas/errors.rb CHANGED
@@ -3,109 +3,83 @@
3
3
  module Nylas
4
4
  Error = Class.new(::StandardError)
5
5
 
6
- class ModelActionError < Error; end
7
- class ModelNotFilterableError < ModelActionError; end
8
- class ModelNotCreatableError < ModelActionError; end
9
- class ModelNotShowableError < ModelActionError; end
10
- class ModelNotAvailableAsRawError < ModelActionError; end
11
- class ModelNotListableError < ModelActionError; end
12
- class ModelNotFilterableError < ModelActionError; end
13
- class ModelNotSearchableError < ModelActionError; end
14
- class ModelNotUpdatableError < ModelActionError; end
15
- class ModelNotDestroyableError < ModelActionError; end
16
-
17
- class JsonParseError < Error; end
18
-
19
- # Raised when attempting to set a field that is not on a model with mass assignment
20
- class ModelMissingFieldError < ModelActionError
21
- def initialize(field, model)
22
- super("#{field} is not a valid attribute for #{model.class.name}")
23
- end
24
- end
25
-
26
- # Indicates that a given method needs an access token to work.
27
- class NoAuthToken < Error
28
- def initialize(method_name)
29
- super "No access token was provided and the #{method_name} method requires one"
30
- end
31
- end
32
-
33
- UnexpectedAccountAction = Class.new(Error)
34
- UnexpectedResponse = Class.new(Error)
35
-
36
- # Base class to inflate the standard errors returned from the Nylas API
37
- class APIError < Error
38
- attr_accessor :type
39
- attr_accessor :message
40
- attr_accessor :server_error
41
-
42
- def initialize(type, message, server_error = nil)
6
+ # Base error class for API-related errors.
7
+ class AbstractNylasApiError < Error; end
8
+
9
+ # Base error class for SDK-related errors.
10
+ class AbstractNylasSdkError < Error; end
11
+
12
+ # Error class representing a failed parse of a JSON response from the Nylas API.
13
+ class JsonParseError < AbstractNylasSdkError; end
14
+
15
+ # Error class representing a failed response from the Nylas API.
16
+ class NylasApiError < AbstractNylasApiError
17
+ attr_accessor :type, :request_id, :provider_error, :status_code
18
+
19
+ # Initializes an error and assigns the given attributes to it.
20
+ #
21
+ # @param type [Hash] Error type.
22
+ # @param message [String] Error message.
23
+ # @param status_code [Integer] Error status code.
24
+ # @param provider_error [String, nil] Provider error.
25
+ # @param request_id [Hash, nil] The ID of the request.
26
+ def initialize(type, message, status_code, provider_error = nil, request_id = nil)
43
27
  super(message)
44
28
  self.type = type
45
- self.message = message
46
- self.server_error = server_error
29
+ self.status_code = status_code
30
+ self.provider_error = provider_error
31
+ self.request_id = request_id
47
32
  end
48
33
 
49
- def self.parse_error_response(response)
34
+ # Parses the error response.
35
+ #
36
+ # @param response [Hash] Response from the Nylas API.
37
+ # @param status_code [Integer] Error status code.
38
+ def self.parse_error_response(response, status_code)
50
39
  new(
51
40
  response["type"],
52
41
  response["message"],
53
- response["server_error"]
42
+ status_code,
43
+ response["provider_error"]
54
44
  )
55
45
  end
56
46
  end
57
47
 
58
- # Error class representing a 429 error response, with details on the rate limit
59
- class RateLimitError < APIError
60
- attr_accessor :rate_limit
61
- attr_accessor :rate_limit_reset
62
-
63
- RATE_LIMIT_LIMIT_HEADER = "x_ratelimit_limit"
64
- RATE_LIMIT_RESET_HEADER = "x_ratelimit_reset"
65
-
66
- def initialize(type, message, server_error = nil, rate_limit = nil, rate_limit_reset = nil)
67
- super(type, message, server_error)
68
- self.rate_limit = rate_limit
69
- self.rate_limit_reset = rate_limit_reset
48
+ # Error class representing a failed response from the Nylas OAuth integration.
49
+ class NylasOAuthError < AbstractNylasApiError
50
+ attr_accessor :error, :error_description, :error_uri, :error_code, :status_code
51
+
52
+ # Initializes an error and assigns the given attributes to it.
53
+ #
54
+ # @param error [String] Error type.
55
+ # @param error_description [String] Description of the error.
56
+ # @param error_uri [String] Error URI.
57
+ # @param error_code [String] Error code.
58
+ # @param status_code [String] Error status code.
59
+ def initialize(error, error_description, error_uri, error_code, status_code)
60
+ super(error_description)
61
+ self.error = error
62
+ self.error_description = error_description
63
+ self.error_uri = error_uri
64
+ self.error_code = error_code
65
+ self.status_code = status_code
70
66
  end
67
+ end
71
68
 
72
- def self.parse_error_response(response)
73
- rate_limit, rate_limit_rest = extract_rate_limit_details(response)
74
-
75
- new(
76
- response["type"],
77
- response["message"],
78
- response["server_error"],
79
- rate_limit,
80
- rate_limit_rest
81
- )
82
- end
83
-
84
- def self.extract_rate_limit_details(response)
85
- return nil, nil unless response.respond_to?(:headers)
86
-
87
- rate_limit = response.headers[RATE_LIMIT_LIMIT_HEADER.to_sym].to_i
88
- rate_limit_rest = response.headers[RATE_LIMIT_RESET_HEADER.to_sym].to_i
89
-
90
- [rate_limit, rate_limit_rest]
69
+ # Error class representing a timeout from the Nylas SDK.
70
+ class NylasSdkTimeoutError < AbstractNylasSdkError
71
+ attr_accessor :url, :timeout
72
+
73
+ # Initializes an error and assigns the given attributes to it.
74
+ # @param url [String] URL that timed out.
75
+ # @param timeout [Integer] Timeout in seconds.
76
+ # @return [NylasSdkTimeoutError] The error object.
77
+ def initialize(url, timeout)
78
+ super("Nylas SDK timed out before receiving a response from the server.")
79
+ self.url = url
80
+ self.timeout = timeout
91
81
  end
92
-
93
- private_class_method :extract_rate_limit_details
94
82
  end
95
83
 
96
- AccessDenied = Class.new(APIError)
97
- ResourceNotFound = Class.new(APIError)
98
- MethodNotAllowed = Class.new(APIError)
99
- InvalidRequest = Class.new(APIError)
100
- UnauthorizedRequest = Class.new(APIError)
101
- ResourceRemoved = Class.new(APIError)
102
- TeapotError = Class.new(APIError)
103
- RequestTimedOut = Class.new(APIError)
104
- MessageRejected = Class.new(APIError)
105
- SendingQuotaExceeded = Class.new(RateLimitError)
106
- ServiceUnavailable = Class.new(APIError)
107
- BadGateway = Class.new(APIError)
108
- InternalError = Class.new(APIError)
109
- EndpointNotYetImplemented = Class.new(APIError)
110
- MailProviderError = Class.new(APIError)
84
+ HTTP_SUCCESS_CODES = [200, 201, 202, 302].freeze
111
85
  end
@@ -0,0 +1,140 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "http_client"
4
+
5
+ module Nylas
6
+ # Allows resources to perform API operations on the Nylas API endpoints without exposing the HTTP
7
+ # client to the end user.
8
+ module ApiOperations
9
+ # Performs a GET call to the Nylas API.
10
+ module Get
11
+ protected
12
+
13
+ include HttpClient
14
+ # Performs a GET call to the Nylas API.
15
+ #
16
+ # @param path [String] Destination path for the call.
17
+ # @param query_params [Hash, {}] Query params to pass to the call.
18
+ # @return Nylas data object and API Request ID.
19
+ def get(path:, query_params: {})
20
+ response = execute(
21
+ method: :get,
22
+ path: path,
23
+ query: query_params,
24
+ payload: nil,
25
+ api_key: api_key,
26
+ timeout: timeout
27
+ )
28
+
29
+ [response[:data], response[:request_id]]
30
+ end
31
+ end
32
+
33
+ # Performs a POST call to the Nylas API.
34
+ module Post
35
+ protected
36
+
37
+ include HttpClient
38
+ # Performs a POST call to the Nylas API.
39
+ #
40
+ # @param path [String] Destination path for the call.
41
+ # @param query_params [Hash, {}] Query params to pass to the call.
42
+ # @param request_body [String, Hash, nil] Request body to pass to the call.
43
+ # @param headers [Hash, {}] Additional HTTP headers to include in the payload.
44
+ # @return Nylas data object and API Request ID.
45
+ def post(path:, query_params: {}, request_body: nil, headers: {})
46
+ response = execute(
47
+ method: :post,
48
+ path: path,
49
+ query: query_params,
50
+ payload: request_body,
51
+ headers: headers,
52
+ api_key: api_key,
53
+ timeout: timeout
54
+ )
55
+
56
+ [response[:data], response[:request_id]]
57
+ end
58
+ end
59
+
60
+ # Performs a PUT call to the Nylas API.
61
+ module Put
62
+ protected
63
+
64
+ include HttpClient
65
+ # Performs a PUT call to the Nylas API.
66
+ #
67
+ # @param path [String] Destination path for the call.
68
+ # @param query_params [Hash, {}] Query params to pass to the call.
69
+ # @param request_body [String, Hash, nil] Request body to pass to the call.
70
+ # @param headers [Hash, {}] Additional HTTP headers to include in the payload.
71
+ # @return Nylas data object and API Request ID.
72
+ def put(path:, query_params: {}, request_body: nil, headers: {})
73
+ response = execute(
74
+ method: :put,
75
+ path: path,
76
+ query: query_params,
77
+ payload: request_body,
78
+ headers: headers,
79
+ api_key: api_key,
80
+ timeout: timeout
81
+ )
82
+
83
+ [response[:data], response[:request_id]]
84
+ end
85
+ end
86
+
87
+ # Performs a PATCH call to the Nylas API.
88
+ module Patch
89
+ protected
90
+
91
+ include HttpClient
92
+ # Performs a PATCH call to the Nylas API.
93
+ #
94
+ # @param path [String] Destination path for the call.
95
+ # @param query_params [Hash, {}] Query params to pass to the call.
96
+ # @param request_body [String, Hash, nil] Request body to pass to the call.
97
+ # @param headers [Hash, {}] Additional HTTP headers to include in the payload.
98
+ # @return Nylas data object and API Request ID.
99
+ def patch(path:, query_params: {}, request_body: nil, headers: {})
100
+ response = execute(
101
+ method: :patch,
102
+ path: path,
103
+ query: query_params,
104
+ payload: request_body,
105
+ headers: headers,
106
+ api_key: api_key,
107
+ timeout: timeout
108
+ )
109
+
110
+ [response[:data], response[:request_id]]
111
+ end
112
+ end
113
+
114
+ # Performs a DELETE call to the Nylas API.
115
+ module Delete
116
+ protected
117
+
118
+ include HttpClient
119
+ # Performs a DELETE call to the Nylas API.
120
+ #
121
+ # @param path [String] Destination path for the call.
122
+ # @param query_params [Hash, {}] Query params to pass to the call.
123
+ # @param headers [Hash, {}] Additional HTTP headers to include in the payload.
124
+ # @return Nylas data object and API Request ID.
125
+ def delete(path:, query_params: {}, headers: {})
126
+ response = execute(
127
+ method: :delete,
128
+ path: path,
129
+ query: query_params,
130
+ headers: headers,
131
+ payload: nil,
132
+ api_key: api_key,
133
+ timeout: timeout
134
+ )
135
+
136
+ [response[:data], response[:request_id]]
137
+ end
138
+ end
139
+ end
140
+ end