schul云内容api(已弃用)
schul-cloud-ressources-api-v1的Python项目详细描述
资源api包允许轻松访问schul云资源服务器。 要了解如何定义api,请参阅repository。
访问API
假设,服务器在http://localhost:8080/v1下运行。 您可以使用api连接到它。 如果没有服务器,可以从包中获取测试服务器 schul_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)
api对象允许访问服务器。 在这里,您可以看到如何访问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(resource)# verify the resource is on the serverall_my_resssources_on_the_server=api.get_resource_ids()assertresponse.idinall_my_resssources_on_the_server# get the resource from the serverresource_copy=api.get_resource(response.id)assertresource_copy==resource# delete the resourceapi.delete_resource(response.id)
认证
有以下身份验证选项:
- 无身份验证:这是默认设置,无需执行任何操作。
- 基本身份验证:使用用户名和密码进行身份验证
- api_密钥身份验证:提供一个密钥来授权请求。
身份验证是全局状态。 所有ApiClients使用此全局状态。 因此,一次只能在一个api上进行身份验证。
importschul_cloud_resources_api_v1.authasauth
您可以删除所有身份验证。这是默认情况。
auth.none()
您可以使用用户名和密码进行身份验证。这是基本认证 <;https://en.wikipedia.org/wiki/basic_access_authentication>;。
auth.basic("username","password")
您可以使用api密钥进行身份验证。
auth.api_key("your-api-key")
验证资源
使用资源时,可能需要验证它们是否具有正确的格式。 格式在resource-schema中指定。 此架构包含在API中。
fromschul_cloud_resources_api_v1.schemaimport(get_valid_examples,get_invalid_examples,validate_resource,is_valid_resource)
您可以测试资源是否有效或不使用是否有效
如果您想进一步了解资源无效的原因,可以使用validate\u resource。 这会导致一个错误,即url属性不存在,但却是必需的。valid_resource=get_valid_examples()[0]assertis_valid_resource(valid_resource)invalid_resource=get_invalid_examples()[0]assertnotis_valid_resource(invalid_resource)
validate_resource({'title':'hello'})
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'}
进一步阅读
- 要编辑此描述,可以编辑file on Github。 您可以使用this editor。