Skip to content

Commit

Permalink
Support optionally marking address as residential
Browse files Browse the repository at this point in the history
  • Loading branch information
cgunther committed Jul 21, 2022
1 parent d2878fd commit 3be456d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/ups/builders/address_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class AddressBuilder < BuilderBase
# @option opts [String] :state State
# @option opts [String] :postal_code Zip or Postal Code
# @option opts [String] :country Country
# @option opts [Boolean] :residential_address Whether destination is considered residential
# @raise [InvalidAttributeError] If the passed :state is nil or an
# empty string and the :country is IE
def initialize(opts = {})
Expand Down Expand Up @@ -132,6 +133,7 @@ def to_xml
address << state
address << postal_code
address << country
address << Element.new('ResidentialAddress') if opts[:residential_address]
end
end
end
Expand Down
14 changes: 14 additions & 0 deletions spec/ups/builders/address_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,18 @@
end
end
end

describe 'residential address' do
it 'is not a residential address by default' do
address = UPS::Builders::AddressBuilder.new(address_line_1: 'Googleplex', city: 'Mountain View', state: 'California', postal_code: '94043', country: 'US')

expect(address.to_xml.locate('ResidentialAddress')).must_equal([])
end

it 'is indicates when specified as a residential address' do
address = UPS::Builders::AddressBuilder.new(address_line_1: 'Googleplex', city: 'Mountain View', state: 'California', postal_code: '94043', country: 'US', residential_address: true)

expect(address.to_xml.locate('ResidentialAddress')).wont_equal([])
end
end
end

0 comments on commit 3be456d

Please sign in to comment.