home

Boost Blog

DigitalNZ client library for ruby

Posted by jeremy on July 24th, 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
Tags: ruby

This entry was posted on Friday, July 24th, 2009 at 10:56 am and is filed under Ruby on Rails. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

2 Responses to “DigitalNZ client library for ruby”

  1. Henry Maddocks says:
    July 24, 2009 at 1:58 pm

    Nicely done. Don’t think I’ll bother with mine anymore.

  2. jeremy says:
    July 24, 2009 at 3:19 pm

    Thanks Henry; any improvements / patches would be welcome. I haven’t got metadata fetching in there yet.

Leave a Reply

Click here to cancel reply.

CommentLuv Enabledshow more

  • Categories

    • Agile (3)
    • Cool tools (5)
    • Curriculum (2)
    • Design (6)
    • Development (14)
    • Drupal (1)
    • e-Learning (6)
    • Publishing (1)
    • Random thoughts (2)
    • Ruby on Rails (8)
    • Social media (6)
    • Usabilty (2)
  • Archives

    • July 2010 (6)
    • June 2010 (2)
    • April 2010 (1)
    • March 2010 (1)
    • February 2010 (1)
    • January 2010 (3)
    • December 2009 (1)
    • November 2009 (1)
    • October 2009 (4)
    • September 2009 (2)
    • August 2009 (3)
    • July 2009 (6)
    • June 2009 (1)
    • May 2009 (1)
    • April 2009 (2)
    • March 2009 (1)
  • Boost Loves Design

    • I love Typography
    • IntuitionHQ | easy website usability
    • OMG It even has a watermark
    • Follow me on Twitter
    © Boost Limited.
    All rights reserved.
    CONTACT US
    info@boost.co.nz
    tel. (04) 939 0062
    fax. (04) 939 0063

    Level 6, 175 Victoria Street
    PO Box 11504, Wellington
    New Zealand