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.



187
188
189
# File 'lib/oai/provider.rb', line 187

def delete_support
  @delete_support
end

.emailObject

Returns the value of attribute email.



187
188
189
# File 'lib/oai/provider.rb', line 187

def email
  @email
end

.formatsObject (readonly)

Returns the value of attribute formats.



186
187
188
# File 'lib/oai/provider.rb', line 186

def formats
  @formats
end

.granularityObject

Returns the value of attribute granularity.



187
188
189
# File 'lib/oai/provider.rb', line 187

def granularity
  @granularity
end

.modelObject

Returns the value of attribute model.



187
188
189
# File 'lib/oai/provider.rb', line 187

def model
  @model
end

.nameObject

Returns the value of attribute name.



187
188
189
# File 'lib/oai/provider.rb', line 187

def name
  @name
end

.prefixObject

Returns the value of attribute prefix.



187
188
189
# File 'lib/oai/provider.rb', line 187

def prefix
  @prefix
end

.urlObject

Returns the value of attribute url.



187
188
189
# File 'lib/oai/provider.rb', line 187

def url
  @url
end

Class Method Details

.format(prefix) ⇒ Object



198
199
200
# File 'lib/oai/provider.rb', line 198

def format(prefix)
  @formats[prefix]
end

.format_supported?(prefix) ⇒ Boolean

Returns:

  • (Boolean)


194
195
196
# File 'lib/oai/provider.rb', line 194

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

.register_format(format) ⇒ Object



189
190
191
192
# File 'lib/oai/provider.rb', line 189

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



261
262
263
# File 'lib/oai/provider.rb', line 261

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



231
232
233
# File 'lib/oai/provider.rb', line 231

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.



249
250
251
# File 'lib/oai/provider.rb', line 249

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.



243
244
245
# File 'lib/oai/provider.rb', line 243

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.



255
256
257
# File 'lib/oai/provider.rb', line 255

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.



237
238
239
# File 'lib/oai/provider.rb', line 237

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



294
295
296
# File 'lib/oai/provider.rb', line 294

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

#process_request(params = {}) ⇒ Object

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

:until => 'November') # thanks Chronic!

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



270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
# File 'lib/oai/provider.rb', line 270

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