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 sorting and projecting to private resters #826

Merged
merged 2 commits into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 31 additions & 4 deletions mp_api/client/routes/_messages.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import datetime
from typing import List
from typing import List, Optional

from emmet.core._messages import MessagesDoc, MessageType

Expand Down Expand Up @@ -39,16 +39,43 @@ def set_message(

return self._post_resource(body=d).get("data")

def get_messages(self, last_updated: datetime): # pragma: no cover
def get_messages(
self,
last_updated: datetime,
sort_fields: Optional[List[str]] = None,
num_chunks: Optional[int] = None,
chunk_size: int = 1000,
all_fields: bool = True,
fields: Optional[List[str]] = None,
): # pragma: no cover
"""Get user settings.

Args:
last_updated: Datetime to use to query for newer messages
last_updated (datetime): Datetime to use to query for newer messages
sort_fields (List[str]): Fields used to sort results. Prefix with '-' to sort in descending order.
num_chunks (int): Maximum number of chunks of data to yield. None will yield all possible.
chunk_size (int): Number of data entries per chunk.
all_fields (bool): Whether to return all fields in the document. Defaults to True.
fields (List[str]): List of fields to project.
Returns:
Dictionary with messages data


Raises:
MPRestError.
"""
return self._search(last_updated=last_updated)
query_params = {}

if sort_fields:
query_params.update(
{"_sort_fields": ",".join([s.strip() for s in sort_fields])}
)

return self._search(
last_updated=last_updated,
num_chunks=num_chunks,
chunk_size=chunk_size,
all_fields=all_fields,
fields=fields,
**query_params
)
5 changes: 3 additions & 2 deletions mp_api/client/routes/_user_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,17 @@ def patch_user_time_settings(self, consumer_id, time): # pragma: no cover
params={"consumer_id": consumer_id},
).get("data")

def get_user_settings(self, consumer_id): # pragma: no cover
def get_user_settings(self, consumer_id, fields): # pragma: no cover
"""Get user settings.

Args:
consumer_id: Consumer ID for the user
fields: List of fields to project
Returns:
Dictionary with consumer_id and settings.


Raises:
MPRestError.
"""
return self.get_data_by_id(consumer_id)
return self.get_data_by_id(consumer_id, fields)