Skip to content

Commit

Permalink
Add new fields; provider for code exchange and custom_headers for dra…
Browse files Browse the repository at this point in the history
…fts/messages (#360)

This PR adds two new fields:
- `provider` to `CodeExchangeResponse`
- `custom_headers` to `CreateDraftRequest`, `UpdateDraftRequest`, and `SendMessageRequest`
  • Loading branch information
mrashed-dev authored May 3, 2024
1 parent 763e911 commit 39710f8
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 1 deletion.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ nylas-python Changelog

Unreleased
----------------
* Add clean messages support
* Added support for adding custom headers to outgoing requests
* Added support for `provider` field in code exchange response
* Added clean messages support
* Added additional webhook triggers
* Made event visibility optional to support iCloud events

v6.1.1
----------------
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

0 comments on commit 39710f8

Please sign in to comment.