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

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)

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.0.1.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

opvoeden_api_client-2.0.1-py2.py3-none-any.whl (10.5 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

File hashes

Hashes for opvoeden-api-client-2.0.1.tar.gz
Algorithm Hash digest
SHA256 9a5d1a4f20afbf5813b9538fde8e3fd547d7edf1d4b1d0ac7472ee2c18cbafb9
MD5 6d97a089983c7735c5d61a1fdedfc856
BLAKE2b-256 cdea31ab78c21e6b1e3d8d1174fa4dc8d250596eb549871924dbfd1d8695a4a0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opvoeden_api_client-2.0.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 4f94e472314af5a302ed68fa532e975ba3effb964aa2442bb95b1709a13a79da
MD5 062b57269c2e02b4aaabfe01381631e2
BLAKE2b-256 e4e12a0750fded000b86f8b7f38b508de5810dfd4e8c0193f1a94241ef7c31dd

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