schul云内容api(已弃用)

schul-cloud-ressources-api-v1的Python项目详细描述


资源api包允许轻松访问schul云资源服务器。 要了解如何定义api,请参阅repository

安装

您可以使用PyPI中的pip安装包

pip install schul_cloud_resources_api_v1

访问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)

您可以测试资源是否有效或不使用是否有效

valid_resource=get_valid_examples()[0]assertis_valid_resource(valid_resource)invalid_resource=get_invalid_examples()[0]assertnotis_valid_resource(invalid_resource)

如果您想进一步了解资源无效的原因,可以使用validate\u resource

validate_resource({'title':'hello'})

这会导致一个错误,即url属性不存在,但却是必需的。

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'}

进一步阅读

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
如何使用java向dropup html/css添加项目   如何从java中的向量向量打印   Java Maven库项目模板   java使用atmosphere api还是直接使用grizzly?   java JComponent仅部分显示   如何将动态值传递给自定义注释,以从Java数据进行映射。性质   java破解已实现方法的返回类型的最佳方法?   java Netbeans在JFrame Gui布局中覆盖图像   spring java仅向登录用户显示注销按钮   java如何对com进行身份验证。谷歌。云bigquery。带有服务帐户的BigQuery`   java禁止空字符串参数和抛出RuntimeException以阻止方法继续的利弊   java分析项目中的所有JAR以获取版本和许可证信息   Java,数据库为什么要分配一个新对象,而我们可以直接将它放入数据库