Class: AddressValidator::Validator
- Inherits:
-
Object
- Object
- AddressValidator::Validator
- Defined in:
- lib/address_validator/validator.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #build_address(attrs) ⇒ Object
- #build_request(address) ⇒ Object
-
#initialize ⇒ Validator
constructor
A new instance of Validator.
- #validate(address) ⇒ Object
Constructor Details
#initialize ⇒ Validator
Returns a new instance of Validator.
7 8 9 |
# File 'lib/address_validator/validator.rb', line 7 def initialize @client = Client.new end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
5 6 7 |
# File 'lib/address_validator/validator.rb', line 5 def client @client end |
Instance Method Details
#build_address(attrs) ⇒ Object
20 21 22 |
# File 'lib/address_validator/validator.rb', line 20 def build_address(attrs) AddressValidator::Address.new(attrs) end |
#build_request(address) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/address_validator/validator.rb', line 24 def build_request(address) xml = Builder::XmlMarkup.new xml.instruct! xml.AddressValidationRequest do xml.Request do xml.RequestAction 'XAV' # must be XAV xml.RequestOption '3' # validation + classification end xml.MaximumListSize('1') xml << address.to_xml end xml.target! end |
#validate(address) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/address_validator/validator.rb', line 11 def validate(address) if address.is_a?(::Hash) address = build_address(address) end request = build_request(address) @client.post(request) end |