From 0125db510f2039258f470fd0159a025083c42cd9 Mon Sep 17 00:00:00 2001 From: Mostafa Rashed <17770919+mrashed-dev@users.noreply.github.com> Date: Tue, 17 Oct 2023 13:09:32 -0400 Subject: [PATCH] Add connector endpoints --- nylas/client.py | 11 ++++ nylas/resources/connectors.py | 103 ++++++++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100644 nylas/resources/connectors.py diff --git a/nylas/client.py b/nylas/client.py index 0b42e1c5..176ad346 100644 --- a/nylas/client.py +++ b/nylas/client.py @@ -3,6 +3,7 @@ from nylas.resources.applications import Applications from nylas.resources.auth import Auth from nylas.resources.calendars import Calendars +from nylas.resources.connectors import Connectors from nylas.resources.events import Events from nylas.resources.webhooks import Webhooks @@ -52,6 +53,16 @@ def applications(self) -> Applications: """ return Applications(self.http_client) + @property + def connectors(self) -> Connectors: + """ + Access the Connectors API. + + Returns: + The Connectors API. + """ + return Connectors(self.http_client) + @property def calendars(self) -> Calendars: """ diff --git a/nylas/resources/connectors.py b/nylas/resources/connectors.py new file mode 100644 index 00000000..799f8abb --- /dev/null +++ b/nylas/resources/connectors.py @@ -0,0 +1,103 @@ +from nylas.handler.api_resources import ( + ListableApiResource, + FindableApiResource, + CreatableApiResource, + UpdatableApiResource, + DestroyableApiResource, +) +from nylas.models.auth import Provider +from nylas.models.connectors import ( + ListConnectorQueryParams, + Connector, + CreateConnectorRequest, +) +from nylas.models.response import ListResponse, Response, DeleteResponse + + +class Connectors( + ListableApiResource, + FindableApiResource, + CreatableApiResource, + UpdatableApiResource, + DestroyableApiResource, +): + def list(self, query_params: ListConnectorQueryParams) -> ListResponse[Connector]: + """ + Return all Connectors. + + Args: + query_params: The query parameters to include in the request. + + Returns: + The list of Connectors. + """ + + return super(Connectors, self).list( + path="/v3/connectors", response_type=Connector, query_params=query_params + ) + + def find(self, provider: Provider) -> Response[Connector]: + """ + Return a connector associated with the provider. + + Args: + provider: The provider associated to the connector to retrieve. + + Returns: + The Connector. + """ + return super(Connectors, self).find( + path=f"/v3/connectors/{provider}", + response_type=Connector, + ) + + def create(self, request_body: CreateConnectorRequest) -> Response[Connector]: + """ + Create a connector. + + Args: + request_body: The values to create the connector with. + + Returns: + The created connector. + """ + return super(Connectors, self).create( + path=f"/v3/connectors", + request_body=request_body, + response_type=Connector, + ) + + def update( + self, provider: Provider, request_body: CreateConnectorRequest + ) -> Response[Connector]: + """ + Create a connector. + + Args: + provider: The provider associated to the connector to update. + request_body: The values to update the connector with. + + Returns: + The created connector. + """ + return super(Connectors, self).update( + path=f"/v3/connectors/{provider}", + request_body=request_body, + response_type=Connector, + method="PATCH", + ) + + def destroy(self, provider: Provider) -> DeleteResponse: + """ + Delete a connector. + + Args: + provider: The provider associated to the connector to delete. + + Returns: + The deleted connector. + """ + return super(Connectors, self).destroy( + path=f"/v3/connectors/{provider}", + response_type=Connector, + )