Using steve - richardapi

This module holds a series of functions that use the richard API to move data back and forth.

steve.richardapi

New in version 0.2.

Note

Carl, Ryan: These functions are for you!

They use an auth token. If you need an auth token, let one of the pyvideo admin know.

steve.richardapi.get_all_categories(api_url)

Given an api_url, retrieves all categories

Parameters:api_url – URL for the api.
Returns:list of dicts each belonging to a category
Raises:steve.restapi.Http5xxException – if there’s a server error

Example:

from steve.util import get_all_categories

cats = get_all_categories('http://pyvideo.org/api/v1/')
print [cat['title'] for cat in cats]

# Prints something like:
# [u'PyCon 2012', u'PyCon 2011', etc.]
steve.richardapi.get_category(api_url, title)

Gets information for specified category

Parameters:
  • api_url – URL for the api
  • title – title of category to retrieve
Returns:

category data

Raises:

steve.richardapi.DoesNotExist – if the category doesn’t exist

steve.richardapi.get_video(api_url, auth_token, video_id)

Gets information for specified video

Parameters:
  • api_url – URL for the api
  • auth_token – auth token
  • video_id – The id for the video
Returns:

video data

Raises:

steve.richardapi.DoesNotExist – if the video doesn’t exist

steve.richardapi.create_video(api_url, auth_token, video_data)

Creates a video on the site

This creates a video on the site using HTTP POST. It returns the video data it posted which also contains the id.

Note

This doesn’t yet check to see if the video already exists.

Parameters:
  • api_url – URL for the api
  • auth_token – auth token
  • video_data – Python dict holding the values to create this video
Returns:

the video data

Raises:
  • steve.restapi.Http5xxException – if there’s a server error
  • steve.richardapi.MissingRequiredData – if the video_data is missing keys that are required

Example:

import datetime

from steve.util import STATE_LIVE, create_video, MissingRequiredData

try:
    video = create_video(
        'http://pyvideo.org/api/v1/',
        auth_token='ou812authkey',
        video_data={
            'category': 'Test Category',
            'state': STATE_LIVE,
            'title': 'Test video title',
            'speakers': ['Jimmy Discotheque'],
            'language': 'English',
            'added': datetime.datetime.now().isoformat()
        })

    # Prints the video data.
    print video

except MissingRequiredData as exc:
    # Prints the errors
    print exc

Note

Check the richard project in the video app at models.py for up-to-date list of fields and their types.

https://github.com/pyvideo/richard/blob/master/richard/videos/models.py

steve.richardapi.update_video(api_url, auth_token, video_id, video_data)

Updates an existing video on the site

This updates an existing video on the site using HTTP PUT. It returns the final video data.

Warning

This stomps on the data that’s currently there. If you have the video_id wrong, then this will overwrite the current data.

Be very careful about updating existing video data. Best to get it, make sure the id is correct (check the title? the slug?), and then update it.

Parameters:
  • api_url – URL for the api
  • auth_token – auth token
  • video_id – The id for the video
  • video_data – Python dict holding all the data for this video
Returns:

the updated video data

Raises:

Example:

import datetime

from steve.util import STATE_LIVE, update_video, MissingRequiredData

try:
    video = update_video(
        'http://pyvideo.org/api/v1/',
        auth_token='ou812authkey',
        video_id=1101,
        video_data={
            'id': 1101,
            'category': 'Test Category',
            'state': STATE_LIVE,
            'title': 'Test video title',
            'speakers': ['Jimmy Discotheque'],
            'language': 'English',
            'added': datetime.datetime.now().isoformat()
        })

    # Prints the video data.
    print video

except MissingRequiredData as exc:
    # Prints the errors
    print exc

Note

Check the richard project in the video app at models.py for up-to-date list of fields and their types.

https://github.com/pyvideo/richard/blob/master/richard/videos/models.py