Class: LoyaltyApIs::Offer
- Defined in:
- lib/loyalty_ap_is/models/offer.rb
Overview
Offer Model.
Instance Attribute Summary collapse
-
#description ⇒ String
Description of the partner's offer, set up upon offer configuration.
-
#offer_id ⇒ Integer
Offer ID provided upon offer configuration.
-
#reference_id ⇒ String
Unique Reference ID for the transaction from the partner.
-
#title ⇒ String
Title of the partner's offer, given upon configuration.
-
#valid_from ⇒ DateTime
Offer validity start date in JSON recommended format: "yyyy-MM-ddTHH:mm:ssZ".
-
#valid_to ⇒ DateTime
Offer validity end date in JSON recommended format: "yyyy-MM-ddTHH:mm:ssZ".
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(offer_id:, reference_id:, title:, description:, valid_from:, valid_to: SKIP, additional_properties: nil) ⇒ Offer
constructor
A new instance of Offer.
-
#inspect ⇒ Object
Provides a debugging-friendly string with detailed object information.
- #to_custom_valid_from ⇒ Object
- #to_custom_valid_to ⇒ Object
-
#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(offer_id:, reference_id:, title:, description:, valid_from:, valid_to: SKIP, additional_properties: nil) ⇒ Offer
Returns a new instance of Offer.
81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/loyalty_ap_is/models/offer.rb', line 81 def initialize(offer_id:, reference_id:, title:, description:, valid_from:, valid_to: SKIP, additional_properties: nil) # Add additional model properties to the instance additional_properties = {} if additional_properties.nil? @offer_id = offer_id @reference_id = reference_id @title = title @description = description @valid_from = valid_from @valid_to = valid_to unless valid_to == SKIP @additional_properties = additional_properties end |
Instance Attribute Details
#description ⇒ String
Description of the partner's offer, set up upon offer configuration
28 29 30 |
# File 'lib/loyalty_ap_is/models/offer.rb', line 28 def description @description end |
#offer_id ⇒ Integer
Offer ID provided upon offer configuration
15 16 17 |
# File 'lib/loyalty_ap_is/models/offer.rb', line 15 def offer_id @offer_id end |
#reference_id ⇒ String
Unique Reference ID for the transaction from the partner. Used to identify duplicate requests.
20 21 22 |
# File 'lib/loyalty_ap_is/models/offer.rb', line 20 def reference_id @reference_id end |
#title ⇒ String
Title of the partner's offer, given upon configuration
24 25 26 |
# File 'lib/loyalty_ap_is/models/offer.rb', line 24 def title @title end |
#valid_from ⇒ DateTime
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
40 41 42 |
# File 'lib/loyalty_ap_is/models/offer.rb', line 40 def valid_from @valid_from end |
#valid_to ⇒ DateTime
Offer validity end 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
Nullable field value, in case of the offer has infinite valid to.
53 54 55 |
# File 'lib/loyalty_ap_is/models/offer.rb', line 53 def valid_to @valid_to end |
Class Method Details
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/loyalty_ap_is/models/offer.rb', line 96 def self.from_hash(hash) return nil unless hash # Extract variables from the hash. offer_id = hash.key?('offerId') ? hash['offerId'] : nil reference_id = hash.key?('referenceId') ? hash['referenceId'] : nil title = hash.key?('title') ? hash['title'] : nil description = hash.key?('description') ? hash['description'] : nil valid_from = if hash.key?('validFrom') (DateTimeHelper.from_rfc3339(hash['validFrom']) if hash['validFrom']) end 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. Offer.new(offer_id: offer_id, reference_id: reference_id, title: title, description: description, valid_from: valid_from, valid_to: valid_to, additional_properties: additional_properties) end |
.names ⇒ Object
A mapping from model property names to API property names.
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/loyalty_ap_is/models/offer.rb', line 56 def self.names @_hash = {} if @_hash.nil? @_hash['offer_id'] = 'offerId' @_hash['reference_id'] = 'referenceId' @_hash['title'] = 'title' @_hash['description'] = 'description' @_hash['valid_from'] = 'validFrom' @_hash['valid_to'] = 'validTo' @_hash end |
.nullables ⇒ Object
An array for nullable fields
75 76 77 78 79 |
# File 'lib/loyalty_ap_is/models/offer.rb', line 75 def self.nullables %w[ valid_to ] end |
.optionals ⇒ Object
An array for optional fields
68 69 70 71 72 |
# File 'lib/loyalty_ap_is/models/offer.rb', line 68 def self.optionals %w[ valid_to ] end |
Instance Method Details
#inspect ⇒ Object
Provides a debugging-friendly string with detailed object information.
147 148 149 150 151 152 153 |
# File 'lib/loyalty_ap_is/models/offer.rb', line 147 def inspect class_name = self.class.name.split('::').last "<#{class_name} offer_id: #{@offer_id.inspect}, reference_id: #{@reference_id.inspect},"\ " title: #{@title.inspect}, description: #{@description.inspect}, valid_from:"\ " #{@valid_from.inspect}, valid_to: #{@valid_to.inspect}, additional_properties:"\ " #{@additional_properties}>" end |
#to_custom_valid_from ⇒ Object
130 131 132 |
# File 'lib/loyalty_ap_is/models/offer.rb', line 130 def to_custom_valid_from DateTimeHelper.to_rfc3339(valid_from) end |
#to_custom_valid_to ⇒ Object
134 135 136 |
# File 'lib/loyalty_ap_is/models/offer.rb', line 134 def to_custom_valid_to DateTimeHelper.to_rfc3339(valid_to) end |
#to_s ⇒ Object
Provides a human-readable string representation of the object.
139 140 141 142 143 144 |
# File 'lib/loyalty_ap_is/models/offer.rb', line 139 def to_s class_name = self.class.name.split('::').last "<#{class_name} offer_id: #{@offer_id}, reference_id: #{@reference_id}, title: #{@title},"\ " description: #{@description}, valid_from: #{@valid_from}, valid_to: #{@valid_to},"\ " additional_properties: #{@additional_properties}>" end |