Class: Afterpay::Consumer

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Consumer

Returns a new instance of Consumer.



7
8
9
10
11
12
# File 'lib/afterpay/consumer.rb', line 7

def initialize(attributes = {})
  @email = attributes[:email]
  @phone = attributes[:phone] || ""
  @first_name = attributes[:first_name] || ""
  @last_name = attributes[:last_name] || ""
end

Instance Attribute Details

#emailObject

Returns the value of attribute email.



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

def email
  @email
end

#first_nameObject

Returns the value of attribute first_name.



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

def first_name
  @first_name
end

#last_nameObject

Returns the value of attribute last_name.



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

def last_name
  @last_name
end

#phoneObject

Returns the value of attribute phone.



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

def phone
  @phone
end

Class Method Details

.from_response(response) ⇒ Object

Builds Consumer from response



24
25
26
27
28
29
30
31
32
33
# File 'lib/afterpay/consumer.rb', line 24

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

  new(
    email: response[:email],
    first_name: response[:givenNames],
    last_name: response[:surname],
    phone: response[:phoneNumber]
  )
end

Instance Method Details

#to_hashObject



14
15
16
17
18
19
20
21
# File 'lib/afterpay/consumer.rb', line 14

def to_hash
  {
    phoneNumber: phone,
    givenNames: first_name,
    surname: last_name,
    email: email
  }
end