Class: Fieldhand::Repository

Inherits:
Object
  • Object
show all
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 = Logger.null) ⇒ Repository

Return a new repository with the given base URL and an optional logger.

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

Defaults to using a null logger specific to this platform.



24
25
26
27
# File 'lib/fieldhand/repository.rb', line 24

def initialize(uri, logger = Logger.null)
  @uri = uri.is_a?(::URI) ? uri : URI(uri)
  @logger = logger
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



17
18
19
# File 'lib/fieldhand/repository.rb', line 17

def logger
  @logger
end

#uriObject (readonly)

Returns the value of attribute uri.



17
18
19
# File 'lib/fieldhand/repository.rb', line 17

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



118
119
120
121
122
123
124
125
# File 'lib/fieldhand/repository.rb', line 118

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



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

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



35
36
37
# File 'lib/fieldhand/repository.rb', line 35

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



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

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



89
90
91
92
93
# File 'lib/fieldhand/repository.rb', line 89

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



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

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