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

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
36
# 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

#emailVAProfile::Models::Email

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

Returns:



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

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:



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

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:



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

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:



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

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:



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

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.



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

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:



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

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:



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

def response
  @response ||= response_from_redis_or_service
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



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

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:



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

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:



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

def text_permission
  return unless @user.loa3?

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

#work_phoneVAProfile::Models::Telephone

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

Returns:



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

def work_phone
  return unless @user.loa3?

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