Skip to main content

Client for Stichting Opvoeden API V2

Project description

A client for the stichtingopvoeden.nl API version 2.

Usage

Import the client class from opvoeden_api.client and instantiate it with an API key:

client = Client(MY_API_KEY)

The client methods map to the following set of endpoints:

Method

Endpoint

contentset_list

/rest/v2/contentset

contentset(contentset_id)

/rest/v2/contentset/{id}

article(external_reference)

/rest/v2/article/{externalReference}

image(image_id)

/rest/v2/image/{id}

Data types

Each client method returns a different data type.

ContentSet

The contentset_list method returns a list of ContentSet objects.

A ContentSet object has of the following properties:

  • contentset_id

  • name

  • description

  • is_default

Refer to the API data types docs for more information on these fields.

ArticleNode

The contentset(contentset_id) method returns a single ArticleNode. This node represents the root of a tree of Articles.

An ArticleNode has the following properties:

article

The Article instance associated with this node

children

A list of ArticleNode instances of which the current node is the parent.

It is possible to iterate over an article node. This will traverse the entire tree in a depth first order. So, for example, to get a flat list of all the articles in a tree one could do this:

tree = client.contentset(1)
articles = [node.article for node in tree if node.article]

To recurse over the tree use the children property:

def visit(node, parent=None):
    """
    Visit each node in the tree.
    """
    # do something with node, then recurse
    for child in node.children:
        visit(child, node)

tree = client.contentset(1)
visit(tree)

Article

The article(external_reference) method returns a single Article instance. Another way to get an Article object is by accessing the article property of an ArticleNode.

An Article has the following properties:

  • external_reference

  • short_title

  • title

  • article_text

  • parent_reference

  • position

  • last_change_date

  • canonicaltag

  • tags

Refer to the API data types docs for more information on these fields.

In addition to these fields the Article object also provides these properties:

path

The url of the article. This is identical to the canonicaltag but the schema://domain prefix is stripped.

slug

The last element of the path. i.e. if path is '/foo/bar/' then slug will be 'bar'.

Image

The image(image_id) method returns a single Image instance.

  • image_id

  • data

  • content_type

  • name

  • creation_date

Refer to the API data types docs for more information on these fields.

Converting image data to binary

The Image object also provides an as_binary method.

This method converts to base64 encoded value of the data property to binary. The return value of this method can be used to store images on a file system.

Article utils

The article_text of Articles returned by the contentset method can contain a number special placeholder strings.

opvoeden_api.article_utils provides functions to deal with these placeholders.

Replace JGZ placeholders

To replace JGZ placeholders with appropriate strings use replace_jgz.

By default these are the substitutions:

Placeholder

Substitution

jgz

centrum voor Jeugd en Gezin (CJG)

Jgz

Centrum voor Jeugd en Gezin (CJG)

jgzs

CJG’s

Jgzs

CJG’s

de jgzs

de CJG’s

De jgzs

De CJG’s

het jgz

het Centrum voor Jeugd en Gezin (CJG)

Het jgz

Het Centrum voor Jeugd en Gezin (CJG)

To override any of the substitutions use the optional substitutions argument to replace_jgz i.e.:

replace_jgz(article_text, substitutions={
    'jgz': 'centrum voor Jeugd en Gezin'
})

Replace image placeholders

To replace image placeholders use replace_images with a replacement callback.

The replacement callback is called with the image_id for each placeholder in the article text.

If the replacement callback returns anything other than None the placeholder is replaced with the return value.

For example:

image_id_to_src = {
    '1': '/media/1.gif',
    '2': '/media/2.gif'
}

def get_image_tag(image_id):
    src = image_id_to_src.get(image_id, None)
    if src:
        return '<img src="{}">'.format(src)

Replace video placeholders

To replace YouTube video placeholders use replace_videos with a replacement callback.

The replacement callback is called with the video_id, embed_url and external_url for each placeholder in the article text.

If the replacement callback returns anything other than None the placeholder is replaced with the return value.

Some examples:

def get_video_embed(video_id, embed_url, external_url):
    """Create an iframe to embed the video"""
    return '<iframe src="{}">'.format(embed_url)


def get_video_link(video_id, embed_url, external_url):
    """Create a link to the video player on opvoeden.nl"""
    return '<a href="{}" target="_blank">Watch the video</a>'.format(
        external_url)

Changes

v2.1.0

  • Expose article tags

v2.0.1

  • Fix YouTube url regex

v2.0.0

  • Use API version 2

v1.0.0

  • Initial release

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

opvoeden-api-client-2.1.0.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

opvoeden_api_client-2.1.0-py2.py3-none-any.whl (10.7 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file opvoeden-api-client-2.1.0.tar.gz.

File metadata

File hashes

Hashes for opvoeden-api-client-2.1.0.tar.gz
Algorithm Hash digest
SHA256 e3e2784b3d4bb94ee023d0628a697d30617bc4bc5100c4fc299d3547eba4a7ed
MD5 82248e5d19548ddaaf2d922f2595bd16
BLAKE2b-256 73ad8cbeb9ae00864c4b661d93b963d2a6944c8bbaa459e584cdca4005fb66e5

See more details on using hashes here.

File details

Details for the file opvoeden_api_client-2.1.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for opvoeden_api_client-2.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 d7d5701b173affe1508ae783bf155c780e60efaa33e629334a0099d08e965066
MD5 dfe7fbfe7c070c183fb789ccda9dee7c
BLAKE2b-256 900d18bfd59c1417e9691b797c9127d1f2251cef577eec576f27de3cca5cb558

See more details on using hashes here.

Supported by

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