Class: Customerio::TriggerBroadcastRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/customerio/requests/trigger_broadcast_request.rb

Constant Summary collapse

AUDIENCE_FIELDS =
%i[recipients emails ids per_user_data data_file_url].freeze
OPTIONAL_FIELDS =
%i[data email_add_duplicates email_ignore_missing id_ignore_missing].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ TriggerBroadcastRequest

Returns a new instance of TriggerBroadcastRequest.

Raises:

  • (ArgumentError)


11
12
13
14
15
16
17
18
19
20
# File 'lib/customerio/requests/trigger_broadcast_request.rb', line 11

def initialize(opts)
  raise ArgumentError, "broadcast_id is required" unless opts.key?(:broadcast_id)
  raise ArgumentError, "broadcast_id must be an integer" unless opts[:broadcast_id].is_a?(Integer)

  @broadcast_id = opts[:broadcast_id]
  @message = opts.select { |field, _value| valid_field?(field) }

  audience = AUDIENCE_FIELDS.select { |field| @message.key?(field) }
  raise ArgumentError, "only one of #{AUDIENCE_FIELDS.join(', ')} can be present" if audience.length > 1
end

Instance Attribute Details

#broadcast_idObject (readonly)

Returns the value of attribute broadcast_id.



9
10
11
# File 'lib/customerio/requests/trigger_broadcast_request.rb', line 9

def broadcast_id
  @broadcast_id
end

#messageObject (readonly)

Returns the value of attribute message.



9
10
11
# File 'lib/customerio/requests/trigger_broadcast_request.rb', line 9

def message
  @message
end