Class: LoyaltyApIs::ErrorPresenter

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/loyalty_ap_is/models/error_presenter.rb

Overview

ErrorPresenter Model.

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(app_error_code:, message:, reason: SKIP, subject: SKIP, subject_type: SKIP, type: SKIP, additional_properties: nil) ⇒ ErrorPresenter

Returns a new instance of ErrorPresenter.



90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/loyalty_ap_is/models/error_presenter.rb', line 90

def initialize(app_error_code:, message:, reason: SKIP, subject: SKIP,
               subject_type: SKIP, type: SKIP, additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @app_error_code = app_error_code
  @message = message
  @reason = reason unless reason == SKIP
  @subject = subject unless subject == SKIP
  @subject_type = subject_type unless subject_type == SKIP
  @type = type unless type == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#app_error_codeString

custom error code for developer or user Note: One of the following values will be returned: 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1009, 1010, 1011, 1012, 1014, 1015, 1016

Returns:

  • (String)


17
18
19
# File 'lib/loyalty_ap_is/models/error_presenter.rb', line 17

def app_error_code
  @app_error_code
end

#messageString

Custom error message
Note: One of the following values will be returned:

- Offer does not exist
- Customer does not exist
- Valid from date is invalid
- ValidityPeriod is invalid
- Offer is by default assigned to all customers, which cannot be

changed.

  • Assignment is not allowed
  • Customer assign should have validity dates.
  • Customer assign validity start date should be before the validity end date.
  • Customer assign validity dates must be between the offer assignable dates.
  • Offer validity start date should not be in the past.
  • Customer already assigned to this offer.
  • Offer module is disabled
  • Partner code is not valid for this offer
  • Reference ID already used
  • Partner assignment already ended for this customer

Returns:

  • (String)


40
41
42
# File 'lib/loyalty_ap_is/models/error_presenter.rb', line 40

def message
  @message
end

#reasonString

reason for the error

Returns:

  • (String)


44
45
46
# File 'lib/loyalty_ap_is/models/error_presenter.rb', line 44

def reason
  @reason
end

#subjectString

subject of the error. Examples will be shared later

Returns:

  • (String)


48
49
50
# File 'lib/loyalty_ap_is/models/error_presenter.rb', line 48

def subject
  @subject
end

#subject_typeString

subject type of the error. Examples will be shared later.

Returns:

  • (String)


52
53
54
# File 'lib/loyalty_ap_is/models/error_presenter.rb', line 52

def subject_type
  @subject_type
end

#typeString

Type of error. Examples will be shared later.

Returns:

  • (String)


56
57
58
# File 'lib/loyalty_ap_is/models/error_presenter.rb', line 56

def type
  @type
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/loyalty_ap_is/models/error_presenter.rb', line 105

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  app_error_code = hash.key?('appErrorCode') ? hash['appErrorCode'] : nil
  message = hash.key?('message') ? hash['message'] : nil
  reason = hash.key?('reason') ? hash['reason'] : SKIP
  subject = hash.key?('subject') ? hash['subject'] : SKIP
  subject_type = hash.key?('subjectType') ? hash['subjectType'] : SKIP
  type = hash.key?('type') ? hash['type'] : SKIP

  # Create a new hash for additional properties, removing known properties.
  new_hash = hash.reject { |k, _| names.value?(k) }

  additional_properties = APIHelper.get_additional_properties(
    new_hash, proc { |value| value }
  )

  # Create object from extracted values.
  ErrorPresenter.new(app_error_code: app_error_code,
                     message: message,
                     reason: reason,
                     subject: subject,
                     subject_type: subject_type,
                     type: type,
                     additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



59
60
61
62
63
64
65
66
67
68
# File 'lib/loyalty_ap_is/models/error_presenter.rb', line 59

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['app_error_code'] = 'appErrorCode'
  @_hash['message'] = 'message'
  @_hash['reason'] = 'reason'
  @_hash['subject'] = 'subject'
  @_hash['subject_type'] = 'subjectType'
  @_hash['type'] = 'type'
  @_hash
end

.nullablesObject

An array for nullable fields



81
82
83
84
85
86
87
88
# File 'lib/loyalty_ap_is/models/error_presenter.rb', line 81

def self.nullables
  %w[
    reason
    subject
    subject_type
    type
  ]
end

.optionalsObject

An array for optional fields



71
72
73
74
75
76
77
78
# File 'lib/loyalty_ap_is/models/error_presenter.rb', line 71

def self.optionals
  %w[
    reason
    subject
    subject_type
    type
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



142
143
144
145
146
147
148
# File 'lib/loyalty_ap_is/models/error_presenter.rb', line 142

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} app_error_code: #{@app_error_code.inspect}, message: #{@message.inspect},"\
  " reason: #{@reason.inspect}, subject: #{@subject.inspect}, subject_type:"\
  " #{@subject_type.inspect}, type: #{@type.inspect}, additional_properties:"\
  " #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



134
135
136
137
138
139
# File 'lib/loyalty_ap_is/models/error_presenter.rb', line 134

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} app_error_code: #{@app_error_code}, message: #{@message}, reason:"\
  " #{@reason}, subject: #{@subject}, subject_type: #{@subject_type}, type: #{@type},"\
  " additional_properties: #{@additional_properties}>"
end