Class: OAI::Provider::Base

Inherits:
Object
  • Object
show all
Includes:
OAI::Provider
Defined in:
lib/oai/provider.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.delete_supportObject

Returns the value of attribute delete_support.



207
208
209
# File 'lib/oai/provider.rb', line 207

def delete_support
  @delete_support
end

.descriptionObject

Returns the value of attribute description.



207
208
209
# File 'lib/oai/provider.rb', line 207

def description
  @description
end

.emailObject

Returns the value of attribute email.



207
208
209
# File 'lib/oai/provider.rb', line 207

def email
  @email
end

.formatsObject (readonly)

Returns the value of attribute formats.



206
207
208
# File 'lib/oai/provider.rb', line 206

def formats
  @formats
end

.granularityObject

Returns the value of attribute granularity.



207
208
209
# File 'lib/oai/provider.rb', line 207

def granularity
  @granularity
end

.identifierObject

Returns the value of attribute identifier.



207
208
209
# File 'lib/oai/provider.rb', line 207

def identifier
  @identifier
end

.modelObject

Returns the value of attribute model.



207
208
209
# File 'lib/oai/provider.rb', line 207

def model
  @model
end

.nameObject

Returns the value of attribute name.



207
208
209
# File 'lib/oai/provider.rb', line 207

def name
  @name
end

.prefixObject

Returns the value of attribute prefix.



207
208
209
# File 'lib/oai/provider.rb', line 207

def prefix
  @prefix
end

.urlObject

Returns the value of attribute url.



207
208
209
# File 'lib/oai/provider.rb', line 207

def url
  @url
end

Class Method Details

.format(prefix) ⇒ Object



218
219
220
221
222
223
224
# File 'lib/oai/provider.rb', line 218

def format(prefix)
  if @formats[prefix].nil?
    raise OAI::FormatException.new
  else
    @formats[prefix]
  end
end

.format_supported?(prefix) ⇒ Boolean

Returns:

  • (Boolean)


214
215
216
# File 'lib/oai/provider.rb', line 214

def format_supported?(prefix)
  @formats.keys.include?(prefix)
end

.register_format(format) ⇒ Object



209
210
211
212
# File 'lib/oai/provider.rb', line 209

def register_format(format)
  @formats ||= {}
  @formats[format.prefix] = format
end

Instance Method Details

#get_record(options = {}) ⇒ Object

Equivalent to ‘&verb=GetRecord’, returns a record matching the required :identifier option



288
289
290
# File 'lib/oai/provider.rb', line 288

def get_record(options = {})
  Response::GetRecord.new(self.class, options).to_xml
end

#identify(options = {}) ⇒ Object

Equivalent to ‘&verb=Identify’, returns information about the repository



258
259
260
# File 'lib/oai/provider.rb', line 258

def identify(options = {})
  Response::Identify.new(self.class, options).to_xml
end

#list_identifiers(options = {}) ⇒ Object

Equivalent to ‘&verb=ListIdentifiers’, returns a list of record headers that meet the supplied criteria.



276
277
278
# File 'lib/oai/provider.rb', line 276

def list_identifiers(options = {})
  Response::ListIdentifiers.new(self.class, options).to_xml
end

#list_metadata_formats(options = {}) ⇒ Object

Equivalent to ‘&verb=ListMetadataFormats’, returns a list of metadata formats supported by the repository.



270
271
272
# File 'lib/oai/provider.rb', line 270

def (options = {})
  Response::ListMetadataFormats.new(self.class, options).to_xml
end

#list_records(options = {}) ⇒ Object

Equivalent to ‘&verb=ListRecords’, returns a list of records that meet the supplied criteria.



282
283
284
# File 'lib/oai/provider.rb', line 282

def list_records(options = {})
  Response::ListRecords.new(self.class, options).to_xml
end

#list_sets(options = {}) ⇒ Object

Equivalent to ‘&verb=ListSets’, returns a list of sets that are supported by the repository or an error if sets are not supported.



264
265
266
# File 'lib/oai/provider.rb', line 264

def list_sets(options = {})
  Response::ListSets.new(self.class, options).to_xml
end

#methodize(verb) ⇒ Object

Convert valid OAI-PMH verbs into ruby method calls



321
322
323
# File 'lib/oai/provider.rb', line 321

def methodize(verb)
  verb.gsub(/[A-Z]/) {|m| "_#{m.downcase}"}.sub(/^\_/,'')
end

#process_request(params = {}) ⇒ Object

xml_response = process_verb(‘ListRecords’, :from => ‘October 1, 2005’,

:until => 'November 1, 2005')

If you are implementing a web interface using process_request is the preferred way.



297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
# File 'lib/oai/provider.rb', line 297

def process_request(params = {})
  begin

    # Allow the request to pass in a url
    self.class.url = params['url'] ? params.delete('url') : self.class.url

    verb = params.delete('verb') || params.delete(:verb)

    unless verb and OAI::Const::VERBS.keys.include?(verb)
      raise OAI::VerbException.new
    end

    send(methodize(verb), params)

  rescue => err
    if err.respond_to?(:code)
      Response::Error.new(self.class, err).to_xml
    else
      raise err
    end
  end
end