-
Notifications
You must be signed in to change notification settings - Fork 40
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
Add EndpointPayload ABC and Specific Payload Dataclasses for API Requests #208
base: master
Are you sure you want to change the base?
Conversation
Adds minimal structure within a new client folder
Adds: - A Node dataclass which models an individual node (with dcid, name, etc) - A NodeGroup dataclass which represents a list of Node objects - An Arcs dataclass, which represents arcs (with a label and containing NodeGroups) - A Properties dataclass which represents a list of Properties
Adds: - An Observation dataclass which models an individual observation (date, value) - An OrderedFacets dataclass which models the 'ordered facets' of observations - A Variable dataclass which represents a variable data (grouped by entity) - A Facet class which represents the metadata for a facet
Adds: - A candidate dataclass to model candidates in the response (with dcid and dominanType) - An Entity dataclass to model entities with their resolution candidates
Adds: - A Cell dataclass to model a single cell in a row - A Row modelling a row with cells.
Adds tests for node, observation, resolve and sparql models.
DCResponse just wraps around the api response
Validates instance. Builds header. Manages post requests, including multi-page responses
Fixes a typo on the return type of the post_request function
- EndpointPayload as an ABC - NodePayload to model the required payload for node calls - Observation Payload to model the required payload for observation calls (additionally enums for valid observation select fields and valid date strings) -ResolvePayload to model the required payload for resolve calls - SparqlPayload to model the required payload for Sparql calls
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @jm-rivera ! To make things a little simpler with this stack of PRs, it may be easier to just address all comments in this PR (208). what do you think?
@dataclass | ||
class NodePayload(EndpointPayload): | ||
""" | ||
A dataclass to structure, normalize, and validate the payload for a node API request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you note that this is specifically for the /v2/node endpoint?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same for the other payload below
Note:
First PR in the stack: #202
Second PR in the stack: #203
Third PR in the stack: #204
Fourth PR in the stack #205
Previous PR in the stack #206
Will manually rebase as PRs in the stack are merged to make it easier to review the changes introduced in this PR.
This PR adds 'payload' dataclasses for the API endpoints.
The
EndpointPayload
class is an Abstract Base Class, which defines the structure for all other payload classes. Payload classes are in charge of normalizing and validating the payload before it is used for a POST request. They also implement a.to_dict
property for easy access to the correctly structured payload data as a python dictionary.Details:
datacommons_client/endpoints/payloads.py
: Added abstract base classEndpointPayload
and specific payload classes (NodePayload
,ObservationPayload
,ResolvePayload
,SparqlPayload
) to structure, normalize, and validate payloads for different API requests.Tests
datacommons_client/tests/endpoints/test_payloads.py
: Introduced test cases for each payload class.