From 606fecd730676b833caaf767ee7103ecdd73ce90 Mon Sep 17 00:00:00 2001 From: Coren Date: Wed, 1 Jul 2015 11:41:07 +0200 Subject: [PATCH 1/4] OAI Provider helper methods should be able to provide value and attributes. For instance: def relation [ 'value without atribute', [ 'french value', { 'xml:lang' => 'fre' } ] ] end gives value without atributefrench value --- lib/oai/provider/metadata_format.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/oai/provider/metadata_format.rb b/lib/oai/provider/metadata_format.rb index fcf6bad..6fd82d2 100755 --- a/lib/oai/provider/metadata_format.rb +++ b/lib/oai/provider/metadata_format.rb @@ -34,7 +34,7 @@ def encode(model, record) values = value_for(field, record, map) if values.respond_to?(:each) values.each do |value| - xml.tag! "#{element_namespace}:#{field}", value + xml.tag! "#{element_namespace}:#{field}", *value end else xml.tag! "#{element_namespace}:#{field}", values From a2170308527e16e972f4966dd457406d91c94c64 Mon Sep 17 00:00:00 2001 From: Coren Date: Tue, 29 Sep 2015 12:12:59 +0200 Subject: [PATCH 2/4] Fix rdoc parsing problem --- lib/oai/harvester/logging.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/oai/harvester/logging.rb b/lib/oai/harvester/logging.rb index 9df8c4b..fd13771 100755 --- a/lib/oai/harvester/logging.rb +++ b/lib/oai/harvester/logging.rb @@ -24,8 +24,7 @@ def start(sites = nil, interactive = false) @logger.info { "Starting regular harvest" } orig_start(sites) begin - OAI::Harvester:: - Mailer.send(@config.mail_server, @config.email, @summary) + OAI::Harvester::Mailer.send(@config.mail_server, @config.email, @summary) rescue @logger.error { "Error sending out summary email: #{$!}"} end From 79c5c68aa25f20e83c3a1d684deaa1aa97a6c36c Mon Sep 17 00:00:00 2001 From: Coren Date: Tue, 29 Sep 2015 12:54:57 +0200 Subject: [PATCH 3/4] Add completeListSize response metadata --- lib/oai/client/response.rb | 6 ++++-- lib/oai/xpath.rb | 12 ++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/oai/client/response.rb b/lib/oai/client/response.rb index 75c5580..83343ea 100644 --- a/lib/oai/client/response.rb +++ b/lib/oai/client/response.rb @@ -18,11 +18,13 @@ module OAI # ``` class Response include OAI::XPath - attr_reader :doc, :resumption_token, :resumption_block + attr_reader :doc, :resumption_token, :resumption_block, :complete_list_size def initialize(doc, &resumption_block) @doc = doc - @resumption_token = xpath(doc, './/resumptionToken') + rt_node = xpath_first(doc, './/resumptionToken') + @resumption_token = get_text(rt_node) + @complete_list_size = get_attribute(rt_node, 'completeListSize') @resumption_block = resumption_block # throw an exception if there was an error diff --git a/lib/oai/xpath.rb b/lib/oai/xpath.rb index 85c70da..0bd9df5 100644 --- a/lib/oai/xpath.rb +++ b/lib/oai/xpath.rb @@ -22,12 +22,16 @@ def xpath_first(doc, path) # get text for first matching node def xpath(doc, path) el = xpath_first(doc, path) - return unless el - case parser_type(doc) + get_text el + end + + def get_text(node) + return unless node + case parser_type(node) when 'libxml' - return el.content + return node.content when 'rexml' - return el.text + return node.text end return nil end From f4f4a6979cf358bf7eee3f051d01e5fde66cf2ed Mon Sep 17 00:00:00 2001 From: Coren Date: Tue, 29 Sep 2015 12:56:28 +0200 Subject: [PATCH 4/4] Add uri called to debug output, and try to keep Session Cookie if one is provided --- lib/oai/client.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/oai/client.rb b/lib/oai/client.rb index 90982b4..6e7627a 100644 --- a/lib/oai/client.rb +++ b/lib/oai/client.rb @@ -202,12 +202,13 @@ def list_sets(opts={}) def do_request(verb, opts = nil) # fire off the request and return appropriate DOM object uri = build_uri(verb, opts) + debug(uri) xml = strip_invalid_utf_8_chars(get(uri)) if @parser == 'libxml' # remove default namespace for oai-pmh since libxml # isn't able to use our xpaths to get at them # if you know a way around thins please let me know - xml = xml.gsub( + xml.gsub!( /xmlns=\"http:\/\/www.openarchives.org\/OAI\/.\..\/\"/, '') end return load_document(xml) @@ -263,7 +264,8 @@ def get(uri) req.url uri req.headers.merge! @headers end - + # Keep cookie session. Needed for old & buggy OAI-PMH provider + @headers['Cookie'] ||= response['set-cookie'] response.body end