Class: VAProfileRedis::V2::ContactInformation
- Inherits:
-
Common::RedisStore
- Object
- Common::RedisStore
- VAProfileRedis::V2::ContactInformation
- Includes:
- Common::CacheAside
- Defined in:
- app/models/va_profile_redis/v2/contact_information.rb
Constant Summary
Constants inherited from Common::RedisStore
Common::RedisStore::REQ_CLASS_INSTANCE_VARS
Instance Attribute Summary collapse
-
#user ⇒ User
The user being queried in VA Profile.
Class Method Summary collapse
Instance Method Summary collapse
- #contact_info_service ⇒ Object private
- #dig_out(key, type, matcher) ⇒ Object private
-
#email ⇒ VAProfile::Models::Email
Returns the user’s email model.
-
#fax_number ⇒ VAProfile::Models::Telephone
Returns the user’s fax number.
-
#home_phone ⇒ VAProfile::Models::Telephone
Returns the user’s home phone.
-
#mailing_address ⇒ VAProfile::Models::Address
Returns the user’s mailing address.
-
#mobile_phone ⇒ VAProfile::Models::Telephone
Returns the user’s mobile phone.
-
#populate_from_redis ⇒ Object
This method allows us to populate the local instance of a VAProfileRedis::V2::ContactInformation object with the uuid necessary to perform subsequent actions on the key such as deletion.
-
#residential_address ⇒ VAProfile::Models::Address
Returns the user’s residence.
-
#response ⇒ VAProfile::ContactInformation::PersonResponse
the redis cache.
- #response_from_redis_or_service ⇒ Object private
-
#status ⇒ Integer <> String
The status of the last VAProfile::V2::ContactInformation::Service response, or not authorized for for users < LOA 3.
-
#temporary_phone ⇒ VAProfile::Models::Telephone
Returns the user’s temporary phone.
- #value_for(key) ⇒ Object private
-
#work_phone ⇒ VAProfile::Models::Telephone
Returns the user’s work phone.
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
#user ⇒ User
Returns the user being queried in VA Profile.
28 29 30 |
# File 'app/models/va_profile_redis/v2/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/v2/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_service ⇒ Object (private)
179 180 181 |
# File 'app/models/va_profile_redis/v2/contact_information.rb', line 179 def contact_info_service @service ||= VAProfile::V2::ContactInformation::Service.new @user end |
#dig_out(key, type, matcher) ⇒ Object (private)
159 160 161 162 163 164 165 166 167 |
# File 'app/models/va_profile_redis/v2/contact_information.rb', line 159 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 |
#email ⇒ VAProfile::Models::Email
Returns the user’s email model. In VA Profile, a user can only have one email address.
42 43 44 45 46 |
# File 'app/models/va_profile_redis/v2/contact_information.rb', line 42 def email return unless @user.loa3? value_for('emails')&.first end |
#fax_number ⇒ VAProfile::Models::Telephone
Returns the user’s fax number. In VA Profile, a user can only have one fax number.
119 120 121 122 123 |
# File 'app/models/va_profile_redis/v2/contact_information.rb', line 119 def fax_number return unless @user.loa3? dig_out('telephones', 'phone_type', VAProfile::Models::Telephone::FAX) end |
#home_phone ⇒ VAProfile::Models::Telephone
Returns the user’s home phone. In VA Profile, a user can only have one home phone.
75 76 77 78 79 |
# File 'app/models/va_profile_redis/v2/contact_information.rb', line 75 def home_phone return unless @user.loa3? dig_out('telephones', 'phone_type', VAProfile::Models::Telephone::HOME) end |
#mailing_address ⇒ VAProfile::Models::Address
Returns the user’s mailing address. In VA Profile, a user can only have one mailing address.
64 65 66 67 68 |
# File 'app/models/va_profile_redis/v2/contact_information.rb', line 64 def mailing_address return unless @user.loa3? dig_out('addresses', 'address_pou', VAProfile::Models::V3::Address::CORRESPONDENCE) end |
#mobile_phone ⇒ VAProfile::Models::Telephone
Returns the user’s mobile phone. In VA Profile, a user can only have one mobile phone.
86 87 88 89 90 |
# File 'app/models/va_profile_redis/v2/contact_information.rb', line 86 def mobile_phone return unless @user.loa3? dig_out('telephones', 'phone_type', VAProfile::Models::Telephone::MOBILE) end |
#populate_from_redis ⇒ Object
This method allows us to populate the local instance of a VAProfileRedis::V2::ContactInformation object with the uuid necessary to perform subsequent actions on the key such as deletion.
147 148 149 |
# File 'app/models/va_profile_redis/v2/contact_information.rb', line 147 def populate_from_redis response_from_redis_or_service end |
#residential_address ⇒ VAProfile::Models::Address
Returns the user’s residence. In VA Profile, a user can only have one residence address.
53 54 55 56 57 |
# File 'app/models/va_profile_redis/v2/contact_information.rb', line 53 def residential_address return unless @user.loa3? dig_out('addresses', 'address_pou', VAProfile::Models::V3::Address::RESIDENCE) end |
#response ⇒ VAProfile::ContactInformation::PersonResponse
the redis cache. If that is unavailable, it calls the VAProfile::V2::ContactInformation::Service#get_person endpoint.
140 141 142 |
# File 'app/models/va_profile_redis/v2/contact_information.rb', line 140 def response @response ||= response_from_redis_or_service end |
#response_from_redis_or_service ⇒ Object (private)
169 170 171 172 173 174 175 176 177 |
# File 'app/models/va_profile_redis/v2/contact_information.rb', line 169 def response_from_redis_or_service unless VAProfile::Configuration::SETTINGS.contact_information.cache_enabled return contact_info_service.get_person end do_cached_with(key: @user.uuid) do contact_info_service.get_person end end |
#status ⇒ Integer <> String
The status of the last VAProfile::V2::ContactInformation::Service response, or not authorized for for users < LOA 3
130 131 132 133 134 |
# File 'app/models/va_profile_redis/v2/contact_information.rb', line 130 def status return VAProfile::V2::ContactInformation::PersonResponse::RESPONSE_STATUS[:not_authorized] unless @user.loa3? response.status end |
#temporary_phone ⇒ VAProfile::Models::Telephone
Returns the user’s temporary phone. In VA Profile, a user can only have one temporary phone.
108 109 110 111 112 |
# File 'app/models/va_profile_redis/v2/contact_information.rb', line 108 def temporary_phone return unless @user.loa3? dig_out('telephones', 'phone_type', VAProfile::Models::Telephone::TEMPORARY) end |
#value_for(key) ⇒ Object (private)
153 154 155 156 157 |
# File 'app/models/va_profile_redis/v2/contact_information.rb', line 153 def value_for(key) value = response&.person&.send(key) value.presence end |
#work_phone ⇒ VAProfile::Models::Telephone
Returns the user’s work phone. In VA Profile, a user can only have one work phone.
97 98 99 100 101 |
# File 'app/models/va_profile_redis/v2/contact_information.rb', line 97 def work_phone return unless @user.loa3? dig_out('telephones', 'phone_type', VAProfile::Models::Telephone::WORK) end |