Class: LGY::Service
- Inherits:
-
Common::Client::Base
- Object
- Common::Client::Base
- LGY::Service
- Defined in:
- lib/lgy/service.rb
Constant Summary collapse
- STATSD_KEY_PREFIX =
'api.lgy'
- SENTRY_TAG =
{ team: 'vfs-ebenefits' }.freeze
Instance Method Summary collapse
-
#coe_status ⇒ Object
rubocop:disable Metrics/MethodLength.
- #get_application ⇒ Object
- #get_coe_documents ⇒ Object
- #get_coe_file ⇒ Object
-
#get_determination ⇒ Object
rubocop:enable Metrics/MethodLength.
-
#get_document(id) ⇒ Object
It is necessary to fetch a list of the user’s documents and check whether the requested document is within that list, to ensure that a vet cannot access documents belonging to other vets.
-
#initialize(edipi:, icn:) ⇒ Service
constructor
A new instance of Service.
- #pdf_headers ⇒ Object
- #post_document(payload:) ⇒ Object
- #put_application(payload:) ⇒ Object
- #request_headers ⇒ Object
Methods included from SentryLogging
#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger
Methods included from Common::Client::Concerns::Monitoring
Methods inherited from Common::Client::Base
configuration, #raise_backend_exception
Constructor Details
#initialize(edipi:, icn:) ⇒ Service
Returns a new instance of Service.
14 15 16 17 |
# File 'lib/lgy/service.rb', line 14 def initialize(edipi:, icn:) @edipi = edipi @icn = icn end |
Instance Method Details
#coe_status ⇒ Object
rubocop:disable Metrics/MethodLength
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 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/lgy/service.rb', line 20 def coe_status if get_determination.body['status'] == 'ELIGIBLE' && get_application.status == 404 { status: 'ELIGIBLE', reference_number: get_determination.body['reference_number'] } elsif get_determination.body['status'] == 'UNABLE_TO_DETERMINE_AUTOMATICALLY' { status: 'UNABLE_TO_DETERMINE_AUTOMATICALLY', reference_number: get_determination.body['reference_number'] } elsif get_determination.body['status'] == 'ELIGIBLE' && get_application.status == 200 { status: 'AVAILABLE', application_create_date: get_application.body['create_date'], reference_number: get_determination.body['reference_number'] } elsif get_determination.body['status'] == 'NOT_ELIGIBLE' { status: 'DENIED', application_create_date: get_determination.body['determination_date'], reference_number: get_determination.body['reference_number'] } elsif get_determination.body['status'] == 'PENDING' && get_application.status == 404 # Kelli said we'll never having a pending status w/o an application, but LGY sqa data is getting hand crafted { status: 'PENDING', reference_number: get_determination.body['reference_number'] } elsif get_determination.body['status'] == 'PENDING' && get_application.body['status'] == 'SUBMITTED' # SUBMITTED & RECEIVED ARE COMBINED ON LGY SIDE { status: 'PENDING', application_create_date: get_application.body['create_date'], reference_number: get_determination.body['reference_number'] } elsif get_determination.body['status'] == 'PENDING' && get_application.body['status'] == 'RETURNED' { status: 'PENDING_UPLOAD', application_create_date: get_application.body['create_date'], reference_number: get_determination.body['reference_number'] } else ( 'Unexpected COE statuses!', :error, { determination_status: get_determination.body['status'], application_status: get_application.body['status'], get_application_status: get_application.status }, { team: 'vfs-ebenefits' } ) nil end end |
#get_application ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/lgy/service.rb', line 68 def get_application @get_application ||= with_monitoring do perform( :get, "#{end_point}/application", { 'edipi' => @edipi, 'icn' => @icn }, request_headers ) end rescue Common::Client::Errors::ClientError => e # if the Veteran is automatically approved, LGY will return a 404 (no application exists) return e if e.status == 404 raise e end |
#get_coe_documents ⇒ Object
133 134 135 136 137 138 139 140 141 142 |
# File 'lib/lgy/service.rb', line 133 def get_coe_documents with_monitoring do perform( :get, "#{end_point}/documents", { 'edipi' => @edipi, 'icn' => @icn }, request_headers ) end end |
#get_coe_file ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/lgy/service.rb', line 104 def get_coe_file with_monitoring do perform( :get, "#{end_point}/documents/coe/file", { 'edipi' => @edipi, 'icn' => @icn }, request_headers.merge(pdf_headers) ) end rescue Common::Client::Errors::ClientError => e # a 404 is expected if no COE is available return e if e.status == 404 raise e end |
#get_determination ⇒ Object
rubocop:enable Metrics/MethodLength
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/lgy/service.rb', line 57 def get_determination @get_determination ||= with_monitoring do perform( :get, "#{end_point}/determination", { 'edipi' => @edipi, 'icn' => @icn }, request_headers ) end end |
#get_document(id) ⇒ Object
It is necessary to fetch a list of the user’s documents and check whether the requested document is within that list, to ensure that a vet cannot access documents belonging to other vets. LGY does not have a similar validation on their end.
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/lgy/service.rb', line 148 def get_document(id) with_monitoring do document_ids = get_coe_documents.body.map { |doc| doc['id'].to_s } if document_ids.include?(id) perform( :get, "#{end_point}/document/#{id}/file", { 'edipi' => @edipi, 'icn' => @icn }, request_headers.merge(pdf_headers) ) else raise Common::Exceptions::RecordNotFound, id end end end |
#pdf_headers ⇒ Object
170 171 172 173 174 |
# File 'lib/lgy/service.rb', line 170 def pdf_headers { 'Accept' => 'application/octet-stream', 'Content-Type' => 'application/octet-stream' } end |
#post_document(payload:) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/lgy/service.rb', line 120 def post_document(payload:) with_monitoring do perform( :post, "#{end_point}/document?edipi=#{@edipi}&icn=#{@icn}", payload.to_json, request_headers ) end rescue Common::Client::Errors::ClientError => e raise e end |
#put_application(payload:) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/lgy/service.rb', line 84 def put_application(payload:) with_monitoring do response = perform( :put, "#{end_point}/application?edipi=#{@edipi}&icn=#{@icn}", payload.to_json, request_headers ) response.body end rescue Common::Client::Errors::ClientError => e ( "COE application submission failed with http status: #{e.status}", :error, { message: e., status: e.status, body: e.body }, { team: 'vfs-ebenefits' } ) raise e end |
#request_headers ⇒ Object
164 165 166 167 168 |
# File 'lib/lgy/service.rb', line 164 def request_headers { Authorization: "api-key { \"appId\":\"#{Settings.lgy.app_id}\", \"apiKey\": \"#{Settings.lgy.api_key}\"}" } end |