Skip to content

Commit

Permalink
Add connector endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
mrashed-dev committed Oct 17, 2023
1 parent 36f0793 commit 0125db5
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 0 deletions.
11 changes: 11 additions & 0 deletions nylas/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
"""
Expand Down
103 changes: 103 additions & 0 deletions nylas/resources/connectors.py
Original file line number Diff line number Diff line change
@@ -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,
)

0 comments on commit 0125db5

Please sign in to comment.