nylas 5.17.0 → 6.0.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/lib/nylas/client.rb +62 -0
  3. data/lib/nylas/config.rb +19 -0
  4. data/lib/nylas/errors.rb +41 -89
  5. data/lib/nylas/handler/admin_api_operations.rb +95 -0
  6. data/lib/nylas/handler/api_operations.rb +138 -0
  7. data/lib/nylas/handler/grants_api_operations.rb +99 -0
  8. data/lib/nylas/handler/http_client.rb +179 -0
  9. data/lib/nylas/resources/applications.rb +27 -0
  10. data/lib/nylas/resources/auth.rb +197 -0
  11. data/lib/nylas/resources/calendars.rb +31 -0
  12. data/lib/nylas/resources/events.rb +20 -0
  13. data/lib/nylas/resources/grants.rb +20 -0
  14. data/lib/nylas/resources/redirect_uris.rb +20 -0
  15. data/lib/nylas/resources/resource.rb +18 -0
  16. data/lib/nylas/resources/webhooks.rb +37 -0
  17. data/lib/nylas/version.rb +1 -1
  18. data/lib/nylas.rb +20 -148
  19. metadata +70 -257
  20. data/lib/nylas/account.rb +0 -56
  21. data/lib/nylas/api.rb +0 -246
  22. data/lib/nylas/application_details.rb +0 -13
  23. data/lib/nylas/calendar.rb +0 -46
  24. data/lib/nylas/calendar_collection.rb +0 -144
  25. data/lib/nylas/categorize.rb +0 -14
  26. data/lib/nylas/collection.rb +0 -175
  27. data/lib/nylas/component.rb +0 -35
  28. data/lib/nylas/component_collection.rb +0 -10
  29. data/lib/nylas/constraints.rb +0 -56
  30. data/lib/nylas/contact.rb +0 -53
  31. data/lib/nylas/contact_group.rb +0 -23
  32. data/lib/nylas/current_account.rb +0 -23
  33. data/lib/nylas/delta.rb +0 -56
  34. data/lib/nylas/deltas.rb +0 -19
  35. data/lib/nylas/deltas_collection.rb +0 -40
  36. data/lib/nylas/draft.rb +0 -100
  37. data/lib/nylas/email_address.rb +0 -12
  38. data/lib/nylas/event.rb +0 -144
  39. data/lib/nylas/event_collection.rb +0 -15
  40. data/lib/nylas/event_conferencing.rb +0 -12
  41. data/lib/nylas/event_conferencing_autocreate.rb +0 -10
  42. data/lib/nylas/event_conferencing_details.rb +0 -14
  43. data/lib/nylas/event_notification.rb +0 -17
  44. data/lib/nylas/file.rb +0 -75
  45. data/lib/nylas/filter_attributes.rb +0 -25
  46. data/lib/nylas/folder.rb +0 -26
  47. data/lib/nylas/free_busy.rb +0 -13
  48. data/lib/nylas/free_busy_collection.rb +0 -48
  49. data/lib/nylas/http_client.rb +0 -279
  50. data/lib/nylas/im_address.rb +0 -11
  51. data/lib/nylas/job_status.rb +0 -27
  52. data/lib/nylas/job_status_collection.rb +0 -21
  53. data/lib/nylas/label.rb +0 -27
  54. data/lib/nylas/logging.rb +0 -41
  55. data/lib/nylas/message.rb +0 -98
  56. data/lib/nylas/message_headers.rb +0 -27
  57. data/lib/nylas/message_tracking.rb +0 -13
  58. data/lib/nylas/model/attributable.rb +0 -89
  59. data/lib/nylas/model/attribute_definition.rb +0 -24
  60. data/lib/nylas/model/attributes.rb +0 -97
  61. data/lib/nylas/model/list_attribute_definition.rb +0 -39
  62. data/lib/nylas/model/transferable.rb +0 -53
  63. data/lib/nylas/model.rb +0 -217
  64. data/lib/nylas/native_authentication.rb +0 -39
  65. data/lib/nylas/neural.rb +0 -87
  66. data/lib/nylas/neural_categorizer.rb +0 -29
  67. data/lib/nylas/neural_clean_conversation.rb +0 -33
  68. data/lib/nylas/neural_contact_link.rb +0 -11
  69. data/lib/nylas/neural_contact_name.rb +0 -11
  70. data/lib/nylas/neural_message_options.rb +0 -35
  71. data/lib/nylas/neural_ocr.rb +0 -16
  72. data/lib/nylas/neural_sentiment_analysis.rb +0 -17
  73. data/lib/nylas/neural_signature_contact.rb +0 -81
  74. data/lib/nylas/neural_signature_extraction.rb +0 -18
  75. data/lib/nylas/new_message.rb +0 -39
  76. data/lib/nylas/nylas_date.rb +0 -25
  77. data/lib/nylas/open_hours.rb +0 -15
  78. data/lib/nylas/outbox.rb +0 -116
  79. data/lib/nylas/outbox_job_status.rb +0 -19
  80. data/lib/nylas/outbox_message.rb +0 -17
  81. data/lib/nylas/participant.rb +0 -13
  82. data/lib/nylas/phone_number.rb +0 -11
  83. data/lib/nylas/physical_address.rb +0 -17
  84. data/lib/nylas/raw_message.rb +0 -25
  85. data/lib/nylas/recurrence.rb +0 -11
  86. data/lib/nylas/registry.rb +0 -42
  87. data/lib/nylas/room_resource.rb +0 -19
  88. data/lib/nylas/rsvp.rb +0 -24
  89. data/lib/nylas/scheduler.rb +0 -51
  90. data/lib/nylas/scheduler_booking_confirmation.rb +0 -24
  91. data/lib/nylas/scheduler_booking_request.rb +0 -17
  92. data/lib/nylas/scheduler_collection.rb +0 -104
  93. data/lib/nylas/scheduler_config.rb +0 -20
  94. data/lib/nylas/scheduler_time_slot.rb +0 -14
  95. data/lib/nylas/search_collection.rb +0 -10
  96. data/lib/nylas/send_grid_verified_status.rb +0 -12
  97. data/lib/nylas/services/tunnel.rb +0 -128
  98. data/lib/nylas/thread.rb +0 -66
  99. data/lib/nylas/time_slot.rb +0 -16
  100. data/lib/nylas/time_slot_capacity.rb +0 -13
  101. data/lib/nylas/timespan.rb +0 -20
  102. data/lib/nylas/token_info.rb +0 -20
  103. data/lib/nylas/types.rb +0 -168
  104. data/lib/nylas/web_page.rb +0 -11
  105. data/lib/nylas/webhook.rb +0 -111
  106. data/lib/nylas/when.rb +0 -75
