diff --git a/lib/nylas.rb b/lib/nylas.rb index 1894c4ff..74493af3 100644 --- a/lib/nylas.rb +++ b/lib/nylas.rb @@ -30,7 +30,10 @@ require_relative "nylas/resources/applications" require_relative "nylas/resources/auth" require_relative "nylas/resources/calendars" +require_relative "nylas/resources/connectors" +require_relative "nylas/resources/credentials" require_relative "nylas/resources/events" require_relative "nylas/resources/grants" +require_relative "nylas/resources/messages" require_relative "nylas/resources/redirect_uris" require_relative "nylas/resources/webhooks" diff --git a/lib/nylas/client.rb b/lib/nylas/client.rb index b7f098f8..00303569 100644 --- a/lib/nylas/client.rb +++ b/lib/nylas/client.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require_relative "resources/calendars" +require_relative "resources/connectors" require_relative "resources/messages" require_relative "resources/events" require_relative "resources/auth" @@ -39,6 +40,13 @@ def calendars Calendars.new(self) end + # The connector resources for your Nylas application. + # + # @return [Nylas::Connectors] Connector resources for your Nylas application. + def connectors + Connectors.new(self) + end + # The event resources for your Nylas application. # # @return [Nylas::Events] Event resources for your Nylas application diff --git a/lib/nylas/handler/admin_api_operations.rb b/lib/nylas/handler/admin_api_operations.rb deleted file mode 100644 index da167288..00000000 --- a/lib/nylas/handler/admin_api_operations.rb +++ /dev/null @@ -1,95 +0,0 @@ -# frozen_string_literal: true - -require_relative "http_client" -require_relative "api_operations" - -module Nylas - # Allows resources to perform CRUD operations on the Admin API endpoints without exposing the - # HTTP client to the end user. - module AdminApiOperations - include HttpClient - # Creates a Nylas object. - module Create - include ApiOperations::Post - # Creates a Nylas object. - # - # @param query_params [Hash, {}] Query params to pass to the request. - # @param request_body [Hash, nil] Request body to pass to the request. - # @return [Array(Hash, String)] Created Nylas object and API Request ID. - def create(query_params: {}, request_body: nil) - post( - path: "#{api_uri}/v3/#{resource_name}", - query_params: query_params, - request_body: request_body - ) - end - end - - # Lists Nylas objects. - module List - include ApiOperations::Get - # Lists Nylas objects. - # - # @param query_params [Hash, {}] Query params to pass to the request. - # @return [Array(Hash, String)] List of Nylas objects and API Request ID. - def list(query_params: {}) - get( - path: "#{api_uri}/v3/#{resource_name}", - query_params: query_params - ) - end - end - - # Finds a Nylas object. - module Find - include ApiOperations::Get - # Finds a Nylas object. - # - # @param object_id [String] Object ID. - # @param query_params [Hash, {}] Query params to pass to the request. - # @return [Array(Hash, String)] Nylas object and API Request ID. - def find(object_id:, query_params: {}) - get( - path: "#{api_uri}/v3/#{resource_name}/#{object_id}", - query_params: query_params - ) - end - end - - # Updates a Nylas object. - module Update - include ApiOperations::Put - # Updates a Nylas object. - # - # @param object_id [String] Object ID. - # @param query_params [Hash, {}] Query params to pass to the request. - # @param request_body [Hash, nil] Request body to pass to the request. - # @return [Array(Hash, String)] Updated Nylas object and API Request ID. - def update(object_id:, query_params: {}, request_body: nil) - put( - path: "#{api_uri}/v3/#{resource_name}/#{object_id}", - query_params: query_params, - request_body: request_body - ) - end - end - - # Deletes a Nylas object. - module Destroy - include ApiOperations::Delete - # Deletes a Nylas object. - # - # @param object_id [String] Object ID. - # @param query_params [Hash, {}] Query params to pass to the request. - # @return [Array(TrueClass, String)] True and the API Request ID for the delete operation. - def destroy(object_id:, query_params: {}) - _, request_id = delete( - path: "#{api_uri}/v3/#{resource_name}/#{object_id}", - query_params: query_params - ) - - [true, request_id] - end - end - end -end diff --git a/lib/nylas/handler/api_operations.rb b/lib/nylas/handler/api_operations.rb index 5b70379c..209cc6b6 100644 --- a/lib/nylas/handler/api_operations.rb +++ b/lib/nylas/handler/api_operations.rb @@ -13,7 +13,7 @@ module Get # # @param path [String] Destination path for the call. # @param query_params [Hash, {}] Query params to pass to the call. - # @return [Array(Hash, String)] List of Nylas objects and API Request ID. + # @return Nylas data object and API Request ID. def get(path:, query_params: {}) response = execute( method: :get, @@ -39,7 +39,7 @@ module Post # @param query_params [Hash, {}] Query params to pass to the call. # @param request_body [String, Hash, nil] Request body to pass to the call. # @param headers [Hash, {}] Additional HTTP headers to include in the payload. - # @return [Array(Hash, String)] List of Nylas objects and API Request ID. + # @return Nylas data object and API Request ID. def post(path:, query_params: {}, request_body: nil, headers: {}) response = execute( method: :post, @@ -66,7 +66,7 @@ module Put # @param query_params [Hash, {}] Query params to pass to the call. # @param request_body [String, Hash, nil] Request body to pass to the call. # @param headers [Hash, {}] Additional HTTP headers to include in the payload. - # @return [Array(Hash, String)] List of Nylas objects and API Request ID. + # @return Nylas data object and API Request ID. def put(path:, query_params: {}, request_body: nil, headers: {}) response = execute( method: :put, @@ -93,7 +93,7 @@ module Patch # @param query_params [Hash, {}] Query params to pass to the call. # @param request_body [String, Hash, nil] Request body to pass to the call. # @param headers [Hash, {}] Additional HTTP headers to include in the payload. - # @return [Array(Hash, String)] List of Nylas objects and API Request ID. + # @return Nylas data object and API Request ID. def patch(path:, query_params: {}, request_body: nil, headers: {}) response = execute( method: :patch, @@ -119,7 +119,7 @@ module Delete # @param path [String] Destination path for the call. # @param query_params [Hash, {}] Query params to pass to the call. # @param headers [Hash, {}] Additional HTTP headers to include in the payload. - # @return [Array(Hash, String)] List of Nylas objects and API Request ID. + # @return Nylas data object and API Request ID. def delete(path:, query_params: {}, headers: {}) response = execute( method: :delete, diff --git a/lib/nylas/handler/grants_api_operations.rb b/lib/nylas/handler/grants_api_operations.rb deleted file mode 100644 index fec7573a..00000000 --- a/lib/nylas/handler/grants_api_operations.rb +++ /dev/null @@ -1,99 +0,0 @@ -# frozen_string_literal: true - -require_relative "http_client" -require_relative "api_operations" - -module Nylas - # Allows resources to perform CRUD operations on the Grants API endpoints without exposing the - # HTTP client to the end user. - module GrantsApiOperations - # Creates a Nylas object. - module Create - include ApiOperations::Post - # Creates a Nylas object. - # - # @param identifier [String] Grant ID or email account in which to create the object. - # @param query_params [Hash, {}] Query params to pass to the request. - # @param request_body [Hash, nil] Request body to pass to the request. - # @return [Array(Hash, String)] Created Nylas object and API Request ID. - def create(identifier:, query_params: {}, request_body: nil) - post( - path: "#{api_uri}/v3/grants/#{identifier}/#{resource_name}", - query_params: query_params, - request_body: request_body - ) - end - end - - # Lists Nylas objects. - module List - include ApiOperations::Get - # Lists Nylas objects. - # - # @param identifier [String] Grant ID or email account to query. - # @param query_params [Hash, {}] Query params to pass to the request. - # @return [Array(Hash, String)] List of Nylas objects and API Request ID. - def list(identifier:, query_params: {}) - get( - path: "#{api_uri}/v3/grants/#{identifier}/#{resource_name}", - query_params: query_params - ) - end - end - - # Finds a Nylas object. - module Find - include ApiOperations::Get - # Finds a Nylas object. - # - # @param identifier [String] Grant ID or email account to query. - # @param object_id [String] Object ID. - # @param query_params [Hash, {}] Query params to pass to the request. - # @return [Array(Hash, String)] Nylas object and API request ID. - def find(identifier:, object_id:, query_params: {}) - get( - path: "#{api_uri}/v3/grants/#{identifier}/#{resource_name}/#{object_id}", - query_params: query_params - ) - end - end - - # Updates a Nylas object. - module Update - include ApiOperations::Put - # Updates a Nylas object. - # - # @param identifier [String] Grant ID or email account in which to update an object. - # @param object_id [String] Object ID. - # @param query_params [Hash, {}] Query params to pass to the request. - # @param request_body [Hash, nil] Request body to pass to the request. - # @return [Array(Hash, String)] Updated Nylas object and API Request ID. - def update(identifier:, object_id:, query_params: {}, request_body: nil) - put( - path: "#{api_uri}/v3/grants/#{identifier}/#{resource_name}/#{object_id}", - query_params: query_params, - request_body: request_body - ) - end - end - - # Deletes a Nylas object. - module Destroy - include ApiOperations::Delete - # Deletes a Nylas object. - # - # @param identifier [String] Grant ID or email account from which to delete an object. - # @param object_id [String] Object ID. - # @param query_params [Hash, {}] Query params to pass to the request. - # @return [Array(TrueClass, String)] True and the API Request ID for the delete operation. - def destroy(identifier:, object_id:, query_params: {}) - _, request_id = delete( - path: "#{api_uri}/v3/grants/#{identifier}/#{resource_name}/#{object_id}", - query_params: query_params - ) - - [true, request_id] - end - end - end -end diff --git a/lib/nylas/resources/applications.rb b/lib/nylas/resources/applications.rb index bdd4cf68..af7c4a1e 100644 --- a/lib/nylas/resources/applications.rb +++ b/lib/nylas/resources/applications.rb @@ -13,7 +13,7 @@ class Applications < Resource # Initializes the application. def initialize(sdk_instance) - super("applications", sdk_instance) + super(sdk_instance) @redirect_uris = RedirectUris.new(sdk_instance) end diff --git a/lib/nylas/resources/auth.rb b/lib/nylas/resources/auth.rb index 1a305fd1..ded915cf 100644 --- a/lib/nylas/resources/auth.rb +++ b/lib/nylas/resources/auth.rb @@ -18,7 +18,7 @@ class Auth < Resource # Initializes Auth. def initialize(sdk_instance) - super("auth", sdk_instance) + super(sdk_instance) @grants = Grants.new(sdk_instance) end diff --git a/lib/nylas/resources/calendars.rb b/lib/nylas/resources/calendars.rb index bf84ae22..f928997d 100644 --- a/lib/nylas/resources/calendars.rb +++ b/lib/nylas/resources/calendars.rb @@ -1,25 +1,83 @@ # frozen_string_literal: true require_relative "resource" -require_relative "../handler/grants_api_operations" +require_relative "../handler/api_operations" module Nylas - # Calendars + # Nylas Calendar API class Calendars < Resource - include GrantsApiOperations::Create - include GrantsApiOperations::Update - include GrantsApiOperations::List - include GrantsApiOperations::Destroy - include GrantsApiOperations::Find - - # Initializes Calendars. - def initialize(sdk_instance) - super("calendars", sdk_instance) + include ApiOperations::Get + include ApiOperations::Post + include ApiOperations::Put + include ApiOperations::Delete + + # Return all calendars. + # + # @param identifier [String] Grant ID or email account to query. + # @param query_params [Hash, nil] Query params to pass to the request. + # @return [Array(Array(Hash), String)] The list of calendars and API Request ID. + def list(identifier:, query_params: nil) + get( + path: "#{api_uri}/v3/grants/#{identifier}/calendars", + query_params: query_params + ) + end + + # Return a calendar. + # + # @param identifier [String] Grant ID or email account to query. + # @param calendar_id [String] The id of the calendar to return. + # Use "primary" to refer to the primary calendar associated with grant. + # @return [Array(Hash, String)] The calendar and API request ID. + def find(identifier:, calendar_id:) + get( + path: "#{api_uri}/v3/grants/#{identifier}/calendars/#{calendar_id}" + ) + end + + # Create a calendar. + # + # @param identifier [String] Grant ID or email account in which to create the object. + # @param request_body [Hash] The values to create the calendar with. + # @return [Array(Hash, String)] The created calendar and API Request ID. + def create(identifier:, request_body:) + post( + path: "#{api_uri}/v3/grants/#{identifier}/calendars", + request_body: request_body + ) + end + + # Update a calendar. + # + # @param identifier [String] Grant ID or email account in which to update an object. + # @param calendar_id [String] The id of the calendar to update. + # Use "primary" to refer to the primary calendar associated with grant. + # @param request_body [Hash] The values to update the calendar with + # @return [Array(Hash, String)] The updated calendar and API Request ID. + def update(identifier:, calendar_id:, request_body:) + put( + path: "#{api_uri}/v3/grants/#{identifier}/calendars/#{calendar_id}", + request_body: request_body + ) + end + + # Delete a calendar. + # + # @param identifier [String] Grant ID or email account from which to delete an object. + # @param calendar_id [String] The id of the calendar to delete. + # Use "primary" to refer to the primary calendar associated with grant. + # @return [Array(TrueClass, String)] True and the API Request ID for the delete operation. + def destroy(identifier:, calendar_id:) + _, request_id = delete( + path: "#{api_uri}/v3/grants/#{identifier}/calendars/#{calendar_id}" + ) + + [true, request_id] end # Checks multiple calendars to find available time slots for a single meeting. # - # @param request_body Hash Request body to pass to the request. + # @param request_body [Hash] Request body to pass to the request. # @return [Array(Hash, String)] Availability object and API request ID. def get_availability(request_body:) post( diff --git a/lib/nylas/resources/connectors.rb b/lib/nylas/resources/connectors.rb new file mode 100644 index 00000000..1e738240 --- /dev/null +++ b/lib/nylas/resources/connectors.rb @@ -0,0 +1,80 @@ +# frozen_string_literal: true + +require_relative "resource" +require_relative "../handler/api_operations" + +module Nylas + # Nylas Connectors API + class Connectors < Resource + include ApiOperations::Get + include ApiOperations::Post + include ApiOperations::Put + include ApiOperations::Delete + + # Access the Credentials API + attr_reader :credentials + + # Initializes Connectors. + def initialize(sdk_instance) + super(sdk_instance) + + @credentials = Credentials.new(sdk_instance) + end + + # Return all connectors. + # + # @param query_params [Hash, nil] Query params to pass to the request. + # @return [Array(Array(Hash), String)] The list of connectors and API Request ID. + def list(query_params: nil) + get( + path: "#{api_uri}/v3/connectors", + query_params: query_params + ) + end + + # Return a connector. + # + # @param provider [String] The provider associated to the connector to retrieve. + # @return [Array(Hash, String)] The connector and API request ID. + def find(provider:) + get( + path: "#{api_uri}/v3/connectors/#{provider}" + ) + end + + # Create a connector. + # + # @param request_body [Hash] The values to create the connector with. + # @return [Array(Hash, String)] The created connector and API Request ID. + def create(request_body:) + post( + path: "#{api_uri}/v3/connectors", + request_body: request_body + ) + end + + # Update a connector. + # + # @param provider [String] The provider associated to the connector to update. + # @param request_body [Hash] The values to update the connector with + # @return [Array(Hash, String)] The updated connector and API Request ID. + def update(provider:, request_body:) + put( + path: "#{api_uri}/v3/connectors/#{provider}", + request_body: request_body + ) + end + + # Delete a connector. + # + # @param provider [String] The provider associated to the connector to delete. + # @return [Array(TrueClass, String)] True and the API Request ID for the delete operation. + def destroy(provider:) + _, request_id = delete( + path: "#{api_uri}/v3/connectors/#{provider}" + ) + + [true, request_id] + end + end +end diff --git a/lib/nylas/resources/credentials.rb b/lib/nylas/resources/credentials.rb new file mode 100644 index 00000000..f7a339c7 --- /dev/null +++ b/lib/nylas/resources/credentials.rb @@ -0,0 +1,75 @@ +# frozen_string_literal: true + +require_relative "resource" +require_relative "../handler/api_operations" + +module Nylas + # Nylas Connectors API + class Credentials < Resource + include ApiOperations::Get + include ApiOperations::Post + include ApiOperations::Put + include ApiOperations::Delete + + # Return all credentials. + # + # @param provider [String] The provider associated to the credential to list from + # @param query_params [Hash, nil] Query params to pass to the request. + # @return [Array(Array(Hash), String)] The list of credentials and API Request ID. + def list(provider:, query_params: nil) + get( + path: "#{api_uri}/v3/connectors/#{provider}/creds", + query_params: query_params + ) + end + + # Return a connector. + # + # @param provider [String] The provider associated to the connector to retrieve. + # @param credential_id [String] The id of the credentials to retrieve. + # @return [Array(Hash, String)] The connector and API request ID. + def find(provider:, credential_id:) + get( + path: "#{api_uri}/v3/connectors/#{provider}/creds/#{credential_id}" + ) + end + + # Create a connector. + # + # @param provider [String] The provider associated to the credential being created + # @param request_body [Hash] The values to create the connector with. + # @return [Array(Hash, String)] The created connector and API Request ID. + def create(provider:, request_body:) + post( + path: "#{api_uri}/v3/connectors/#{provider}/creds", + request_body: request_body + ) + end + + # Update a connector. + # + # @param provider [String] The provider associated to the connector to update from. + # @param credential_id [String] The id of the credentials to update. + # @param request_body [Hash] The values to update the connector with + # @return [Array(Hash, String)] The updated connector and API Request ID. + def update(provider:, credential_id:, request_body:) + put( + path: "#{api_uri}/v3/connectors/#{provider}/creds/#{credential_id}", + request_body: request_body + ) + end + + # Delete a connector. + # + # @param provider [String] The provider associated to the connector to delete. + # @param credential_id [String] The id of the credentials to delete. + # @return [Array(TrueClass, String)] True and the API Request ID for the delete operation. + def destroy(provider:, credential_id:) + _, request_id = delete( + path: "#{api_uri}/v3/connectors/#{provider}/creds/#{credential_id}" + ) + + [true, request_id] + end + end +end diff --git a/lib/nylas/resources/events.rb b/lib/nylas/resources/events.rb index 65c86171..afd796b5 100644 --- a/lib/nylas/resources/events.rb +++ b/lib/nylas/resources/events.rb @@ -1,20 +1,83 @@ # frozen_string_literal: true require_relative "resource" -require_relative "../handler/grants_api_operations" +require_relative "../handler/api_operations" module Nylas - # Events + # Nylas Events API class Events < Resource - include GrantsApiOperations::Create - include GrantsApiOperations::Update - include GrantsApiOperations::List - include GrantsApiOperations::Destroy - include GrantsApiOperations::Find - - # Initializes Events. - def initialize(sdk_instance) - super("events", sdk_instance) + include ApiOperations::Get + include ApiOperations::Post + include ApiOperations::Put + include ApiOperations::Delete + + # Return all events. + # + # @param identifier [String] Grant ID or email account to query. + # @param query_params [Hash] Query params to pass to the request. + # @return [Array(Array(Hash), String)] The list of events and API Request ID. + def list(identifier:, query_params:) + get( + path: "#{api_uri}/v3/grants/#{identifier}/events", + query_params: query_params + ) + end + + # Return an event. + # + # @param identifier [String] Grant ID or email account to query. + # @param event_id [String] The id of the event to return. + # @param query_params [Hash] The query parameters to include in the request + # @return [Array(Hash, String)] The event and API request ID. + def find(identifier:, event_id:, query_params:) + get( + path: "#{api_uri}/v3/grants/#{identifier}/events/#{event_id}", + query_params: query_params + ) + end + + # Create an event. + # + # @param identifier [String] Grant ID or email account in which to create the object. + # @param request_body [Hash] The values to create the event with. + # @param query_params [Hash] The query parameters to include in the request. + # @return [Array(Hash, String)] The created event and API Request ID. + def create(identifier:, request_body:, query_params:) + post( + path: "#{api_uri}/v3/grants/#{identifier}/events", + query_params: query_params, + request_body: request_body + ) + end + + # Update an event. + # + # @param identifier [String] Grant ID or email account in which to update an object. + # @param event_id [String] The id of the event to update. + # @param request_body [Hash] The values to update the event with + # @param query_params [Hash] The query parameters to include in the request + # @return [Array(Hash, String)] The updated event and API Request ID. + def update(identifier:, event_id:, request_body:, query_params:) + put( + path: "#{api_uri}/v3/grants/#{identifier}/events/#{event_id}", + query_params: query_params, + request_body: request_body + ) + end + + # Delete an event. + # + # @param identifier [String] Grant ID or email account from which to delete an object. + # @param event_id [String] The id of the event to delete. + # @param query_params [Hash] The query parameters to include in the request + # @return [Array(TrueClass, String)] True and the API Request ID for the delete operation. + def destroy(identifier:, event_id:, query_params:) + _, request_id = delete( + path: "#{api_uri}/v3/grants/#{identifier}/events/#{event_id}", + query_params: query_params + ) + + [true, request_id] end end end diff --git a/lib/nylas/resources/grants.rb b/lib/nylas/resources/grants.rb index a7e8bf5c..02abc82b 100644 --- a/lib/nylas/resources/grants.rb +++ b/lib/nylas/resources/grants.rb @@ -1,20 +1,70 @@ # frozen_string_literal: true require_relative "resource" -require_relative "../handler/admin_api_operations" +require_relative "../handler/api_operations" module Nylas # Grants class Grants < Resource - include AdminApiOperations::Create - include AdminApiOperations::Update - include AdminApiOperations::List - include AdminApiOperations::Destroy - include AdminApiOperations::Find - - # Initializes Grants. - def initialize(sdk_instance) - super("grants", sdk_instance) + include ApiOperations::Get + include ApiOperations::Post + include ApiOperations::Put + include ApiOperations::Delete + + # Return all grants. + # + # @param query_params [Hash, nil] Query params to pass to the request. + # @return [Array(Array(Hash), String)] The list of grants and API Request ID. + def list(query_params: nil) + get( + path: "#{api_uri}/v3/grant", + query_params: query_params + ) + end + + # Return a grant. + # + # @param grant_id [String] The id of the grant to return. + # @return [Array(Hash, String)] The grant and API request ID. + def find(grant_id:) + get( + path: "#{api_uri}/v3/grant/#{grant_id}" + ) + end + + # Create a Grant via Custom Authentication. + # + # @param request_body [Hash] The values to create the Grant with. + # @return [Array(Hash, String)] Created grant and API Request ID. + def create(request_body) + post( + path: "#{api_uri}/v3/#{resource_name}/custom", + request_body: request_body + ) + end + + # Update a grant. + # + # @param grant_id [String] The id of the grant to update. + # @param request_body [Hash] The values to update the grant with + # @return [Array(Hash, String)] The updated grant and API Request ID. + def update(grant_id:, request_body:) + put( + path: "#{api_uri}/v3/grant/#{grant_id}", + request_body: request_body + ) + end + + # Delete a grant. + # + # @param grant_id [String] The id of the grant to delete. + # @return [Array(TrueClass, String)] True and the API Request ID for the delete operation. + def destroy(grant_id:) + _, request_id = delete( + path: "#{api_uri}/v3/grant/#{grant_id}" + ) + + [true, request_id] end end end diff --git a/lib/nylas/resources/messages.rb b/lib/nylas/resources/messages.rb index f7d8f207..c3d7fed7 100644 --- a/lib/nylas/resources/messages.rb +++ b/lib/nylas/resources/messages.rb @@ -1,19 +1,65 @@ # frozen_string_literal: true require_relative "resource" -require_relative "../handler/grants_api_operations" +require_relative "../handler/api_operations" module Nylas - # Calendars + # Nylas Messages API class Messages < Resource - include GrantsApiOperations::Update - include GrantsApiOperations::List - include GrantsApiOperations::Destroy - include GrantsApiOperations::Find + include ApiOperations::Get + include ApiOperations::Put + include ApiOperations::Delete - # Initializes Calendars. - def initialize(sdk_instance) - super("messages", sdk_instance) + # Return all messages. + # + # @param identifier [String] Grant ID or email account to query. + # @param query_params [Hash, nil] Query params to pass to the request. + # @return [Array(Array(Hash), String)] The list of messages and API Request ID. + def list(identifier:, query_params: nil) + get( + path: "#{api_uri}/v3/grants/#{identifier}/messages", + query_params: query_params + ) + end + + # Return a message. + # + # @param identifier [String] Grant ID or email account to query. + # @param message_id [String] The id of the message to return. + # Use "primary" to refer to the primary message associated with grant. + # @return [Array(Hash, String)] The message and API request ID. + def find(identifier:, message_id:) + get( + path: "#{api_uri}/v3/grants/#{identifier}/messages/#{message_id}" + ) + end + + # Update a message. + # + # @param identifier [String] Grant ID or email account in which to update an object. + # @param message_id [String] The id of the message to update. + # Use "primary" to refer to the primary message associated with grant. + # @param request_body [Hash] The values to update the message with + # @return [Array(Hash, String)] The updated message and API Request ID. + def update(identifier:, message_id:, request_body:) + put( + path: "#{api_uri}/v3/grants/#{identifier}/messages/#{message_id}", + request_body: request_body + ) + end + + # Delete a message. + # + # @param identifier [String] Grant ID or email account from which to delete an object. + # @param message_id [String] The id of the message to delete. + # Use "primary" to refer to the primary message associated with grant. + # @return [Array(TrueClass, String)] True and the API Request ID for the delete operation. + def destroy(identifier:, message_id:) + _, request_id = delete( + path: "#{api_uri}/v3/grants/#{identifier}/messages/#{message_id}" + ) + + [true, request_id] end end end diff --git a/lib/nylas/resources/redirect_uris.rb b/lib/nylas/resources/redirect_uris.rb index 684eb50a..5976e1ab 100644 --- a/lib/nylas/resources/redirect_uris.rb +++ b/lib/nylas/resources/redirect_uris.rb @@ -1,20 +1,68 @@ # frozen_string_literal: true require_relative "resource" -require_relative "../handler/admin_api_operations" +require_relative "../handler/api_operations" module Nylas - # Redirect URIs + # A collection of redirect URI related API endpoints. class RedirectUris < Resource - include AdminApiOperations::Create - include AdminApiOperations::Update - include AdminApiOperations::List - include AdminApiOperations::Destroy - include AdminApiOperations::Find - - # Initializes redirect URIs. - def initialize(sdk_instance) - super("applications/redirect-uris", sdk_instance) + include ApiOperations::Get + include ApiOperations::Post + include ApiOperations::Put + include ApiOperations::Delete + + # Return all redirect uris. + # + # @return [Array(Array(Hash), String)] The list of redirect uris and API Request ID. + def list + get( + path: "#{api_uri}/v3/applications/redirect-uris" + ) + end + + # Return a redirect uri. + # + # @param redirect_uri_id [String] The id of the redirect uri to return. + # @return [Array(Hash, String)] The redirect uri and API request ID. + def find(redirect_uri_id:) + get( + path: "#{api_uri}/v3/applications/redirect-uris/#{redirect_uri_id}" + ) + end + + # Create a redirect uri. + # + # @param request_body [Hash] The values to create the redirect uri with. + # @return [Array(Hash, String)] The created redirect uri and API Request ID. + def create(request_body:) + post( + path: "#{api_uri}/v3/applications/redirect-uris", + request_body: request_body + ) + end + + # Update a redirect uri. + # + # @param redirect_uri_id [String] The id of the redirect uri to update. + # @param request_body [Hash] The values to update the redirect uri with + # @return [Array(Hash, String)] The updated redirect uri and API Request ID. + def update(redirect_uri_id:, request_body:) + put( + path: "#{api_uri}/v3/applications/redirect-uris/#{redirect_uri_id}", + request_body: request_body + ) + end + + # Delete a redirect uri. + # + # @param redirect_uri_id [String] The id of the redirect uri to delete. + # @return [Array(TrueClass, String)] True and the API Request ID for the delete operation. + def destroy(redirect_uri_id:) + _, request_id = delete( + path: "#{api_uri}/v3/applications/redirect-uris/#{redirect_uri_id}" + ) + + [true, request_id] end end end diff --git a/lib/nylas/resources/resource.rb b/lib/nylas/resources/resource.rb index b12d6863..cd79ebf0 100644 --- a/lib/nylas/resources/resource.rb +++ b/lib/nylas/resources/resource.rb @@ -5,8 +5,7 @@ module Nylas # Used by all Nylas API resources class Resource # Initializes a resource. - def initialize(resource_name, sdk_instance) - @resource_name = resource_name + def initialize(sdk_instance) @api_key = sdk_instance.api_key @api_uri = sdk_instance.api_uri @timeout = sdk_instance.timeout diff --git a/lib/nylas/resources/webhooks.rb b/lib/nylas/resources/webhooks.rb index d36b4dfd..eed12f42 100644 --- a/lib/nylas/resources/webhooks.rb +++ b/lib/nylas/resources/webhooks.rb @@ -1,37 +1,85 @@ -# frozen_string_literal: true +# frozen_string_literal: trues require_relative "resource" -require_relative "../handler/grants_api_operations" +require_relative "../handler/api_operations" module Nylas # Module representing the possible 'trigger' values in a Webhook. # @see https://developer.nylas.com/docs/api#post/a/client_id/webhooks module WebhookTrigger - CALENDAR_CREATED = "calendar.created" - CALENDAR_UPDATED = "calendar.updated" - CALENDAR_DELETED = "calendar.deleted" - EVENT_CREATED = "event.created" - EVENT_UPDATED = "event.updated" - EVENT_DELETED = "event.deleted" - GRANT_CREATED = "grant.created" - GRANT_UPDATED = "grant.updated" - GRANT_DELETED = "grant.deleted" - GRANT_EXPIRED = "grant.expired" - MESSAGE_SEND_SUCCESS = "message.send_success" - MESSAGE_SEND_FAILED = "message.send_failed" + CALENDAR_CREATED = "calendar.created".freeze + CALENDAR_UPDATED = "calendar.updated".freeze + CALENDAR_DELETED = "calendar.deleted".freeze + EVENT_CREATED = "event.created".freeze + EVENT_UPDATED = "event.updated".freeze + EVENT_DELETED = "event.deleted".freeze + GRANT_CREATED = "grant.created".freeze + GRANT_UPDATED = "grant.updated".freeze + GRANT_DELETED = "grant.deleted".freeze + GRANT_EXPIRED = "grant.expired".freeze + MESSAGE_SEND_SUCCESS = "message.send_success".freeze + MESSAGE_SEND_FAILED = "message.send_failed".freeze end - # Webhooks + # Nylas Webhooks API class Webhooks < Resource - include GrantsApiOperations::Create - include GrantsApiOperations::Update - include GrantsApiOperations::List - include GrantsApiOperations::Destroy - include GrantsApiOperations::Find - - # Initializes webhooks. - def initialize(parent) - super("webhooks", parent) + include ApiOperations::Get + include ApiOperations::Post + include ApiOperations::Put + include ApiOperations::Delete + + # Return all webhooks. + # + # @return [Array(Array(Hash), String)] The list of webhooks and API Request ID. + def list + get( + path: "#{api_uri}/v3/webhooks" + ) + end + + # Return a webhook. + # + # @param webhook_id [String] The id of the webhook to return. + # @return [Array(Hash, String)] The webhook and API request ID. + def find(webhook_id:) + get( + path: "#{api_uri}/v3/webhooks/#{webhook_id}" + ) + end + + # Create a webhook. + # + # @param request_body [Hash] The values to create the webhook with. + # @return [Array(Hash, String)] The created webhook and API Request ID. + def create(request_body:) + post( + path: "#{api_uri}/v3/webhooks", + request_body: request_body + ) + end + + # Update a webhook. + # + # @param webhook_id [String] The id of the webhook to update. + # @param request_body [Hash] The values to update the webhook with + # @return [Array(Hash, String)] The updated webhook and API Request ID. + def update(webhook_id:, request_body:) + put( + path: "#{api_uri}/v3/webhooks/#{webhook_id}", + request_body: request_body + ) + end + + # Delete a webhook. + # + # @param webhook_id [String] The id of the webhook to delete. + # @return [Array(TrueClass, String)] True and the API Request ID for the delete operation. + def destroy(webhook_id:) + _, request_id = delete( + path: "#{api_uri}/v3/webhooks/#{webhook_id}" + ) + + [true, request_id] end end end