Skip to content

Commit

Permalink
Move Grants to NylasClient and custom authentication to Auth (#324
Browse files Browse the repository at this point in the history
)

* Move custom auth out of grants to auth

* move grants entry point out of auth to nylasclient

* Update CHANGELOG.md
  • Loading branch information
mrashed-dev committed Dec 29, 2023
1 parent f264973 commit bc9bc8b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 28 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ nylas-python Changelog

v6.0.0b8
----------------
* **BREAKING CHANGES**: Moved grants API out of `Auth` to `NylasClient`
* **BREAKING CHANGES**: Moved `Grants.create()` to `Auth.customAuthentication()`
* Added helper function for attaching files to messages
* Fixed issues with sending messages and creating drafts

Expand Down
12 changes: 12 additions & 0 deletions nylas/client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from nylas.resources.grants import Grants

from nylas.config import DEFAULT_SERVER_URL
from nylas.handler.http_client import HttpClient
from nylas.resources.applications import Applications
Expand Down Expand Up @@ -107,6 +109,16 @@ def folders(self) -> Folders:
"""
return Folders(self.http_client)

@property
def grants(self) -> Grants:
"""
Access the Grants API.
Returns:
The Grants API.
"""
return Grants(self.http_client)

@property
def messages(self) -> Messages:
"""
Expand Down
32 changes: 22 additions & 10 deletions nylas/resources/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import urllib.parse
import uuid

from nylas.models.grant import CreateGrantRequest, Grant

from nylas.models.auth import (
CodeExchangeResponse,
PkceAuthUrl,
Expand Down Expand Up @@ -57,16 +59,6 @@ def _build_query_with_admin_consent(config: dict) -> dict:


class Auth(Resource):
@property
def grants(self) -> Grants:
"""
Access the Grants API.
Returns:
The Grants API.
"""
return Grants(self._http_client)

def url_for_oauth2(self, config: URLForAuthenticationConfig) -> str:
"""
Build the URL for authenticating users to your application via Hosted Authentication.
Expand Down Expand Up @@ -99,6 +91,26 @@ def exchange_code_for_token(

return self._get_token(request_body)

def custom_authentication(
self, request_body: CreateGrantRequest
) -> Response[Grant]:
"""
Create a Grant via Custom Authentication.
Args:
request_body: The values to create the Grant with.
Returns:
The created Grant.
"""

json_response = self._http_client._execute(
method="POST",
path=f"/v3/connect/custom",
request_body=request_body,
)
return Response.from_dict(json_response, Grant)

def refresh_access_token(
self, request: TokenExchangeRequest
) -> CodeExchangeResponse:
Expand Down
18 changes: 0 additions & 18 deletions nylas/resources/grants.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
from nylas.handler.api_resources import (
ListableApiResource,
FindableApiResource,
CreatableApiResource,
UpdatableApiResource,
DestroyableApiResource,
)
from nylas.models.grants import (
Grant,
ListGrantsQueryParams,
CreateGrantRequest,
UpdateGrantRequest,
)
from nylas.models.response import Response, ListResponse, DeleteResponse
Expand All @@ -17,7 +15,6 @@
class Grants(
ListableApiResource,
FindableApiResource,
CreatableApiResource,
UpdatableApiResource,
DestroyableApiResource,
):
Expand Down Expand Up @@ -51,21 +48,6 @@ def find(self, grant_id: str) -> Response[Grant]:
path=f"/v3/grants/{grant_id}", response_type=Grant
)

def create(self, request_body: CreateGrantRequest) -> Response[Grant]:
"""
Create a Grant via Custom Authentication.
Args:
request_body: The values to create the Grant with.
Returns:
The created Grant.
"""

return super(Grants, self).create(
path=f"/v3/connect/custom", response_type=Grant, request_body=request_body
)

def update(
self, grant_id: str, request_body: UpdateGrantRequest
) -> Response[Grant]:
Expand Down

0 comments on commit bc9bc8b

Please sign in to comment.