@@ -0,0 +1,179 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rest-client"
4
+
5
+ require_relative "../errors"
6
+ require_relative "../version"
7
+
8
+ module Nylas
9
+ require "yajl"
10
+ require "base64"
11
+
12
+ # Plain HTTP client that can be used to interact with the Nylas API without any type casting.
13
+ module HttpClient
14
+ protected
15
+
16
+ attr_accessor :api_server
17
+ attr_writer :default_headers
18
+
19
+ # Sends a request to the Nylas API. Returns a successful response if the request succeeds, or a
20
+ # failed response if the request encounters a JSON parse error.
21
+ #
22
+ # @param method [Symbol] HTTP method for the API call. Either :get, :post, :delete, or :patch.
23
+ # @param path [String, nil] Relative path from the API Base. This is the preferred way to execute
24
+ # arbitrary or-not-yet-SDK-ified API commands.
25
+ # @param headers [Hash, {}] Additional HTTP headers to include in the payload.
26
+ # @param query [Hash, {}] Hash of names and values to include in the query section of the URI
27
+ # fragment.
28
+ # @param payload [String, Hash, nil] Body to send with the request.
29
+ # @param api_key [Hash, nil] API key to send with the request.
30
+ # @param timeout [Hash, nil] Timeout value to send with the request.
31
+ # @return [Object] Parsed JSON response from the API.
32
+ def execute(method:, path: nil, headers: {}, query: {}, payload: nil, api_key: nil, timeout: nil)
33
+ request = build_request(method: method, path: path, headers: headers,
34
+ query: query, payload: payload, api_key: api_key, timeout: timeout)
35
+ rest_client_execute(**request) do |response, _request, result|
36
+ content_type = nil
37
+
38
+ if response.headers && response.headers[:content_type]
39
+ content_type = response.headers[:content_type].downcase
40
+ end
41
+
42
+ begin
43
+ response = parse_response(response) if content_type == "application/json"
44
+ rescue Nylas::JsonParseError
45
+ handle_failed_response(result, response, path)
46
+ raise
47
+ end
48
+
49
+ handle_failed_response(result, response, path)
50
+ return response
51
+ end
52
+ end
53
+
54
+ # Builds a request sent to the Nylas API.
55
+ #
56
+ # @param method [Symbol] HTTP method for the API call. Either :get, :post, :delete, or :patch.
57
+ # @param path [String, nil] Relative path from the API Base.
58
+ # @param headers [Hash, {}] Additional HTTP headers to include in the payload.
59
+ # @param query [Hash, {}] Hash of names and values to include in the query section of the URI
60
+ # fragment.
61
+ # @param payload [String, Hash, nil] Body to send with the request.
62
+ # @param timeout [Hash, nil] Timeout value to send with the request.
63
+ # @param api_key [Hash, nil] API key to send with the request.
64
+ # @return [Object] The request information after processing. This includes an updated payload
65
+ # and headers.
66
+ def build_request(
67
+ method:, path: nil, headers: {}, query: {}, payload: nil, timeout: nil, api_key: nil
68
+ )
69
+ url = path
70
+ url = add_query_params_to_url(url, query)
71
+ resulting_headers = default_headers.merge(headers).merge(auth_header(api_key))
72
+ serialized_payload = payload&.to_json
73
+
74
+ { method: method, url: url, payload: serialized_payload, headers: resulting_headers, timeout: timeout }
75
+ end
76
+
77
+ # Sets the default headers for API requests.
78
+ def default_headers
79
+ @default_headers ||= {
80
+ "X-Nylas-API-Wrapper" => "ruby",
81
+ "User-Agent" => "Nylas Ruby SDK #{Nylas::VERSION} - #{RUBY_VERSION}",
82
+ "Content-type" => "application/json"
83
+ }
84
+ end
85
+
86
+ # Parses the response from the Nylas API.
87
+ def parse_response(response)
88
+ return response if response.is_a?(Enumerable)
89
+
90
+ Yajl::Parser.new(symbolize_names: true).parse(response)
91
+ rescue Yajl::ParseError
92
+ raise Nylas::JsonParseError
93
+ end
94
+
95
+ private
96
+
97
+ # Sends a request to the Nylas REST API.
98
+ #
99
+ # @param method [Symbol] HTTP method for the API call. Either :get, :post, :delete, or :patch.
100
+ # @param url [String] URL for the API call.
101
+ # @param headers [Hash] HTTP headers to include in the payload.
102
+ # @param payload [String, Hash] Body to send with the request.
103
+ # @param timeout [Hash] Timeout value to send with the request.
104
+ def rest_client_execute(method:, url:, headers:, payload:, timeout:, &block)
105
+ ::RestClient::Request.execute(method: method, url: url, payload: payload,
106
+ headers: headers, timeout: timeout, &block)
107
+ end
108
+
109
+ # Handles failed responses from the Nylas API.
110
+ def handle_failed_response(result, response, path)
111
+ http_code = result.code.to_i
112
+
113
+ handle_anticipated_failure_mode(http_code, response, path)
114
+ end
115
+
116
+ # Handles anticipated failure states in the Nylas API.
117
+ def handle_anticipated_failure_mode(http_code, response, path)
118
+ return if HTTP_SUCCESS_CODES.include?(http_code)
119
+
120
+ case response
121
+ when Hash
122
+ raise error_hash_to_exception(response, http_code, path)
123
+ else
124
+ raise NylasApiError.parse_error_response(response, http_code)
125
+ end
126
+ end
127
+
128
+ # Converts error hashes to exceptions.
129
+ def error_hash_to_exception(response, status_code, path)
130
+ return if !response || !response.key?(:error)
131
+
132
+ if %W[#{api_uri}/v3/connect/token #{api_uri}/v3/connect/revoke].include?(path)
133
+ NylasOAuthError.new(response[:error], response[:error_description], response[:error_uri],
134
+ response[:error_code], status_code)
135
+ else
136
+ error_obj = response[:error]
137
+ provider_error = error_obj.fetch(:provider_error, nil)
138
+
139
+ NylasApiError.new(error_obj[:type], error_obj[:message], status_code, provider_error,
140
+ response[:request_id])
141
+ end
142
+ end
143
+
144
+ # Adds query parameters to a URL.
145
+ #
146
+ # @return [String] Processed URL, including query params.
147
+ def add_query_params_to_url(url, query)
148
+ unless query.empty?
149
+ uri = URI.parse(url)
150
+ query = custom_params(query)
151
+ params = URI.decode_www_form(uri.query || "") + query.to_a
152
+ uri.query = URI.encode_www_form(params)
153
+ url = uri.to_s
154
+ end
155
+
156
+ url
157
+ end
158
+
159
+ # Defines custom parameters for a metadata_pair query.
160
+ #
161
+ # @return [String] Custom parameter in "<key>:<value>" format.
162
+ def custom_params(query)
163
+ # Convert hash to "<key>:<value>" form for metadata_pair query.
164
+ if query.key?(:metadata_pair)
165
+ pairs = query[:metadata_pair].map do |key, value|
166
+ "#{key}:#{value}"
167
+ end
168
+ query[:metadata_pair] = pairs
169
+ end
170
+
171
+ query
172
+ end
173
+
174
+ # Set the authorization header for an API query.
175
+ def auth_header(api_key)
176
+ { "Authorization" => "Bearer #{api_key}" }
177
+ end
178
+ end
179
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "resource"
4
+ require_relative "redirect_uris"
5
+ require_relative "../handler/api_operations"
6
+
7
+ module Nylas
8
+ # Application
9
+ class Applications < Resource
10
+ include ApiOperations::Get
11
+
12
+ attr_reader :redirect_uris
13
+
14
+ # Initializes the application.
15
+ def initialize(sdk_instance)
16
+ super("applications", sdk_instance)
17
+ @redirect_uris = RedirectUris.new(sdk_instance)
18
+ end
19
+
20
+ # Gets the application object.
21
+ #
22
+ # @return [Array(Hash, String)] Application object and API Request ID.
23
+ def info
24
+ get(path: "#{api_uri}/v3/applications")
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,197 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "digest"
4
+ require "base64"
5
+ require "securerandom"
6
+ require "ostruct"
7
+ require "uri"
8
+
9
+ require_relative "resource"
10
+ require_relative "grants"
11
+ require_relative "../handler/api_operations"
12
+
13
+ module Nylas
14
+ # Auth
15
+ class Auth < Resource
16
+ include ApiOperations::Post
17
+ include ApiOperations::Get
18
+
19
+ # Initializes Auth.
20
+ def initialize(sdk_instance)
21
+ super("auth", sdk_instance)
22
+
23
+ @grants = Grants.new(sdk_instance)
24
+ end
25
+
26
+ attr_reader :grants
27
+
28
+ # Builds the URL for authenticating users to your application with OAuth 2.0.
29
+ #
30
+ # @param config [Hash] Configuration for building the URL.
31
+ # @return [String] URL for hosted authentication.
32
+ def url_for_oauth2(config)
33
+ url_auth_builder(config).to_s
34
+ end
35
+
36
+ # Exchanges an authorization code for an access token.
37
+ #
38
+ # @param request [Hash] Code exchange request.
39
+ # @return [Hash] Token object.
40
+ def exchange_code_for_token(request)
41
+ request[:grant_type] = "authorization_code"
42
+
43
+ execute_token_request(request)
44
+ end
45
+
46
+ # Refreshes an access token.
47
+ #
48
+ # @param request [Hash] Code exchange request.
49
+ # @return [Hash] Refreshed token object.
50
+ def refresh_access_token(request)
51
+ request[:grant_type] = "refresh_token"
52
+
53
+ execute_token_request(request)
54
+ end
55
+
56
+ # Builds the URL for authenticating users to your application with OAuth 2.0 and PKCE.
57
+ # IMPORTANT: You must store the 'secret' returned to use it inside the CodeExchange flow.
58
+ #
59
+ # @param config [Hash] Configuration for building the URL.
60
+ # @return [OpenStruct] URL for hosted authentication with the secret and the hashed secret.
61
+ def url_for_oauth2_pkce(config)
62
+ url = url_auth_builder(config)
63
+
64
+ # Generates a secret and hashes it.
65
+ secret = SecureRandom.uuid
66
+ secret_hash = hash_pkce_secret(secret)
67
+
68
+ # Adds code challenge to URL generation.
69
+ url.query = build_query_with_pkce(config, secret_hash)
70
+
71
+ # Returns the URL with secret and hashed secret.
72
+ OpenStruct.new(secret: secret, secret_hash: secret_hash, url: url.to_s)
73
+ end
74
+
75
+ # Builds the URL for admin consent authentication for Microsoft.
76
+ #
77
+ # @param config [Hash] Configuration for the authentication request.
78
+ # @return [String] URL for hosted authentication.
79
+ def url_for_admin_consent(config)
80
+ config_with_provider = config.merge("provider" => "microsoft")
81
+ url = url_auth_builder(config_with_provider)
82
+
83
+ query_params = build_query_with_admin_consent(config)
84
+ url.query = URI.encode_www_form(query_params)
85
+
86
+ url.to_s
87
+ end
88
+
89
+ # Revokes a single access token.
90
+ #
91
+ # @param token [String] Access token to revoke.
92
+ # @return [Boolean] True if the access token was revoked successfully.
93
+ def revoke(token)
94
+ post(
95
+ path: "#{api_uri}/v3/connect/revoke",
96
+ query_params: {
97
+ token: token
98
+ }
99
+ )
100
+ true
101
+ end
102
+
103
+ private
104
+
105
+ # Builds the query with admin consent authentication for Microsoft.
106
+ #
107
+ # @param config [Hash] Configuration for the query.
108
+ # @return [Array(Hash, String)] Updated list of parameters, including those specific to admin
109
+ # consent.
110
+ def build_query_with_admin_consent(config)
111
+ params = build_query(config)
112
+
113
+ # Appends new params specific for admin consent.
114
+ params["response_type"] = "adminconsent"
115
+ params["credential_id"] = config["credentialId"]
116
+
117
+ params
118
+ end
119
+
120
+ # Builds the query with PKCE.
121
+ #
122
+ # @param config [Hash] Configuration for the query.
123
+ # @param secret_hash [Hash] Hashed secret.
124
+ # @return [Array(Hash, String)] Updated list of encoded parameters, including those specific
125
+ # to PKCE.
126
+ def build_query_with_pkce(config, secret_hash)
127
+ params = build_query(config)
128
+
129
+ # Appends new PKCE specific params.
130
+ params["code_challenge_method"] = "s256"
131
+ params["code_challenge"] = secret_hash
132
+
133
+ URI.encode_www_form(params)
134
+ end
135
+
136
+ # Builds the authentication URL.
137
+ #
138
+ # @param config [Hash] Configuration for the query.
139
+ # @return [Array(Hash, String)] List of components for the authentication URL.
140
+ def url_auth_builder(config)
141
+ builder = URI.parse(api_uri)
142
+ builder.path = "/v3/connect/auth"
143
+ builder.query = build_query(config)
144
+
145
+ builder
146
+ end
147
+
148
+ # Builds the query.
149
+ #
150
+ # @param config [Hash] Configuration for the query.
151
+ # @return [Array(Hash, String)] List of encoded parameters for the query.
152
+ def build_query(config)
153
+ params = {
154
+ "client_id" => config[:client_id],
155
+ "redirect_uri" => config[:redirect_uri],
156
+ "access_type" => config[:access_type] || "online",
157
+ "response_type" => "code"
158
+ }
159
+
160
+ params["provider"] = config[:provider] if config[:provider]
161
+ if config[:login_hint]
162
+ params["login_hint"] = config[:login_hint]
163
+ params["include_grant_scopes"] = config[:include_grant_scopes].to_s if config[:include_grant_scopes]
164
+ end
165
+ params["scope"] = config[:scope].join(" ") if config[:scope]
166
+ params["prompt"] = config[:prompt] if config[:prompt]
167
+ params["metadata"] = config[:metadata] if config[:metadata]
168
+ params["state"] = config[:state] if config[:state]
169
+
170
+ URI.encode_www_form(params)
171
+ end
172
+
173
+ # Hashes the secret for PKCE authentication.
174
+ #
175
+ # @param secret [String] Randomly-generated authentication secret.
176
+ # @return [Hash] Hashed authentication secret.
177
+ def hash_pkce_secret(secret)
178
+ Digest::SHA256.digest(secret).unpack1("H*")
179
+ Base64.strict_encode64(Digest::SHA256.digest(secret))
180
+ end
181
+
182
+ # Sends the token request to the Nylas API.
183
+ #
184
+ # @param request [Hash] Code exchange request.
185
+ def execute_token_request(request)
186
+ execute(
187
+ method: :post,
188
+ path: "#{api_uri}/v3/connect/token",
189
+ query: {},
190
+ payload: request,
191
+ headers: {},
192
+ api_key: api_key,
193
+ timeout: timeout
194
+ )
195
+ end
196
+ end
197
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "resource"
4
+ require_relative "../handler/grants_api_operations"
5
+
6
+ module Nylas
7
+ # Calendars
8
+ class Calendars < Resource
9
+ include GrantsApiOperations::Create
10
+ include GrantsApiOperations::Update
11
+ include GrantsApiOperations::List
12
+ include GrantsApiOperations::Destroy
13
+ include GrantsApiOperations::Find
14
+
15
+ # Initializes Calendars.
16
+ def initialize(sdk_instance)
17
+ super("calendars", sdk_instance)
18
+ end
19
+
20
+ # Checks multiple calendars to find available time slots for a single meeting.
21
+ #
22
+ # @param request_body [Hash, nil] Request body to pass to the request.
23
+ # @return [Array(Hash, String)] Availability object and API request ID.
24
+ def get_availability(request_body: nil)
25
+ post(
26
+ path: "#{api_uri}/v3/calendars/availability",
27
+ request_body: request_body
28
+ )
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "resource"
4
+ require_relative "../handler/grants_api_operations"
5
+
6
+ module Nylas
7
+ # Events
8
+ class Events < Resource
9
+ include GrantsApiOperations::Create
10
+ include GrantsApiOperations::Update
11
+ include GrantsApiOperations::List
12
+ include GrantsApiOperations::Destroy
13
+ include GrantsApiOperations::Find
14
+
15
+ # Initializes Events.
16
+ def initialize(sdk_instance)
17
+ super("events", sdk_instance)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "resource"
4
+ require_relative "../handler/admin_api_operations"
5
+
6
+ module Nylas
7
+ # Grants
8
+ class Grants < Resource
9
+ include AdminApiOperations::Create
10
+ include AdminApiOperations::Update
11
+ include AdminApiOperations::List
12
+ include AdminApiOperations::Destroy
13
+ include AdminApiOperations::Find
14
+
15
+ # Initializes Grants.
16
+ def initialize(sdk_instance)
17
+ super("grants", sdk_instance)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "resource"
4
+ require_relative "../handler/admin_api_operations"
5
+
6
+ module Nylas
7
+ # Redirect URIs
8
+ class RedirectUris < Resource
9
+ include AdminApiOperations::Create
10
+ include AdminApiOperations::Update
11
+ include AdminApiOperations::List
12
+ include AdminApiOperations::Destroy
13
+ include AdminApiOperations::Find
14
+
15
+ # Initializes redirect URIs.
16
+ def initialize(sdk_instance)
17
+ super("applications/redirect-uris", sdk_instance)
18
+ end
19
+ end
20
+ 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
+ class Resource
6
+ # Initializes a resource.
7
+ def initialize(resource_name, sdk_instance)
8
+ @resource_name = resource_name
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,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "resource"
4
+ require_relative "../handler/grants_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
+ end
23
+
24
+ # Webhooks
25
+ class Webhooks < Resource
26
+ include GrantsApiOperations::Create
27
+ include GrantsApiOperations::Update
28
+ include GrantsApiOperations::List
29
+ include GrantsApiOperations::Destroy
30
+ include GrantsApiOperations::Find
31
+
32
+ # Initializes webhooks.
33
+ def initialize(parent)
34
+ super("webhooks", parent)
35
+ end
36
+ end
37
+ end
data/lib/nylas/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nylas
4
- VERSION = "5.17.0"
4
+ VERSION = "6.0.0.beta.1"
5
5
  end