Class: Eco::API::Session::Batch::Feedback

Inherits:
Object
  • Object
show all
Extended by:
Getters, Identifiers
Includes:
Generate, JobDependencies, RequestStat
Defined in:
lib/eco/api/session/batch/feedback.rb,
lib/eco/api/session/batch/feedback/getters.rb,
lib/eco/api/session/batch/feedback/generate.rb,
lib/eco/api/session/batch/feedback/identifiers.rb,
lib/eco/api/session/batch/feedback/request_stat.rb,
lib/eco/api/session/batch/feedback/request_stats.rb,
lib/eco/api/session/batch/feedback/job_dependencies.rb

Defined Under Namespace

Modules: Generate, Getters, Identifiers, JobDependencies, RequestStat Classes: RequestStats

Instance Attribute Summary collapse

Pure feedback methods collapse

Instance Method Summary collapse

Methods included from Getters

get_attr, get_row

Methods included from Identifiers

person_ref

Methods included from Generate

#generate

Methods included from RequestStat

#request_stats

Methods included from JobDependencies

#job_requests, #name, #options, #sets, #type

Constructor Details

#initialize(job:) ⇒ Feedback

Returns a new instance of Feedback.

Parameters:



22
23
24
25
26
27
# File 'lib/eco/api/session/batch/feedback.rb', line 22

def initialize(job:)
  msg = "A Eco::API::Session::Batch::Job object is required. Given: #{job.class}"
  raise msg unless job.is_a?(Eco::API::Session::Batch::Job)

  @job  = job
end

Instance Attribute Details

#jobEco::API::Session::Batch::Job (readonly)

batch job the feedback is associated with

Returns:



6
7
8
# File 'lib/eco/api/session/batch/feedback.rb', line 6

def job
  @job
end

Instance Method Details

#as_update(entry, add_feedback: true) ⇒ Object

Note:

for better feedback

Slightly modifies the behaviour of Ecoportal::API::Common::BaseModel#as_update, so schema details fields show the alt_id. It also fixes possible patch updates that are incomplete or unnecessary.

Parameters:

  • entry (Hash, Ecoportal::API::V1::Person, Ecoportal::API::Internal::Person)
  • add_feedback (Boolean) (defaults to: true)

    if true it tweak the hash update with additional data.



37
38
39
40
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
# File 'lib/eco/api/session/batch/feedback.rb', line 37

def as_update(entry, add_feedback: true)
  return entry if entry.is_a?(Hash)

  # assuming entry.is_a?(Ecoportal::API::V1::Person)

  if only_ids?
    # @todo entry.respond_to?(:as_json)
    hash = entry.as_json.slice('id', 'external_id', 'email')
  else
    # @todo entry.respond_to?(:as_update)
    hash     = entry.as_update

    details  = hash['details']
    h_fields = details && details['fields']

    if add_feedback && h_fields
      h_fields.each do |fld|
        fld.merge!('alt_id' => entry.details.get_field(fld['id']).alt_id)
      end
    end

      = hash['account']
    invites  =  && .keys == ['send_invites']
    ninvites = invites && !['send_invites']

    if ninvites
      hash.delete('account')
      hash.delete('id') if hash.keys == ['id']
    end
  end

  hash || {}
end