Sha256: aafbb9188fe3f453a6f6524b57c27e7ef956f524a843a3b1f7fd537decce5290

Contents?: true

Size: 1.31 KB

Versions: 6

Compression:

Stored size: 1.31 KB

Contents

# encoding: utf-8
require 'oai'
require 'libis/tools/extend/hash'

module Libis
  module Services
    module Rosetta
      class OaiPmh
        include OAI::XPath

        def initialize(base_url = 'http://depot.lias.be', options = {})
          @oai_client = OAI::Client.new(base_url + '/oaiprovider/request', options)
        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
        end

      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
libis-services-0.1.5 lib/libis/services/rosetta/oai_pmh.rb
libis-services-0.1.3 lib/libis/services/rosetta/oai_pmh.rb
libis-services-0.1.2 lib/libis/services/rosetta/oai_pmh.rb
libis-services-0.1.1 lib/libis/services/rosetta/oai_pmh.rb
libis-services-0.1.0-java lib/libis/services/rosetta/oai_pmh.rb
libis-services-0.0.3 lib/libis/services/rosetta/oai_pmh.rb