Class: OAI::Provider::Base
- Inherits:
-
Object
- Object
- OAI::Provider::Base
- 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
-
.delete_support ⇒ Object
Returns the value of attribute delete_support.
-
.description ⇒ Object
Returns the value of attribute description.
-
.email ⇒ Object
Returns the value of attribute email.
-
.formats ⇒ Object
readonly
Returns the value of attribute formats.
-
.granularity ⇒ Object
Returns the value of attribute granularity.
-
.identifier ⇒ Object
Returns the value of attribute identifier.
-
.model ⇒ Object
Returns the value of attribute model.
-
.name ⇒ Object
Returns the value of attribute name.
-
.prefix ⇒ Object
Returns the value of attribute prefix.
-
.url ⇒ Object
Returns the value of attribute url.
Instance Attribute Summary collapse
- #delete_support ⇒ Object
- #description ⇒ Object
- #email ⇒ Object
- #granularity ⇒ Object
- #identifier ⇒ Object
- #model ⇒ Object
- #name ⇒ Object
- #prefix ⇒ Object
- #url ⇒ Object
Class Method Summary collapse
Instance Method Summary collapse
- #format(*args) ⇒ Object
- #format_supported?(*args) ⇒ Boolean
- #formats ⇒ Object
-
#get_record(options = {}) ⇒ Object
Equivalent to ‘&verb=GetRecord’, returns a record matching the required :identifier option.
-
#identify(options = {}) ⇒ Object
Equivalent to ‘&verb=Identify’, returns information about the repository.
-
#initialize(options = {}) ⇒ Base
constructor
A new instance of Base.
-
#list_identifiers(options = {}) ⇒ Object
Equivalent to ‘&verb=ListIdentifiers’, returns a list of record headers that meet the supplied criteria.
-
#list_metadata_formats(options = {}) ⇒ Object
Equivalent to ‘&verb=ListMetadataFormats’, returns a list of metadata formats supported by the repository.
-
#list_records(options = {}) ⇒ Object
Equivalent to ‘&verb=ListRecords’, returns a list of records that meet the supplied criteria.
-
#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.
-
#methodize(verb) ⇒ Object
Convert valid OAI-PMH verbs into ruby method calls.
-
#process_request(params = {}) ⇒ Object
xml_response = process_verb(‘ListRecords’, :from => ‘October 1, 2005’, :until => ‘November 1, 2005’).
-
#provider_context ⇒ Object
The traditional interaction of a Provider has been to:.
Constructor Details
#initialize(options = {}) ⇒ Base
Returns a new instance of Base.
329 330 331 332 |
# File 'lib/oai/provider.rb', line 329 def initialize( = {}) provider_context = .fetch(:provider_context) { :class_based } @provider_context = PROVIDER_CONTEXTS.fetch(provider_context) end |
Class Attribute Details
.delete_support ⇒ Object
Returns the value of attribute delete_support.
274 275 276 |
# File 'lib/oai/provider.rb', line 274 def delete_support @delete_support end |
.description ⇒ Object
Returns the value of attribute description.
274 275 276 |
# File 'lib/oai/provider.rb', line 274 def description @description end |
.email ⇒ Object
Returns the value of attribute email.
274 275 276 |
# File 'lib/oai/provider.rb', line 274 def email @email end |
.formats ⇒ Object (readonly)
Returns the value of attribute formats.
273 274 275 |
# File 'lib/oai/provider.rb', line 273 def formats @formats end |
.granularity ⇒ Object
Returns the value of attribute granularity.
274 275 276 |
# File 'lib/oai/provider.rb', line 274 def granularity @granularity end |
.identifier ⇒ Object
Returns the value of attribute identifier.
274 275 276 |
# File 'lib/oai/provider.rb', line 274 def identifier @identifier end |
.model ⇒ Object
Returns the value of attribute model.
274 275 276 |
# File 'lib/oai/provider.rb', line 274 def model @model end |
.name ⇒ Object
Returns the value of attribute name.
274 275 276 |
# File 'lib/oai/provider.rb', line 274 def name @name end |
.prefix ⇒ Object
Returns the value of attribute prefix.
274 275 276 |
# File 'lib/oai/provider.rb', line 274 def prefix @prefix end |
.url ⇒ Object
Returns the value of attribute url.
274 275 276 |
# File 'lib/oai/provider.rb', line 274 def url @url end |
Instance Attribute Details
#delete_support ⇒ Object
397 398 399 |
# File 'lib/oai/provider.rb', line 397 def delete_support @delete_support || self.class.delete_support end |
#description ⇒ Object
413 414 415 |
# File 'lib/oai/provider.rb', line 413 def description @description || self.class.description end |
#email ⇒ Object
393 394 395 |
# File 'lib/oai/provider.rb', line 393 def email @email || self.class.email end |
#granularity ⇒ Object
401 402 403 |
# File 'lib/oai/provider.rb', line 401 def granularity @granularity || self.class.granularity end |
#identifier ⇒ Object
409 410 411 |
# File 'lib/oai/provider.rb', line 409 def identifier @identifier || self.class.identifier end |
#model ⇒ Object
405 406 407 |
# File 'lib/oai/provider.rb', line 405 def model @model || self.class.model end |
#name ⇒ Object
381 382 383 |
# File 'lib/oai/provider.rb', line 381 def name @name || self.class.name end |
#prefix ⇒ Object
389 390 391 |
# File 'lib/oai/provider.rb', line 389 def prefix @prefix || self.class.prefix end |
#url ⇒ Object
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
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
369 370 371 |
# File 'lib/oai/provider.rb', line 369 def format_supported?(*args) self.class.format_supported?(*args) end |
#formats ⇒ Object
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( = {}) Response::GetRecord.new(provider_context, ).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( = {}) Response::Identify.new(provider_context, ).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( = {}) Response::ListIdentifiers.new(provider_context, ).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 ( = {}) Response::ListMetadataFormats.new(provider_context, ).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( = {}) Response::ListRecords.new(provider_context, ).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( = {}) Response::ListSets.new(provider_context, ).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_context ⇒ Object
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 |