Class: Preneeds::Service
- Inherits:
-
Common::Client::Base
- Object
- Common::Client::Base
- Preneeds::Service
- Includes:
- Common::Client::Concerns::Monitoring
- Defined in:
- lib/preneeds/service.rb
Overview
Proxy Service for the EOAS (Eligibility Office Automation System) Service’s PreNeed Applications endpoints. Requests are SOAP format, and the request bodies are built using the ‘Savon` gem, The `Mail` gem is used to generate attachments for the #receive_pre_need_application method. The actual submission of requests is facilitated using methods defined in the Common::Client::Base parent class.
Constant Summary collapse
- STATSD_KEY_PREFIX =
Prefix string for StatsD monitoring
'api.preneeds'
- STARTING_CID =
Used in building SOAP request
'<soap-request-body@soap>'
Instance Method Summary collapse
-
#build_body_and_headers(soap, burial_form) ⇒ Hash
private
Builds SOAP body and headers for #receive_pre_need_application.
-
#build_multipart(soap, attachments) ⇒ Mail::Message
private
Builds SOAP attachments for #receive_pre_need_application.
-
#get_cemeteries ⇒ Common::Collection<Preneeds::Cemetery>
POST to retrieve military cemeteries.
-
#receive_pre_need_application(burial_form) ⇒ Preneeds::ReceiveApplication
POST to submit a BurialForm.
-
#savon_client ⇒ Savon::Client
private
Savon client for building SOAP request; initialized with PreNeeds WSDL.
Methods included from Common::Client::Concerns::Monitoring
#increment, #increment_failure, #increment_total, #with_monitoring
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
Instance Method Details
#build_body_and_headers(soap, burial_form) ⇒ Hash (private)
Builds SOAP body and headers for #receive_pre_need_application
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/preneeds/service.rb', line 67 def build_body_and_headers(soap, burial_form) headers = {} body = if burial_form. multipart = build_multipart(soap, burial_form.) multipart.header.fields.each do |field| headers[field.name] = field.to_s end headers['Content-Type'] = 'multipart/related; ' \ "boundary=\"#{multipart.boundary}\"; " \ "type=\"application/xop+xml\"; start=\"#{STARTING_CID}\"; " \ 'start-info="text/xml"' multipart.body.encoded else soap.body end { body:, headers: } end |
#build_multipart(soap, attachments) ⇒ Mail::Message (private)
Builds SOAP attachments for #receive_pre_need_application
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/preneeds/service.rb', line 101 def build_multipart(soap, ) multipart = Mail.new soap_part = Mail::Part.new do content_type 'application/xop+xml; charset=UTF-8; type="text/xml"' body soap.body content_id STARTING_CID end multipart.add_part(soap_part) .each do || file = .file multipart.add_file( filename: .name, content: file.read ) part = multipart.parts.last part.content_id("<#{.data_handler}>") part.content_type(file.content_type) end multipart end |
#get_cemeteries ⇒ Common::Collection<Preneeds::Cemetery>
POST to retrieve military cemeteries
27 28 29 30 31 32 |
# File 'lib/preneeds/service.rb', line 27 def get_cemeteries soap = savon_client.build_request(:get_cemeteries, message: {}) json = with_monitoring { perform(:post, '', soap.body).body } Common::Collection.new(Cemetery, **json) end |
#receive_pre_need_application(burial_form) ⇒ Preneeds::ReceiveApplication
POST to submit a BurialForm
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/preneeds/service.rb', line 39 def receive_pre_need_application(burial_form) tracking_number = burial_form.tracking_number soap = savon_client.build_request( :receive_pre_need_application, message: { pre_need_request: burial_form.as_eoas } ) body_and_headers = build_body_and_headers(soap, burial_form) json = with_monitoring { perform(:post, '', body_and_headers[:body], body_and_headers[:headers]).body } Sentry.set_extras(response: json) json = json[:data].merge('tracking_number' => tracking_number) ReceiveApplication.new(json) end |
#savon_client ⇒ Savon::Client (private)
Savon client for building SOAP request; initialized with PreNeeds WSDL
132 133 134 |
# File 'lib/preneeds/service.rb', line 132 def savon_client @savon ||= Savon.client(wsdl: Settings.preneeds.wsdl) end |