Skip to content

Commit 2910584

Browse files
CUST-5289 [v3] Python SDK ListGrantsQueryParams uses camelCase keys t… (#464)
1 parent c15faa5 commit 2910584

3 files changed

Lines changed: 91 additions & 7 deletions

File tree

nylas/models/grants.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,23 +83,30 @@ class ListGrantsQueryParams(TypedDict):
8383
limit: The maximum number of objects to return.
8484
This field defaults to 10. The maximum allowed value is 200.
8585
offset: Offset grant results by this number.
86-
sortBy: Sort entries by field name
87-
orderBy: Specify ascending or descending order.
86+
sort_by: Sort entries by field name.
87+
order_by: Specify ascending or descending order.
8888
since: Scope grants from a specific point in time by Unix timestamp.
8989
before: Scope grants to a specific point in time by Unix timestamp.
9090
email: Filtering your query based on grant email address (if applicable)
91-
grantStatus: Filtering your query based on grant email status (if applicable)
91+
grant_status: Filtering your query based on grant email status (if applicable)
9292
ip: Filtering your query based on grant IP address
9393
provider: Filtering your query based on OAuth provider
94+
sortBy: Deprecated camelCase alias for sort_by.
95+
orderBy: Deprecated camelCase alias for order_by.
96+
grantStatus: Deprecated camelCase alias for grant_status.
9497
"""
9598

9699
limit: NotRequired[int]
97100
offset: NotRequired[int]
98-
sortBy: NotRequired[str]
99-
orderBy: NotRequired[str]
101+
sort_by: NotRequired[str]
102+
order_by: NotRequired[str]
100103
since: NotRequired[int]
101104
before: NotRequired[int]
102105
email: NotRequired[str]
103-
grantStatus: NotRequired[str]
106+
grant_status: NotRequired[str]
104107
ip: NotRequired[str]
105108
provider: NotRequired[Provider]
109+
# Backward-compatible aliases for callers still passing camelCase keys.
110+
sortBy: NotRequired[str]
111+
orderBy: NotRequired[str]
112+
grantStatus: NotRequired[str]

nylas/resources/grants.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,28 @@
1313
from nylas.models.response import Response, ListResponse, DeleteResponse
1414

1515

16+
def _normalize_grants_query_params(query_params: ListGrantsQueryParams = None) -> dict:
17+
if not query_params:
18+
return query_params
19+
20+
normalized_query_params = dict(query_params)
21+
key_aliases = {
22+
"sortBy": "sort_by",
23+
"orderBy": "order_by",
24+
"grantStatus": "grant_status",
25+
}
26+
27+
for camel_case_key, snake_case_key in key_aliases.items():
28+
if camel_case_key in normalized_query_params:
29+
if snake_case_key not in normalized_query_params:
30+
normalized_query_params[snake_case_key] = normalized_query_params[
31+
camel_case_key
32+
]
33+
del normalized_query_params[camel_case_key]
34+
35+
return normalized_query_params
36+
37+
1638
class Grants(
1739
ListableApiResource,
1840
FindableApiResource,
@@ -47,7 +69,7 @@ def list(
4769
return super().list(
4870
path="/v3/grants",
4971
response_type=Grant,
50-
query_params=query_params,
72+
query_params=_normalize_grants_query_params(query_params),
5173
overrides=overrides,
5274
)
5375

tests/resources/test_grants.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,61 @@ def test_list_grants(self, http_client_list_response):
6868
"GET", "/v3/grants", None, None, None, overrides=None
6969
)
7070

71+
def test_list_grants_normalizes_camel_case_query_params(
72+
self, http_client_list_response
73+
):
74+
grants = Grants(http_client_list_response)
75+
76+
grants.list(
77+
query_params={
78+
"sortBy": "created_at",
79+
"orderBy": "asc",
80+
"grantStatus": "valid",
81+
"limit": 10,
82+
}
83+
)
84+
85+
http_client_list_response._execute.assert_called_once_with(
86+
"GET",
87+
"/v3/grants",
88+
None,
89+
{
90+
"sort_by": "created_at",
91+
"order_by": "asc",
92+
"grant_status": "valid",
93+
"limit": 10,
94+
},
95+
None,
96+
overrides=None,
97+
)
98+
99+
def test_list_grants_prefers_snake_case_query_params(self, http_client_list_response):
100+
grants = Grants(http_client_list_response)
101+
102+
grants.list(
103+
query_params={
104+
"sortBy": "updated_at",
105+
"sort_by": "created_at",
106+
"orderBy": "desc",
107+
"order_by": "asc",
108+
"grantStatus": "invalid",
109+
"grant_status": "valid",
110+
}
111+
)
112+
113+
http_client_list_response._execute.assert_called_once_with(
114+
"GET",
115+
"/v3/grants",
116+
None,
117+
{
118+
"sort_by": "created_at",
119+
"order_by": "asc",
120+
"grant_status": "valid",
121+
},
122+
None,
123+
overrides=None,
124+
)
125+
71126
def test_find_grant(self, http_client_response):
72127
grants = Grants(http_client_response)
73128

0 commit comments

Comments
 (0)