#!/usr/bin/env ruby # Note: This assumes we're running from the root of the resync project $LOAD_PATH << File.dirname(__FILE__) require 'lib/resync' # ------------------------------------------------------------ # Reading a capability list puts "\n------------------------------------------------------------" puts "A capability list:\n" capabilitylist_xml = ' http://example.com/dataset1/resourcelist.xml http://example.com/dataset1/resourcedump.xml http://example.com/dataset1/changelist.xml http://example.com/dataset1/changedump.xml ' capability_list = Resync::XMLParser.parse(capabilitylist_xml) puts ' Links:' capability_list.links.each do |l| puts " #{l.rel}: #{l.uri}" end puts ' Resources:' capability_list.resources.each do |r| puts " #{r.uri} (#{r.capability})" end # ------------------------------------------------------------ # Creating a changelist puts "\n------------------------------------------------------------" puts "A change list:\n\n" change_list = Resync::ChangeList.new( links: [ Resync::Link.new( rel: 'up', uri: 'http://example.com/dataset1/capabilitylist.xml' ) ], metadata: Resync::Metadata.new( capability: 'changelist', from_time: Time.utc(2013, 1, 3) ), resources: [ Resync::Resource.new( uri: 'http://example.com/res4', modified_time: Time.utc(2013, 1, 3, 17), metadata: Resync::Metadata.new( change: Resync::Types::Change::UPDATED, hashes: { 'sha-256' => 'f4OxZX_x_DFGFDgghgdfb6rtSx-iosjf6735432nklj' }, length: 56_778, mime_type: 'application/json' ), links: [ Resync::Link.new( rel: 'http://www.openarchives.org/rs/terms/patch', uri: 'http://example.com/res4-json-patch', modified_time: Time.utc(2013, 1, 3, 17), hashes: { 'sha-256' => 'f4OxZX_x_DFGFDgghgdfb6rtSx-iosjf6735432nklj' }, length: 73, mime_type: 'application/json-patch' ) ] ), Resync::Resource.new( uri: 'http://example.com/res5-full.tiff', modified_time: Time.utc(2013, 1, 3, 18), metadata: Resync::Metadata.new( change: Resync::Types::Change::DELETED ) ) ] ) xml = change_list.save_to_xml formatter = REXML::Formatters::Pretty.new formatter.write(xml, $stdout) puts