diff --git a/CHANGELOG.md b/CHANGELOG.md index 1574255b..f0679d20 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog ### 6.0.0-beta.3 / TBD +* Add support for contacts API * Fixed issue when sending message without attachments ### 6.0.0-beta.2 / 2023-11-21 diff --git a/lib/nylas.rb b/lib/nylas.rb index e3f4d033..b0375607 100644 --- a/lib/nylas.rb +++ b/lib/nylas.rb @@ -32,6 +32,7 @@ require_relative "nylas/resources/auth" require_relative "nylas/resources/calendars" require_relative "nylas/resources/connectors" +require_relative "nylas/resources/contacts" require_relative "nylas/resources/credentials" require_relative "nylas/resources/drafts" require_relative "nylas/resources/events" diff --git a/lib/nylas/client.rb b/lib/nylas/client.rb index acc94628..bf7de90d 100644 --- a/lib/nylas/client.rb +++ b/lib/nylas/client.rb @@ -62,6 +62,13 @@ def connectors Connectors.new(self) end + # The contact resources for your Nylas application. + # + # @return [Nylas::Contacts] Contact resources for your Nylas application. + def contacts + Contacts.new(self) + end + # The draft resources for your Nylas application. # # @return [Nylas::Drafts] Draft resources for your Nylas application. diff --git a/lib/nylas/resources/contacts.rb b/lib/nylas/resources/contacts.rb new file mode 100644 index 00000000..99b904a3 --- /dev/null +++ b/lib/nylas/resources/contacts.rb @@ -0,0 +1,89 @@ +# frozen_string_literal: true + +require_relative "resource" +require_relative "../handler/api_operations" + +module Nylas + # Nylas Contact API + class Contacts < Resource + include ApiOperations::Get + include ApiOperations::Post + include ApiOperations::Put + include ApiOperations::Delete + + # Return all contacts. + # + # @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 contacts and API Request ID. + def list(identifier:, query_params: nil) + get( + path: "#{api_uri}/v3/grants/#{identifier}/contacts", + query_params: query_params + ) + end + + # Return a contact. + # + # @param identifier [String] Grant ID or email account to query. + # @param contact_id [String] The id of the contact to return. + # @param query_params [Hash, nil] Query params to pass to the request. + # @return [Array(Hash, String)] The contact and API request ID. + def find(identifier:, contact_id:, query_params: nil) + get( + path: "#{api_uri}/v3/grants/#{identifier}/contacts/#{contact_id}", + query_params: query_params + ) + end + + # Create a contact. + # + # @param identifier [String] Grant ID or email account in which to create the object. + # @param request_body [Hash] The values to create the contact with. + # @return [Array(Hash, String)] The created contact and API Request ID. + def create(identifier:, request_body:) + post( + path: "#{api_uri}/v3/grants/#{identifier}/contacts", + request_body: request_body + ) + end + + # Update a contact. + # + # @param identifier [String] Grant ID or email account in which to update an object. + # @param contact_id [String] The id of the contact to update. + # @param request_body [Hash] The values to update the contact with + # @return [Array(Hash, String)] The updated contact and API Request ID. + def update(identifier:, contact_id:, request_body:) + put( + path: "#{api_uri}/v3/grants/#{identifier}/contacts/#{contact_id}", + request_body: request_body + ) + end + + # Delete a contact. + # + # @param identifier [String] Grant ID or email account from which to delete an object. + # @param contact_id [String] The id of the contact to delete. + # @return [Array(TrueClass, String)] True and the API Request ID for the delete operation. + def destroy(identifier:, contact_id:) + _, request_id = delete( + path: "#{api_uri}/v3/grants/#{identifier}/contacts/#{contact_id}" + ) + + [true, request_id] + end + + # Return all contact groups. + # + # @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 contact groups and API Request ID. + def contact_groups(identifier:, query_params: nil) + get( + path: "#{api_uri}/v3/grants/#{identifier}/contacts/groups", + query_params: query_params + ) + end + end +end