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.
Constant Summary collapse
- ATTRIBUTE_MAP =
[ [:name, :name], [:address, :street], [:address2, :street2], [:city, :city], [:region, :region], [:state, :state], [:postal_code, :postal_code], [:country, :country] ]
Instance Attribute Summary collapse
-
#address_type ⇒ Object
:nodoc:.
-
#city ⇒ Object
:nodoc:.
-
#country ⇒ Object
:nodoc:.
-
#name ⇒ Object
:nodoc:.
-
#postal_code ⇒ Object
:nodoc:.
-
#region ⇒ Object
:nodoc:.
-
#state ⇒ Object
:nodoc:.
-
#street ⇒ Object
:nodoc:.
-
#street2 ⇒ Object
:nodoc:.
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
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/paytrace/address.rb', line 31 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
:nodoc:
7 8 9 |
# File 'lib/paytrace/address.rb', line 7 def address_type @address_type end |
#city ⇒ Object
:nodoc:
7 8 9 |
# File 'lib/paytrace/address.rb', line 7 def city @city end |
#country ⇒ Object
:nodoc:
7 8 9 |
# File 'lib/paytrace/address.rb', line 7 def country @country end |
#name ⇒ Object
:nodoc:
7 8 9 |
# File 'lib/paytrace/address.rb', line 7 def name @name end |
#postal_code ⇒ Object
:nodoc:
7 8 9 |
# File 'lib/paytrace/address.rb', line 7 def postal_code @postal_code end |
#region ⇒ Object
:nodoc:
7 8 9 |
# File 'lib/paytrace/address.rb', line 7 def region @region end |
#state ⇒ Object
:nodoc:
7 8 9 |
# File 'lib/paytrace/address.rb', line 7 def state @state end |
#street ⇒ Object
:nodoc:
7 8 9 |
# File 'lib/paytrace/address.rb', line 7 def street @street end |
#street2 ⇒ Object
:nodoc:
7 8 9 |
# File 'lib/paytrace/address.rb', line 7 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
46 47 48 49 50 51 52 53 |
# File 'lib/paytrace/address.rb', line 46 def set_request(request) ATTRIBUTE_MAP.each do |request_name, attribute_name| unless request_name == :region && address_type == :billing # special case # this is ugly, but it saves us from subclassing just to change field names in a predictable way... request.set_param("#{address_type.to_s}_#{request_name}".to_sym, self.send(attribute_name)) end end end |