Class: PayTrace::Address
- Inherits:
-
Object
- Object
- PayTrace::Address
- Defined in:
- lib/paytrace/address.rb
Overview
Abstracts an address – two types are possible, shipping and billing. Note: the “region” parameter can only be defined for shipping addresses, and the default address type (if unspecified) is billing.
Instance Attribute Summary collapse
-
#address_type ⇒ Object
Returns the value of attribute address_type.
-
#city ⇒ Object
Returns the value of attribute city.
-
#country ⇒ Object
Returns the value of attribute country.
-
#name ⇒ Object
Returns the value of attribute name.
-
#postal_code ⇒ Object
Returns the value of attribute postal_code.
-
#region ⇒ Object
Returns the value of attribute region.
-
#state ⇒ Object
Returns the value of attribute state.
-
#street ⇒ Object
Returns the value of attribute street.
-
#street2 ⇒ Object
Returns the value of attribute street2.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Address
constructor
Initialize a new address instance.
-
#set_request(request) ⇒ Object
Applies the address parameters to a request object for proper formatting to the API Parameters: * request – the request object to apply this address to.
Constructor Details
#initialize(options = {}) ⇒ Address
Initialize a new address instance. Parameters are symbolic keys in a hash. They are:
-
:name – the name on this address
-
:street – the street address
-
:street2 – an optional second line of street address (apartment, suite, etc.)
-
:city – the city
-
:state – the state
-
:country – the country
-
:postal_code – the postal/zip code
-
:address_type – either :billing or :shipping
-
:region – the region (often county); note, only used for shipping addresses, ignored for billing addresses
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/paytrace/address.rb', line 18 def initialize(={}) @name = [:name] @street = [:street] @street2 = [:street2] @city = [:city] @state = [:state] @country = [:country] @postal_code = [:postal_code ] @address_type = [:address_type] || :billing @region = [:region] if @address_type == :shipping # special case for shipping addresses end |
Instance Attribute Details
#address_type ⇒ Object
Returns the value of attribute address_type.
6 7 8 |
# File 'lib/paytrace/address.rb', line 6 def address_type @address_type end |
#city ⇒ Object
Returns the value of attribute city.
6 7 8 |
# File 'lib/paytrace/address.rb', line 6 def city @city end |
#country ⇒ Object
Returns the value of attribute country.
6 7 8 |
# File 'lib/paytrace/address.rb', line 6 def country @country end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/paytrace/address.rb', line 6 def name @name end |
#postal_code ⇒ Object
Returns the value of attribute postal_code.
6 7 8 |
# File 'lib/paytrace/address.rb', line 6 def postal_code @postal_code end |
#region ⇒ Object
Returns the value of attribute region.
6 7 8 |
# File 'lib/paytrace/address.rb', line 6 def region @region end |
#state ⇒ Object
Returns the value of attribute state.
6 7 8 |
# File 'lib/paytrace/address.rb', line 6 def state @state end |
#street ⇒ Object
Returns the value of attribute street.
6 7 8 |
# File 'lib/paytrace/address.rb', line 6 def street @street end |
#street2 ⇒ Object
Returns the value of attribute street2.
6 7 8 |
# File 'lib/paytrace/address.rb', line 6 def street2 @street2 end |
Instance Method Details
#set_request(request) ⇒ Object
Applies the address parameters to a request object for proper formatting to the API Parameters:
-
request – the request object to apply this address to
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/paytrace/address.rb', line 33 def set_request(request) atype_str = address_type.to_s request.set_param(:"#{atype_str}_name", name) if name request.set_param(:"#{atype_str}_address", street) if street request.set_param(:"#{atype_str}_address2", street2) if street2 request.set_param(:"#{atype_str}_city", city) if city request.set_param(:"#{atype_str}_region", region) if region request.set_param(:"#{atype_str}_state", state) if state request.set_param(:"#{atype_str}_postal_code", postal_code) if postal_code request.set_param(:"#{atype_str}_country", country) if country end |