Class: VAProfile::Person::Service

Inherits:
Service show all
Includes:
Common::Client::Concerns::Monitoring, ERB::Util
Defined in:
lib/va_profile/person/service.rb

Constant Summary collapse

STATSD_KEY_PREFIX =
"#{VAProfile::Service::STATSD_KEY_PREFIX}.person".freeze

Instance Method Summary collapse

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

#increment, #increment_failure, #increment_total, #with_monitoring

Methods inherited from Service

breakers_service, #final_failure?, #handle_error, #initialize, #log_dates, #parse_messages, #perform, #person_transaction?, #person_transaction_failure?, #raise_backend_exception, #raise_invalid_body, #report_stats_on, #save_error_details

Methods inherited from Common::Client::Base

#config, configuration, #connection, #delete, #get, #perform, #post, #put, #raise_backend_exception, #raise_not_authenticated, #request, #sanitize_headers!, #service_name

Methods included from SentryLogging

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

Constructor Details

This class inherits a constructor from VAProfile::Service

Instance Method Details

#build_icn_with_aaid!(icn) ⇒ Object (private)



46
47
48
49
50
51
52
53
54
# File 'lib/va_profile/person/service.rb', line 46

def build_icn_with_aaid!(icn)
  if icn.present?
    "#{icn}#{Identity::Parsers::GCIdsConstants::ICN_ASSIGNING_AUTHORITY_ID}"
  elsif @user&.icn_with_aaid.present?
    @user.icn_with_aaid
  else
    raise 'User does not have a valid ICN with an Assigning Authority ID'
  end
end

#empty_bodyObject (private)



56
57
58
59
60
61
62
# File 'lib/va_profile/person/service.rb', line 56

def empty_body
  {
    bio: {
      sourceDate: Time.zone.now.iso8601
    }
  }.to_json
end

#encode_url!(icn) ⇒ Object (private)



40
41
42
43
44
# File 'lib/va_profile/person/service.rb', line 40

def encode_url!(icn)
  encoded_icn_with_aaid = url_encode(build_icn_with_aaid!(icn))

  "#{Identity::Parsers::GCIdsConstants::VA_ROOT_OID}/#{encoded_icn_with_aaid}"
end

#init_vet360_id(icn = nil) ⇒ VAProfile::ContactInformation::PersonTransactionResponse

Initializes a vet360_id for a user that does not have one. Can be used when a current user is present, or through a rake task when no user is present (through passing in their ICN). This is an asynchronous process for VAProfile, so it returns VAProfile transaction information.

Parameters:

  • icn (String) (defaults to: nil)

    A users ICN. Only required when current user is absent. Intended to be used in a rake task.

Returns:



27
28
29
30
31
32
33
34
# File 'lib/va_profile/person/service.rb', line 27

def init_vet360_id(icn = nil)
  with_monitoring do
    raw_response = perform(:post, encode_url!(icn), empty_body)
    VAProfile::ContactInformation::PersonTransactionResponse.from(raw_response, @user)
  end
rescue => e
  handle_error(e)
end