Schul-Cloud内容API(已弃用)
项目描述
资源API包允许轻松访问Schul-Cloud资源服务器。要了解API的定义概述,请参阅仓库。
安装
您可以通过pip从PyPI安装此包
pip install schul_cloud_resources_api_v1
访问API
假设,一个服务器在http://localhost:8080/v1下运行。您可以使用API连接到它。如果您没有服务器,您可以从schul_cloud_resources_server_tests包中获取测试服务器。
# import the api classes for access
from schul_cloud_resources_api_v1 import ApiClient, ResourceApi
# create the client objects
url = "http://localhost:8080/v1"
client = ApiClient(url)
api = ResourceApi(client)
“api”对象提供了对服务器的访问。在这里,您可以看到如何访问API
# import the resource examples
from schul_cloud_resources_api_v1.schema import get_valid_examples
# get a valid resource
resource = get_valid_examples()[0]
print(resource)
# add the resource to the server
response = api.add_resource(resource)
# verify the resource is on the server
all_my_resssources_on_the_server = api.get_resource_ids()
assert response.id in all_my_resssources_on_the_server
# get the resource from the server
resource_copy = api.get_resource(response.id)
assert resource_copy == resource
# delete the resource
api.delete_resource(response.id)
认证
有以下认证选项
无认证:这是默认设置,无需执行任何操作。
基本认证:使用用户名和密码进行认证
API密钥认证:提供密钥以授权请求。
认证是全局状态。所有ApiClients都使用此全局状态。因此,您一次只能认证一个API。
import schul_cloud_resources_api_v1.auth as auth
您可以移除所有认证。这是默认情况。
auth.none()
您可以使用用户名和密码进行认证。这是基本认证。
auth.basic("username", "password")
您可以使用API密钥进行认证。
auth.api_key("your-api-key")
验证资源
在使用资源时,您可能想验证它们是否具有正确的格式。格式在资源模式中指定。此模式包含在api中。
from schul_cloud_resources_api_v1.schema import (
get_valid_examples, get_invalid_examples, validate_resource, is_valid_resource
)
您可以使用is_valid_resource测试资源是否有效。
valid_resource = get_valid_examples()[0]
assert is_valid_resource(valid_resource)
invalid_resource = get_invalid_examples()[0]
assert not is_valid_resource(invalid_resource)
如果您想了解更多关于资源无效的原因,可以使用validate_resource。
validate_resource({'title': 'hello'})
这导致一个错误,即缺少但必需的url属性。
jsonschema.exceptions.ValidationError: 'url' is a required property
Failed validating 'required' in schema:
{'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'}
On instance:
{'title': 'hello'}
进一步阅读
要编辑此说明,您可以编辑GitHub上的文件。您可以使用此编辑器。
项目详情
关闭
schul_cloud_ressources_api_v1-1.0.0.64.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | f16f1d39365617664fc217f6aae40cc0ae92078067dad0d6d063754d9b1fd536 |
|
MD5 | 5d57fbfe2c9903cb34e19490910b8749 |
|
BLAKE2b-256 | 5ef99cb1da02c25e11ee5de5f87ce0f9fd89408d0f0fb873d99d3b11870430af |
关闭
schul_cloud_ressources_api_v1-1.0.0.64-py3-none-any.whl 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | ad782e636adc74d5a196b3cb55b27c3c752d2a3a363c7292ca3959a778d12762 |
|
MD5 | 453cfec8056fe8b6c2db0293962b5fbd |
|
BLAKE2b-256 | 95bac5bcc07940e0b2125f8b1137cd0e3273a1b1a974352e6a8c16fc1ed7b85e |