Class: Fieldhand::Repository

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/fieldhand/repository.rb

Overview

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

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, logger_or_options = {}) ⇒ Repository

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.



37
38
39
40
# 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

Instance Attribute Details

#logger_or_optionsObject (readonly)

Returns the value of attribute logger_or_options.



20
21
22
# File 'lib/fieldhand/repository.rb', line 20

def logger_or_options
  @logger_or_options
end

#uriObject (readonly)

Returns the value of attribute uri.



20
21
22
# File 'lib/fieldhand/repository.rb', line 20

def uri
  @uri
end

Instance Method Details

#get(identifier, arguments = {}) ⇒ Object

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



131
132
133
134
135
136
137
138
# 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 = {}) ⇒ Object

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



116
117
118
119
120
# File 'lib/fieldhand/repository.rb', line 116

def identifiers(arguments = {})
  query = Arguments.new(arguments).to_query

  paginator.items('ListIdentifiers', ListIdentifiersParser, query)
end

#identifyObject

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



48
49
50
# File 'lib/fieldhand/repository.rb', line 48

def identify
  paginator.items('Identify', IdentifyParser).first
end

#metadata_formats(identifier = nil) ⇒ Object

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



59
60
61
62
63
64
# File 'lib/fieldhand/repository.rb', line 59

def (identifier = nil)
  query = {}
  query['identifier'] = identifier if identifier

  paginator.items('ListMetadataFormats', ListMetadataFormatsParser, query)
end

#records(arguments = {}) ⇒ Object

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.

end “‘

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



102
103
104
105
106
# File 'lib/fieldhand/repository.rb', line 102

def records(arguments = {})
  query = Arguments.new(arguments).to_query

  paginator.items('ListRecords', ListRecordsParser, query)
end

#setsObject

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



72
73
74
# File 'lib/fieldhand/repository.rb', line 72

def sets
  paginator.items('ListSets', ListSetsParser)
end