lib/libis/services/rosetta/oai_pmh.rb in libis-services-0.1.5 vs lib/libis/services/rosetta/oai_pmh.rb in libis-services-0.1.7
- old
+ new
@@ -1,46 +1,18 @@
-# encoding: utf-8
-require 'oai'
-require 'libis/tools/extend/hash'
+require 'libis/services/oai'
module Libis
module Services
module Rosetta
- class OaiPmh
- include OAI::XPath
+ class OaiPmh < Libis::Services::Oai
def initialize(base_url = 'http://depot.lias.be', options = {})
- @oai_client = OAI::Client.new(base_url + '/oaiprovider/request', options)
+ super('http://depot.lias.be')
end
- def sets
- response = @oai_client.list_sets
- response.map do |oai_set|
- {name: oai_set.name, spec: oai_set.spec, description: oai_set.description}.cleanup
- end
- end
-
- def collections(institute, status = {})
- result = records("#{institute}-collections", status)
- result.map do |record|
- record[:title] = xpath_first(record[:metadata], './/dc:title').text
- end
- end
-
- def records(spec, status = {})
- options = { set: spec }
- options[:resumption_token] = status[:token] if status[:token]
- result = []
- response = @oai_client.list_records(options)
- response.each do |record|
- next if record.deleted?
- result << {
- id: record.header.identifier,
- date: record.header.datestamp,
- metadata: record.metadata,
- }
- end
- result
+ def collections(institute, token = nil, query = Query.new)
+ query.set = "#{institute}-collections"
+ records(token, query)
end
end
end
end