#!/usr/bin/ruby -w
#
# $Id: browse_node_lookup1,v 1.1 2008/03/24 16:08:37 ianmacd Exp $

require 'amazon/aws'
require 'amazon/aws/search'

include Amazon::AWS
include Amazon::AWS::Search

# This is the node for Social Sciences.
#
START_NODE = '11232'

def follow_node(node)

  req ||= Request.new
  req.locale = 'us'

  bnl = BrowseNodeLookup.new( node, {} )
  bnl_rg ||= ResponseGroup.new( 'BrowseNodeInfo' )
  resp = req.search( bnl, bnl_rg )

  items = resp.browse_node_sets.browse_nodes

  items.each do |item|

    if item.children
      puts '%s (%s) has the following children:' % [ item.name, node ]

      item.children.each do |child|
        puts '  %s' % [ child.name ]
      end
      puts

      item.children.each do |child|
        follow_node( child.browse_node_id )
      end

    else
      puts '%s (%s) has no children.' % [ item.name, node ]
    end
  end
end

follow_node( START_NODE )
