Module: OaiPmh::Helpers
- Included in:
- Provider
- Defined in:
- lib/oaipmh/helpers.rb
Instance Method Summary collapse
- #build_scope_hash ⇒ Object
-
#echo_params(verb, opts) ⇒ Object
Echo the request parameters back to the client.
-
#ensure_valid(verb, opts) ⇒ Object
Massage the options until they are bit more palatable.
-
#header ⇒ Object
Output the OAI-PMH header.
-
#parse_date(dt_string) ⇒ Object
Use of Chronic here is mostly for human interactions.
Instance Method Details
#build_scope_hash ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/oaipmh/helpers.rb', line 23 def build_scope_hash params = {} params[:from] = parse_date(@opts[:from]) if @opts[:from] params[:until] = parse_date(@opts[:until]) if @opts[:until] params[:set] = @opts[:set] if @opts[:set] params end |
#echo_params(verb, opts) ⇒ Object
Echo the request parameters back to the client. See spec.
19 20 21 |
# File 'lib/oaipmh/helpers.rb', line 19 def echo_params(verb, opts) @xml.request(@url, {:verb => verb}.merge(opts)) end |
#ensure_valid(verb, opts) ⇒ Object
Massage the options until they are bit more palatable.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/oaipmh/helpers.rb', line 41 def ensure_valid(verb, opts) return {} unless opts popts = {} opts.keys.each do |k| # Ensure they are all lowercase symbols nk = k.to_s.downcase.intern popts[nk] = opts[k] end # shorten the big ugly long ones popts[:id] = popts.delete(:identifier) if popts[:identifier] popts[:prefix] = popts.delete(:metadataprefix) if popts[:metadataprefix] popts[:token] = popts.delete(:resumptiontoken) if popts[:resumptiontoken] raise ArgumentException.new unless popts.empty? || (popts.keys - OaiPmh::Const::VERBS[verb]).empty? popts end |
#header ⇒ Object
Output the OAI-PMH header
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/oaipmh/helpers.rb', line 5 def header @xml = Builder::XmlMarkup.new @xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8" @xml.tag!('OAI-PMH', 'xmlns' => "http://www.openarchives.org/OAI/2.0/", 'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance", 'xsi:schemaLocation' => %{http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd}) do @xml.responseDate Time.now.utc.xmlschema yield end end |
#parse_date(dt_string) ⇒ Object
Use of Chronic here is mostly for human interactions. It’s nice to be able to say ‘?verb=ListRecords&from=October&until=November’
33 34 35 36 37 38 |
# File 'lib/oaipmh/helpers.rb', line 33 def parse_date(dt_string) # Oddly Chronic doesn't parse an UTC encoded datetime. # Luckily Time does dt = Chronic.parse(dt_string) || Time.parse(dt_string) dt.strftime("%Y-%m-%d %H:%M:%S") end |