-
Notifications
You must be signed in to change notification settings - Fork 167
Use a shared struct for address proofing results #7097
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| module Proofing | ||
| class AddressResult | ||
| attr_reader :success, :errors, :exception, :vendor_name, :transaction_id, :reference | ||
|
|
||
| def initialize( | ||
| success:, | ||
| errors:, | ||
| exception:, | ||
| vendor_name:, | ||
| transaction_id: '', | ||
| reference: '' | ||
| ) | ||
| @success = success | ||
| @errors = errors | ||
| @exception = exception | ||
| @vendor_name = vendor_name | ||
| @transaction_id = transaction_id | ||
| @reference = reference | ||
| end | ||
|
|
||
| def success? | ||
| success | ||
| end | ||
|
|
||
| def timed_out? | ||
| exception.is_a?(Proofing::TimeoutError) | ||
| end | ||
|
|
||
| def to_h | ||
| { | ||
| exception: exception, | ||
| errors: errors, | ||
| success: success?, | ||
| timed_out: timed_out?, | ||
| transaction_id: transaction_id, | ||
| reference: reference, | ||
| vendor_name: vendor_name, | ||
| } | ||
| end | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,10 +10,36 @@ def initialize(config) | |
|
|
||
| def proof(applicant) | ||
| response = VerificationRequest.new(config: config, applicant: applicant).send | ||
| return Proofing::LexisNexis::PhoneFinder::Result.new(response) | ||
| return build_result_from_response(response) | ||
| rescue => exception | ||
| NewRelic::Agent.notice_error(exception) | ||
| ResultWithException.new(exception, vendor_name: 'lexisnexis:phone_finder') | ||
| AddressResult.new( | ||
| success: false, | ||
| errors: {}, | ||
| exception: exception, | ||
| vendor_name: 'lexisnexis:phone_finder', | ||
| ) | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def build_result_from_response(verification_response) | ||
| AddressResult.new( | ||
| success: verification_response.verification_status == 'passed', | ||
| errors: parse_verification_errors(verification_response), | ||
| exception: nil, | ||
| vendor_name: 'lexisnexis:phone_finder', | ||
| transaction_id: verification_response.conversation_id, | ||
| reference: verification_response.reference, | ||
| ) | ||
| end | ||
|
|
||
| def parse_verification_errors(verification_response) | ||
| errors = Hash.new { |h, k| h[k] = [] } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i see you 😍
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you learn something new every day |
||
| verification_response.verification_errors.each do |key, value| | ||
| errors[key] << value | ||
| end | ||
| errors | ||
| end | ||
| end | ||
| end | ||
|
|
||
This file was deleted.
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe easier to default reference to nil than empty string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just trying to keep reference consistent with transaction_id
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand the reasoning for making it nil vs empty string? I think all we do is log it and the result is the same in the end, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess
nilto me is a more real "isn't there" vs some sort of default from empty string, but you're right, for most situations they're the same