Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for detect provider endpoint #354

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ on:
# but only for the main branch
push:
branches:
- main
- v5
pull_request:
branches:
- main
- v5

jobs:
pytest:
Expand Down Expand Up @@ -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" .
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------------
Expand Down
1 change: 1 addition & 0 deletions examples/hosted-oauth/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
1 change: 1 addition & 0 deletions examples/native-authentication-gmail/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
45 changes: 33 additions & 12 deletions nylas/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,27 @@
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 = {

Check warning on line 231 in nylas/client/client.py

View check run for this annotation

Codecov / codecov/patch

nylas/client/client.py#L230-L231

Added lines #L230 - L231 were not covered by tests
"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()

Check warning on line 239 in nylas/client/client.py

View check run for this annotation

Codecov / codecov/patch

nylas/client/client.py#L237-L239

Added lines #L237 - L239 were not covered by tests

def token_for_code(self, code):
"""
Exchange an authorization code for an access token
Expand Down Expand Up @@ -643,9 +664,9 @@

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 = (
Expand Down Expand Up @@ -675,9 +696,9 @@

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))
Expand All @@ -698,9 +719,9 @@

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 = (
Expand All @@ -719,9 +740,9 @@
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 "",
)

Expand Down
Loading