Web Services/API/Reference

Views

This reference manual describes how to utilize the mygpoclient API Client Library to interface with the gpodder.net web service. The client library provides a well-tested implementation that adheres to the.

To make sure that the library is working and all dependencies are installed, please install the dependencies listed in the DEPENDENCIES file. After that, you can easily run the unit tests that come with the library:

make test

This will run all unit tests and doctests in the library. After the tests have been completed, you should get a summary with the test and code coverage statistics. The output should look like the following example if everything works (please note that the statement count could be different as development of the library continues):

The SimpleClient class is the most basic way of interacting with the gpodder.net web service. You can use it to provide quick integration of an existing application or in cases where your client code has to be stateless. Please use the Advanced API client (which has a superset of SimpleClient's features) for more advanced use cases.

Make sure that the mygpoclient package is in your sys.path. You can set the PYTHONPATH environment variable to the Git checkout folder or add it to the sys.path list in Python. After that, you can import the simple module of the mygpoclient package:

The client provides access to user-specific data, so you need to have the username and password of the user you want to authenticate as ready. Also, as gpodder.net is open source, and can potentially run on hosts different from gpodder.net, you can optionally provide the hostname.

Let's suppose we want to authenticate as user john and the password secret to the default web service (that's gpodder.net). To create a client object, we would use the following code:

client = simple.SimpleClient('john', 'secret')

If you have the web service running on another host (for example on port 1337 on the local host or localhost), you can specify the host and port as third argument to the SimpleClient constructor (but you still need to provide username and password in this case):

You can download a list of podcast subscriptions with SimpleClient.get_subscriptions(device_id). The given device_id has to exist for the logged-in user. If the device does not exist, a mygpoclient.http.NotFound exception is raised.

To download the subscription list of the device legacy, use:

subscriptions = client.get_subscriptions('legacy')

The resulting list contains URLs of all the subscribed podcasts for this device:

As with the download function, you can also upload subscriptions. For this, you need to use the SimpleClient.put_subscriptions(device_id, urls) function. The function returns True if the upload operation was successful, or False otherwise. An example usage would be like this:

The existing list of subscriptions is always overwritten, and the user's subscription history will mark all podcasts that have been in the list before but have been removed from the uploaded subscription list as unsubscribed.

Now that we have discussed the basics, we can write a simple but feature-complete command-line application for downloading and uploading subscription lists (this code can also be found in the source tree as simple-client):

Given a device ID, you can update the list of subscriptions via the update_subscriptions() method. You need to pass a device_id and two lists (one for the URLs that have been added and one for the URLs that have been removed) to update the subscriptions on the server, for example:

You can use empty lists if you just add or remove items. As you can see in the code example, the function (if successful) returns a UpdateResult object. The UpdateResult object contains a "update_urls" attribute that is a list of (old_url, new_url) tuples in case the server has re-written URLs. According to the API documentation, the client application must update the old_url values with new_url values (these have been sanitized). The "since" attribute of the result object can be used for requesting changes since the last upload, like this:

updates = client.pull_subscriptions('abcdevice', result.since)

The "updates" return value here is a SubscriptionChanges object that contains a new "since" attribute (that can be used for subsequent requests) and two lists ("add" and "remove") of URLs that should be processed by the client by creating and removing subscriptions.

The api.MygPodderClient class provides two methods for dealing with devices: get_devices() (which returns a list of PodcastDevice objects) and update_device_settings() for modifying the device-specific settings on the server side. Here is an example script to use both functions to rename all users's device to "My Device" on the server: