osfclient icon indicating copy to clipboard operation
osfclient copied to clipboard

[WIP] Add functions to work with metadata

Open Heiss opened this issue 5 years ago • 0 comments

This PR implements multiple methods to work with the projects within OSF. Also it adds a new init parameter to specify a test instance of OSF.

Example for usage:

for project in OSF(token="ASFXXXXXXXXX", address="https://api.test.osf.io/v2").projects():
  print(project.metadata())
  project.delete()

Currently there is small rubbish from my first attempt to use OSFclient as an jsonld client for my work. I will remove it later (or do you want to use it maybe? On my workplace, we use jsonld as our format for distributed informations. It is a nice to have).

This PR adds the following methods to models:

OSF model:

  • projects(): Returns all projects for given session
  • project(id): Returns only the specified project with id
  • create_project(self, title, category=None, description=None, tags=None): create a project with given metadata (category defaults to "project")

Project model:

  • metadata(only_mutable=False, jsonld=False): returns the metadata of current project, can be used to get jsonld and filter to only mutable attributes.
  • update(json=None): updates the current project to the given json
  • delete(): deletes the current project

File model:

  • copyfileobj(): accepts now BytesIO object, because it uses now read(1) instead of peek(1), which is only implemented for buffered IO objects or file objects.

Currently, this changes are already used in my project.

Heiss avatar Oct 23 '20 11:10 Heiss