diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1337be5d..113e5941 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: @@ -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" . 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 ---------------- 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(): diff --git a/nylas/client/client.py b/nylas/client/client.py index 9a480517..b82c27cd 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 @@ -643,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 = ( @@ -675,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)) @@ -698,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 = ( @@ -719,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 "", )