class Fieldhand::Repository

A repository is a network accessible server that can process the 6 OAI-PMH requests.

See www.openarchives.org/OAI/openarchivesprotocol.html

Attributes

logger_or_options[R]
uri[R]

Public Class Methods

new(uri, logger_or_options = {}) click to toggle source

Return a new repository with the given base URL and an optional logger, timeout, maximum number of retries, retry interval, bearer token and headers.

The base URL can be passed as a `URI` or anything that can be parsed as a URI such as a string.

For backward compatibility, the second argument can either be a logger or a hash containing a logger, timeout, maximum number of retries, retry interval, bearer token and headers.

Defaults to using a null logger specific to this platform, a timeout of 60 seconds, a maximum number of retries of 0, a retry interval of 10 seconds, no bearer token and no headers.

# File lib/fieldhand/repository.rb, line 37
def initialize(uri, logger_or_options = {})
  @uri = uri.is_a?(::URI) ? uri : URI(uri)
  @logger_or_options = logger_or_options
end

Public Instance Methods

get(identifier, arguments = {}) click to toggle source

Send a GetRecord request to the repository with the given identifier and optional metadata prefix and return a `Record`.

Supports passing a :metadata_prefix argument with a given metadata prefix which otherwise defaults to “oai_dc”.

Raises a `NetworkError` if there is an issue contacting the repository or a `ProtocolError` if received in response.

See www.openarchives.org/OAI/openarchivesprotocol.html#GetRecord

# File lib/fieldhand/repository.rb, line 131
def get(identifier, arguments = {})
  query = {
    'identifier' => identifier,
    'metadataPrefix' => arguments.fetch(:metadata_prefix, 'oai_dc')
  }

  paginator.items('GetRecord', GetRecordParser, query).first
end
identifiers(arguments = {}) click to toggle source

Send a ListIdentifiers request to the repository with optional arguments and return an `Enumerator` of `Header`s.

This supports the same arguments as `Fieldhand::Repository#records` but only returns record headers.

Raises a `NetworkError` if there is an issue contacting the repository or a `ProtocolError` if received in response.

See www.openarchives.org/OAI/openarchivesprotocol.html#ListIdentifiers

# File lib/fieldhand/repository.rb, line 116
def identifiers(arguments = {})
  query = Arguments.new(arguments).to_query

  paginator.items('ListIdentifiers', ListIdentifiersParser, query)
end
identify() click to toggle source

Send an Identify request to the repository and return an `Identify` response.

Raises a `NetworkError` if there is an issue contacting the repository or a `ProtocolError` if received in response.

See www.openarchives.org/OAI/openarchivesprotocol.html#Identify

# File lib/fieldhand/repository.rb, line 48
def identify
  paginator.items('Identify', IdentifyParser).first
end
metadata_formats(identifier = nil) click to toggle source

Send a ListMetadataFormats request to the repository (with an optional identifier) and return an `Enumerator` of `MetadataFormat`s.

Raises a `NetworkError` if there is an issue contacting the repository or a `ProtocolError` if received in response.

See www.openarchives.org/OAI/openarchivesprotocol.html#ListMetadataFormats

# File lib/fieldhand/repository.rb, line 59
def metadata_formats(identifier = nil)
  query = {}
  query['identifier'] = identifier if identifier

  paginator.items('ListMetadataFormats', ListMetadataFormatsParser, query)
end
records(arguments = {}) click to toggle source

Send a ListRecords request to the repository with optional arguments and return an `Enumerator` of `Records`s.

The following arguments can be used:

  • :metadata_prefix - The prefix of the metadata format to be used for record metadata, defaults to “oai_dc”

  • :from - A `Date`, `Time` or formatted string specifying a lower bound for datestamp-based selective harvesting

  • :until - A `Date`, `Time` or formatted string specifying an upper bound for datestamp-based selective harvesting

  • :set - A `Set` or string set spec which specifies set criteria for selective harvesting

  • :resumption_token - A valid resumption token for resuming a previous request (note that Fieldhand typically

    handles resumption internally so this should not be normally used)

Raises a `NetworkError` if there is an issue contacting the repository or a `ProtocolError` if received in response.

# Examples

“` repository = Fieldhand::Repository.new('www.example.com/oai') repository.records.each do |record|

next if record.deleted?

puts record.metadata

end “`

See www.openarchives.org/OAI/openarchivesprotocol.html#ListRecords

# File lib/fieldhand/repository.rb, line 102
def records(arguments = {})
  query = Arguments.new(arguments).to_query

  paginator.items('ListRecords', ListRecordsParser, query)
end
sets() click to toggle source

Send a ListSets request to the repository and return an `Enumerator` of `Set`s.

Raises a `NetworkError` if there is an issue contacting the repository or a `ProtocolError` if received in response.

See www.openarchives.org/OAI/openarchivesprotocol.html#ListSets

# File lib/fieldhand/repository.rb, line 72
def sets
  paginator.items('ListSets', ListSetsParser)
end

Private Instance Methods

paginator() click to toggle source
# File lib/fieldhand/repository.rb, line 142
def paginator
  @paginator ||= Paginator.new(uri, logger_or_options)
end