Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

Schul-Cloud Content API

Project Description

The resources API package allows easy access to the Schul-Cloud resources 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_resources_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_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)

The api object gives access to the server. Here, you can see how to access the 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({"data": {"type": "resource", "attributes": resource}})

# verify the resource is on the server
all_my_resssources_on_the_server = [
    _id.id for _id in api.get_resource_ids().data]
assert response.data.id in all_my_resssources_on_the_server

# get the resource from the server
resource_copy = api.get_resource(response.data.id)
assert resource_copy == resource.data.attributes

# delete the resource
api.delete_resource(response.data.id)

Authentication

There are these options for authentication:

  • no authentication: this is the default and nothing needs to be done.
  • basic authentication: authentication with user name and password
  • api-key authentication: a key is supplied to authorize the requests.

The authentication is a global state. All ApiClients use this global state. Thus, you can only authenticate at one API at a time.

import schul_cloud_resources_api_v1.auth as auth

You can remove all authentication. This is the default case.

auth.none()

You can authenticate with username and password. This is Basic Authentication.

auth.basic("username", "password")

You can authenticate with an api key.

auth.api_key("your-api-key")

Validating Resources

When you use resources, you may want to verify if they have the correct format. The format is specified in the resource-schema. This schema is included in this package.

from schul_cloud_resources_api_v1.schema import (
    get_valid_examples, get_invalid_examples, validate_resource, is_valid_resource
)

You can test if a resource is valid by calling 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)

If you would like to find out more about why the resource is not valid, you can use validate_resource.

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

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

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

Further Reading

Release History

Release History

This version
History Node

1.0.0.326

History Node

1.0.0.323

History Node

1.0.0.316

History Node

1.0.0.312

History Node

1.0.0.277

History Node

1.0.0.262

History Node

1.0.0.259

History Node

1.0.0.253

History Node

1.0.0.250

History Node

1.0.0.235

History Node

1.0.0.234

History Node

1.0.0.231

History Node

1.0.0.230

History Node

1.0.0.229

History Node

1.0.0.226

History Node

1.0.0.225

History Node

1.0.0.208

History Node

1.0.0.207

History Node

1.0.0.204

History Node

1.0.0.203

History Node

1.0.0.196

History Node

1.0.0.193

History Node

1.0.0.190

History Node

1.0.0.189

History Node

1.0.0.184

History Node

1.0.0.181

History Node

1.0.0.176

History Node

1.0.0.170

History Node

1.0.0.167

History Node

1.0.0.164

History Node

1.0.0.160

History Node

1.0.0.159

History Node

1.0.0.158

History Node

1.0.0.155

History Node

1.0.0.154

History Node

1.0.0.153

History Node

1.0.0.148

History Node

1.0.0.133

History Node

1.0.0.130

History Node

1.0.0.121

History Node

1.0.0.118

History Node

1.0.0.115

History Node

1.0.0.112

History Node

1.0.0.103

History Node

1.0.0.100

History Node

1.0.0.85

History Node

1.0.0.80

History Node

1.0.0.79

History Node

1.0.0.78

History Node

1.0.0.71

History Node

1.0.0.70

History Node

1.0.0.66

History Node

1.0.0.65

Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
schul_cloud_resources_api_v1-1.0.0.326-py3-none-any.whl (84.6 kB) Copy SHA256 Checksum SHA256 py3 Wheel Sep 26, 2017
schul_cloud_resources_api_v1-1.0.0.326.tar.gz (34.3 kB) Copy SHA256 Checksum SHA256 Source Sep 26, 2017

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting