Class: VAProfile::ContactInformation::Service

Inherits:
Service show all
Includes:
Common::Client::Concerns::Monitoring
Defined in:
lib/va_profile/contact_information/service.rb

Constant Summary collapse

CONTACT_INFO_CHANGE_TEMPLATE =
Settings.vanotify.services.va_gov.template_id.contact_info_change
EMAIL_PERSONALISATIONS =
{
  address: 'Address',
  residence_address: 'Home address',
  correspondence_address: 'Mailing address',
  email: 'Email address',
  phone: 'Phone number',
  home_phone: 'Home phone number',
  mobile_phone: 'Mobile phone number',
  work_phone: 'Work phone number'
}.freeze

Constants inherited from Service

Service::STATSD_KEY_PREFIX

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Common::Client::Concerns::Monitoring

#with_monitoring

Methods inherited from Service

breakers_service, #initialize, #perform

Methods inherited from Common::Client::Base

configuration, #raise_backend_exception

Methods included from SentryLogging

#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger

Constructor Details

This class inherits a constructor from VAProfile::Service

Class Method Details

.get_person(vet360_id) ⇒ Object



58
59
60
61
# File 'lib/va_profile/contact_information/service.rb', line 58

def self.get_person(vet360_id)
  stub_user = OpenStruct.new(vet360_id:)
  new(stub_user).get_person
end

Instance Method Details

#get_address_transaction_status(transaction_id) ⇒ VAProfile::ContactInformation::EmailTransactionResponse

GET’s the status of an address transaction from the VAProfile api

Parameters:

  • transaction_id (int)

    the transaction_id to check

Returns:



120
121
122
123
124
125
126
127
128
# File 'lib/va_profile/contact_information/service.rb', line 120

def get_address_transaction_status(transaction_id)
  route = "#{@user.vet360_id}/addresses/status/#{transaction_id}"
  transaction_status = get_transaction_status(route, AddressTransactionResponse)

  changes = transaction_status.changed_field
  send_contact_change_notification(transaction_status, changes)

  transaction_status
end

#get_email_transaction_status(transaction_id) ⇒ VAProfile::ContactInformation::EmailTransactionResponse

GET’s the status of an email transaction from the VAProfile api

Parameters:

  • transaction_id (int)

    the transaction_id to check

Returns:



159
160
161
162
163
164
165
166
# File 'lib/va_profile/contact_information/service.rb', line 159

def get_email_transaction_status(transaction_id)
  route = "#{@user.vet360_id}/emails/status/#{transaction_id}"
  transaction_status = get_transaction_status(route, EmailTransactionResponse)

  send_email_change_notification(transaction_status)

  transaction_status
end

#get_permission_transaction_status(transaction_id) ⇒ VAProfile::ContactInformation::PermissionTransactionResponse

GET’s the status of a permission transaction from the VAProfile api

Parameters:

  • transaction_id (int)

    the transaction_id to check

Returns:



214
215
216
217
# File 'lib/va_profile/contact_information/service.rb', line 214

def get_permission_transaction_status(transaction_id)
  route = "#{@user.vet360_id}/permissions/status/#{transaction_id}"
  get_transaction_status(route, PermissionTransactionResponse)
end

#get_personVAProfile::ContactInformation::PersonResponse

GET’s a Person bio from the VAProfile API If a user is not found in VAProfile, an empty PersonResponse with a 404 status will be returned

Returns:



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/va_profile/contact_information/service.rb', line 32

def get_person
  with_monitoring do
    vet360_id_present!
    raw_response = perform(:get, @user.vet360_id)

    PersonResponse.from(raw_response)
  end
rescue Common::Client::Errors::ClientError => e
  if e.status == 404
    log_exception_to_sentry(
      e,
      { vet360_id: @user.vet360_id },
      { va_profile: :person_not_found },
      :warning
    )

    return PersonResponse.new(404, person: nil)
  elsif e.status >= 400 && e.status < 500
    return PersonResponse.new(e.status, person: nil)
  end

  handle_error(e)
rescue => e
  handle_error(e)
end

#get_person_transaction_status(transaction_id) ⇒ VAProfile::ContactInformation::PersonTransactionResponse

GET’s the status of a person transaction from the VAProfile api. Does not validate the presence of a vet360_id before making the service call, as POSTing a person initializes a vet360_id.

Parameters:

  • transaction_id (String)

    the transaction_id to check

Returns:



225
226
227
228
229
230
231
232
233
234
# File 'lib/va_profile/contact_information/service.rb', line 225

def get_person_transaction_status(transaction_id)
  with_monitoring do
    raw_response = perform(:get, "status/#{transaction_id}")
    VAProfile::Stats.increment_transaction_results(raw_response, 'init_vet360_id')

    VAProfile::ContactInformation::PersonTransactionResponse.from(raw_response, @user)
  end
rescue => e
  handle_error(e)
end

#get_telephone_transaction_status(transaction_id) ⇒ VAProfile::ContactInformation::TelephoneTransactionResponse

GET’s the status of a telephone transaction from the VAProfile api

Parameters:

  • transaction_id (int)

    the transaction_id to check

Returns:



186
187
188
189
190
191
192
193
194
# File 'lib/va_profile/contact_information/service.rb', line 186

