Class: NewStoreApi::Customer1

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/new_store_api/models/customer1.rb

Overview

Customer object for optional risk assessment.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

Constructor Details

#initialize(email = nil, first_name = SKIP, last_name = SKIP, shipping_address = SKIP) ⇒ Customer1

Returns a new instance of Customer1.



52
53
54
55
56
57
58
# File 'lib/new_store_api/models/customer1.rb', line 52

def initialize(email = nil, first_name = SKIP, last_name = SKIP,
               shipping_address = SKIP)
  @email = email
  @first_name = first_name unless first_name == SKIP
  @last_name = last_name unless last_name == SKIP
  @shipping_address = shipping_address unless shipping_address == SKIP
end

Instance Attribute Details

#emailString

E-Mail

Returns:

  • (String)


14
15
16
# File 'lib/new_store_api/models/customer1.rb', line 14

def email
  @email
end

#first_nameString

First name

Returns:

  • (String)


18
19
20
# File 'lib/new_store_api/models/customer1.rb', line 18

def first_name
  @first_name
end

#last_nameString

Last name

Returns:

  • (String)


22
23
24
# File 'lib/new_store_api/models/customer1.rb', line 22

def last_name
  @last_name
end

#shipping_addressShippingAddress

Shipping address of the customer used for risk assessment only.

Returns:



26
27
28
# File 'lib/new_store_api/models/customer1.rb', line 26

def shipping_address
  @shipping_address
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/new_store_api/models/customer1.rb', line 61

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  email = hash.key?('email') ? hash['email'] : nil
  first_name = hash.key?('first_name') ? hash['first_name'] : SKIP
  last_name = hash.key?('last_name') ? hash['last_name'] : SKIP
  shipping_address = ShippingAddress.from_hash(hash['shipping_address']) if
    hash['shipping_address']

  # Create object from extracted values.
  Customer1.new(email,
                first_name,
                last_name,
                shipping_address)
end

.namesObject

A mapping from model property names to API property names.



29
30
31
32
33
34
35
36
# File 'lib/new_store_api/models/customer1.rb', line 29

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['email'] = 'email'
  @_hash['first_name'] = 'first_name'
  @_hash['last_name'] = 'last_name'
  @_hash['shipping_address'] = 'shipping_address'
  @_hash
end

.nullablesObject

An array for nullable fields



48
49
50
# File 'lib/new_store_api/models/customer1.rb', line 48

def self.nullables
  []
end

.optionalsObject

An array for optional fields



39
40
41
42
43
44
45
# File 'lib/new_store_api/models/customer1.rb', line 39

def self.optionals
  %w[
    first_name
    last_name
    shipping_address
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



86
87
88
89
90
# File 'lib/new_store_api/models/customer1.rb', line 86

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} email: #{@email.inspect}, first_name: #{@first_name.inspect}, last_name:"\
  " #{@last_name.inspect}, shipping_address: #{@shipping_address.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



79
80
81
82
83
# File 'lib/new_store_api/models/customer1.rb', line 79

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} email: #{@email}, first_name: #{@first_name}, last_name: #{@last_name},"\
  " shipping_address: #{@shipping_address}>"
end