Skip to content

Commit

Permalink
Added credentials to the connectors
Browse files Browse the repository at this point in the history
  • Loading branch information
Kiran Raju authored and Kiran Raju committed Oct 17, 2023
1 parent d3c0ed7 commit ab5efe3
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 11 deletions.
33 changes: 33 additions & 0 deletions nylas/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from nylas import Client
from nylas.models.credentials import CredentialRequest, UpdateCredentialRequest

client_id = "547b1b75-6623-4dcd-8ea9-baf50cf00952"
client_secret = "JzL6OyQVaXvowk8czuGW45mHhVCoHfnZW"
api_key = "nyk_v0_JlN7OgZUgsmEoCx6tguhTMGcRqE0XpoLZz6Lp3824ivER13baJbXENK9EPYw5eKU"


nylas = Client(
api_key=api_key,
)

creds_data = {"client_id":"bce5ddf5-038e-4653-9843-ec1d4274549e","client_secret":"ZM48Q~Yng3WqXjM2D3f..zZ4g.LBJWFCmE_b7b3Y"}
#
#
creds_created,_ = nylas.connectors.credentials.create("microsoft",CredentialRequest(name="Test creds",credential_type="adminconsent",credential_data=creds_data))
# #
print(creds_created)
# # #
list_response = nylas.connectors.credentials.list("microsoft");
#
print(list_response)
#
creds,_ = nylas.connectors.credentials.find("microsoft",creds_created.id)
# #
print(creds)

updated_creds,_=nylas.connectors.credentials.update("microsoft",creds_created.id,UpdateCredentialRequest(name="New creds",credential_data=creds_data))
# #
print(updated_creds)

deleted_response = nylas.connectors.credentials.destroy("microsoft",updated_creds.id)
print(deleted_response)
11 changes: 0 additions & 11 deletions nylas/resources/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
URLForAdminConsentConfig,
)
from nylas.models.response import Response
from nylas.resources.credentials import Credentials
from nylas.resources.grants import Grants
from nylas.resources.resource import Resource

Expand Down Expand Up @@ -59,16 +58,6 @@ def _build_query_with_admin_consent(config: dict) -> dict:

class Auth(Resource):

@property
def credentials(self) -> Credentials:
"""
Access the Credentials API.
Returns:
The Credentials API.
"""
return Credentials(self._http_client)

@property
def grants(self) -> Grants:
"""
Expand Down
11 changes: 11 additions & 0 deletions nylas/resources/connectors.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from nylas.resources.credentials import Credentials

from nylas.handler.api_resources import (
ListableApiResource,
FindableApiResource,
Expand All @@ -22,6 +24,15 @@ class Connectors(
UpdatableApiResource,
DestroyableApiResource,
):
@property
def credentials(self) -> Credentials:
"""
Access the Credentials API.
Returns:
The Credentials API.
"""
return Credentials(self._http_client)
def list(self, query_params: ListConnectorQueryParams) -> ListResponse[Connector]:
"""
Return all Connectors.
Expand Down

0 comments on commit ab5efe3

Please sign in to comment.