Class: Courier::Send::AudienceRecipient
- Inherits:
-
Object
- Object
- Courier::Send::AudienceRecipient
- Defined in:
- lib/trycourier/send/types/audience_recipient.rb
Instance Attribute Summary collapse
-
#additional_properties ⇒ Object
readonly
Returns the value of attribute additional_properties.
-
#audience_id ⇒ Object
readonly
Returns the value of attribute audience_id.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#filters ⇒ Object
readonly
Returns the value of attribute filters.
Class Method Summary collapse
-
.from_json(json_object:) ⇒ Send::AudienceRecipient
Deserialize a JSON object to an instance of AudienceRecipient.
-
.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(audience_id:, data: nil, filters: nil, additional_properties: nil) ⇒ Send::AudienceRecipient constructor
-
#to_json(*_args) ⇒ JSON
Serialize an instance of AudienceRecipient to a JSON object.
Constructor Details
#initialize(audience_id:, data: nil, filters: nil, additional_properties: nil) ⇒ Send::AudienceRecipient
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/trycourier/send/types/audience_recipient.rb', line 17 def initialize(audience_id:, data: nil, filters: nil, additional_properties: nil) # @type [String] A unique identifier associated with an Audience. A message will be sent to each user in the audience. @audience_id = audience_id # @type [Send::MESSAGE_DATA] @data = data # @type [Array<Send::AudienceFilter>] @filters = filters # @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.
10 11 12 |
# File 'lib/trycourier/send/types/audience_recipient.rb', line 10 def additional_properties @additional_properties end |
#audience_id ⇒ Object (readonly)
Returns the value of attribute audience_id.
10 11 12 |
# File 'lib/trycourier/send/types/audience_recipient.rb', line 10 def audience_id @audience_id end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
10 11 12 |
# File 'lib/trycourier/send/types/audience_recipient.rb', line 10 def data @data end |
#filters ⇒ Object (readonly)
Returns the value of attribute filters.
10 11 12 |
# File 'lib/trycourier/send/types/audience_recipient.rb', line 10 def filters @filters end |
Class Method Details
.from_json(json_object:) ⇒ Send::AudienceRecipient
Deserialize a JSON object to an instance of AudienceRecipient
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/trycourier/send/types/audience_recipient.rb', line 32 def self.from_json(json_object:) struct = JSON.parse(json_object, object_class: OpenStruct) parsed_json = JSON.parse(json_object) audience_id = struct.audience_id data = struct.data filters = parsed_json["filters"]&.map do |v| v = v.to_json Send::AudienceFilter.from_json(json_object: v) end new(audience_id: audience_id, data: data, filters: filters, 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.
55 56 57 58 59 |
# File 'lib/trycourier/send/types/audience_recipient.rb', line 55 def self.validate_raw(obj:) obj.audience_id.is_a?(String) != false || raise("Passed value for field obj.audience_id is not the expected type, validation failed.") obj.data&.is_a?(Hash) != false || raise("Passed value for field obj.data is not the expected type, validation failed.") obj.filters&.is_a?(Array) != false || raise("Passed value for field obj.filters is not the expected type, validation failed.") end |
Instance Method Details
#to_json(*_args) ⇒ JSON
Serialize an instance of AudienceRecipient to a JSON object
47 48 49 |
# File 'lib/trycourier/send/types/audience_recipient.rb', line 47 def to_json(*_args) { "audience_id": @audience_id, "data": @data, "filters": @filters }.to_json end |