Skip to content

Commit

Permalink
Add support for contacts API (#438)
Browse files Browse the repository at this point in the history
This PR adds support for the contacts API.
  • Loading branch information
mrashed-dev authored Dec 4, 2023
1 parent 15926fe commit 7b405ed
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/nylas.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 7 additions & 0 deletions lib/nylas/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
89 changes: 89 additions & 0 deletions lib/nylas/resources/contacts.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 7b405ed

Please sign in to comment.