Skip to content

Create dedicated methods for GET and POST#7

Merged
tetienne merged 2 commits intomasterfrom
enhancement/clean_request
Jul 20, 2020
Merged

Create dedicated methods for GET and POST#7
tetienne merged 2 commits intomasterfrom
enhancement/clean_request

Conversation

@tetienne
Copy link
Copy Markdown
Collaborator

No description provided.

Comment thread tahoma_api/client.py
Comment on lines +144 to +156
async def __get(self, endpoint: str) -> Any:
""" Make a GET request to the TaHoma API """
async with self.session.get(f"{self.api_url}{endpoint}") as response:
await self.check_response(response)
return await response.json()

async def __post(self, endpoint: str, payload: Optional[JSON] = None,) -> Any:
""" Make a POST request to the TaHoma API """
async with self.session.post(
f"{self.api_url}{endpoint}", data=payload
) as response:
await self.check_response(response)
return await response.json()
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iMicknl I don't call humps.decamelize for each response. I prefer call it only when needed to avoid useless process.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can understand, since we don't always process the response. For the event listener response you would need it as well (and it is missing now).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, we will have to think about it once implemented.

Comment thread tahoma_api/models.py
@tetienne tetienne requested review from iMicknl and vlebourl July 20, 2020 08:16
Copy link
Copy Markdown
Contributor

@vlebourl vlebourl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar enough with the work you guys did on the API, so I'll trust you on this one.
Looks good to me though

Comment thread tahoma_api/client.py
operation (polling)
"""
response = await self.__do_http_request("POST", f"events/{listener_id}/fetch")
response = await self.__post(f"events/{listener_id}/fetch")
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add humps here as well?

Copy link
Copy Markdown
Collaborator Author

@tetienne tetienne Jul 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? We don't build the model here. We can create a Device from this response?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decimalising is not just for the models. Currently, no model has been created for the event listener, however this JSON can be consumed already and it would be good to have snake_case keys in there, instead of camelCase.

Otherwise, we add it back in a new PR, where we also add proper models.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to do it in another PR when the model will be ready. Here it will make not yet sense.

@tetienne tetienne merged commit de8fe93 into master Jul 20, 2020
@tetienne tetienne deleted the enhancement/clean_request branch July 20, 2020 10:45
tetienne added a commit that referenced this pull request Feb 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants