From 419bc948d38cb6037c72594738e4425f01e650d2 Mon Sep 17 00:00:00 2001 From: aj07mm Date: Thu, 23 Sep 2021 16:50:44 -0300 Subject: [PATCH 1/2] Adding messages and drafts as attrs to Thread and removing as props. view=expanded in all calls --- nylas/client/client.py | 2 ++ nylas/client/restful_model_collection.py | 1 - nylas/client/restful_models.py | 12 +++--------- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/nylas/client/client.py b/nylas/client/client.py index f8b1c5e9..a9c5689e 100644 --- a/nylas/client/client.py +++ b/nylas/client/client.py @@ -363,6 +363,7 @@ def _get_resources(self, cls, extra=None, **filters): converted_filters = convert_datetimes_to_timestamps( filters, cls.datetime_filter_attrs ) + converted_filters["view"] = "expanded" url = str(URLObject(url).add_query_params(converted_filters.items())) response = self._get_http_session(cls.api_root).get(url) results = _validate(response).json() @@ -386,6 +387,7 @@ def _get_resource_raw( converted_filters = convert_datetimes_to_timestamps( filters, cls.datetime_filter_attrs ) + converted_filters["view"] = "expanded" url = str(URLObject(url).add_query_params(converted_filters.items())) response = self._get_http_session(cls.api_root).get( url, headers=headers, stream=stream diff --git a/nylas/client/restful_model_collection.py b/nylas/client/restful_model_collection.py index 596c2a68..00d0aa6e 100644 --- a/nylas/client/restful_model_collection.py +++ b/nylas/client/restful_model_collection.py @@ -133,7 +133,6 @@ def _get_model_collection(self, offset=0, limit=CHUNK_SIZE): filters["offset"] = offset if not filters.get("limit"): filters["limit"] = limit - return self.api._get_resources(self.model_class, **filters) def _get_model(self, id): diff --git a/nylas/client/restful_models.py b/nylas/client/restful_models.py index 9e498aec..a656f858 100644 --- a/nylas/client/restful_models.py +++ b/nylas/client/restful_models.py @@ -302,8 +302,10 @@ def messages(self): class Thread(NylasAPIObject): attrs = [ "draft_ids", - "id", "message_ids", + "drafts", + "messages", + "id", "account_id", "object", "participants", @@ -339,14 +341,6 @@ class Thread(NylasAPIObject): def __init__(self, api): NylasAPIObject.__init__(self, Thread, api) - @property - def messages(self): - return self.child_collection(Message, thread_id=self.id) - - @property - def drafts(self): - return self.child_collection(Draft, thread_id=self.id) - @property def folders(self): if self._folders: From 06abe4bd01e2d49193e8588a29d2f5f7b68583a4 Mon Sep 17 00:00:00 2001 From: aj07mm Date: Fri, 15 Oct 2021 12:46:53 -0300 Subject: [PATCH 2/2] view=expanded just for Thread resource --- nylas/client/client.py | 4 +--- nylas/client/restful_model_collection.py | 8 ++++---- nylas/client/restful_models.py | 8 ++++++++ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/nylas/client/client.py b/nylas/client/client.py index a9c5689e..bfe319f1 100644 --- a/nylas/client/client.py +++ b/nylas/client/client.py @@ -295,7 +295,7 @@ def accounts(self): @property def threads(self): - return RestfulModelCollection(Thread, self) + return RestfulModelCollection(Thread, self, view="expanded") @property def folders(self): @@ -363,7 +363,6 @@ def _get_resources(self, cls, extra=None, **filters): converted_filters = convert_datetimes_to_timestamps( filters, cls.datetime_filter_attrs ) - converted_filters["view"] = "expanded" url = str(URLObject(url).add_query_params(converted_filters.items())) response = self._get_http_session(cls.api_root).get(url) results = _validate(response).json() @@ -387,7 +386,6 @@ def _get_resource_raw( converted_filters = convert_datetimes_to_timestamps( filters, cls.datetime_filter_attrs ) - converted_filters["view"] = "expanded" url = str(URLObject(url).add_query_params(converted_filters.items())) response = self._get_http_session(cls.api_root).get( url, headers=headers, stream=stream diff --git a/nylas/client/restful_model_collection.py b/nylas/client/restful_model_collection.py index 00d0aa6e..197f979a 100644 --- a/nylas/client/restful_model_collection.py +++ b/nylas/client/restful_model_collection.py @@ -83,9 +83,10 @@ def where(self, filter=None, **filters): pairs = convert_metadata_pairs_to_array(filters["metadata_pair"]) filters["metadata_pair"] = pairs - collection = copy(self) - collection.filters = filters - return collection + for k, v in filters.items(): + self.filters[k] = v + + return copy(self) def get(self, id): return self._get_model(id) @@ -127,7 +128,6 @@ def __getitem__(self, key): return self._get_model_collection(key, 1)[0] # Private functions - def _get_model_collection(self, offset=0, limit=CHUNK_SIZE): filters = copy(self.filters) filters["offset"] = offset diff --git a/nylas/client/restful_models.py b/nylas/client/restful_models.py index a656f858..6cfd903b 100644 --- a/nylas/client/restful_models.py +++ b/nylas/client/restful_models.py @@ -341,6 +341,14 @@ class Thread(NylasAPIObject): def __init__(self, api): NylasAPIObject.__init__(self, Thread, api) + @property + def messages(self): + return self.child_collection(Message, thread_id=self.id) + + @property + def drafts(self): + return self.child_collection(Draft, thread_id=self.id) + @property def folders(self): if self._folders: