Class: Afterpay::Address

Inherits:
Object
  • Object
show all
Defined in:
lib/afterpay/address.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Address

Returns a new instance of Address.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/afterpay/address.rb', line 7

def initialize(attributes = {})
  @name = attributes[:name]
  @line_1 = attributes[:line_1] || ""
  @line_2 = attributes[:line_2] || ""
  @area_1 = attributes[:area_1] || ""
  @area_2 = attributes[:area_2] || ""
  @region = attributes[:region] || ""
  @postcode = attributes[:postcode]
  @country = attributes[:country] || "AU"
  @phone = attributes[:phone]
end

Instance Attribute Details

#area_1Object

Returns the value of attribute area_1.



5
6
7
# File 'lib/afterpay/address.rb', line 5

def area_1
  @area_1
end

#area_2Object

Returns the value of attribute area_2.



5
6
7
# File 'lib/afterpay/address.rb', line 5

def area_2
  @area_2
end

#countryObject

Returns the value of attribute country.



5
6
7
# File 'lib/afterpay/address.rb', line 5

def country
  @country
end

#line_1Object

Returns the value of attribute line_1.



5
6
7
# File 'lib/afterpay/address.rb', line 5

def line_1
  @line_1
end

#line_2Object

Returns the value of attribute line_2.



5
6
7
# File 'lib/afterpay/address.rb', line 5

def line_2
  @line_2
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/afterpay/address.rb', line 5

def name
  @name
end

#phoneObject

Returns the value of attribute phone.



5
6
7
# File 'lib/afterpay/address.rb', line 5

def phone
  @phone
end

#postcodeObject

Returns the value of attribute postcode.



5
6
7
# File 'lib/afterpay/address.rb', line 5

def postcode
  @postcode
end

#regionObject

Returns the value of attribute region.



5
6
7
# File 'lib/afterpay/address.rb', line 5

def region
  @region
end

Class Method Details

.from_response(response) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/afterpay/address.rb', line 33

def self.from_response(response)
  return nil if response.nil?

  new(
    name: response[:name],
    line_1: response[:line1],
    line_2: response[:line2],
    area_1: response[:area1],
    area_2: response[:area2],
    region: response[:region],
    postcode: response[:postcode],
    country: response[:countryCode],
    phone: response[:phoneNumber]
  )
end

Instance Method Details

#to_hashObject



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/afterpay/address.rb', line 19

def to_hash
  {
    name: name,
    line1: line_1,
    line2: line_2,
    area_1: area_1,
    area_2: area_2,
    region: region,
    postcode: postcode.to_s,
    countryCode: country,
    phoneNumber: phone.to_s
  }
end