Return a pyDataverse object from an API requests
When pulling a dataset, the response object contains the json of the dataset. Would it be attractive to instead return a Dataset object?
The Dataset class would simply contain getter and setter functions for all properties and the constructor only needs the json as an input. I assume this would improve clarity (one could create a print function to show the metadata maybe using pandas?).
Additionally, a Dataset object could be passed to other functions like create_dataset.
This is a good idea. I had at the beginning different return types implemented, but to offer full control to the user, i removed it.
Am trying to list up all return_types, that could be of interest
- json (default)
- dict
- Dataset/Dataverse/Datafile object
- requests object
In the case of multiple returns, one could return a subDictionary containing all return types and the user can decide on the return desired.
return {'json':jsonObject, 'dict':dictObject, ...}
...
json = returnDict["json"]
Or some kind of return class.
json = returnClass.getJson()
In general, to keep the module as simple, tidy and modular as possible, I want to define each abstraction level in detail and give the users as much freedom as possible. A user should be able to decide, what it wants to do with the responses, and I should not limit their options I think. This said, from that point on, a lot of abstractions can be made, to offer functions for specific use-cases. Once the core works well, the next level of abstraction can be tackled.
To be more concrete: The first step is to develop get() and set() to create proper dicts as output. This will then be used to connect all kinds of i/o formats (to_json, from_json, to_xml, from_xml and so on). Once this is done, the passing of objects could also be an option (or just pass the Dataset.to_json() output as JSON string into the API call directly).
Will be solved in #132.
As discussed during the 2024-02-14 meeting of the pyDataverse working group, we are closing old milestones in favor of a new project board at https://github.com/orgs/gdcc/projects/1 and removing issues (like this one) from those old milestones. Please feel free to join the working group! You can find us at https://py.gdcc.io and https://dataverse.zulipchat.com/#narrow/stream/377090-python