Module: OaiPmh
- Defined in:
- lib/oaipmh/set.rb,
lib/oaipmh/model.rb,
lib/oaipmh/helpers.rb,
lib/oaipmh/metadata.rb,
lib/oaipmh/provider.rb,
lib/oaipmh/constants.rb,
lib/oaipmh/exceptions.rb,
lib/oaipmh/extensions/camping.rb
Overview
provider.rb
Copyright © 2006 William Groppe
Will Groppe [email protected]
Open Archives Initiative - Protocol for Metadata Harvesting see www.openarchives.org/
Features
-
Easily setup a simple repository
-
Simple integration with ActiveRecord
-
Dublin Core metadata format included
-
Easily add addition metadata formats
-
Adaptable to any data source
Current shortcomings
-
No resumption tokens
-
Doesn’t validate metadata
-
No deletion support
-
Many others I can’t think of right now. :-)
ActiveRecord integration
To successfully use ActiveRecord as a OAI PMH datasource the database table should include an updated_at column so that updates to the table are tracked by ActiveRecord. This provides much of the base functionality for selecting update periods.
To understand how the data is extracted from the AR model it’s best to just go thru the logic:
Does the model respond to ‘to_prefix’? Where prefix is the metadata prefix. If it does then just include the response from the model. So if you want to provide custom or complex metadata you can simply define a ‘to_prefix’ method on your model.
Example:
class Record < ActiveRecord::Base
def to_oai_dc
xml = Builder::XmlMarkup.new
xml.tag!('oai_dc:dc',
'xmlns:oai_dc' => "http://www.openarchives.org/OAI/2.0/oai_dc/",
'xmlns:dc' => "http://purl.org/dc/elements/1.1/",
'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance",
'xsi:schemaLocation' =>
%{http://www.openarchives.org/OAI/2.0/oai_dc/
http://www.openarchives.org/OAI/2.0/oai_dc.xsd}) do
xml.oai_dc :title, title
xml.oai_dc :subject, subject
end
xml.to_s
end
end
If the model doesn’t define a ‘to_prefix’ then start iterating thru the defined metadata fields.
Grab a mapping if one exists by trying to call ‘map_prefix’.
Now do the iteration and try calling methods on the model that match the field names, or the mapped field names.
So with Dublin Core we end up with the following:
-
Check for ‘title’ mapped to a different method.
-
Call model.titles - try plural
-
Call model.title - try singular last
Extremely contrived Blog example:
class Post < ActiveRecord::Base
def map_oai_dc
{:subject => :tags,
:description => :text,
:creator => :user,
:contibutor => :comments}
end
end
Supporting custom metadata
See OaiPmh::Metadata for details.
Examples
Sub classing a provider
class MyProvider < OaiPmh::Provider
name 'My little OAI provider'
url 'http://localhost/provider'
prefix 'oai:localhost'
email 'root@localhost' # String or Array
deletes 'no' # future versions will support deletes
granularity 'YYYY-MM-DDThh:mm:ssZ' # update resolution
model MyModel # Class to get data from
end
# Now use it
provider = MyProvider.new
provider.identify
provider.list_sets
provider.
# these verbs require a working model
provider.list_identifiers
provider.list_records
provider.get_record('oai:localhost/1')
Configuring the default provider
class OaiPmh::Provider
name 'My little OAI Provider'
url 'http://localhost/provider'
prefix 'oai:localhost'
email 'root@localhost' # String or Array
deletes 'no' # future versions will support deletes
granularity 'YYYY-MM-DDThh:mm:ssZ' # update resolution
model MyModel # Class to get data from
end
Defined Under Namespace
Modules: Const, Goes, Helpers, Metadata, Model Classes: ArgumentException, FormatException, IdException, MetadataFormatException, NoMatchException, OAIException, Provider, ResumptionTokenException, Set, SetException, VerbException
Constant Summary collapse
- METADATA =
{}