Class: Cielo::API30::Customer

Inherits:
Object
  • Object
show all
Defined in:
lib/cielo/api30/customer.rb

Overview

Customer data

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Customer

Returns a new instance of Customer.



21
22
23
# File 'lib/cielo/api30/customer.rb', line 21

def initialize(name)
  @name = name
end

Instance Attribute Details

#addressAddress

Customer’s address

Returns:

  • (Address)

    the current value of address



12
13
14
# File 'lib/cielo/api30/customer.rb', line 12

def address
  @address
end

#birth_dateObject

Returns the value of attribute birth_date.



13
14
15
# File 'lib/cielo/api30/customer.rb', line 13

def birth_date
  @birth_date
end

#birthDateString

Customer’s birth date

Returns:

  • (String)

    the current value of birthDate



12
13
14
# File 'lib/cielo/api30/customer.rb', line 12

def birthDate
  @birthDate
end

#delivery_addressObject

Returns the value of attribute delivery_address.



13
14
15
# File 'lib/cielo/api30/customer.rb', line 13

def delivery_address
  @delivery_address
end

#deliveryAddressAddress

The delivery address

Returns:

  • (Address)

    the current value of deliveryAddress



12
13
14
# File 'lib/cielo/api30/customer.rb', line 12

def deliveryAddress
  @deliveryAddress
end

#emailString

Customer email

Returns:

  • (String)

    the current value of email



12
13
14
# File 'lib/cielo/api30/customer.rb', line 12

def email
  @email
end

#identityString

Customer id

Returns:

  • (String)

    the current value of identity



12
13
14
# File 'lib/cielo/api30/customer.rb', line 12

def identity
  @identity
end

#identity_typeObject

Returns the value of attribute identity_type.



13
14
15
# File 'lib/cielo/api30/customer.rb', line 13

def identity_type
  @identity_type
end

#identityTypeString

The type of customer id

Returns:

  • (String)

    the current value of identityType



12
13
14
# File 'lib/cielo/api30/customer.rb', line 12

def identityType
  @identityType
end

#nameString

Customer name

Returns:

  • (String)

    the current value of name



12
13
14
# File 'lib/cielo/api30/customer.rb', line 12

def name
  @name
end

Class Method Details

.from_json(data) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/cielo/api30/customer.rb', line 31

def self.from_json(data)
  return if data.nil?

  customer = new(data["Name"])
  customer.email = data["Email"]
  customer.birth_date = data["BirthDate"]
  customer.identity = data["Identity"]
  customer.identity_type = data["IdentityType"]
  customer.address = Address.from_json(data["Address"])
  customer.delivery_address = Address.from_json(data["DeliveryAddress"])
  customer
end

Instance Method Details

#as_json(options = {}) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/cielo/api30/customer.rb', line 44

def as_json(options={})
  {
    Name: @name,
    Email: @email,
    BirthDate: @birth_date,
    Identity: @identity,
    IdentityType: @identity_type,
    Address: @address,
    DeliveryAddress: @delivery_address
  }
end

#to_json(*options) ⇒ Object



25
26
27
28
29
# File 'lib/cielo/api30/customer.rb', line 25

def to_json(*options)
  hash = as_json(*options)
  hash.reject! {|k,v| v.nil?}
  hash.to_json(*options)
end