Omeka Client

A REST client for Omeka, using the API introduced in Omeka 2.1.

Lincoln Mullen | [email protected] | http://lincolnmullen.com

Installation

Add this line to your application's Gemfile:

gem 'omeka_client'

And then execute:

bundle install

Or install it yourself:

gem install omeka_client

Usage

See the Omeka API documentation for information about what is possible with the Omeka's API.

First, load the gem in your script:

require "omeka_client"

Next, create a client to interact with your Omeka site. You'll need your endpoint and, optionally, an API key.

client = OmekaClient::Client.new("http://localhost/omeka/api", "api_key")
# => #<OmekaClient::Client:0x007f4307937aa0>

You can use the convenience methods for easy access to data. The most useful methods return classes that represent OmekaItems.

item = client.omeka_items(1)
item.id
# => 1
item.public
# => true
item.dublin_core.title
# => "Questions of the Soul"
item.dublin_core.author
# => "Hecker, Isaac Thomas, 1819-1888."
item.item_type
# => "book"
item..binding
# => "cloth"

item = client.omeka_items
# returns array of OmekaItem instances

There are some helper methods to get other results in other forms:

site_info = client.site
puts site_info['title']
# => Omeka RC Dev

items = client.items
puts items[0]['id']
# => 1
puts items[0]['url']
# => http://localhost/omeka/api/items/1

If you want more flexibility about what you're requesting, you can use the lower-level methods.

client.get('collections', 1)

client.get_hash('collections', 1)

If you just want a raw REST connection to Omeka, then you can access the underlying instance from the Rest gem.

client.connection

Testing and documentation

You can run the tests by running rake test. You'll need to have an Omeka site running at least 2.1-RC1 to use the tests.

You can generate the documentation by running rake yard.

Future plans

For now the gem only handles GET requests. I'm going to work on making methods that pull information out of Omeka as robust as possible before I deal with POST, PUT, and DELETE. In particular, the class representations of Omeka items are important. Contributions are more than welcome.

License

This gem is licensed under the GPLv3, the same as Omeka.

Thanks

This gem is based on Jim Safely's sample client for Python. And of course many thanks to all the amazing Omeka developers.