Skip to content

Commit

Permalink
fix: convert nested dicts to correct bungie case
Browse files Browse the repository at this point in the history
  • Loading branch information
Kigstn committed Feb 21, 2023
1 parent 082715d commit d56ef89
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 31 deletions.
34 changes: 22 additions & 12 deletions bungio/api/bungie/destiny2.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ async def search_destiny_player_by_bungie_name(
"""

response = await self._client.http.search_destiny_player_by_bungie_name(
membership_type=getattr(membership_type, "value", membership_type), auth=auth, **data.to_dict()
membership_type=getattr(membership_type, "value", membership_type),
auth=auth,
**data.to_dict(_return_to_bungie_case=False)
)
return [
await UserInfoCard.from_dict(data=value, client=self._client, membership_type=membership_type, auth=auth)
Expand Down Expand Up @@ -463,7 +465,7 @@ async def transfer_item(self, data: DestinyItemTransferRequest, auth: AuthData)
The model which is returned by bungie. [General endpoint information.](https://bungie-net.github.io/multi/index.html)
"""

response = await self._client.http.transfer_item(auth=auth, **data.to_dict())
response = await self._client.http.transfer_item(auth=auth, **data.to_dict(_return_to_bungie_case=False))
return response["Response"]

async def pull_from_postmaster(self, data: DestinyPostmasterTransferRequest, auth: AuthData) -> int:
Expand All @@ -481,7 +483,7 @@ async def pull_from_postmaster(self, data: DestinyPostmasterTransferRequest, aut
The model which is returned by bungie. [General endpoint information.](https://bungie-net.github.io/multi/index.html)
"""

response = await self._client.http.pull_from_postmaster(auth=auth, **data.to_dict())
response = await self._client.http.pull_from_postmaster(auth=auth, **data.to_dict(_return_to_bungie_case=False))
return response["Response"]

async def equip_item(self, data: DestinyItemActionRequest, auth: AuthData) -> int:
Expand All @@ -499,7 +501,7 @@ async def equip_item(self, data: DestinyItemActionRequest, auth: AuthData) -> in
The model which is returned by bungie. [General endpoint information.](https://bungie-net.github.io/multi/index.html)
"""

response = await self._client.http.equip_item(auth=auth, **data.to_dict())
response = await self._client.http.equip_item(auth=auth, **data.to_dict(_return_to_bungie_case=False))
return response["Response"]

async def equip_items(self, data: DestinyItemSetActionRequest, auth: AuthData) -> DestinyEquipItemResults:
Expand All @@ -517,7 +519,7 @@ async def equip_items(self, data: DestinyItemSetActionRequest, auth: AuthData) -
The model which is returned by bungie. [General endpoint information.](https://bungie-net.github.io/multi/index.html)
"""

response = await self._client.http.equip_items(auth=auth, **data.to_dict())
response = await self._client.http.equip_items(auth=auth, **data.to_dict(_return_to_bungie_case=False))
return await DestinyEquipItemResults.from_dict(data=response, client=self._client, auth=auth)

async def set_item_lock_state(self, data: DestinyItemStateRequest, auth: AuthData) -> int:
Expand All @@ -535,7 +537,7 @@ async def set_item_lock_state(self, data: DestinyItemStateRequest, auth: AuthDat
The model which is returned by bungie. [General endpoint information.](https://bungie-net.github.io/multi/index.html)
"""

response = await self._client.http.set_item_lock_state(auth=auth, **data.to_dict())
response = await self._client.http.set_item_lock_state(auth=auth, **data.to_dict(_return_to_bungie_case=False))
return response["Response"]

async def set_quest_tracked_state(self, data: DestinyItemStateRequest, auth: AuthData) -> int:
Expand All @@ -553,7 +555,9 @@ async def set_quest_tracked_state(self, data: DestinyItemStateRequest, auth: Aut
The model which is returned by bungie. [General endpoint information.](https://bungie-net.github.io/multi/index.html)
"""

response = await self._client.http.set_quest_tracked_state(auth=auth, **data.to_dict())
response = await self._client.http.set_quest_tracked_state(
auth=auth, **data.to_dict(_return_to_bungie_case=False)
)
return response["Response"]

async def insert_socket_plug(
Expand All @@ -573,7 +577,7 @@ async def insert_socket_plug(
The model which is returned by bungie. [General endpoint information.](https://bungie-net.github.io/multi/index.html)
"""

response = await self._client.http.insert_socket_plug(auth=auth, **data.to_dict())
response = await self._client.http.insert_socket_plug(auth=auth, **data.to_dict(_return_to_bungie_case=False))
return await DestinyItemChangeResponse.from_dict(data=response, client=self._client, auth=auth)

async def insert_socket_plug_free(
Expand All @@ -593,7 +597,9 @@ async def insert_socket_plug_free(
The model which is returned by bungie. [General endpoint information.](https://bungie-net.github.io/multi/index.html)
"""

response = await self._client.http.insert_socket_plug_free(auth=auth, **data.to_dict())
response = await self._client.http.insert_socket_plug_free(
auth=auth, **data.to_dict(_return_to_bungie_case=False)
)
return await DestinyItemChangeResponse.from_dict(data=response, client=self._client, auth=auth)

async def get_post_game_carnage_report(
Expand Down Expand Up @@ -634,7 +640,7 @@ async def report_offensive_post_game_carnage_report_player(
"""

response = await self._client.http.report_offensive_post_game_carnage_report_player(
activity_id=activity_id, auth=auth, **data.to_dict()
activity_id=activity_id, auth=auth, **data.to_dict(_return_to_bungie_case=False)
)
return response["Response"]

Expand Down Expand Up @@ -1113,7 +1119,9 @@ async def awa_initialize_request(self, data: AwaPermissionRequested, auth: AuthD
The model which is returned by bungie. [General endpoint information.](https://bungie-net.github.io/multi/index.html)
"""

response = await self._client.http.awa_initialize_request(auth=auth, **data.to_dict())
response = await self._client.http.awa_initialize_request(
auth=auth, **data.to_dict(_return_to_bungie_case=False)
)
return await AwaInitializeResponse.from_dict(data=response, client=self._client, auth=auth)

async def awa_provide_authorization_result(self, data: AwaUserResponse, auth: Optional[AuthData] = None) -> int:
Expand All @@ -1128,7 +1136,9 @@ async def awa_provide_authorization_result(self, data: AwaUserResponse, auth: Op
The model which is returned by bungie. [General endpoint information.](https://bungie-net.github.io/multi/index.html)
"""

response = await self._client.http.awa_provide_authorization_result(auth=auth, **data.to_dict())
response = await self._client.http.awa_provide_authorization_result(
auth=auth, **data.to_dict(_return_to_bungie_case=False)
)
return response["Response"]

async def awa_get_action_token(self, correlation_id: str, auth: AuthData) -> AwaAuthorizationResult:
Expand Down
4 changes: 3 additions & 1 deletion bungio/api/bungie/forum.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,9 @@ async def get_recruitment_thread_summaries(
The model which is returned by bungie. [General endpoint information.](https://bungie-net.github.io/multi/index.html)
"""

response = await self._client.http.get_recruitment_thread_summaries(auth=auth, **data.to_dict())
response = await self._client.http.get_recruitment_thread_summaries(
auth=auth, **data.to_dict(_return_to_bungie_case=False)
)
return [
await ForumRecruitmentDetail.from_dict(data=value, client=self._client, auth=auth)
for value in response["Response"]
Expand Down
44 changes: 30 additions & 14 deletions bungio/api/bungie/group_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ async def group_search(self, data: GroupQuery, auth: Optional[AuthData] = None)
The model which is returned by bungie. [General endpoint information.](https://bungie-net.github.io/multi/index.html)
"""

response = await self._client.http.group_search(auth=auth, **data.to_dict())
response = await self._client.http.group_search(auth=auth, **data.to_dict(_return_to_bungie_case=False))
return await GroupSearchResponse.from_dict(data=response, client=self._client, auth=auth)

async def get_group(self, group_id: int, auth: Optional[AuthData] = None) -> GroupResponse:
Expand Down Expand Up @@ -189,7 +189,7 @@ async def get_group_by_name_v2(
The model which is returned by bungie. [General endpoint information.](https://bungie-net.github.io/multi/index.html)
"""

response = await self._client.http.get_group_by_name_v2(auth=auth, **data.to_dict())
response = await self._client.http.get_group_by_name_v2(auth=auth, **data.to_dict(_return_to_bungie_case=False))
return await GroupResponse.from_dict(data=response, client=self._client, auth=auth)

async def get_group_optional_conversations(
Expand Down Expand Up @@ -228,7 +228,9 @@ async def edit_group(self, data: GroupEditAction, group_id: int, auth: AuthData)
The model which is returned by bungie. [General endpoint information.](https://bungie-net.github.io/multi/index.html)
"""

response = await self._client.http.edit_group(group_id=group_id, auth=auth, **data.to_dict())
response = await self._client.http.edit_group(
group_id=group_id, auth=auth, **data.to_dict(_return_to_bungie_case=False)
)
return response["Response"]

async def edit_clan_banner(self, data: ClanBanner, group_id: int, auth: AuthData) -> int:
Expand All @@ -247,7 +249,9 @@ async def edit_clan_banner(self, data: ClanBanner, group_id: int, auth: AuthData
The model which is returned by bungie. [General endpoint information.](https://bungie-net.github.io/multi/index.html)
"""

response = await self._client.http.edit_clan_banner(group_id=group_id, auth=auth, **data.to_dict())
response = await self._client.http.edit_clan_banner(
group_id=group_id, auth=auth, **data.to_dict(_return_to_bungie_case=False)
)
return response["Response"]

async def edit_founder_options(self, data: GroupOptionsEditAction, group_id: int, auth: AuthData) -> int:
Expand All @@ -266,7 +270,9 @@ async def edit_founder_options(self, data: GroupOptionsEditAction, group_id: int
The model which is returned by bungie. [General endpoint information.](https://bungie-net.github.io/multi/index.html)
"""

response = await self._client.http.edit_founder_options(group_id=group_id, auth=auth, **data.to_dict())
response = await self._client.http.edit_founder_options(
group_id=group_id, auth=auth, **data.to_dict(_return_to_bungie_case=False)
)
return response["Response"]

async def add_optional_conversation(
Expand All @@ -287,7 +293,9 @@ async def add_optional_conversation(
The model which is returned by bungie. [General endpoint information.](https://bungie-net.github.io/multi/index.html)
"""

response = await self._client.http.add_optional_conversation(group_id=group_id, auth=auth, **data.to_dict())
response = await self._client.http.add_optional_conversation(
group_id=group_id, auth=auth, **data.to_dict(_return_to_bungie_case=False)
)
return response["Response"]

async def edit_optional_conversation(
Expand All @@ -310,7 +318,7 @@ async def edit_optional_conversation(
"""

response = await self._client.http.edit_optional_conversation(
conversation_id=conversation_id, group_id=group_id, auth=auth, **data.to_dict()
conversation_id=conversation_id, group_id=group_id, auth=auth, **data.to_dict(_return_to_bungie_case=False)
)
return response["Response"]

Expand Down Expand Up @@ -473,7 +481,7 @@ async def ban_member(
membership_id=membership_id,
membership_type=getattr(membership_type, "value", membership_type),
auth=auth,
**data.to_dict()
**data.to_dict(_return_to_bungie_case=False)
)
return response["Response"]

Expand Down Expand Up @@ -625,7 +633,9 @@ async def approve_all_pending(
The model which is returned by bungie. [General endpoint information.](https://bungie-net.github.io/multi/index.html)
"""

response = await self._client.http.approve_all_pending(group_id=group_id, auth=auth, **data.to_dict())
response = await self._client.http.approve_all_pending(
group_id=group_id, auth=auth, **data.to_dict(_return_to_bungie_case=False)
)
return [
await EntityActionResult.from_dict(data=value, client=self._client, group_id=group_id, auth=auth)
for value in response["Response"]
Expand All @@ -649,7 +659,9 @@ async def deny_all_pending(
The model which is returned by bungie. [General endpoint information.](https://bungie-net.github.io/multi/index.html)
"""

response = await self._client.http.deny_all_pending(group_id=group_id, auth=auth, **data.to_dict())
response = await self._client.http.deny_all_pending(
group_id=group_id, auth=auth, **data.to_dict(_return_to_bungie_case=False)
)
return [
await EntityActionResult.from_dict(data=value, client=self._client, group_id=group_id, auth=auth)
for value in response["Response"]
Expand All @@ -673,7 +685,9 @@ async def approve_pending_for_list(
The model which is returned by bungie. [General endpoint information.](https://bungie-net.github.io/multi/index.html)
"""

response = await self._client.http.approve_pending_for_list(group_id=group_id, auth=auth, **data.to_dict())
response = await self._client.http.approve_pending_for_list(
group_id=group_id, auth=auth, **data.to_dict(_return_to_bungie_case=False)
)
return [
await EntityActionResult.from_dict(data=value, client=self._client, group_id=group_id, auth=auth)
for value in response["Response"]
Expand Down Expand Up @@ -709,7 +723,7 @@ async def approve_pending(
membership_id=membership_id,
membership_type=getattr(membership_type, "value", membership_type),
auth=auth,
**data.to_dict()
**data.to_dict(_return_to_bungie_case=False)
)
return response["Response"]

Expand All @@ -731,7 +745,9 @@ async def deny_pending_for_list(
The model which is returned by bungie. [General endpoint information.](https://bungie-net.github.io/multi/index.html)
"""

response = await self._client.http.deny_pending_for_list(group_id=group_id, auth=auth, **data.to_dict())
response = await self._client.http.deny_pending_for_list(
group_id=group_id, auth=auth, **data.to_dict(_return_to_bungie_case=False)
)
return [
await EntityActionResult.from_dict(data=value, client=self._client, group_id=group_id, auth=auth)
for value in response["Response"]
Expand Down Expand Up @@ -880,7 +896,7 @@ async def individual_group_invite(
membership_id=membership_id,
membership_type=getattr(membership_type, "value", membership_type),
auth=auth,
**data.to_dict()
**data.to_dict(_return_to_bungie_case=False)
)
return await GroupApplicationResponse.from_dict(
data=response,
Expand Down
2 changes: 1 addition & 1 deletion bungio/api/bungie/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ async def claim_partner_offer(self, data: PartnerOfferClaimRequest, auth: AuthDa
The model which is returned by bungie. [General endpoint information.](https://bungie-net.github.io/multi/index.html)
"""

response = await self._client.http.claim_partner_offer(auth=auth, **data.to_dict())
response = await self._client.http.claim_partner_offer(auth=auth, **data.to_dict(_return_to_bungie_case=False))
return response["Response"]

async def apply_missing_partner_offers_without_claim(
Expand Down
4 changes: 3 additions & 1 deletion bungio/api/bungie/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,5 +190,7 @@ async def search_by_global_name_post(
The model which is returned by bungie. [General endpoint information.](https://bungie-net.github.io/multi/index.html)
"""

response = await self._client.http.search_by_global_name_post(page=page, auth=auth, **data.to_dict())
response = await self._client.http.search_by_global_name_post(
page=page, auth=auth, **data.to_dict(_return_to_bungie_case=False)
)
return await UserSearchResponse.from_dict(data=response, client=self._client, page=page, auth=auth)
4 changes: 3 additions & 1 deletion bungio/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ def _convert_to_bungie_case(string: str) -> str:
split = string.split("_")
return "".join((split[0], *(s.capitalize() for s in split[1:])))

def to_dict(self) -> dict:
def to_dict(self, _return_to_bungie_case: bool = True) -> dict:
"""
Convert the model into a dict representation bungie accepts
Expand All @@ -476,6 +476,8 @@ def to_dict(self) -> dict:
continue

value = getattr(self, name)
if _return_to_bungie_case:
name = self._convert_to_bungie_case(name)

if inspect.ismethod(value) or inspect.isfunction(value):
continue
Expand Down
2 changes: 1 addition & 1 deletion generate_api_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ async def {func_name}(self"""
for param in params:
request_params.append(f"""{param["name"]}={param["format"].format(name=param["name"])}""")
if body:
request_params.append("**data.to_dict()")
request_params.append("**data.to_dict(_return_to_bungie_case=False)")

text += f"""
response = await self._client.http.{func_name}({", ".join(request_params)})
Expand Down

0 comments on commit d56ef89

Please sign in to comment.