Class: ServiceObjects::AssignEmailAddress

Inherits:
Base
  • Object
show all
Defined in:
lib/service_objects/assign_email_address.rb

Constant Summary collapse

EMAIL_TYPE =
:university
MAKE_EMAIL_PRIMARY =
true

Instance Attribute Summary

Attributes inherited from Base

#change

Instance Method Summary collapse

Methods inherited from Base

ignore?, #initialize

Constructor Details

This class inherits a constructor from ServiceObjects::Base

Instance Method Details

#callObject


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/service_objects/assign_email_address.rb', line 6

def call
  email_options = EmailAddressOptions.new(change.affiliations, change.preferred_name, change.first_name, change.middle_name, change.last_name).to_a
  return nil if email_options.none?

  unique_email = UniqueEmailAddress.new(email_options).best
  full_unique_email = GoogleAccount.full_email(unique_email)

  response = Trogdir::APIClient::Emails.new.create(uuid: change.person_uuid, address: full_unique_email, type: EMAIL_TYPE, primary: MAKE_EMAIL_PRIMARY).perform
  if response.success?
    UpdateLegacyEmailTable.new(change).insert(full_unique_email)
    :create
  else
    raise TrogdirAPIError, response.parse['error']
  end
end

#ignore?Boolean

Returns:

  • (Boolean)

22
23
24
# File 'lib/service_objects/assign_email_address.rb', line 22

def ignore?
  !(change.affiliation_added? && !change.university_email_exists?)
end