Skip to content

Commit 6e52aff

Browse files
committed
Support optionally marking address as residential
1 parent d4de7cc commit 6e52aff

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/ups/builders/address_builder.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class AddressBuilder < BuilderBase
2020
# @option opts [String] :state State
2121
# @option opts [String] :postal_code Zip or Postal Code
2222
# @option opts [String] :country Country
23+
# @option opts [Boolean] :residential_address Whether destination is considered residential
2324
# @raise [InvalidAttributeError] If the passed :state is nil or an
2425
# empty string and the :country is IE
2526
def initialize(opts = {})
@@ -132,6 +133,7 @@ def to_xml
132133
address << state
133134
address << postal_code
134135
address << country
136+
address << Element.new('ResidentialAddress') if opts[:residential_address]
135137
end
136138
end
137139
end

spec/ups/builders/address_builder_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,18 @@
114114
end
115115
end
116116
end
117+
118+
describe 'residential address' do
119+
it 'is not a residential address by default' do
120+
address = UPS::Builders::AddressBuilder.new(address_line_1: 'Googleplex', city: 'Mountain View', state: 'California', postal_code: '94043', country: 'US')
121+
122+
expect(address.to_xml.locate('ResidentialAddress')).must_equal([])
123+
end
124+
125+
it 'is indicates when specified as a residential address' do
126+
address = UPS::Builders::AddressBuilder.new(address_line_1: 'Googleplex', city: 'Mountain View', state: 'California', postal_code: '94043', country: 'US', residential_address: true)
127+
128+
expect(address.to_xml.locate('ResidentialAddress')).wont_equal([])
129+
end
130+
end
117131
end

0 commit comments

Comments
 (0)