DigitalNZ client library for ruby
By Nathan Donaldson in Other on July 24, 2009
We’ve just released a new client library for accessing the digitalnz.org’s search API. This library uses nokogiri for speedily parsing the XML, making it faster than an existing dnz client library using JSON parsing.
Installation
sudo gem install dnz-client
Or for the bleeding edge (if there is one):
sudo gem install boost-dnz-client
You’ll need to have an API key from digitalnz.org
Examples
Simple search
require 'dnz/client'
client = DNZ::Client.new('api_key')
search = client.search('otago')
search.results.each do |result|
puts result.title
end
Fetch all categories
require 'dnz/client'
client = DNZ::Client.new('api_key')
categories = client.categories
categories.each do |category|
puts "Category %s has %d results" % [category.name, category.count]
end
Fetch a facet
require 'dnz/client'
client = DNZ::Client.new('api_key')
search = client.search('otago', :facets => ['category'])
search.facets['category'].each do |category|
puts 'Search for otago has %d items in category %s' % [category.count, category.name]
end


