-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Base resource and get resource added * Task endpoint updated to match new resource * Base resource and get resource added * Task endpoint updated to match new resource * Consumer post resource added * User settings post endpoint added * Generaic post method added to core client * Find structure endpoint updates * Remove consumer endpoints from docs * Linting * pycodestyle linting * Mypy cleanup * flake8 fixes * Consumer settings endpoint data model change * mypy fixes
- Loading branch information
Jason Munro
authored
Mar 30, 2021
1 parent
89e6fa0
commit f63376a
Showing
37 changed files
with
590 additions
and
283 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from mp_api._consumer.models import UserSettingsDoc | ||
from mp_api.core.client import BaseRester | ||
|
||
|
||
class UserSettingsRester(BaseRester): | ||
|
||
suffix = "user_settings" | ||
document_model = UserSettingsDoc | ||
|
||
def set_user_settings(self, consumer_id, settings): | ||
""" | ||
Set user settings. | ||
Args: | ||
consumer_id: Consumer ID for the user | ||
settings: Dictionary with user settings | ||
Returns: | ||
Dictionary with consumer_id and write status. | ||
Raises: | ||
MPRestError | ||
""" | ||
return self._post_resource( | ||
body=settings, params={"consumer_id": consumer_id} | ||
).get("data") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from pydantic import BaseModel, Field | ||
|
||
|
||
class UserSettingsDoc(BaseModel): | ||
""" | ||
Defines data for user settings | ||
""" | ||
|
||
consumer_id: str = Field( | ||
None, title="Consumer ID", description="Consumer ID for a specific user." | ||
) | ||
|
||
settings: dict = Field( | ||
None, | ||
title="Consumer ID settings", | ||
description="Settings defined for a specific user.", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from typing import Dict | ||
from fastapi import Query, Body | ||
from mp_api.core.utils import STORE_PARAMS | ||
from mp_api.core.query_operator import QueryOperator | ||
|
||
|
||
class UserSettingsQuery(QueryOperator): | ||
"""Query operators to provide user settings information""" | ||
|
||
def query( | ||
self, | ||
consumer_id: str = Query(..., title="Consumer ID",), | ||
settings: Dict = Body(..., title="User settings",), | ||
) -> STORE_PARAMS: | ||
|
||
self.cid = consumer_id | ||
self.settings = settings | ||
|
||
crit = {"consumer_id": consumer_id, "settings": settings} | ||
|
||
return {"criteria": crit} | ||
|
||
def post_process(self, written): | ||
|
||
d = [{"consumer_id": self.cid, "settings": self.settings}] | ||
|
||
return d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from mp_api.core.resource import ConsumerPostResource | ||
from mp_api._consumer.models import UserSettingsDoc | ||
from mp_api._consumer.query_operator import UserSettingsQuery | ||
|
||
|
||
def set_settings_resource(consumer_settings_store): | ||
resource = ConsumerPostResource( | ||
consumer_settings_store, | ||
UserSettingsDoc, | ||
query_operators=[UserSettingsQuery()], | ||
tags=["Consumer"], | ||
) | ||
|
||
return resource |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.