Package: schul-cloud-resources-api-v1
The resources API package allows easy access to the Schul-Cloud resources servers.
To get an overview about how the api is defined, please refer to therepository.InstallationYou can install the package with pip fromPyPIpipinstallschul_cloud_resources_api_v1Accessing the APISuppose, a server runs underhttp://localhost:8080/v1.
You can use the api to connect to it.
If you do not have a server, you can get a test server from the packageschul_cloud_resources_server_tests.# import the api classes for accessfromschul_cloud_resources_api_v1importApiClient,ResourceApi# create the client objectsurl="http://localhost:8080/v1"client=ApiClient(url)api=ResourceApi(client)Theapiobject gives access to the server.
Here, you can see how to access the api:# import the resource examplesfromschul_cloud_resources_api_v1.schemaimportget_valid_examples# get a valid resourceresource=get_valid_examples()[0]print(resource)# add the resource to the serverresponse=api.add_resource({"data":{"type":"resource","attributes":resource}})# verify the resource is on the serverall_my_resssources_on_the_server=[_id.idfor_idinapi.get_resource_ids().data]assertresponse.data.idinall_my_resssources_on_the_server# get the resource from the serverresource_copy=api.get_resource(response.data.id)assertresource_copy==resource.data.attributes# delete the resourceapi.delete_resource(response.data.id)AuthenticationThere are these options for authentication:no authentication: this is the default and nothing needs to be done.basic authentication: authentication with user name and passwordapi-key authentication: a key is supplied to authorize the requests.The authentication is a global state.
AllApiClientsuse this global state.
Thus, you can only authenticate at one API at a time.importschul_cloud_resources_api_v1.authasauthYou can remove all authentication. This is the default case.auth.none()You can authenticate with username and password. This isBasic Authentication.auth.basic("username","password")You can authenticate with an api key.auth.api_key("your-api-key")Validating ResourcesWhen you use resources, you may want to verify if they have the correct format.
The format is specified in theresource-schema.
This schema is included in this package.fromschul_cloud_resources_api_v1.schemaimport(get_valid_examples,get_invalid_examples,validate_resource,is_valid_resource)You can test if a resource is valid by callingis_valid_resourcevalid_resource=get_valid_examples()[0]assertis_valid_resource(valid_resource)invalid_resource=get_invalid_examples()[0]assertnotis_valid_resource(invalid_resource)If you would like to find out more about why the resource is not valid, you can usevalidate_resource.validate_resource({'title':'hello'})In this example, it results in an error that theurlproperty is not present but is required.jsonschema.exceptions.ValidationError:'url'isarequiredpropertyFailedvalidating'required'inschema:{'properties':{'contentCategory':{'$ref':'#/definitions/ContentCategory'},'contextUrl':{'$ref':'#/definitions/URL'},'curricula':{'items':{'$ref':'../curriculum/curriculum.json'},'type':'array'},'dimensions':{'$ref':'#/definitions/Dimensions'},'duration':{'type':'number'},'languages':{'description':'As described in IEEE ''LOM, Section 1.3 ''http://129.115.100.158/txlor/docs/IEEE_LOM_1484_12_1_v1_Final_Draft.pdf','items':{'$ref':'#/definitions/Language'},'type':'array'},'licenses':{'items':{'$ref':'../license/license.json'},'type':'array'},'mimeType':{'description':'https://tools.ietf.org/html/rfc2046','example':'text/html','type':'string'},'size':{'format':'int64','type':'integer'},'thumbnail':{'$ref':'#/definitions/URL'},'title':{'description':'The title of the resource.','example':'Schul-Cloud','type':'string'},'url':{'$ref':'#/definitions/URL'}},'required':['title','url','licenses','mimeType','contentCategory','languages'],'type':'object'}Oninstance:{'title':'hello'}Related PackagesTheServer Testsuse this library to test servers implementing the API defined in therepository.Further ReadingTo edit this description, you can edit thefile on Github.
You can usethis editor.