Class: Courier::Send::AudienceRecipient

Inherits:
Object
  • Object
show all
Defined in:
lib/trycourier/send/types/audience_recipient.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(audience_id:, data: nil, filters: nil, additional_properties: nil) ⇒ Send::AudienceRecipient

Parameters:

  • audience_id (String)

    A unique identifier associated with an Audience. A message will be sent to each user in the audience.

  • data (Send::MESSAGE_DATA) (defaults to: nil)
  • filters (Array<Send::AudienceFilter>) (defaults to: nil)
  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



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_propertiesObject (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_idObject (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

#dataObject (readonly)

Returns the value of attribute data.



10
11
12
# File 'lib/trycourier/send/types/audience_recipient.rb', line 10

def data
  @data
end

#filtersObject (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

Parameters:

  • json_object (JSON)

Returns:



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.

Parameters:

  • obj (Object)

Returns:

  • (Void)


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

Returns:

  • (JSON)


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