Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OAI Provider helper methods should be able to provide value and attributes #47

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/oai/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
6 changes: 4 additions & 2 deletions lib/oai/client/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions lib/oai/harvester/logging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/oai/provider/metadata_format.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions lib/oai/xpath.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down