module Dhis2::Api::Findable::ClassMethods
Public Instance Methods
find(client, id, fields: :all, raw: false)
click to toggle source
docs.dhis2.org/2.25/en/developer/html/webapi_metadata_object_filter.html
# File lib/dhis2/api/findable.rb, line 12 def find(client, id, fields: :all, raw: false) raise Dhis2::PrimaryKeyMissingError if id.nil? if id.is_a? Array list(client, { filter: "id:in:[#{id.join(',')}]", fields: fields, page_size: id.size }, raw) else if raw client.get(path: "#{resource_name}/#{id}", raw: true) else new(client, client.get(path: "#{resource_name}/#{id}")) end end end
find_by(client, clauses, fields: :all, raw: false)
click to toggle source
# File lib/dhis2/api/findable.rb, line 41 def find_by(client, clauses, fields: :all, raw: false) list( client, fields: fields, filter: clauses.map { |field, value| "#{field}:eq:#{value}" }, raw: raw ).first end
find_paginated(client, ids, fields: :all, batch_size: 100, raw: false)
click to toggle source
batch size is to prevent from sending get requests with uri too long max uri length is around 2000 chars, a dhis id is around 11 chars, 100 is a safe default
# File lib/dhis2/api/findable.rb, line 28 def find_paginated(client, ids, fields: :all, batch_size: 100, raw: false) Enumerator.new do |yielder| loop do ids.each_slice(batch_size) do |array| find(client, array, fields: fields, raw: raw).map do |item| yielder << item end end raise StopIteration end end end