Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Connector support #292

Merged
merged 5 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
3 changes: 2 additions & 1 deletion nylas/models/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
AccessType = Literal["online", "offline"]
""" Literal for the access type of the authentication URL. """

Provider = Literal["google", "imap", "microsoft"]
Provider = Literal["google", "imap", "microsoft", "virtual-calendar"]
""" Literal for the different authentication providers. """


Expand Down Expand Up @@ -129,6 +129,7 @@ class TokenInfoResponse:
sub: The token's subject.
email: The email address of the Grant belonging to the user's token.
"""

iss: str
aud: str
iat: int
Expand Down
10 changes: 5 additions & 5 deletions nylas/models/calendars.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from dataclasses_json import dataclass_json
from typing_extensions import TypedDict, NotRequired

from nylas.models.list_query_params import ListQueryParams


@dataclass_json
@dataclass
Expand Down Expand Up @@ -44,20 +46,18 @@ class Calendar:
metadata: Optional[Dict[str, Any]] = None


class ListCalendersQueryParams(TypedDict):
class ListCalendersQueryParams(ListQueryParams):
"""
Interface of the query parameters for listing calendars.

Attributes:
limit: The maximum number of objects to return.
limit (NotRequired[int]): The maximum number of objects to return.
This field defaults to 50. The maximum allowed value is 200.
page_token: An identifier that specifies which page of data to return.
page_token (NotRequired[str]): An identifier that specifies which page of data to return.
This value should be taken from a ListResponse object's next_cursor parameter.
metadata_pair: Pass in your metadata key-value pair to search for metadata.
"""

limit: NotRequired[int]
page_token: NotRequired[str]
metadata_pair: NotRequired[Dict[str, str]]


Expand Down
162 changes: 162 additions & 0 deletions nylas/models/connectors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
from dataclasses import dataclass
from typing import Dict, Any, List, Optional, Union
from typing_extensions import TypedDict, NotRequired

from dataclasses_json import dataclass_json

from nylas.models.auth import Provider
from nylas.models.list_query_params import ListQueryParams


@dataclass_json
@dataclass
class Connector:
"""
Interface representing the Nylas connector response.

Attributes:
name: Custom name of the connector
provider: The provider type
settings: Optional settings from provider
scope: Default scopes for the connector
"""

name: str
provider: Provider
settings: Optional[Dict[str, Any]] = None
scope: Optional[List[str]] = None


class BaseCreateConnectorRequest(TypedDict):
"""
Interface representing the base Nylas connector creation request.

Attributes:
name: Custom name of the connector
provider: The provider type
"""

name: str
provider: Provider


class GoogleCreateConnectorSettings(TypedDict):
"""
Interface representing a Google connector creation request.

Attributes:
client_id: The Google Client ID
client_secret: The Google Client Secret
topic_name: The Google Pub/Sub topic name
"""

client_id: str
client_secret: str
topic_name: NotRequired[str]


class MicrosoftCreateConnectorSettings(TypedDict):
"""
Interface representing a Microsoft connector creation request.

Attributes:
client_id: The Google Client ID
client_secret: The Google Client Secret
tenant: The Microsoft tenant ID
"""

client_id: str
client_secret: str
tenant: NotRequired[str]


class GoogleCreateConnectorRequest(BaseCreateConnectorRequest):
"""
Interface representing the base Nylas connector creation request.

Attributes:
name (str): Custom name of the connector
provider (Provider): The provider type, should be Google
settings: The Google OAuth provider credentials and settings
scope: The Google OAuth scopes
"""

settings: GoogleCreateConnectorSettings
scope: NotRequired[List[str]]


class MicrosoftCreateConnectorRequest(BaseCreateConnectorRequest):
"""
Interface representing the base Nylas connector creation request.

Attributes:
name (str): Custom name of the connector
provider (Provider): The provider type, should be Google
settings: The Microsoft OAuth provider credentials and settings
scope: The Microsoft OAuth scopes
"""

settings: MicrosoftCreateConnectorSettings
scope: NotRequired[List[str]]


class ImapCreateConnectorRequest(BaseCreateConnectorRequest):
"""
Interface representing the base Nylas connector creation request.

Attributes:
name (str): Custom name of the connector
provider (Provider): The provider type, should be IMAP
"""

pass


class VirtualCalendarsCreateConnectorRequest(BaseCreateConnectorRequest):
"""
Interface representing the base Nylas connector creation request.

Attributes:
name (str): Custom name of the connector
provider (Provider): The provider type
"""

pass


CreateConnectorRequest = Union[
GoogleCreateConnectorRequest,
MicrosoftCreateConnectorRequest,
ImapCreateConnectorRequest,
VirtualCalendarsCreateConnectorRequest,
]
""" The type of the Nylas connector creation request. """


class UpdateConnectorRequest(TypedDict):
"""
Interface representing the base Nylas connector creation request.

Attributes:
name: Custom name of the connector
settings: The OAuth provider credentials and settings
scope: The OAuth scopes
"""

name: NotRequired[str]
settings: NotRequired[Dict[str, Any]]
scope: NotRequired[List[str]]


class ListConnectorQueryParams(ListQueryParams):
"""
Interface of the query parameters for listing connectors.

Attributes:
limit (NotRequired[int]): The maximum number of objects to return.
This field defaults to 50. The maximum allowed value is 200.
page_token (NotRequired[str]): An identifier that specifies which page of data to return.
This value should be taken from a ListResponse object's next_cursor parameter.
"""

pass
11 changes: 6 additions & 5 deletions nylas/models/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from dataclasses_json import dataclass_json, config
from typing_extensions import TypedDict, NotRequired

from nylas.models.list_query_params import ListQueryParams

Status = Literal["confirmed", "tentative", "cancelled"]
""" Literal representing the status of an Event. """

Expand Down Expand Up @@ -660,7 +662,7 @@ class UpdateEventRequest(TypedDict):
hide_participants: NotRequired[bool]


class ListEventQueryParams(TypedDict):
class ListEventQueryParams(ListQueryParams):
"""
Interface representing the query parameters for listing events.

Expand All @@ -684,9 +686,10 @@ class ListEventQueryParams(TypedDict):
busy: Returns events with a busy status of true.
order_by: Order results by the specified field.
Currently only start is supported.
limit: The maximum number of objects to return.
limit (NotRequired[int]): The maximum number of objects to return.
This field defaults to 50. The maximum allowed value is 200.
page_token: An identifier that specifies which page of data to return.
page_token (NotRequired[str]): An identifier that specifies which page of data to return.
This value should be taken from a ListResponse object's next_cursor parameter.
"""

calendar_id: str
Expand All @@ -700,8 +703,6 @@ class ListEventQueryParams(TypedDict):
expand_recurring: NotRequired[bool]
busy: NotRequired[bool]
order_by: NotRequired[str]
limit: NotRequired[int]
page_token: NotRequired[str]


class CreateEventQueryParams(TypedDict):
Expand Down
17 changes: 17 additions & 0 deletions nylas/models/list_query_params.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from typing import Dict
from typing_extensions import TypedDict, NotRequired


class ListQueryParams(TypedDict):
"""
Interface of the query parameters for listing resources.

Attributes:
limit: The maximum number of objects to return.
This field defaults to 50. The maximum allowed value is 200.
page_token: An identifier that specifies which page of data to return.
This value should be taken from a ListResponse object's next_cursor parameter.
"""

limit: NotRequired[int]
page_token: NotRequired[str]
Loading
Loading