Class: LoyaltyApIs::OfferAssignment

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

Overview

OfferAssignment 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(reference_id:, consumer_uuid:, offer_id:, valid_from: SKIP, validity_period: SKIP, valid_to: SKIP, additional_properties: nil) ⇒ OfferAssignment

Returns a new instance of OfferAssignment.



94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/loyalty_ap_is/models/offer_assignment.rb', line 94

def initialize(reference_id:, consumer_uuid:, offer_id:, valid_from: SKIP,
               validity_period: SKIP, valid_to: SKIP,
               additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @reference_id = reference_id
  @consumer_uuid = consumer_uuid
  @offer_id = offer_id
  @valid_from = valid_from unless valid_from == SKIP
  @validity_period = validity_period unless validity_period == SKIP
  @valid_to = valid_to unless valid_to == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#consumer_uuidUUID | String

SSO uuid of the user signed in with Shell credentials Format: 32 hexadecimal digits grouped the following way: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Returns:

  • (UUID | String)


22
23
24
# File 'lib/loyalty_ap_is/models/offer_assignment.rb', line 22

def consumer_uuid
  @consumer_uuid
end

#offer_idString

Offer identifier shared by Shell. Format: string(30)

Returns:

  • (String)


27
28
29
# File 'lib/loyalty_ap_is/models/offer_assignment.rb', line 27

def offer_id
  @offer_id
end

#reference_idString

Unique Reference ID for the transaction from the partner. Used to identify duplicate requests.

Returns:

  • (String)


16
17
18
# File 'lib/loyalty_ap_is/models/offer_assignment.rb', line 16

def reference_id
  @reference_id
end

#valid_fromDateTime

Offer validity start date in JSON recommended format: "yyyy-MM-ddTHH:mm:ssZ". The date format must follow ISO_8601. If 'Z' is written immediately after the time, it is considered UTC.
Time offset from UTC can be appended instead of 'Z' using plus or minus signs. Negative UTC offsets describe a time zone west of UTC�00:00, where the civil time is behind (or earlier) than UTC. Positive UTC offsets describe a time zone east of UTC�00:00, where the civil time is ahead (or later) than UTC

Returns:

  • (DateTime)


39
40
41
# File 'lib/loyalty_ap_is/models/offer_assignment.rb', line 39

def valid_from
  @valid_from
end

#valid_toDateTime

Offer validity end date in JSON recommended format: "yyyy-MM-ddTHH:mm:ssZ". Field value is ignored if validityPeriod is bigger than zero. The date format must follow ISO_8601. If 'Z' is written immediately after the time, it is considered UTC.
Time offset from UTC can be appended instead of 'Z' using plus or minus signs. Negative UTC offsets describe a time zone west of UTC�00:00, where the civil time is behind (or earlier) than UTC. Positive UTC offsets describe a time zone east of UTC�00:00, where the civil time is ahead (or later) than UTC

Returns:

  • (DateTime)


64
65
66
# File 'lib/loyalty_ap_is/models/offer_assignment.rb', line 64

def valid_to
  @valid_to
end

#validity_periodFloat

Offer validity period (Number of days) If validityPeriod is greater than zero, validTo will be ignored. The offer will be valid till:

validfrom + validityperiod

If the resulting valid to date would be during the day, then its validity is modified to last until midnight in the timezone of the validFrom date. E.g. If valiFrom is "2021-03-08T17:12:55Z+01:00" (Central European time) and validtyPeriod is 3 then the offer will be valid till "2021-03-11T23:59:59Z+01:00" (Central European Time)

Returns:

  • (Float)


51
52
53
# File 'lib/loyalty_ap_is/models/offer_assignment.rb', line 51

def validity_period
  @validity_period
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/loyalty_ap_is/models/offer_assignment.rb', line 110

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  reference_id = hash.key?('referenceId') ? hash['referenceId'] : nil
  consumer_uuid = hash.key?('consumerUuid') ? hash['consumerUuid'] : nil
  offer_id = hash.key?('offerId') ? hash['offerId'] : nil
  valid_from = if hash.key?('validFrom')
                 (DateTimeHelper.from_rfc3339(hash['validFrom']) if hash['validFrom'])
               else
                 SKIP
               end
  validity_period =
    hash.key?('validityPeriod') ? hash['validityPeriod'] : SKIP
  valid_to = if hash.key?('validTo')
               (DateTimeHelper.from_rfc3339(hash['validTo']) if hash['validTo'])
             else
               SKIP
             end

  # 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.
  OfferAssignment.new(reference_id: reference_id,
                      consumer_uuid: consumer_uuid,
                      offer_id: offer_id,
                      valid_from: valid_from,
                      validity_period: validity_period,
                      valid_to: valid_to,
                      additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



67
68
69
70
71
72
73
74
75
76
# File 'lib/loyalty_ap_is/models/offer_assignment.rb', line 67

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['reference_id'] = 'referenceId'
  @_hash['consumer_uuid'] = 'consumerUuid'
  @_hash['offer_id'] = 'offerId'
  @_hash['valid_from'] = 'validFrom'
  @_hash['validity_period'] = 'validityPeriod'
  @_hash['valid_to'] = 'validTo'
  @_hash
end

.nullablesObject

An array for nullable fields



88
89
90
91
92
# File 'lib/loyalty_ap_is/models/offer_assignment.rb', line 88

def self.nullables
  %w[
    valid_to
  ]
end

.optionalsObject

An array for optional fields



79
80
81
82
83
84
85
# File 'lib/loyalty_ap_is/models/offer_assignment.rb', line 79

def self.optionals
  %w[
    valid_from
    validity_period
    valid_to
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



164
165
166
167
168
169
170
# File 'lib/loyalty_ap_is/models/offer_assignment.rb', line 164

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} reference_id: #{@reference_id.inspect}, consumer_uuid:"\
  " #{@consumer_uuid.inspect}, offer_id: #{@offer_id.inspect}, valid_from:"\
  " #{@valid_from.inspect}, validity_period: #{@validity_period.inspect}, valid_to:"\
  " #{@valid_to.inspect}, additional_properties: #{@additional_properties}>"
end

#to_custom_valid_fromObject



147
148
149
# File 'lib/loyalty_ap_is/models/offer_assignment.rb', line 147

def to_custom_valid_from
  DateTimeHelper.to_rfc3339(valid_from)
end

#to_custom_valid_toObject



151
152
153
# File 'lib/loyalty_ap_is/models/offer_assignment.rb', line 151

def to_custom_valid_to
  DateTimeHelper.to_rfc3339(valid_to)
end

#to_sObject

Provides a human-readable string representation of the object.



156
157
158
159
160
161
# File 'lib/loyalty_ap_is/models/offer_assignment.rb', line 156

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} reference_id: #{@reference_id}, consumer_uuid: #{@consumer_uuid}, offer_id:"\
  " #{@offer_id}, valid_from: #{@valid_from}, validity_period: #{@validity_period}, valid_to:"\
  " #{@valid_to}, additional_properties: #{@additional_properties}>"
end