Class: VAProfileRedis::ContactInformation

Inherits:
Common::RedisStore show all
Includes:
Common::CacheAside
Defined in:
app/models/va_profile_redis/contact_information.rb

Overview

Facade for VAProfile::ContactInformation::Service. The user_serializer delegates to this class through the User model.

When a person is requested from the serializer, it returns either a cached response in Redis or from the VAProfile::ContactInformation::Service.

Constant Summary

Constants inherited from Common::RedisStore

Common::RedisStore::REQ_CLASS_INSTANCE_VARS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Common::CacheAside

#cache, #cached?, #do_cached_with, #set_attributes

Methods inherited from Common::RedisStore

create, delete, #destroy, #destroyed?, exists?, #expire, find, find_or_build, #initialize, #initialize_dup, keys, #persisted?, pop, redis_key, redis_store, redis_ttl, #save, #save!, #ttl, #update, #update!

Constructor Details

This class inherits a constructor from Common::RedisStore

Instance Attribute Details

#userUser

Returns the user being queried in VA Profile.

Returns:

  • (User)

    the user being queried in VA Profile



28
29
30
# File 'app/models/va_profile_redis/contact_information.rb', line 28

def user
  @user
end

Class Method Details

.for_user(user) ⇒ Object



30
31
32
33
34
35
# File 'app/models/va_profile_redis/contact_information.rb', line 30

def self.for_user(user)
  contact_info      = new
  contact_info.user = user
  contact_info.populate_from_redis
  contact_info
end

Instance Method Details

#contact_info_serviceObject (private)



188
189
190
# File 'app/models/va_profile_redis/contact_information.rb', line 188

def contact_info_service
  @service ||= VAProfile::ContactInformation::Service.new @user
end

#dig_out(key, type, matcher) ⇒ Object (private)



170
171
172
173
174
175
176
177
178
# File 'app/models/va_profile_redis/contact_information.rb', line 170

def dig_out(key, type, matcher)
  response_value = value_for(key)

  return if response_value.blank?

  response_value.find do |contact_info|
    contact_info.send(type) == matcher
  end
end

#emailVAProfile::Models::Email

Returns the user’s email model. In VA Profile, a user can only have one email address.

Returns:



42
43
44
45
46
# File 'app/models/va_profile_redis/contact_information.rb', line 42

def email
  return unless @user.loa3?

  value_for('emails')&.first
end

#fax_numberVAProfile::Models::Telephone

Returns the user’s fax number. In VA Profile, a user can only have one fax number.

Returns:



119
120
121
122
123
# File 'app/models/va_profile_redis/contact_information.rb', line 119

def fax_number
  return unless @user.loa3?

  dig_out('telephones', 'phone_type', VAProfile::Models::Telephone::FAX)
end

#home_phoneVAProfile::Models::Telephone

Returns the user’s home phone. In VA Profile, a user can only have one home phone.

Returns:



75
76
77
78
79
# File 'app/models/va_profile_redis/contact_information.rb', line 75

def home_phone
  return unless @user.loa3?

  dig_out('telephones', 'phone_type', VAProfile::Models::Telephone::HOME)
end

#mailing_addressVAProfile::Models::Address

Returns the user’s mailing address. In VA Profile, a user can only have one mailing address.

Returns:



64
65
66
67
68
# File 'app/models/va_profile_redis/contact_information.rb', line 64

def mailing_address
  return unless @user.loa3?

  dig_out('addresses', 'address_pou', VAProfile::Models::Address::CORRESPONDENCE)
end

#mobile_phoneVAProfile::Models::Telephone

Returns the user’s mobile phone. In VA Profile, a user can only have one mobile phone.

Returns:



86
87
88
89
90
# File 'app/models/va_profile_redis/contact_information.rb', line 86

def mobile_phone
  return unless @user.loa3?

  dig_out('telephones', 'phone_type', VAProfile::Models::Telephone::MOBILE)
end

#populate_from_redisObject

This method allows us to populate the local instance of a VAProfileRedis::ContactInformation object with the uuid necessary to perform subsequent actions on the key such as deletion.



158
159
160
# File 'app/models/va_profile_redis/contact_information.rb', line 158

def populate_from_redis
  response_from_redis_or_service
end

#residential_addressVAProfile::Models::Address

Returns the user’s residence. In VA Profile, a user can only have one residence address.

Returns:



53
54
55
56
57
# File 'app/models/va_profile_redis/contact_information.rb', line 53

def residential_address
  return unless @user.loa3?

  dig_out('addresses', 'address_pou', VAProfile::Models::Address::RESIDENCE)
end

#responseVAProfile::ContactInformation::PersonResponse

the redis cache. If that is unavailable, it calls the VAProfile::ContactInformation::Service#get_person endpoint.

Returns:



151
152
153
# File 'app/models/va_profile_redis/contact_information.rb', line 151

def response
  @response ||= response_from_redis_or_service
end

#response_from_redis_or_serviceObject (private)



180
181
182
183
184
185
186
# File 'app/models/va_profile_redis/contact_information.rb', line 180

def response_from_redis_or_service
  return contact_info_service.get_person unless VAProfile::Configuration::SETTINGS.contact_information.cache_enabled

  do_cached_with(key: @user.uuid) do
    contact_info_service.get_person
  end
end

#statusInteger <> String

The status of the last VAProfile::ContactInformation::Service response, or not authorized for for users < LOA 3

Returns:

  • (Integer <> String)

    the status of the last VAProfile::ContactInformation::Service response



141
142
143
144
145
# File 'app/models/va_profile_redis/contact_information.rb', line 141

def status
  return VAProfile::ContactInformation::PersonResponse::RESPONSE_STATUS[:not_authorized] unless @user.loa3?

  response.status
end

#temporary_phoneVAProfile::Models::Telephone

Returns the user’s temporary phone. In VA Profile, a user can only have one temporary phone.

Returns:



108
109
110
111
112
# File 'app/models/va_profile_redis/contact_information.rb', line 108

def temporary_phone
  return unless @user.loa3?

  dig_out('telephones', 'phone_type', VAProfile::Models::Telephone::TEMPORARY)
end

#text_permissionVAProfile::Models::Permission

Returns the user’s text permission. In VA Profile, a user can only have one text permission.

Returns:



130
131
132
133
134
# File 'app/models/va_profile_redis/contact_information.rb', line 130

def text_permission
  return unless @user.loa3?

  dig_out('permissions', 'permission_type', VAProfile::Models::Permission::TEXT)
end

#value_for(key) ⇒ Object (private)



164
165
166
167
168
# File 'app/models/va_profile_redis/contact_information.rb', line 164

def value_for(key)
  value = response&.person&.send(key)

  value.presence
end

#work_phoneVAProfile::Models::Telephone

Returns the user’s work phone. In VA Profile, a user can only have one work phone.

Returns:



97
98
99
100
101
# File 'app/models/va_profile_redis/contact_information.rb', line 97

def work_phone
  return unless @user.loa3?

  dig_out('telephones', 'phone_type', VAProfile::Models::Telephone::WORK)
end