Module: EnjuOai::OaiController::ClassMethods
- Defined in:
- lib/enju_oai/oai_controller.rb
Instance Method Summary collapse
- #check_oai_params(params) ⇒ Object
- #request_attr(from_time, until_time, prefix = 'oai_dc') ⇒ Object
- #set_from_and_until(klass, from_t, until_t) ⇒ Object
- #set_resumption_token(token, from_time, until_time, per_page = 200) ⇒ Object
- #valid_metadata_format?(format) ⇒ Boolean
Instance Method Details
#check_oai_params(params) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/enju_oai/oai_controller.rb', line 9 def check_oai_params(params) oai = {} oai[:errors] = [] case params[:verb] when 'Identify' when 'ListSets' when 'ListMetadataFormats' when 'ListIdentifiers' unless (params[:metadataPrefix]) oai[:errors] << "badArgument" end when 'ListRecords' oai[:metadataPrefix] = params[:metadataPrefix] unless (params[:metadataPrefix]) oai[:errors] << "badArgument" end when 'GetRecord' unless (params[:metadataPrefix]) oai[:errors] << "badArgument" else if params[:identifier].blank? oai[:errors] << "badArgument" end oai[:metadataPrefix] = params[:metadataPrefix] unless (params[:metadataPrefix]) oai[:errors] << "badArgument" end end else oai[:errors] << "badVerb" end oai end |
#request_attr(from_time, until_time, prefix = 'oai_dc') ⇒ Object
55 56 57 58 59 60 |
# File 'lib/enju_oai/oai_controller.rb', line 55 def request_attr(from_time, until_time, prefix = 'oai_dc') attribute = {metadataPrefix: prefix, verb: 'ListRecords'} attribute.merge(from: from_time.utc.iso8601) if from_time attribute.merge(:until => until_time.utc.iso8601) if until_time attribute end |
#set_from_and_until(klass, from_t, until_t) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/enju_oai/oai_controller.rb', line 74 def set_from_and_until(klass, from_t, until_t) if klass.first and klass.last from_t ||= klass.order(:updated_at).first.updated_at.to_s until_t ||= klass.order(:updated_at).last.updated_at.to_s else from_t ||= Time.zone.now.to_s until_t ||= Time.zone.now.to_s end times = {} if /^[12]\d{3}-(0?[1-9]|1[0-2])-(0?[1-9]|[12]\d|3[01])$/ =~ from_t times[:from] = Time.zone.parse(from_t).beginning_of_day else times[:from] = Time.zone.parse(from_t) end if /^[12]\d{3}-(0?[1-9]|1[0-2])-(0?[1-9]|[12]\d|3[01])$/ =~ until_t times[:until] = Time.zone.parse(until_t).end_of_day else times[:until] = Time.zone.parse(until_t) end times[:from] ||= Time.zone.parse(from_t) times[:until] ||= Time.zone.parse(until_t) times end |
#set_resumption_token(token, from_time, until_time, per_page = 200) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/enju_oai/oai_controller.rb', line 62 def set_resumption_token(token, from_time, until_time, per_page = 200) if token cursor = token.split(',').reverse.first.to_i + per_page else cursor = per_page end { token: "f(#{from_time.utc.iso8601.to_s}),u(#{until_time.utc.iso8601.to_s}),#{cursor}", cursor: cursor } end |
#valid_metadata_format?(format) ⇒ Boolean
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/enju_oai/oai_controller.rb', line 43 def (format) if format.present? if ['oai_dc', 'junii2', 'dcndl'].include?(format) true else false end else false end end |