From 08409b34d2892dd2be786321231f0c5a52dd09cb Mon Sep 17 00:00:00 2001 From: Mostafa Rashed <17770919+mrashed-dev@users.noreply.github.com> Date: Mon, 4 Mar 2024 20:22:05 -0500 Subject: [PATCH 1/7] Add support for detect_provider --- nylas/client/client.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/nylas/client/client.py b/nylas/client/client.py index 9a480517..ef003e48 100644 --- a/nylas/client/client.py +++ b/nylas/client/client.py @@ -217,6 +217,27 @@ def send_authorization(self, code): self.access_token = results["access_token"] return results + def detect_provider(self, email): + """ + Detect the provider for a given email address. + + Args: + email (str): The email address you want to check + + Returns: + dict: The response from the API containing the provider, if found + """ + url = "{api_server}/connect/detect-provider".format(api_server=self.api_server) + data = { + "client_id": self.client_id, + "client_secret": self.client_secret, + "email_address": email, + } + + resp = self._request(HttpMethod.POST, url, json=data) + _validate(resp) + return resp.json() + def token_for_code(self, code): """ Exchange an authorization code for an access token @@ -593,7 +614,7 @@ def _get_resource_raw( stream=False, path=None, stream_timeout=None, - **filters + **filters, ): """Get an individual REST resource""" if path is None: From a3853f9e26f9f1d727f2dc4c0a490f3e55dbd56f Mon Sep 17 00:00:00 2001 From: Mostafa Rashed <17770919+mrashed-dev@users.noreply.github.com> Date: Mon, 4 Mar 2024 20:22:24 -0500 Subject: [PATCH 2/7] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a9c651aa..75ed7464 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ nylas-python Changelog Unreleased ---------------- * Add support for `view` parameter in `Threads.search()` +* Add support for detect_provider endpoint v5.14.1 ---------------- From 2fed3a4b2566d4b75a9a54e97d27a778f74cf8da Mon Sep 17 00:00:00 2001 From: Mostafa Rashed <17770919+mrashed-dev@users.noreply.github.com> Date: Mon, 4 Mar 2024 20:40:51 -0500 Subject: [PATCH 3/7] fix ci --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1337be5d..f7d8b476 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,10 +4,10 @@ on: # but only for the main branch push: branches: - - main + - v5 pull_request: branches: - - main + - v5 jobs: pytest: From a6331bc850f27ba0bc086cbef65b47f9ab2410c1 Mon Sep 17 00:00:00 2001 From: Mostafa Rashed <17770919+mrashed-dev@users.noreply.github.com> Date: Mon, 4 Mar 2024 20:46:11 -0500 Subject: [PATCH 4/7] lint --- examples/hosted-oauth/server.py | 1 + examples/native-authentication-gmail/server.py | 1 + 2 files changed, 2 insertions(+) diff --git a/examples/hosted-oauth/server.py b/examples/hosted-oauth/server.py index cd640531..d9eef64c 100644 --- a/examples/hosted-oauth/server.py +++ b/examples/hosted-oauth/server.py @@ -71,6 +71,7 @@ # Teach Flask how to find out that it's behind an ngrok proxy app.wsgi_app = ProxyFix(app.wsgi_app) + # Define what Flask should do when someone visits the root URL of this website. @app.route("/") def index(): diff --git a/examples/native-authentication-gmail/server.py b/examples/native-authentication-gmail/server.py index d1d49a73..197ddb95 100644 --- a/examples/native-authentication-gmail/server.py +++ b/examples/native-authentication-gmail/server.py @@ -90,6 +90,7 @@ # Teach Flask how to find out that it's behind an ngrok proxy app.wsgi_app = ProxyFix(app.wsgi_app) + # Define what Flask should do when someone visits the root URL of this website. @app.route("/") def index(): From c090aa6c3c5d5a8e13a0b2cda1bb2e097baea726 Mon Sep 17 00:00:00 2001 From: Mostafa Rashed <17770919+mrashed-dev@users.noreply.github.com> Date: Mon, 4 Mar 2024 20:58:05 -0500 Subject: [PATCH 5/7] lint again --- nylas/client/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nylas/client/client.py b/nylas/client/client.py index ef003e48..b63223d8 100644 --- a/nylas/client/client.py +++ b/nylas/client/client.py @@ -614,7 +614,7 @@ def _get_resource_raw( stream=False, path=None, stream_timeout=None, - **filters, + **filters ): """Get an individual REST resource""" if path is None: From 1d21c55b6e0b4970d19a3c10ab468c89e1981869 Mon Sep 17 00:00:00 2001 From: Mostafa Rashed <17770919+mrashed-dev@users.noreply.github.com> Date: Mon, 4 Mar 2024 21:43:50 -0500 Subject: [PATCH 6/7] add diff flag for debugging --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f7d8b476..113e5941 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -47,4 +47,4 @@ jobs: run: pip install black - name: Run black - run: black --check --extend-exclude="/examples" . + run: black --check --diff --extend-exclude="/examples" . From 6095eb9f899637c128eb1f8b974b0b95a32e7874 Mon Sep 17 00:00:00 2001 From: Mostafa Rashed <17770919+mrashed-dev@users.noreply.github.com> Date: Mon, 4 Mar 2024 21:49:21 -0500 Subject: [PATCH 7/7] finally lint --- nylas/client/client.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/nylas/client/client.py b/nylas/client/client.py index b63223d8..b82c27cd 100644 --- a/nylas/client/client.py +++ b/nylas/client/client.py @@ -664,9 +664,9 @@ def _get_resource_data(self, cls, resource_id, extra=None, headers=None, **filte def _create_resource(self, cls, data, **kwargs): name = "{prefix}{path}".format( - prefix="/{}/{}".format(cls.api_root, self.client_id) - if cls.api_root - else "", + prefix=( + "/{}/{}".format(cls.api_root, self.client_id) if cls.api_root else "" + ), path="/{}".format(cls.collection_name) if cls.collection_name else "", ) url = ( @@ -696,9 +696,9 @@ def _create_resource(self, cls, data, **kwargs): def _create_resources(self, cls, data): name = "{prefix}{path}".format( - prefix="/{}/{}".format(cls.api_root, self.client_id) - if cls.api_root - else "", + prefix=( + "/{}/{}".format(cls.api_root, self.client_id) if cls.api_root else "" + ), path="/{}".format(cls.collection_name) if cls.collection_name else "", ) url = URLObject(self.api_server).with_path("{name}".format(name=name)) @@ -719,9 +719,9 @@ def _create_resources(self, cls, data): def _delete_resource(self, cls, resource_id, data=None, **kwargs): name = "{prefix}{path}".format( - prefix="/{}/{}".format(cls.api_root, self.client_id) - if cls.api_root - else "", + prefix=( + "/{}/{}".format(cls.api_root, self.client_id) if cls.api_root else "" + ), path="/{}".format(cls.collection_name) if cls.collection_name else "", ) url = ( @@ -740,9 +740,9 @@ def _request_update_resource( if path is None: path = cls.collection_name name = "{prefix}{path}".format( - prefix="/{}/{}".format(cls.api_root, self.client_id) - if cls.api_root - else "", + prefix=( + "/{}/{}".format(cls.api_root, self.client_id) if cls.api_root else "" + ), path="/{}".format(path) if path else "", )