macadmins / jamf-pro-sdk-python

A client library for the Jamf Pro APIs and webhooks.
https://macadmins.github.io/jamf-pro-sdk-python/
MIT License
51 stars 10 forks source link

[Feature Request] Pass a model to the Classic and Pro API request methods as the return type. #52

Open brysontyrrell opened 4 months ago

brysontyrrell commented 4 months ago

Proposal

When using the classic_api_request and pro_api_request methods on the client directly users have to take the response and cast it to an SDK model themselves.

resp = jamf_client.classic_api_request(
    method="get",
    resource_path=f"computergroups/name/{group_name}"
)
group = ClassicComputerGroup(**resp.json()["computer_group"])

Both methods should optionally accept an SDK model as an optional response type. When set, the requests response object is not returned, but the method attempts to instantiate the provided model from the data.

group = jamf_client.classic_api_request(
    method="get",
    resource_path=f"computergroups/name/{group_name}",
    return_model=ClassicComputerGroup
)
macserv commented 3 weeks ago

Makes sense. Would also be nice to make use of Generic/TypeVar in a few choice places (e.g., Page, Pagination).