This project has been archived by its maintainers, and is no longer receiving any updates.
Stichting Opvoeden API client
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 |
|
contentset(contentset_id) |
|
article(external_reference) |
|
image(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 internal link placeholders
To replace internal link placeholders use replace_links with a replacement callback.
The replacement callback is called with the external_id and link_text for each placeholder in the article text.
If the replacement callback returns anything other than None the link is replaced with the return value.
For example:
external_id_to_href = {
'1': '/example/',
'2': '/example/more/'
}
def get_link(external_id, link_text):
"""
Get the url for an article and return an HTML snippet
that links to this url with the given text.
"""
href = external_id_to_href.get(external_id, None)
if href:
return '<a href="{}">{}</a>'.format(href, link_text)
replace_links(article_text, get_link)
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
Metadata
Release files for opvoeden-api-client 2.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| opvoeden-api-client-2.1.0.tar.gz | 11.9 kB | Without provenance | Details for opvoeden-api-client-2.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| opvoeden_api_client-2.1.0-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for opvoeden_api_client-2.1.0-py2.py3-none-any.whl |
Total release size: 22.6 kB
Release files / opvoeden-api-client-2.1.0.tar.gz
| Download URL | opvoeden-api-client-2.1.0.tar.gz |
|---|---|
| Size | 11.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e3e2784b3d4bb94ee023d0628a697d30617bc4bc5100c4fc299d3547eba4a7ed
|
|
BLAKE2b-256 checksum How to use checksums |
73ad8cbeb9ae00864c4b661d93b963d2a6944c8bbaa459e584cdca4005fb66e5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / opvoeden_api_client-2.1.0-py2.py3-none-any.whl
| Download URL | opvoeden_api_client-2.1.0-py2.py3-none-any.whl |
|---|---|
| Size | 10.7 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
d7d5701b173affe1508ae783bf155c780e60efaa33e629334a0099d08e965066
|
|
BLAKE2b-256 checksum How to use checksums |
900d18bfd59c1417e9691b797c9127d1f2251cef577eec576f27de3cca5cb558
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for opvoeden-api-client 2.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.