Skip to main content

Schul-Cloud Content API

Project description

The ressources API package allows easy access to the Schul-Cloud ressources servers. To get an overview about how the api is defined, please refer to the repository.

Installation

You can install the package with pip from PyPI

pip install schul_cloud_ressources_api_v1

Accessing the API

Suppose, a server runs under http://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 package schul_cloud_ressources_server_tests.

# import the api classes for access
from schul_cloud_ressources_api_v1 import ApiClient, RessourceApi

# create the client objects
url = "http://localhost:8080/v1"
client = ApiClient(url)
api = RessourceApi(client)

The api object gives access to the server. Here, you can see how to access the api:

# import the ressource examples
from schul_cloud_ressources_api_v1.schema import get_valid_examples

# get a valid ressource
ressource = get_valid_examples()[0]
print(ressource)

# add the ressource to the server
response = api.add_ressource(ressource)

# verify the ressource is on the server
all_my_resssources_on_the_server = api.get_ressource_ids()
assert response.id in all_my_resssources_on_the_server

# get the ressource from the server
ressource_copy = api.get_ressource(response.id)
assert ressource_copy == ressource

# delete the ressource
api.delete_ressource(response.id)

Verifying Ressources

When you use ressources, you may want to verify if they have the correct format. The format is specified in the ressource-schema. This schema is included in the api.

from schul_cloud_ressources_api_v1.schema import (
    get_valid_examples, get_invalid_examples, validate_ressource, is_valid_ressource
)

You can test if a ressource is valid or not using is_valid_ressource

valid_ressource = get_valid_examples()[0]
assert is_valid_ressource(valid_ressource)

invalid_ressource = get_invalid_examples()[0]
assert not is_valid_ressource(invalid_ressource)

If you would like to find outmore about why the ressource is not valid, you can use validate_ressource.

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

Which results in an error that the url property is not present but is required.

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 ressource.',
                              'example': 'Schul-Cloud',
                              'type': 'string'},
                    'url': {'$ref': '#/definitions/URL'}},
     'required': ['title',
                  'url',
                  'licenses',
                  'mimeType',
                  'contentCategory',
                  'languages'],
     'type': 'object'}

On instance:
    {'title': 'hello'}

Further Reading

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

schul_cloud_ressources_api_v1-1.0.0-36.tar.gz (19.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file schul_cloud_ressources_api_v1-1.0.0-36.tar.gz.

File metadata

File hashes

Hashes for schul_cloud_ressources_api_v1-1.0.0-36.tar.gz
Algorithm Hash digest
SHA256 226193f86413f5ea4987a36114efd6a2f0c7385aa655aa00a662ca26d3b2a600
MD5 59984e1720e8ccf54b41f7c70888dfe7
BLAKE2b-256 fee15d62e2abf15466de5e1ef08eb8d565f8ea61dc4febaaae7b32810400e530

See more details on using hashes here.

File details

Details for the file schul_cloud_ressources_api_v1-1.0.0.post36-py3-none-any.whl.

File metadata

File hashes

Hashes for schul_cloud_ressources_api_v1-1.0.0.post36-py3-none-any.whl
Algorithm Hash digest
SHA256 d5da15275da9eaab388eac4d08d25df380f252192e41755386d8e630b0c6ecee
MD5 f38ec8fc58b22b56ea717639b276bd5a
BLAKE2b-256 e1e6d075d70179990086c02446c7a895a11743a4f1d7aee32d9c70006da3d40d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page