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 Oracle将休眠为ISO 8601日期格式   当有线程时,swing计时器不会停止。睡在Java里面   如何使用swing在java中清空密码字段值(字符串)   如何在编辑文本字段上设置单词java(安卓)   单独类中的java OkHttp请求   java Tomcat配置文件/上下文xml似乎已经崩溃了。请确保它是可分析和有效的。有关详细信息,请参阅服务器日志   java在科尔多瓦的ActivityResult上传递   java如何在映射中保持插入顺序。工厂?   “DataOutputStream”和“ObjectOutputStream”之间的java差异   java从FTP文件列表中获取项目的时间戳   java如何在spring security中为每个人忽略一些资源/URL?   模板类嵌套时新的Java泛型类构造函数问题   java读取并查找文件大小为1GB的行   java如何使用字符串say“stop”停止整数格式的while循环   java是否可以在应用程序启动之间将JVM保留在内存中?   java Springboot出现“出现意外错误(类型=内部服务器错误,状态=500)”的问题