def get_telephone_transaction_status(transaction_id)
  route = "#{@user.vet360_id}/telephones/status/#{transaction_id}"
  transaction_status = get_transaction_status(route, TelephoneTransactionResponse)

  changes = transaction_status.changed_field
  send_contact_change_notification(transaction_status, changes)

  transaction_status
end

#post_address(address) ⇒ VAProfile::ContactInformation::AddressTransactionResponse

POSTs a new address to the VAProfile API

Parameters:

Returns:



106
107
108
# File 'lib/va_profile/contact_information/service.rb', line 106

def post_address(address)
  post_or_put_data(:post, address, 'addresses', AddressTransactionResponse)
end

#post_email(email) ⇒ VAProfile::ContactInformation::EmailTransactionResponse

POSTs a new address to the VAProfile API

Parameters:

Returns:



133
134
135
# File 'lib/va_profile/contact_information/service.rb', line 133

def post_email(email)
  post_or_put_data(:post, email, 'emails', EmailTransactionResponse)
end

#post_permission(permission) ⇒ VAProfile::ContactInformation::PermissionUpdateResponse

POSTs a new permission to the VAProfile API

Parameters:

Returns:

  • (VAProfile::ContactInformation::PermissionUpdateResponse)

    response wrapper around a transaction object



199
200
201
# File 'lib/va_profile/contact_information/service.rb', line 199

def post_permission(permission)
  post_or_put_data(:post, permission, 'permissions', PermissionTransactionResponse)
end

#post_telephone(telephone) ⇒ VAProfile::ContactInformation::TelephoneUpdateResponse

POSTs a new telephone to the VAProfile API

Parameters:

Returns:

  • (VAProfile::ContactInformation::TelephoneUpdateResponse)

    response wrapper around a transaction object



171
172
173
# File 'lib/va_profile/contact_information/service.rb', line 171

def post_telephone(telephone)
  post_or_put_data(:post, telephone, 'telephones', TelephoneTransactionResponse)
end

#put_address(address) ⇒ VAProfile::ContactInformation::AddressTransactionResponse

PUTs an updated address to the VAProfile API

Parameters:

Returns:



113
114
115
# File 'lib/va_profile/contact_information/service.rb', line 113

def put_address(address)
  post_or_put_data(:put, address, 'addresses', AddressTransactionResponse)
end

#put_email(email) ⇒ VAProfile::ContactInformation::EmailTransactionResponse

PUTs an updated address to the VAProfile API

Parameters:

Returns:



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/va_profile/contact_information/service.rb', line 140

def put_email(email)
  old_email =
    begin
      @user.va_profile_email
    rescue
      nil
    end

  response = post_or_put_data(:put, email, 'emails', EmailTransactionResponse)

  transaction = response.transaction
  OldEmail.create(transaction_id: transaction.id, email: old_email) if transaction.received? && old_email.present?

  response
end

#put_permission(permission) ⇒ VAProfile::ContactInformation::PermissionUpdateResponse

PUTs an updated permission to the VAProfile API

Parameters:

Returns:

  • (VAProfile::ContactInformation::PermissionUpdateResponse)

    response wrapper around a transaction object



206
207
208
# File 'lib/va_profile/contact_information/service.rb', line 206

def put_permission(permission)
  post_or_put_data(:put, permission, 'permissions', PermissionTransactionResponse)
end

#put_telephone(telephone) ⇒ VAProfile::ContactInformation::TelephoneUpdateResponse

PUTs an updated telephone to the VAProfile API

Parameters:

Returns:

  • (VAProfile::ContactInformation::TelephoneUpdateResponse)

    response wrapper around a transaction object



178
179
180
# File 'lib/va_profile/contact_information/service.rb', line 178

def put_telephone(telephone)
  post_or_put_data(:put, telephone, 'telephones', TelephoneTransactionResponse)
end

#update_address(address) ⇒ Object



63
64
65
66
67
68
69
70
71
72
# File 'lib/va_profile/contact_information/service.rb', line 63

def update_address(address)
  address_type =
    if address.address_pou == VAProfile::Models::BaseAddress::RESIDENCE
      'residential'
    else
      'mailing'
    end

  update_model(address, "#{address_type}_address", 'address')
end

#update_email(email) ⇒ Object



74
75
76
# File 'lib/va_profile/contact_information/service.rb', line 74

def update_email(email)
  update_model(email, 'email', 'email')
end

#update_permission(permission) ⇒ Object



78
79
80
# File 'lib/va_profile/contact_information/service.rb', line 78

def update_permission(permission)
  update_model(permission, 'text_permission', 'permission')
end

#update_telephone(telephone) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/va_profile/contact_information/service.rb', line 82

def update_telephone(telephone)
  phone_type =
    case telephone.phone_type
    when VAProfile::Models::Telephone::MOBILE
      'mobile_phone'
    when VAProfile::Models::Telephone::HOME
      'home_phone'
    when VAProfile::Models::Telephone::WORK
      'work_phone'
    when VAProfile::Models::Telephone::FAX
      'fax_number'
    when VAProfile::Models::Telephone::TEMPORARY
      'temporary_phone'
    else
      raise 'invalid phone type'
    end

  update_model(telephone, phone_type, 'telephone')
end