sams_client.endpoints.endpoint
– Base Endpoint¶
-
class
Endpoint
(client)¶ Base helper class for endpoint specifics
- Variables
_client (sams_client.client.SamsClient) – Reference to the parent client instance
_read_url (str) – The URL for all read based requests
_write_url (str) – The URL for all write based requests
By using this endpoint, you can implement specific logic required for each type of resource so that you can intercept read/write requests to maniupulate or sanatize the request.
Usage:
# Add a new file under sams_client.endpoints for the resource # i.e. sams_client.endpoints.sets.py from .endpoint import Endpoint class SamsSetEndpoint(Endpoint): _read_url = '/consume/sets' _write_url = '/admin/sets'
Then add a new member variable to
sams_client.client.SamsClient
for users to utilise this new endpoint-
search
(params: Optional[Dict[str, Any]] = None, headers: Optional[Dict[str, Any]] = None, callback: Optional[Callable[[requests.models.Response], requests.models.Response]] = None) → requests.models.Response¶ Helper method to search this endpoint
- Parameters
- Return type
- Returns
The search response
-
get_by_id
(item_id: bson.objectid.ObjectId, headers: Optional[Dict[str, Any]] = None, callback: Optional[Callable[[requests.models.Response], requests.models.Response]] = None) → requests.models.Response¶ Helper method to get a document by its id
- Parameters
item_id (bson.objectid.ObjectId) – The ID of the document
headers (dict) – Dictionary of headers to apply
callback – A callback function to manipulate the response
- Return type
- Returns
The document, if found
-
create
(docs: List[Dict[str, Any]], headers: Optional[Dict[str, Any]] = None, files=None, external_user_id: Optional[str] = None, external_session_id: Optional[str] = None, callback: Optional[Callable[[requests.models.Response], requests.models.Response]] = None) → requests.models.Response¶ Helper method to create a new document(s)
- Parameters
- Return type
- Returns
The newly created document
-
update
(item_id: bson.objectid.ObjectId, updates: Dict[str, Any], headers: Optional[Dict[str, Any]] = None, files=None, external_user_id: Optional[str] = None, external_session_id: Optional[str] = None, callback: Optional[Callable[[requests.models.Response], requests.models.Response]] = None) → requests.models.Response¶ Helper method to update an existing document
- Parameters
item_id (bson.objectid.ObjectId) – The ID of the existing document
updates (dict) – Dictionary with the updates to apply
headers (dict) – Dictionary of headers to apply
callback – A callback function to manipulate the response
- Return type
- Returns
The updated document
-
delete
(item_id: bson.objectid.ObjectId, headers: Optional[Dict[str, Any]] = None, callback: Optional[Callable[[requests.models.Response], requests.models.Response]] = None) → requests.models.Response¶ Helper method to delete an existing document
- Parameters
item_id (bson.objectid.ObjectId) – The ID of the existing document
headers (dict) – Dictionary of the headers to apply
callback – A callback function to manipulate the response
- Return type
- Returns
The delete response