Skip to content

Commit 4630214

Browse files
committed
Fix a bit of code rot in the Python SDK
Summary: Addresses Evan's comments in T3498. Notably: - add a `client.account` property. - fix the README and the example app. Test Plan: Tested manually. Reviewers: spang Reviewed By: spang Subscribers: evan Maniphest Tasks: T3498 Differential Revision: https://phab.nylas.com/D2042
1 parent 516c88e commit 4630214

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ from nylas import APIClient
4949
def index():
5050
redirect_url = "http://0.0.0.0:8888/login_callback"
5151
client = APIClient(APP_ID, APP_SECRET)
52-
return redirect(client.authentication_url(redirect_uri))
52+
return redirect(client.authentication_url(redirect_url))
5353

5454
```
5555

@@ -76,8 +76,8 @@ implementing the auth flow.
7676
client = APIClient(APP_ID, APP_SECRET, token)
7777

7878
# Print out the email address and provider (Gmail, Exchange)
79-
print client.email_address
80-
print client.provider
79+
print client.account.email_address
80+
print client.account.provider
8181
```
8282

8383

nylas/client/client.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
from .util import url_concat, generate_id
1010
from .restful_model_collection import RestfulModelCollection
1111
from .restful_models import (Calendar, Contact, Event, Message, Thread, File,
12-
Account, APIAccount, Tag, Folder, Label, Draft)
12+
Account, APIAccount, SingletonAccount, Tag,
13+
Folder, Label, Draft)
1314
from .errors import (APIClientError, ConnectionError, NotAuthorizedError,
1415
InvalidRequestError, NotFoundError, MethodNotSupportedError,
1516
ServerError, ServiceUnavailableError, ConflictError,
@@ -159,6 +160,10 @@ def is_opensource_api(self):
159160

160161
return False
161162

163+
@property
164+
def account(self):
165+
return self._get_resource(SingletonAccount, '')
166+
162167
@property
163168
def accounts(self):
164169
if self.is_opensource_api():

nylas/client/restful_models.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77

88
class NylasAPIObject(dict):
99
attrs = []
10-
# The Nylas API holds most objectsfor an acount, but some of
11-
# them are under '/a' (mostly the account-management and billing code).
12-
# api_root is a tiny metaprogramming hack to let us use the same
13-
# code for both.
10+
# The Nylas API holds most objects for an account directly under '/',
11+
# but some of them are under '/a' (mostly the account-management
12+
# and billing code). api_root is a tiny metaprogramming hack to let
13+
# us use the same code for both.
1414
api_root = 'n'
1515

1616
def __init__(self, cls, api):
@@ -443,10 +443,6 @@ def child_collection(self, cls, **filters):
443443

444444

445445
class Account(NylasAPIObject):
446-
# The Nylas API holds most objects under '/n/', but some of
447-
# them are under '/a' (mostly the account-management and billing code).
448-
# api_root is a tiny metaprogramming hack to let us use the same
449-
# code for both.
450446
api_root = 'a'
451447

452448
attrs = ["account_id", "trial", "trial_expires", "sync_state",
@@ -482,3 +478,8 @@ def __init__(self, api):
482478
def as_json(self):
483479
dct = NylasAPIObject.as_json(self)
484480
return dct
481+
482+
483+
class SingletonAccount(APIAccount):
484+
# This is an APIAccount that lives under /account.
485+
collection_name = 'account'

0 commit comments

Comments
 (0)