By Nathan Donaldson
Tags: Other
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.
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
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
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
Our web application development work for DigitalNZ