lib/eco/api/session/task.rb in eco-helpers-0.9.1 vs lib/eco/api/session/task.rb in eco-helpers-0.9.2

- old
+ new

@@ -13,9 +13,28 @@ file = file_manager.save_json(people, filename, :timestamp) logger.info("#{people.length} people loaded and saved locally to #{file}.") Eco::API::Organization::People.new(people) end + def search(data, silent: true) + # to scope people to be fresh data got via api + session.logger.info("going to api get entries...") + status = session.batch.search(data, silent: silent) + people = Eco::API::Organization::People.new(status.people) + # get the supervisors + session.logger.info("going to api get supervisors...") + supers = data.each_with_object([]) do |entry, sup| + if entry.respond_to?(:supervisor_id) && !entry.supervisor_id.to_s.strip.empty? + spr = {"id" => entry.supervisor_id} + sup.push(spr) unless sup.include?(spr) + end + end + status = session.batch.search(supers, silent: silent) + people = people.merge(status.people) + session.logger.info("could get #{people.length} people (out of #{data.length} entries)") + people + end + def load_people(filename = enviro.config.people.cache, modifier: [:newest, :api]) modifier = [modifier].flatten people = [] case when !!filename && (load_file?(modifier) || newest_file?(modifier))