Class: LoyaltyApIs::RedemptionItem
- Defined in:
- lib/loyalty_ap_is/models/redemption_item.rb
Overview
RedemptionItem Model.
Instance Attribute Summary collapse
-
#item_id ⇒ String
The itemID identifies the catalogue item in the loyalty system.
-
#points ⇒ Integer
Total number of points to be redeemed from the Shell Loyalty Platform for this item.
-
#quantity ⇒ Integer
Number of items redeemed on the user's behalf.
-
#reason_for_redemption ⇒ String
Reason for the points redemption.
Class Method Summary collapse
-
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
-
.names ⇒ Object
A mapping from model property names to API property names.
-
.nullables ⇒ Object
An array for nullable fields.
-
.optionals ⇒ Object
An array for optional fields.
Instance Method Summary collapse
-
#initialize(item_id:, points:, reason_for_redemption:, quantity: 1, additional_properties: nil) ⇒ RedemptionItem
constructor
A new instance of RedemptionItem.
-
#inspect ⇒ Object
Provides a debugging-friendly string with detailed object information.
-
#to_s ⇒ Object
Provides a human-readable string representation of the object.
Methods inherited from BaseModel
#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json
Constructor Details
#initialize(item_id:, points:, reason_for_redemption:, quantity: 1, additional_properties: nil) ⇒ RedemptionItem
Returns a new instance of RedemptionItem.
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/loyalty_ap_is/models/redemption_item.rb', line 55 def initialize(item_id:, points:, reason_for_redemption:, quantity: 1, additional_properties: nil) # Add additional model properties to the instance additional_properties = {} if additional_properties.nil? @item_id = item_id @quantity = quantity unless quantity == SKIP @points = points @reason_for_redemption = reason_for_redemption @additional_properties = additional_properties end |
Instance Attribute Details
#item_id ⇒ String
The itemID identifies the catalogue item in the loyalty system. Shell will set these up and share the IDs with the partner.
15 16 17 |
# File 'lib/loyalty_ap_is/models/redemption_item.rb', line 15 def item_id @item_id end |
#points ⇒ Integer
Total number of points to be redeemed from the Shell Loyalty Platform for this item.
26 27 28 |
# File 'lib/loyalty_ap_is/models/redemption_item.rb', line 26 def points @points end |
#quantity ⇒ Integer
Number of items redeemed on the user's behalf. If the quantity is not specified, the system will assume a default quantity of 1. This is not used for the calculation of points, but only for displaying to the user.
21 22 23 |
# File 'lib/loyalty_ap_is/models/redemption_item.rb', line 21 def quantity @quantity end |
#reason_for_redemption ⇒ String
Reason for the points redemption. This attribute will be shown to the customer via app/web channel under Transaction History.
31 32 33 |
# File 'lib/loyalty_ap_is/models/redemption_item.rb', line 31 def reason_for_redemption @reason_for_redemption end |
Class Method Details
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/loyalty_ap_is/models/redemption_item.rb', line 68 def self.from_hash(hash) return nil unless hash # Extract variables from the hash. item_id = hash.key?('itemId') ? hash['itemId'] : nil points = hash.key?('points') ? hash['points'] : nil reason_for_redemption = hash.key?('reasonForRedemption') ? hash['reasonForRedemption'] : nil quantity = hash['quantity'] ||= 1 # 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. RedemptionItem.new(item_id: item_id, points: points, reason_for_redemption: reason_for_redemption, quantity: quantity, additional_properties: additional_properties) end |
.names ⇒ Object
A mapping from model property names to API property names.
34 35 36 37 38 39 40 41 |
# File 'lib/loyalty_ap_is/models/redemption_item.rb', line 34 def self.names @_hash = {} if @_hash.nil? @_hash['item_id'] = 'itemId' @_hash['quantity'] = 'quantity' @_hash['points'] = 'points' @_hash['reason_for_redemption'] = 'reasonForRedemption' @_hash end |
.nullables ⇒ Object
An array for nullable fields
51 52 53 |
# File 'lib/loyalty_ap_is/models/redemption_item.rb', line 51 def self.nullables [] end |
.optionals ⇒ Object
An array for optional fields
44 45 46 47 48 |
# File 'lib/loyalty_ap_is/models/redemption_item.rb', line 44 def self.optionals %w[ quantity ] end |
Instance Method Details
#inspect ⇒ Object
Provides a debugging-friendly string with detailed object information.
102 103 104 105 106 107 |
# File 'lib/loyalty_ap_is/models/redemption_item.rb', line 102 def inspect class_name = self.class.name.split('::').last "<#{class_name} item_id: #{@item_id.inspect}, quantity: #{@quantity.inspect}, points:"\ " #{@points.inspect}, reason_for_redemption: #{@reason_for_redemption.inspect},"\ " additional_properties: #{@additional_properties}>" end |
#to_s ⇒ Object
Provides a human-readable string representation of the object.
94 95 96 97 98 99 |
# File 'lib/loyalty_ap_is/models/redemption_item.rb', line 94 def to_s class_name = self.class.name.split('::').last "<#{class_name} item_id: #{@item_id}, quantity: #{@quantity}, points: #{@points},"\ " reason_for_redemption: #{@reason_for_redemption}, additional_properties:"\ " #{@additional_properties}>" end |