Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert API response JSON to Python dict #26

Merged

Conversation

lucioseki
Copy link
Contributor

Some methods in this library are returning the API response JSON
string without converting it to a Python dict.
This is forcing the caller to selectively call json.loads
depending on the retrieved resource (e.g. users resource requires
json.loads, but items doesn't).

This patch makes all the API responses to be converted to a Python
dict, so the caller can consistently use the return value as a dict
regardless the requested resource.

@lucioseki
Copy link
Contributor Author

This PR addresses the issue #25

Copy link
Collaborator

@chdastolfo chdastolfo left a comment

Choose a reason for hiding this comment

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

👍

Copy link
Collaborator

@rhymiz rhymiz left a comment

Choose a reason for hiding this comment

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

@lucioseki my proposal here is to change response.text to response.json() in the graphql client. That's the source of the issue.

Note: requests will raise an exception if you call .json on a response object that does not contain a 2xx or 4xx status code, that can either be handle explicitly by you, or you can call response.raise_for_status() before moving on to calling response.json.

@lucioseki lucioseki requested a review from rhymiz May 19, 2021 21:39
monday/resources/base.py Outdated Show resolved Hide resolved
lucioseki and others added 4 commits May 19, 2021 18:51
Some methods in this library are returning the API response JSON
string without converting it to a Python dict.
This is forcing the caller to selectively call json.loads
depending on the retrieved resource (e.g. `users` resource requires
json.loads, but `items` doesn't).

This patch makes all the API responses to be converted to a Python
dict, so the caller can consistently use the return value as a dict
regardless the requested resource.
Currently, the library converts the response.text returned by the
GraphQL client to a Python dict using json.loads.

But the requests library already has a builtin JSON decoder that
converts a JSON response to a Python dict.

This patch makes the GraphQL return the response.json() result.
The callers no longer need to convert the return value to a dict.
also some code cleanup
@lucioseki lucioseki force-pushed the convert_response_json_to_dict branch from 5eae55b to 669bb0e Compare May 19, 2021 21:53
@lucioseki lucioseki requested a review from rhymiz May 19, 2021 21:55
Copy link
Collaborator

@rhymiz rhymiz left a comment

Choose a reason for hiding this comment

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

This looks good! Thanks for addressing all the comments!

@chdastolfo chdastolfo merged commit 8b92f2f into ProdPerfect:master May 20, 2021
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