iTunes U via Ruby
I’ve been involved with Apple’s iTunes U project since it’s inception. My former employer was one of the initial schools to use iTunes U. We began recording all of our classes lecture material in 2005 as a kind of digital note taking service and the project is still going strong in 2008 (with something like 3000 lectures recorded to date).
The project was a smashing success for us and has since led to iTunes U adoption Unviersity-wide.
Apple released a XML-based webservices API to iTunes U about a year and a half ago. It’s not fantastic1, but it does open up access to iTunes U in new an interesting ways. Unfortunately Apple only provides sample scripts for authenticating to their service, not actually using it for other tasks (like finding or updating material). Double disaster: these scripts are only offered in C, Java, Perl, Python, and Shell, leaving Ruby developers out in the cold.
That’s an odd move, considering Ruby is a first-class citizen in the OS X/Cocoa world, Apple’s Podcast Producer software is written in Ruby, and it seems like every Ruby developer in the world is sporting a Macbook these days.
I’m working (semi-secretly) with a company on a new education-targeted product based in Rails. I can’t talk much about the focus but I can say that products like Blackboard and Sakai are emphatically not the competition. We wanted iTunes U integration to be part of an extended set of plugins available to augment the core product.
We’ve extracted the juicy bits into a new gem called RTunesU. You can snag it via ruby gems
gem install rtunesu
or check out the source from the github repo
git clone git://github.com/trek/rtunesu.git
RTunesU fully wraps Apple’s XML web services inside happy little objects. It’s comparable to the third-party Java library for iTunes U. Those interested in the power of metaprogramming should check out the relative sizes of each library. I think all of RTunesU is smaller than the Course class in Java.
To use it you’ll need access to your institution’s site name, administrator credentials, and shared secret (all provided by Apple at signup time).
Below are some example uses:
Establishing a connection
require 'rtunesu'
include RTunesU
user = RTunesU::User.new(0, 'admin', 'Admin', 'admin@example.com')
u.credentials = ['Administrator@urn:mace:example.edu']
connection = RTunesU::Connection.new(:user => u,
:site => 'example.edu',
:shared_secret => 'STRINGOFTHIRTYTWOLETTERSORDIGITS')
Once you have a connection you can use it to find any Entity in iTunes U if you know it’s type (e.g. ‘Course’, ‘Group’) and its Handle attribute.
course = Course.find(12345678, connection)
#=> <RTunesU::Course:0x355854 Handle=12345678 Name='Learning in iTunes'>
This Entity will have access to all of its attributes and sub-entities and parent entities. You can access attributes and sub-entities with its name as a method. You can access an objets parent entity with the .parent method.
Accessing attributes:
course.Handle
#=> 12345678
course.Name
#=> "Learning in iTunes"
course.Instructor
#=> "James E. Professor"
Accessing sub-entities
course.Groups
#=> [<RTunesU::Group:0x355854>, <RTunesU::Course:0x192044>]
course.Groups.first
#=> <RTunesU::Group:0x355854 Handle=9876543 Name='Lectures'>
course.Groups.first.Name
#=> "Lectures"
Accessing an Entity’s parent
course.parent
#=> <RTunesU::Section:0x9875854>
course.parent.name
#=> "Learning Technologies"
Enjoy!
1. I spoke at WWDC with some folks about this. I won’t name names, but the decision to not follow practices like REST was apparently due to the difficulty of getting WebObjects to live in the present. The current style of interaction being used in iTunes U WS was the easiest to implement on top of the existing code base.

No comments yet
Jump to comment form | comments rss [?] | trackback uri [?]