Class: OAI::Provider::Base

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

Constant Summary collapse

PROVIDER_CONTEXTS =
{
  :class_based => :class_based,
  :instance_based => :instance_based
}

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Base

Returns a new instance of Base.



329
330
331
332
# File 'lib/oai/provider.rb', line 329

def initialize(options = {})
  provider_context = options.fetch(:provider_context) { :class_based }
  @provider_context = PROVIDER_CONTEXTS.fetch(provider_context)
end

Class Attribute Details

.delete_supportObject

Returns the value of attribute delete_support.



274
275
276
# File 'lib/oai/provider.rb', line 274

def delete_support
  @delete_support
end

.descriptionObject

Returns the value of attribute description.



274
275
276
# File 'lib/oai/provider.rb', line 274

def description
  @description
end

.emailObject

Returns the value of attribute email.



274
275
276
# File 'lib/oai/provider.rb', line 274

def email
  @email
end

.formatsObject (readonly)

Returns the value of attribute formats.



273
274
275
# File 'lib/oai/provider.rb', line 273

def formats
  @formats
end

.granularityObject

Returns the value of attribute granularity.



274
275
276
# File 'lib/oai/provider.rb', line 274

def granularity
  @granularity
end

.identifierObject

Returns the value of attribute identifier.



274
275
276
# File 'lib/oai/provider.rb', line 274

def identifier
  @identifier
end

.modelObject

Returns the value of attribute model.



274
275
276
# File 'lib/oai/provider.rb', line 274

def model
  @model
end

.nameObject

Returns the value of attribute name.



274
275
276
# File 'lib/oai/provider.rb', line 274

def name
  @name
end

.prefixObject

Returns the value of attribute prefix.



274
275
276
# File 'lib/oai/provider.rb', line 274

def prefix
  @prefix
end

.urlObject

Returns the value of attribute url.



274
275
276
# File 'lib/oai/provider.rb', line 274

def url
  @url
end

Instance Attribute Details

#delete_supportObject



397
398
399
# File 'lib/oai/provider.rb', line 397

def delete_support
  @delete_support || self.class.delete_support
end

#descriptionObject



413
414
415
# File 'lib/oai/provider.rb', line 413

def description
  @description || self.class.description
end

#emailObject



393
394
395
# File 'lib/oai/provider.rb', line 393

def email
  @email || self.class.email
end

#granularityObject



401
402
403
# File 'lib/oai/provider.rb', line 401

def granularity
  @granularity || self.class.granularity
end

#identifierObject



409
410
411
# File 'lib/oai/provider.rb', line 409

def identifier
  @identifier || self.class.identifier
end

#modelObject



405
406
407
# File 'lib/oai/provider.rb', line 405

def model
  @model || self.class.model
end

#nameObject



381
382
383
# File 'lib/oai/provider.rb', line 381

def name
  @name || self.class.name
end

#prefixObject



389
390
391
# File 'lib/oai/provider.rb', line 389

def prefix
  @prefix || self.class.prefix
end

#urlObject



385
386
387
# File 'lib/oai/provider.rb', line 385

def url
  @url || self.class.url
end

Class Method Details

.format(prefix) ⇒ Object



285
286
287
288
289
290
291
# File 'lib/oai/provider.rb', line 285

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

.format_supported?(prefix) ⇒ Boolean

Returns:

  • (Boolean)


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

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

.register_format(format) ⇒ Object



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

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

Instance Method Details

#format(*args) ⇒ Object



373
374
375
# File 'lib/oai/provider.rb', line 373

def format(*args)
  self.class.format(*args)
end

#format_supported?(*args) ⇒ Boolean

Returns:

  • (Boolean)


369
370
371
# File 'lib/oai/provider.rb', line 369

def format_supported?(*args)
  self.class.format_supported?(*args)
end

#formatsObject



377
378
379
# File 'lib/oai/provider.rb', line 377

def formats
  self.class.formats
end

#get_record(options = {}) ⇒ Object

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



448
449
450
# File 'lib/oai/provider.rb', line 448

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

#identify(options = {}) ⇒ Object

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



418
419
420
# File 'lib/oai/provider.rb', line 418

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

#list_identifiers(options = {}) ⇒ Object

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



436
437
438
# File 'lib/oai/provider.rb', line 436

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

#list_metadata_formats(options = {}) ⇒ Object

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



430
431
432
# File 'lib/oai/provider.rb', line 430

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

#list_records(options = {}) ⇒ Object

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



442
443
444
# File 'lib/oai/provider.rb', line 442

def list_records(options = {})
  Response::ListRecords.new(provider_context, 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.



424
425
426
# File 'lib/oai/provider.rb', line 424

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

#methodize(verb) ⇒ Object

Convert valid OAI-PMH verbs into ruby method calls



481
482
483
# File 'lib/oai/provider.rb', line 481

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.



457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
# File 'lib/oai/provider.rb', line 457

def process_request(params = {})
  begin

    # Allow the request to pass in a url
    provider_context.url = params['url'] ? params.delete('url') : self.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

#provider_contextObject

The traditional interaction of a Provider has been to:

1) Assign attributes to the Provider class 2) Instantiate the Provider class 3) Call response instance methods for theProvider which pass

the Provider class and not the instance.

The above behavior continues unless you initialize the Provider with { :provider_context => :instance_based }. If you do that, then the Provider behavior will be:

1) Assign attributes to Provider class 2) Instantiate the Provider class 3) Call response instance methods for theProvider which pass an

instance of the Provider to those response objects.
a) The instance will mirror all of the assigned Provider class
   attributes, but allows for overriding and extending on a
   case by case basis.

(Dear reader, please note the second behavior is something most of us would’ve assumed to be the case, but for historic now lost reasons is not the case.)



361
362
363
364
365
366
367
# File 'lib/oai/provider.rb', line 361

def provider_context
  if @provider_context == :instance_based
    self
  else
    self.class
  end
end