Class: VAProfile::Demographics::Service
- Inherits:
-
Service
- Object
- Common::Client::Base
- Service
- VAProfile::Demographics::Service
- Includes:
- Common::Client::Concerns::Monitoring
- Defined in:
- lib/va_profile/demographics/service.rb
Constant Summary collapse
- OID =
'2.16.840.1.113883.4.349'
Constants inherited from Service
Instance Method Summary collapse
- #build_response(status, body) ⇒ Object
-
#get_demographics ⇒ Object
Returns a response object containing the user’s preferred name, and gender-identity.
-
#identity_path(dir = nil) ⇒ Object
VA Profile demographic endpoints use the OID (Organizational Identifier), the CSP ID, and the Assigning Authority ID to identify which person will be updated/retrieved.
- #post_or_put_data(method, model, path, response_class) ⇒ Object
- #response_successful?(response) ⇒ Boolean
-
#save_gender_identity(gender_identity) ⇒ Object
PUTs an updated gender_identity to the VAProfile API.
-
#save_preferred_name(preferred_name) ⇒ Object
PUTs an updated preferred_name to the VAProfile API.
Methods included from Common::Client::Concerns::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
Instance Method Details
#build_response(status, body) ⇒ Object
84 85 86 87 88 89 90 91 92 93 |
# File 'lib/va_profile/demographics/service.rb', line 84 def build_response(status, body) DemographicResponse.from( status:, body:, id: @user.account_id, type: 'mvi_models_mvi_profiles', gender: @user.gender_mpi, birth_date: @user.birth_date_mpi ) end |
#get_demographics ⇒ Object
Returns a response object containing the user’s preferred name, and gender-identity
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/va_profile/demographics/service.rb', line 20 def get_demographics with_monitoring do return build_response(401, nil) unless DemographicsPolicy.new(@user).access_update? response = perform(:get, identity_path) build_response(response&.status, response&.body) end rescue Common::Client::Errors::ClientError => e if e.status == 404 log_exception_to_sentry( e, { csp_id_with_aaid: }, { va_profile: :demographics_not_found }, :warning ) return build_response(404, nil) elsif e.status >= 400 && e.status < 500 return build_response(e.status, nil) end handle_error(e) rescue => e handle_error(e) end |
#identity_path(dir = nil) ⇒ Object
VA Profile demographic endpoints use the OID (Organizational Identifier), the CSP ID, and the Assigning Authority ID to identify which person will be updated/retrieved.
79 80 81 82 |
# File 'lib/va_profile/demographics/service.rb', line 79 def identity_path(dir = nil) path = "#{OID}/#{ERB::Util.url_encode(csp_id_with_aaid.to_s)}" dir ? "#{path}/#{dir}" : path end |
#post_or_put_data(method, model, path, response_class) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/va_profile/demographics/service.rb', line 58 def post_or_put_data(method, model, path, response_class) with_monitoring do raise 'User does not have a valid CSP ID' unless DemographicsPolicy.new(@user).access_update? model.set_defaults(@user) response = perform(method, identity_path(path), model.in_json) return response_class.new(200, "#{model.model_name.element}": model) if response_successful?(response) response_class.from(response) end rescue => e handle_error(e) end |
#response_successful?(response) ⇒ Boolean
73 74 75 |
# File 'lib/va_profile/demographics/service.rb', line 73 def response_successful?(response) response&.status == 200 && response&.body == {} end |
#save_gender_identity(gender_identity) ⇒ Object
PUTs an updated gender_identity to the VAProfile API
54 55 56 |
# File 'lib/va_profile/demographics/service.rb', line 54 def save_gender_identity(gender_identity) post_or_put_data(:post, gender_identity, 'gender-identity', GenderIdentityResponse) end |
#save_preferred_name(preferred_name) ⇒ Object
PUTs an updated preferred_name to the VAProfile API
48 49 50 |
# File 'lib/va_profile/demographics/service.rb', line 48 def save_preferred_name(preferred_name) post_or_put_data(:post, preferred_name, 'preferred-name', PreferredNameResponse) end |