Skip to content

Add new fields; provider for code exchange and custom_headers for drafts/messages #360

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

Merged
merged 4 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
nylas-python Changelog
======================

Unreleased
----------------
* Added support for adding custom headers to outgoing requests
* Added support for `provider` field in code exchange response

v6.1.1
----------------
* Improved message sending and draft create/update performance
Expand Down
2 changes: 2 additions & 0 deletions nylas/models/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class CodeExchangeResponse:
refresh_token: Returned only if the code is requested using "access_type=offline".
id_token: A JWT that contains identity information about the user. Digitally signed by Nylas.
token_type: Always "Bearer".
provider: The provider that the code was exchanged with.
"""

access_token: str
Expand All @@ -124,6 +125,7 @@ class CodeExchangeResponse:
refresh_token: Optional[str] = None
id_token: Optional[str] = None
token_type: Optional[str] = None
provider: Optional[Provider] = None


@dataclass_json
Expand Down
16 changes: 16 additions & 0 deletions nylas/models/drafts.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@ class TrackingOptions(TypedDict):
thread_replies: NotRequired[bool]


class CustomHeader(TypedDict):
"""
A key-value pair representing a header that can be added to drafts and outgoing messages.

Attributes:
name: The name of the custom header.
value: The value of the custom header.
"""

name: str
value: str


class CreateDraftRequest(TypedDict):
"""
A request to create a draft.
Expand All @@ -73,6 +86,7 @@ class CreateDraftRequest(TypedDict):
send_at: Unix timestamp to send the message at.
reply_to_message_id: The ID of the message that you are replying to.
tracking_options: Options for tracking opens, links, and thread replies.
custom_headers: Custom headers to add to the message.
"""

body: NotRequired[str]
Expand All @@ -86,6 +100,7 @@ class CreateDraftRequest(TypedDict):
send_at: NotRequired[int]
reply_to_message_id: NotRequired[str]
tracking_options: NotRequired[TrackingOptions]
custom_headers: NotRequired[List[CustomHeader]]


UpdateDraftRequest = CreateDraftRequest
Expand Down Expand Up @@ -148,6 +163,7 @@ class SendMessageRequest(CreateDraftRequest):
send_at (NotRequired[int]): Unix timestamp to send the message at.
reply_to_message_id (NotRequired[str]): The ID of the message that you are replying to.
tracking_options (NotRequired[TrackingOptions]): Options for tracking opens, links, and thread replies.
custom_headers(NotRequired[List[CustomHeader]]): Custom headers to add to the message.
use_draft: Whether or not to use draft support. This is primarily used when dealing with large attachments.
"""

Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def http_client_token_exchange():
"scope": "https://www.googleapis.com/auth/gmail.readonly profile",
"token_type": "Bearer",
"grant_id": "grant_123",
"provider": "google",
}
return mock_http_client

Expand Down
1 change: 1 addition & 0 deletions tests/resources/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def test_get_token(self, http_client_token_exchange):
assert res.scope == "https://www.googleapis.com/auth/gmail.readonly profile"
assert res.token_type == "Bearer"
assert res.grant_id == "grant_123"
assert res.provider == "google"

def test_get_token_info(self, http_client_token_info):
auth = Auth(http_client_token_info)
Expand Down
Loading