Skip to content
This repository has been archived by the owner on Jun 13, 2018. It is now read-only.

adds address validation to usps.rb #410

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

adds address validation to usps.rb #410

wants to merge 11 commits into from

Conversation

pborel
Copy link
Contributor

@pborel pborel commented Nov 9, 2016

To do:

  1. add AddressStandarizationResponse class
  2. add tests

@pborel
Copy link
Contributor Author

pborel commented Nov 9, 2016

This PR is related to issue #409

Copy link
Contributor

@jonathankwok jonathankwok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this feature, @pborel! I understand it's an MVP but it looks like you're on the right track here. After addressing some of the comments, I'd love to see some tests verifying the expected behaviour, as well.

Great work thus far ⭐️ !

xml.AddressValidateRequest('USERID' => @options[:login]) do
xml.IncludeOptionalElements(true)
xml.ReturnCarrierRoute(true)
Array(addresses).each_with_index do |address, id|
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe you need to wrap addresses in an Array() constructor; do we anticipate it ever being not-Array-like?


if success
addresses = Hash.from_xml(response)["AddressValidateResponse"]["Address"]
if addresses.is_a?(Array)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took a look at the response, you should be able to do this to avoid the Array check entirely:

locations = [addresses].flatten.map do |address|
  Location.new(#etc etc)
end

def parse_address_standardize_response(response, addresses, options = {})
success = true
message = ''
address_hash = {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks unused to me.

success = true
message = ''
address_hash = {}
locations = []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you use the map assignment suggestion below, you won't need to initialize an empty array variable.

Array(addresses).each_with_index do |address, id|
xml.Address('ID' => id) do
xml.FirmName(address[:firm_name])
xml.Address1(address[:address1])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the documentation, it looks like Address1 and Address2 are flipped for USPS.

image

We use Address1 as the street address in ActiveShipping but USPS uses it as the suite number, with Address2 being their street address.

# The correct addresses returned from USPS
class AddressStandardizationResponse < Response

attr_reader :locations
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll need an attr_reader for :addresses too.


attr_reader :locations

# Initializes a new AddressStandarizationResponse instance.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation a little off here.

# @param success (see ActiveShipping::Response#initialize)
# @param message (see ActiveShipping::Response#initialize)
# @param params (see ActiveShipping::Response#initialize)
# @option options (see ActiveShipping::Response#initialize)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super
end
end
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A newline is preferred at the end of all files.

@maartenvg maartenvg force-pushed the master branch 2 times, most recently from 6eca161 to 20da555 Compare November 9, 2017 21:10
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants