Class: Eco::API::Session::Batch
- Inherits:
-
Common::Session::BaseSession
- Object
- Common::Session::BaseSession
- Eco::API::Session::Batch
- Defined in:
- lib/eco/api/session/batch.rb,
lib/eco/api/session/batch/job.rb,
lib/eco/api/session/batch/jobs.rb,
lib/eco/api/session/batch/errors.rb,
lib/eco/api/session/batch/status.rb,
lib/eco/api/session/batch/feedback.rb,
lib/eco/api/session/batch/policies.rb,
lib/eco/api/session/batch/base_policy.rb,
lib/eco/api/session/batch/jobs_groups.rb,
lib/eco/api/session/batch/request_stats.rb
Defined Under Namespace
Classes: BasePolicy, Errors, Feedback, Job, Jobs, JobsGroups, Policies, RequestStats, Status
Constant Summary collapse
- DEFAULT_BATCH_BLOCK =
50
- VALID_METHODS =
[:get, :create, :update, :upsert, :delete]
Instance Attribute Summary
Attributes inherited from Common::Session::BaseSession
#api, #config, #environment, #file_manager, #logger, #session
Class Method Summary collapse
-
.valid_method?(value) ⇒ Boolean
true
if the method is supported,false
otherwise.
Instance Method Summary collapse
-
#get_people(people = nil, params: {}, silent: false) ⇒ Array<People>
Gets the people of the organization according
params
. -
#launch(people, method:, params: {}, silent: false) ⇒ Batch::Status
launches a batch of
method
type usingpeople
and the specifiedparams
. - #search(data, silent: false, params: {}) ⇒ Object
Methods inherited from Common::Session::BaseSession
#enviro=, #fatal, #fm, #initialize, #mailer, #mailer?, #s3uploader, #s3uploader?, #sftp, #sftp?
Constructor Details
This class inherits a constructor from Eco::API::Common::Session::BaseSession
Class Method Details
.valid_method?(value) ⇒ Boolean
Returns true
if the method is supported, false
otherwise.
11 12 13 |
# File 'lib/eco/api/session/batch.rb', line 11 def valid_method?(value) VALID_METHODS.include?(value) end |
Instance Method Details
#get_people(people = nil, params: {}, silent: false) ⇒ 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.
26 27 28 29 |
# File 'lib/eco/api/session/batch.rb', line 26 def get_people(people = nil, params: {}, silent: false) return launch(people, method: :get, params: params, silent: silent).people if people.is_a?(Enumerable) return get(params: params, silent: silent) end |
#launch(people, method:, params: {}, silent: false) ⇒ Batch::Status
launches a batch of method
type using people
and the specified params
40 41 42 |
# File 'lib/eco/api/session/batch.rb', line 40 def launch(people, method:, params: {} , silent: false) batch_from(people, method: method, params: params, silent: silent) end |
#search(data, silent: false, params: {}) ⇒ Object
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 |
# File 'lib/eco/api/session/batch.rb', line 44 def search(data, silent: false, params: {}) params = {per_page: DEFAULT_BATCH_BLOCK}.merge(params) launch(data, method: :get, params: params, silent: silent).tap do |status| status.mode = :search entries = status.queue puts "\n" entries.each_with_index do |entry, i| if (i % 10 == 0) percent = i * 100 / entries.length print "Searching: #{percent.round}% (#{i}/#{entries.length} entries)\r" $stdout.flush end unless status.success?(entry) email = nil case when entry.respond_to?(:email) email = entry.email when 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).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 end |