Class: MpApi::Customer
- Inherits:
-
Object
- Object
- MpApi::Customer
- Defined in:
- lib/mp_api/customer.rb
Instance Attribute Summary collapse
-
#email ⇒ Object
readonly
Returns the value of attribute email.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#error_detail ⇒ Object
readonly
Returns the value of attribute error_detail.
-
#external_id ⇒ Object
readonly
Returns the value of attribute external_id.
-
#first_name ⇒ Object
readonly
Returns the value of attribute first_name.
-
#identification_number ⇒ Object
readonly
Returns the value of attribute identification_number.
-
#identification_type ⇒ Object
readonly
Returns the value of attribute identification_type.
-
#phone_area_code ⇒ Object
readonly
Returns the value of attribute phone_area_code.
-
#phone_number ⇒ Object
readonly
Returns the value of attribute phone_number.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Class Method Summary collapse
Instance Method Summary collapse
- #build_json ⇒ Object
- #create ⇒ Object
-
#initialize(external_id: nil, email:, first_name: nil, identification_type:, identification_number:, phone_area_code: "55", phone_number: nil, status: nil, error: nil, error_detail: nil) ⇒ Customer
constructor
A new instance of Customer.
Constructor Details
#initialize(external_id: nil, email:, first_name: nil, identification_type:, identification_number:, phone_area_code: "55", phone_number: nil, status: nil, error: nil, error_detail: nil) ⇒ Customer
Returns a new instance of Customer.
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/mp_api/customer.rb', line 5 def initialize(external_id: nil, email:, first_name: nil, identification_type:, identification_number:, phone_area_code: "55", phone_number: nil, status: nil, error: nil, error_detail: nil) @external_id = external_id @email = email @first_name = first_name @identification_type = identification_type @identification_number = identification_number @phone_area_code = phone_area_code @phone_number = phone_number @status = status @error = error @error_detail = error_detail end |
Instance Attribute Details
#email ⇒ Object (readonly)
Returns the value of attribute email.
4 5 6 |
# File 'lib/mp_api/customer.rb', line 4 def email @email end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
4 5 6 |
# File 'lib/mp_api/customer.rb', line 4 def error @error end |
#error_detail ⇒ Object (readonly)
Returns the value of attribute error_detail.
4 5 6 |
# File 'lib/mp_api/customer.rb', line 4 def error_detail @error_detail end |
#external_id ⇒ Object (readonly)
Returns the value of attribute external_id.
4 5 6 |
# File 'lib/mp_api/customer.rb', line 4 def external_id @external_id end |
#first_name ⇒ Object (readonly)
Returns the value of attribute first_name.
4 5 6 |
# File 'lib/mp_api/customer.rb', line 4 def first_name @first_name end |
#identification_number ⇒ Object (readonly)
Returns the value of attribute identification_number.
4 5 6 |
# File 'lib/mp_api/customer.rb', line 4 def identification_number @identification_number end |
#identification_type ⇒ Object (readonly)
Returns the value of attribute identification_type.
4 5 6 |
# File 'lib/mp_api/customer.rb', line 4 def identification_type @identification_type end |
#phone_area_code ⇒ Object (readonly)
Returns the value of attribute phone_area_code.
4 5 6 |
# File 'lib/mp_api/customer.rb', line 4 def phone_area_code @phone_area_code end |
#phone_number ⇒ Object (readonly)
Returns the value of attribute phone_number.
4 5 6 |
# File 'lib/mp_api/customer.rb', line 4 def phone_number @phone_number end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
4 5 6 |
# File 'lib/mp_api/customer.rb', line 4 def status @status end |
Class Method Details
.build_hash(response) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/mp_api/customer.rb', line 38 def self.build_hash(response) { external_id: response.dig("id"), email: response.dig("email"), first_name: response.dig("first_name"), identification_type: response.dig("identification", "type"), identification_number: response.dig("identification", "number"), phone_area_code: response.dig("phone", "area_code"), phone_number: response.dig("phone", "number"), status: response.dig("status"), error: response.dig("message"), error_detail: response.dig("cause") } end |
Instance Method Details
#build_json ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/mp_api/customer.rb', line 18 def build_json { email: email, first_name: first_name, identification: { type: identification_type, number: identification_number }, phone: { area_code: phone_area_code, number: phone_number } } end |
#create ⇒ Object
33 34 35 36 |
# File 'lib/mp_api/customer.rb', line 33 def create response = Client.new.create_customer(JSON.dump(build_json)) self.class.new(**self.class.build_hash(response.json)) end |