Class: NewStoreApi::Profile

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

Overview

Clienteling profile information for a customer.

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(customer_id = nil, opted_in = nil, opted_out = nil, opted_out_at = nil, phone_number = nil) ⇒ Profile

Returns a new instance of Profile.



56
57
58
59
60
61
62
63
# File 'lib/new_store_api/models/profile.rb', line 56

def initialize(customer_id = nil, opted_in = nil, opted_out = nil,
               opted_out_at = nil, phone_number = nil)
  @customer_id = customer_id
  @opted_in = opted_in
  @opted_out = opted_out
  @opted_out_at = opted_out_at
  @phone_number = phone_number
end

Instance Attribute Details

#customer_idUUID | String

The identifier of the customer.

Returns:

  • (UUID | String)


15
16
17
# File 'lib/new_store_api/models/profile.rb', line 15

def customer_id
  @customer_id
end

#opted_inHash[String, OptedIn]

The opt-in status for the customer per store.

Returns:



19
20
21
# File 'lib/new_store_api/models/profile.rb', line 19

def opted_in
  @opted_in
end

#opted_outTrueClass | FalseClass

Whether the customer has opted out.

Returns:

  • (TrueClass | FalseClass)


23
24
25
# File 'lib/new_store_api/models/profile.rb', line 23

def opted_out
  @opted_out
end

#opted_out_atDateTime

The date when the customer opted out.

Returns:

  • (DateTime)


27
28
29
# File 'lib/new_store_api/models/profile.rb', line 27

def opted_out_at
  @opted_out_at
end

#phone_numberString

The phone number of the customer.

Returns:

  • (String)


31
32
33
# File 'lib/new_store_api/models/profile.rb', line 31

def phone_number
  @phone_number
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/new_store_api/models/profile.rb', line 66

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  customer_id = hash.key?('customer_id') ? hash['customer_id'] : nil
  opted_in = OptedIn.from_hash(hash['opted_in']) if hash['opted_in']

  opted_in = nil unless hash.key?('opted_in')
  opted_out = hash.key?('opted_out') ? hash['opted_out'] : nil
  opted_out_at = if hash.key?('opted_out_at')
                   (DateTimeHelper.from_rfc3339(hash['opted_out_at']) if hash['opted_out_at'])
                 end
  phone_number = hash.key?('phone_number') ? hash['phone_number'] : nil

  # Create object from extracted values.
  Profile.new(customer_id,
              opted_in,
              opted_out,
              opted_out_at,
              phone_number)
end

.namesObject

A mapping from model property names to API property names.



34
35
36
37
38
39
40
41
42
# File 'lib/new_store_api/models/profile.rb', line 34

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['customer_id'] = 'customer_id'
  @_hash['opted_in'] = 'opted_in'
  @_hash['opted_out'] = 'opted_out'
  @_hash['opted_out_at'] = 'opted_out_at'
  @_hash['phone_number'] = 'phone_number'
  @_hash
end

.nullablesObject

An array for nullable fields



50
51
52
53
54
# File 'lib/new_store_api/models/profile.rb', line 50

def self.nullables
  %w[
    opted_out_at
  ]
end

.optionalsObject

An array for optional fields



45
46
47
# File 'lib/new_store_api/models/profile.rb', line 45

def self.optionals
  []
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



100
101
102
103
104
105
# File 'lib/new_store_api/models/profile.rb', line 100

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} customer_id: #{@customer_id.inspect}, opted_in: #{@opted_in.inspect},"\
  " opted_out: #{@opted_out.inspect}, opted_out_at: #{@opted_out_at.inspect}, phone_number:"\
  " #{@phone_number.inspect}>"
end

#to_custom_opted_out_atObject



88
89
90
# File 'lib/new_store_api/models/profile.rb', line 88

def to_custom_opted_out_at
  DateTimeHelper.to_rfc3339(opted_out_at)
end

#to_sObject

Provides a human-readable string representation of the object.



93
94
95
96
97
# File 'lib/new_store_api/models/profile.rb', line 93

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} customer_id: #{@customer_id}, opted_in: #{@opted_in}, opted_out:"\
  " #{@opted_out}, opted_out_at: #{@opted_out_at}, phone_number: #{@phone_number}>"
end