midna

Ruby interface to the Midna API. See the [Rdoc]rdoc.info/projects/tilsammans/midna on how to use it.

This gem chats with the Midna API so you don’t have to. It will give you objects in the Midna namespace, which you can query like Active Record:

# Information about a Broadcaster, such as AVRO
Midna::Broadcaster.find('avro')
# All series for the given Broadcaster
Midna::Broadcaster.series('avro')

# all channels
Midna::Channel.all
# alphanumeric; like NL1
Midna::Channel.find(code)

# series ID from the omroep player
Midna::Series.find(id)
# searches the Solr index by series name
Midna::Series.search(query)

# aflevering/episode ID from the omroep player
Midna::Episode.find(id)
# all episodes for the given Series
Midna::Episode.series(id)
# all episodes for the given Series in the given time window
# start and end are integers (unixtimes)
Midna::Episode.series_window(id, start, end)
# all episodes for the given Series until the given time
# start is an integer (unixtime) and defaults to the current time
Midna::Episode.series_until(id, start)
Midna::Episode.series_until(id, start, :page => 2)
# all episodes for the given Series since the given time
# start is an integer (unixtime) and defaults to the current time
Midna::Episode.series_since(id, start)
Midna::Episode.series_since(id, start, :page => 2)

# code is Channel code
Midna::Broadcast.channel(code)
# all broadcasts for the given Channel in the given time window
# start and end are integers (unixtimes)
Midna::Broadcast.channel_window(id, start, end)

All of these methods will return hashes or arrays of hashes.

Also, Midna is Zelda’s goth sister.

Installation in Rails

Install this plugin as a gem.

For Rails 2, in config/environment.rb

  config.gem 'midna'

For Rails 3, in Gemfile

  gem 'midna'

Then run rake gems:install.

Usage in plain Ruby

First install the gem on your machine like usual:

$ gem install midna

Use sudo if your setup requires it. After this you can require it in your code and work with Midna from there.

require 'rubygems'
require 'midna'

puts Midna::Channel.all
# => [{"name"=>"Nederland 1", "code"=>"NL1"}, {"name"=>"Nederland 2", "code"=>"NL2"}, {"name"=>"Nederland 3 & Z@pp", "code"=>"NL3"}]

Configuration

If you are using rails, create a file called config/initializers/midna.rb with the following configuration. If you are using the gem, execute these lines before you first call any Midna objects.

The gem connects to midna.omroep.nl by default. You can override this by setting the base_uri:

Midna.base_uri = 'http://some.other.host'

Prerequisites

The HTTparty gem.

gem install httparty

Copyright © 2010 Joost Baaij. See LICENSE for details.