Sha256: 12fa36984c3eefa7da701a2549d3f5b6d5330f26cede61d96c8edbbe6767ba47
Contents?: true
Size: 1.73 KB
Versions: 3
Compression:
Stored size: 1.73 KB
Contents
module MpApi class Customer attr_reader :external_id, :email, :first_name, :identification_type, :identification_number, :phone_area_code, :phone_number, :status, :error, :error_detail 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 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 def create response = Client.new.create_customer(JSON.dump(build_json)) self.class.new(**self.class.build_hash(response.json)) end 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 end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
mp_api-1.2.2 | lib/mp_api/customer.rb |
mp_api-1.2.1 | lib/mp_api/customer.rb |
mp_api-1.2.0 | lib/mp_api/customer.rb |