Class: Courier::Send::Preference
- Inherits:
-
Object
- Object
- Courier::Send::Preference
- Defined in:
- lib/trycourier/send/types/preference.rb
Instance Attribute Summary collapse
-
#additional_properties ⇒ Object
readonly
Returns the value of attribute additional_properties.
-
#channel_preferences ⇒ Object
readonly
Returns the value of attribute channel_preferences.
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Class Method Summary collapse
-
.from_json(json_object:) ⇒ Send::Preference
Deserialize a JSON object to an instance of Preference.
-
.validate_raw(obj:) ⇒ Void
Leveraged for Union-type generation, validate_raw attempts to parse the given hash and check each fields type against the current object’s property definitions.
Instance Method Summary collapse
- #initialize(status:, rules: nil, channel_preferences: nil, source: nil, additional_properties: nil) ⇒ Send::Preference constructor
-
#to_json(*_args) ⇒ JSON
Serialize an instance of Preference to a JSON object.
Constructor Details
#initialize(status:, rules: nil, channel_preferences: nil, source: nil, additional_properties: nil) ⇒ Send::Preference
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/trycourier/send/types/preference.rb', line 20 def initialize(status:, rules: nil, channel_preferences: nil, source: nil, additional_properties: nil) # @type [Commons::PreferenceStatus] @status = status # @type [Array<Commons::Rule>] @rules = rules # @type [Array<Commons::ChannelPreference>] @channel_preferences = channel_preferences # @type [Send::ChannelSource] @source = source # @type [OpenStruct] Additional properties unmapped to the current class definition @additional_properties = additional_properties end |
Instance Attribute Details
#additional_properties ⇒ Object (readonly)
Returns the value of attribute additional_properties.
12 13 14 |
# File 'lib/trycourier/send/types/preference.rb', line 12 def additional_properties @additional_properties end |
#channel_preferences ⇒ Object (readonly)
Returns the value of attribute channel_preferences.
12 13 14 |
# File 'lib/trycourier/send/types/preference.rb', line 12 def channel_preferences @channel_preferences end |
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
12 13 14 |
# File 'lib/trycourier/send/types/preference.rb', line 12 def rules @rules end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
12 13 14 |
# File 'lib/trycourier/send/types/preference.rb', line 12 def source @source end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
12 13 14 |
# File 'lib/trycourier/send/types/preference.rb', line 12 def status @status end |
Class Method Details
.from_json(json_object:) ⇒ Send::Preference
Deserialize a JSON object to an instance of Preference
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/trycourier/send/types/preference.rb', line 37 def self.from_json(json_object:) struct = JSON.parse(json_object, object_class: OpenStruct) parsed_json = JSON.parse(json_object) status = struct.status rules = parsed_json["rules"]&.map do |v| v = v.to_json Commons::Rule.from_json(json_object: v) end channel_preferences = parsed_json["channel_preferences"]&.map do |v| v = v.to_json Commons::ChannelPreference.from_json(json_object: v) end source = struct.source new(status: status, rules: rules, channel_preferences: channel_preferences, source: source, additional_properties: struct) end |
.validate_raw(obj:) ⇒ Void
Leveraged for Union-type generation, validate_raw attempts to parse the given hash and check each fields type against the current object’s property definitions.
65 66 67 68 69 70 |
# File 'lib/trycourier/send/types/preference.rb', line 65 def self.validate_raw(obj:) obj.status.is_a?(Commons::PreferenceStatus) != false || raise("Passed value for field obj.status is not the expected type, validation failed.") obj.rules&.is_a?(Array) != false || raise("Passed value for field obj.rules is not the expected type, validation failed.") obj.channel_preferences&.is_a?(Array) != false || raise("Passed value for field obj.channel_preferences is not the expected type, validation failed.") obj.source&.is_a?(Send::ChannelSource) != false || raise("Passed value for field obj.source is not the expected type, validation failed.") end |
Instance Method Details
#to_json(*_args) ⇒ JSON
Serialize an instance of Preference to a JSON object
57 58 59 |
# File 'lib/trycourier/send/types/preference.rb', line 57 def to_json(*_args) { "status": @status, "rules": @rules, "channel_preferences": @channel_preferences, "source": @source }.to_json end |