Class: PaysonAPI::ShippingAddress

Inherits:
Object
  • Object
show all
Defined in:
lib/payson_api/shipping_address.rb

Constant Summary collapse

FORMAT_STRING =
"shippingAddress.%s"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, street_address, postal_code, city, country) ⇒ ShippingAddress

Returns a new instance of ShippingAddress.



8
9
10
11
12
13
14
# File 'lib/payson_api/shipping_address.rb', line 8

def initialize(name, street_address, postal_code, city, country)
  @name = name
  @street_address = street_address
  @postal_code = postal_code
  @city = city
  @country = country
end

Instance Attribute Details

#cityObject

Returns the value of attribute city.



6
7
8
# File 'lib/payson_api/shipping_address.rb', line 6

def city
  @city
end

#countryObject

Returns the value of attribute country.



6
7
8
# File 'lib/payson_api/shipping_address.rb', line 6

def country
  @country
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/payson_api/shipping_address.rb', line 6

def name
  @name
end

#postal_codeObject

Returns the value of attribute postal_code.



6
7
8
# File 'lib/payson_api/shipping_address.rb', line 6

def postal_code
  @postal_code
end

#street_addressObject

Returns the value of attribute street_address.



6
7
8
# File 'lib/payson_api/shipping_address.rb', line 6

def street_address
  @street_address
end

Class Method Details

.parse(data) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/payson_api/shipping_address.rb', line 26

def self.parse(data)
  return unless data[FORMAT_STRING % 'name']
  name = CGI.unescape(data[FORMAT_STRING % 'name'].to_s)
  street_address = CGI.unescape(data[FORMAT_STRING % 'streetAddress'].to_s)
  postal_code = CGI.unescape(data[FORMAT_STRING % 'postalCode'].to_s)
  city = CGI.unescape(data[FORMAT_STRING % 'city'].to_s)
  country = CGI.unescape(data[FORMAT_STRING % 'country'].to_s)
  self.new(name, street_address, postal_code, city, country)
end

Instance Method Details

#to_hashObject



16
17
18
19
20
21
22
23
24
# File 'lib/payson_api/shipping_address.rb', line 16

def to_hash
  {}.tap do |hash|
    hash[FORMAT_STRING % 'name'] = @name
    hash[FORMAT_STRING % 'streetAddress'] = @street_address
    hash[FORMAT_STRING % 'postalCode'] = @postal_code
    hash[FORMAT_STRING % 'city'] = @city
    hash[FORMAT_STRING % 'country'] = @country
  end
end