Awasu » Using the Awasu API: Configuring Awasu
Sunday 5th July 2015 11:55 PM []

Now that we've managed to get information out of Awasu, let's take a look at how to make changes to it.

Creating channels

API entry points are provided for the most common use cases. For example, to subscribe to a feed, with the default channel settings, all you need to do is this:

api.create_channel_by_url( "http://awasu.com/news.xml" )

If you keep an eye on Awasu as you run this, you will see the new channel magically appear in the My Channels window and make its initial update :cool:

Creating a search channel is just as easy:

api.create_search_channel( "best feed reader" )

Plugin channels are a little more complicated, since many of them take parameters, but it's still quite straight-forward [1]This example creates an instance of one of the sample plugins provided in the Awasu installation. You may need to adjust the plugin path if you have Awasu installed in a different location. e.g.

api.create_plugin_channel(
    "c:/Program Files/Awasu/Samples/SamplePythonChannel2/SamplePythonChannel2.py" ,
    { # nb: these are our settings for the the plugin's parameters
        "HomeUrl": "http://foobar.com" , 
        "nItems": 5
    } 
)

Creating channels with non-default settings

The examples above all create channels using the default settings, but what if we want to configure the channel as we create it?

If you look at the documentation for the raw API call to create channels, you will see that it accepts POST data that contains the configuration settings for the new channel [2]The format of this data is the same as that returned by the $/channels/create call.

So, to create a channel using awasu_api, we can do something like this:

api.create_channel(
    """
         http://awasu.com/news.xml 
        
         This is my test channel 
         http://foobar.com 
    """
)

The new channel will be created in Awasu, and if you open up its Properties dialog, you will see it has the new name and home URL we specified in the API call.

Updating channels

Updating channels is almost identical to the process described above: prepare the channel config XML containing the settings we want to change, then send a POST request to Awasu. However, since the awasu_api module (currently) doesn't have an update_channel() entry point, we will have to do things a little differently.

The call_api() function is the workhorse of the AwasuApi class, and all the functions we have used so far are thin wrappers around it. It does all the hard work of preparing requests, sending them to Awasu, then parsing the results, and we can call it directly if there is no wrapper function defined for what we want to do.

So, to update a channel:

api.call_api(
    "channels/update" ,
    api_args = { "id": 29 } ,
    post_data = \
        """
             Updated channel name 
        """    
)

When we call call_api(), we need specify which Awasu API function we want to invoke [3]In this case, $/channels/update., any arguments the Awasu API requires [4]In this case, the channel ID. You can specify a list here, if you want to update multiple channels., and, of course, the POST data containing the new channel settings.

Try running this with the channel open in Awasu, and you will see its name update both in the My Channels window and the channel's browser window. Very cool :cool:

Download the source code here.



   [ + ]

1. This example creates an instance of one of the sample plugins provided in the Awasu installation. You may need to adjust the plugin path if you have Awasu installed in a different location.
2. The format of this data is the same as that returned by the $/channels/create call
3. In this case, $/channels/update.
4. In this case, the channel ID. You can specify a list here, if you want to update multiple channels.
Have your say