Class: Puree::Query::Person
- Inherits:
-
Object
- Object
- Puree::Query::Person
- Defined in:
- lib/openaccess/apc.rb
Overview
Add the creation and modification dates to the selection criteria for publications
Constant Summary collapse
- OPTS =
Maps keyword arguments to Pure query parameters The query parameter is either a String (the name of the parameter) or a Proc which accepts the keyword argument name, value and query parameter hash and modifies the query hash as required.
{ created_end: 'createdDate.toDate', created_start: 'createdDate.fromDate', modified_end: 'modifiedDate.toDate', modified_start: 'modifiedDate.fromDate', order_by: proc do |_opt, values, query| values = [values] unless values.is_a?(Array) values.each_index do |i| value = values[i] if '+-'.include?(value[0]) descending = value[0] == '-' ? 'true' : 'false' value = value[1..-1] else descending = 'false' end param = format('orderBy.property[%d]', i) query[param] = value param = format('orderBy.property[%d].descending', i) query[param] = descending end end, published_end: 'publicationDate.toDate', published_start: 'publicationDate.fromDate', workflow_states: proc do |_opt, values, query| values = [values] unless value.is_a?(Array) values.each_index do |i| param = format('workflowStates.workflowState[%d].workflowName', i) query[param] = 'publication' param = format('workflowStates.workflowState[%d]', i) query[param] = values[i].to_s end end }.freeze
Class Method Summary collapse
-
.query_params(params, **opts) ⇒ void
Adds whitelisted keyword arguments to the supplied query parameter hash.
Instance Method Summary collapse
-
#publication_uuids_extended(uuid:, limit:, **opts) ⇒ Array<String>
Returns an array of publication UUIDs for the given person’s UUID.
-
#publications_extended(uuid:, limit:, **opts) ⇒ Array<Puree::Model::Publication] the array of publications
Returns an array of publications for the given person’s UUID.
Class Method Details
.query_params(params, **opts) ⇒ void
This method returns an undefined value.
Adds whitelisted keyword arguments to the supplied query parameter hash
101 102 103 104 105 106 107 108 109 110 |
# File 'lib/openaccess/apc.rb', line 101 def self.query_params(params, **opts) OPTS.each do |opt, param| next unless opts[opt] if param.is_a?(Proc) param.call(opt, opts[opt], params) else params[param] = opts[opt] end end end |
Instance Method Details
#publication_uuids_extended(uuid:, limit:, **opts) ⇒ Array<String>
Returns an array of publication UUIDs for the given person’s UUID
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/openaccess/apc.rb', line 85 def publication_uuids_extended(uuid:, limit:, **opts) params = { 'associatedPersonUuids.uuid' => uuid, 'rendering' => :system, 'window.size' => limit.to_s, 'window.offset' => (opts[:offset] || 0).to_s } self.class.query_params(params, **opts) headers response = @req.get(build_publication_url, params: params) extract_publication_uuids(make_doc(response.body)) end |
#publications_extended(uuid:, limit:, **opts) ⇒ Array<Puree::Model::Publication] the array of publications
Returns an array of publications for the given person’s UUID
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/openaccess/apc.rb', line 71 def publications_extended(uuid:, limit:, **opts) uuids = publication_uuids_extended(uuid: uuid, limit: limit, **opts) publications = [] uuids.each do |u| publication_extractor = Puree::Extractor::Publication.new(@config) publication = publication_extractor.find uuid: u publications << publication if publication end publications end |