Module: Eco::API::Session::Batch::Searcher
- Included in:
- Eco::API::Session::Batch
- Defined in:
- lib/eco/api/session/batch/searcher.rb
Instance Method Summary collapse
-
#get_people(people = nil, params: {}, silent: false, options: self.options) ⇒ Array<People>
Gets the people of the organization according
params
. -
#search(data, silent: false, params: {}, options: self.options) ⇒ Object
rubocop:disable Metrics/AbcSize.
Instance Method Details
#get_people(people = nil, params: {}, silent: false, options: self.options) ⇒ Array<People>
Note:
- If
people
is given keyspage:
andq
ofparams:
.
Gets the people of the organization according params
.
If people
is not nil
, scopes to only the people specified.
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/eco/api/session/batch/searcher.rb', line 29 def get_people(people = nil, params: {}, silent: false, options: self.) return get(params: params, silent: silent, options: ) unless people.is_a?(Enumerable) launch( people, method: :get, params: params, silent: silent, options: ).people end |
#search(data, silent: false, params: {}, options: self.options) ⇒ Object
rubocop:disable Metrics/AbcSize
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/eco/api/session/batch/searcher.rb', line 41 def search(data, silent: false, params: {}, options: self.) # rubocop:disable Metrics/AbcSize params = {per_page: batch_size()}.merge(params) launch( data, method: :get, params: params, silent: silent, options: ).tap do |status| status.mode = :search entries = status.queue puts "\n" entries.each_with_index do |entry, i| if (i % 10).zero? percent = i * 100 / entries.length print "Searching: #{percent.round}% (#{i}/#{entries.length} entries)\r" $stdout.flush end next if status.success?(entry) email = nil if entry.respond_to?(:email) email = entry.email elsif entry.respond_to?(:to_h) email = entry.to_h["email"] end people_matching = [] email = email.to_s.strip.downcase unless email.empty? people_matching = get( params: params.merge(q: email), silent: silent, options: ).select do |person| person.email == email end end case people_matching.length when 1 status.set_person_match(entry, people_matching.first) when 2..Float::INFINITY status.set_people_match(entry, people_matching) end end end end |