Class: OneSignal::JourneyCondition

Inherits:
Object
  • Object
show all
Defined in:
lib/onesignal/models/journey_condition.rb

Overview

A branch condition. The kind field selects which other fields apply.

Defined Under Namespace

Classes: EnumAttributeValidator

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ JourneyCondition

Initializes the object

Parameters:

  • attributes (Hash) (defaults to: {})

    Model attributes in the form of hash



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/onesignal/models/journey_condition.rb', line 111

def initialize(attributes = {})
  if (!attributes.is_a?(Hash))
    fail ArgumentError, "The input argument (attributes) must be a hash in `OneSignal::JourneyCondition` initialize method"
  end

  # check to see if the attribute exists and convert string to symbol for hash key
  attributes = attributes.each_with_object({}) { |(k, v), h|
    if (!self.class.attribute_map.key?(k.to_sym))
      fail ArgumentError, "`#{k}` is not a valid attribute in `OneSignal::JourneyCondition`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
    end
    h[k.to_sym] = v
  }

  if attributes.key?(:'kind')
    self.kind = attributes[:'kind']
  end

  if attributes.key?(:'included_segment_ids')
    if (value = attributes[:'included_segment_ids']).is_a?(Array)
      self.included_segment_ids = value
    end
  end

  if attributes.key?(:'excluded_segment_ids')
    if (value = attributes[:'excluded_segment_ids']).is_a?(Array)
      self.excluded_segment_ids = value
    end
  end

  if attributes.key?(:'action')
    self.action = attributes[:'action']
  end

  if attributes.key?(:'sending_node_id')
    self.sending_node_id = attributes[:'sending_node_id']
  end

  if attributes.key?(:'client_node_id')
    self.client_node_id = attributes[:'client_node_id']
  end

  if attributes.key?(:'name')
    self.name = attributes[:'name']
  end

  if attributes.key?(:'attributes')
    if (value = attributes[:'attributes']).is_a?(Array)
      self.attributes = value
    end
  end

  if attributes.key?(:'entry_event_match_attributes')
    if (value = attributes[:'entry_event_match_attributes']).is_a?(Array)
      self.entry_event_match_attributes = value
    end
  end
end

Instance Attribute Details

#actionObject

on_notification_action conditions: the notification action to branch on. Which actions apply depends on the sending node's channel.



28
29
30
# File 'lib/onesignal/models/journey_condition.rb', line 28

def action
  @action
end

#attributesObject

Event attribute matchers, as a list of condition groups. Send a single group whose conditions are AND'd together. More than one group is rejected.



40
41
42
# File 'lib/onesignal/models/journey_condition.rb', line 40

def attributes
  @attributes
end

#client_node_idObject

on_notification_action conditions: write-only alternative to sending_node_id. References the sending node by its client_node_id.



34
35
36
# File 'lib/onesignal/models/journey_condition.rb', line 34

def client_node_id
  @client_node_id
end

#entry_event_match_attributesObject

event_trigger conditions: match incoming event properties against the journey's entry event. Only valid on event-triggered journeys.



43
44
45
# File 'lib/onesignal/models/journey_condition.rb', line 43

def entry_event_match_attributes
  @entry_event_match_attributes
end

#excluded_segment_idsObject

segment_membership conditions: Segment UUIDs the user must not belong to.



25
26
27
# File 'lib/onesignal/models/journey_condition.rb', line 25

def excluded_segment_ids
  @excluded_segment_ids
end

#included_segment_idsObject

segment_membership conditions: Segment UUIDs the user must belong to.



22
23
24
# File 'lib/onesignal/models/journey_condition.rb', line 22

def included_segment_ids
  @included_segment_ids
end

#kindObject

Condition kind. Selects which other fields apply.



19
20
21
# File 'lib/onesignal/models/journey_condition.rb', line 19

def kind
  @kind
end

#nameObject

event_trigger conditions: event name, up to 255 characters.



37
38
39
# File 'lib/onesignal/models/journey_condition.rb', line 37

def name
  @name
end

#sending_node_idObject

on_notification_action conditions: id of the sending node this action refers to. Returned on reads; accepted on write.



31
32
33
# File 'lib/onesignal/models/journey_condition.rb', line 31

def sending_node_id
  @sending_node_id
end

Class Method Details

.acceptable_attributesObject

Returns all the JSON keys this model knows about



83
84
85
# File 'lib/onesignal/models/journey_condition.rb', line 83

def self.acceptable_attributes
  attribute_map.values
end

.attribute_mapObject

Attribute mapping from ruby-style variable name to JSON key.



68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/onesignal/models/journey_condition.rb', line 68

def self.attribute_map
  {
    :'kind' => :'kind',
    :'included_segment_ids' => :'included_segment_ids',
    :'excluded_segment_ids' => :'excluded_segment_ids',
    :'action' => :'action',
    :'sending_node_id' => :'sending_node_id',
    :'client_node_id' => :'client_node_id',
    :'name' => :'name',
    :'attributes' => :'attributes',
    :'entry_event_match_attributes' => :'entry_event_match_attributes'
  }
end

.build_from_hash(attributes) ⇒ Object

Builds the object from hash

Parameters:

  • attributes (Hash)

    Model attributes in the form of hash

Returns:

  • (Object)

    Returns the model itself



242
243
244
# File 'lib/onesignal/models/journey_condition.rb', line 242

def self.build_from_hash(attributes)
  new.build_from_hash(attributes)
end

.openapi_nullableObject

List of attributes with nullable: true



103
104
105
106
107
# File 'lib/onesignal/models/journey_condition.rb', line 103

def self.openapi_nullable
  Set.new([
    :'entry_event_match_attributes'
  ])
end

.openapi_typesObject

Attribute type mapping.



88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/onesignal/models/journey_condition.rb', line 88

def self.openapi_types
  {
    :'kind' => :'String',
    :'included_segment_ids' => :'Array<String>',
    :'excluded_segment_ids' => :'Array<String>',
    :'action' => :'String',
    :'sending_node_id' => :'String',
    :'client_node_id' => :'String',
    :'name' => :'String',
    :'attributes' => :'Array<Array<JourneyEventAttribute>>',
    :'entry_event_match_attributes' => :'Array<Object>'
  }
end

Instance Method Details

#==(o) ⇒ Object

Checks equality by comparing each attribute.

Parameters:

  • Object (Object)

    to be compared



213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/onesignal/models/journey_condition.rb', line 213

def ==(o)
  return true if self.equal?(o)
  self.class == o.class &&
      kind == o.kind &&
      included_segment_ids == o.included_segment_ids &&
      excluded_segment_ids == o.excluded_segment_ids &&
      action == o.action &&
      sending_node_id == o.sending_node_id &&
      client_node_id == o.client_node_id &&
      name == o.name &&
      attributes == o.attributes &&
      entry_event_match_attributes == o.entry_event_match_attributes
end

#_deserialize(type, value) ⇒ Object

Deserializes the data based on type

Parameters:

  • string

    type Data type

  • string

    value Value to be deserialized

Returns:

  • (Object)

    Deserialized data



273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
# File 'lib/onesignal/models/journey_condition.rb', line 273

def _deserialize(type, value)
  case type.to_sym
  when :Time
    Time.parse(value)
  when :Date
    Date.parse(value)
  when :String
    value.to_s
  when :Integer
    value.to_i
  when :Float
    value.to_f
  when :Boolean
    if value.to_s =~ /\A(true|t|yes|y|1)\z/i
      true
    else
      false
    end
  when :Object
    # generic object (usually a Hash), return directly
    value
  when /\AArray<(?<inner_type>.+)>\z/
    inner_type = Regexp.last_match[:inner_type]
    value.map { |v| _deserialize(inner_type, v) }
  when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
    k_type = Regexp.last_match[:k_type]
    v_type = Regexp.last_match[:v_type]
    {}.tap do |hash|
      value.each do |k, v|
        hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
      end
    end
  else # model
    # models (e.g. Pet) or oneOf
    klass = OneSignal.const_get(type)
    klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
  end
end

#_to_hash(value) ⇒ Hash

Outputs non-array value in the form of hash For object, use to_hash. Otherwise, just return the value

Parameters:

  • value (Object)

    Any valid value

Returns:

  • (Hash)

    Returns the value in the form of hash



344
345
346
347
348
349
350
351
352
353
354
355
356
# File 'lib/onesignal/models/journey_condition.rb', line 344

def _to_hash(value)
  if value.is_a?(Array)
    value.compact.map { |v| _to_hash(v) }
  elsif value.is_a?(Hash)
    {}.tap do |hash|
      value.each { |k, v| hash[k] = _to_hash(v) }
    end
  elsif value.respond_to? :to_hash
    value.to_hash
  else
    value
  end
end

#build_from_hash(attributes) ⇒ Object

Builds the object from hash

Parameters:

  • attributes (Hash)

    Model attributes in the form of hash

Returns:

  • (Object)

    Returns the model itself



249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# File 'lib/onesignal/models/journey_condition.rb', line 249

def build_from_hash(attributes)
  return nil unless attributes.is_a?(Hash)
  attributes = attributes.transform_keys(&:to_sym)
  self.class.openapi_types.each_pair do |key, type|
    if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
      self.send("#{key}=", nil)
    elsif type =~ /\AArray<(.*)>/i
      # check to ensure the input is an array given that the attribute
      # is documented as an array but the input is not
      if attributes[self.class.attribute_map[key]].is_a?(Array)
        self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
      end
    elsif !attributes[self.class.attribute_map[key]].nil?
      self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
    end
  end

  self
end

#eql?(o) ⇒ Boolean

Parameters:

  • Object (Object)

    to be compared

Returns:

  • (Boolean)

See Also:

  • `==` method


229
230
231
# File 'lib/onesignal/models/journey_condition.rb', line 229

def eql?(o)
  self == o
end

#hashInteger

Calculates hash code according to all attributes.

Returns:

  • (Integer)

    Hash code



235
236
237
# File 'lib/onesignal/models/journey_condition.rb', line 235

def hash
  [kind, included_segment_ids, excluded_segment_ids, action, sending_node_id, client_node_id, name, attributes, entry_event_match_attributes].hash
end

#list_invalid_propertiesObject

Show invalid properties with the reasons. Usually used together with valid?

Returns:

  • Array for valid properties with the reasons



171
172
173
174
175
176
177
178
# File 'lib/onesignal/models/journey_condition.rb', line 171

def list_invalid_properties
  invalid_properties = Array.new
  if @kind.nil?
    invalid_properties.push('invalid value for "kind", kind cannot be nil.')
  end

  invalid_properties
end

#to_bodyHash

to_body is an alias to to_hash (backward compatibility)

Returns:

  • (Hash)

    Returns the object in the form of hash



320
321
322
# File 'lib/onesignal/models/journey_condition.rb', line 320

def to_body
  to_hash
end

#to_hashHash

Returns the object in the form of hash

Returns:

  • (Hash)

    Returns the object in the form of hash



326
327
328
329
330
331
332
333
334
335
336
337
338
# File 'lib/onesignal/models/journey_condition.rb', line 326

def to_hash
  hash = {}
  self.class.attribute_map.each_pair do |attr, param|
    value = self.send(attr)
    if value.nil?
      is_nullable = self.class.openapi_nullable.include?(attr)
      next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
    end

    hash[param] = _to_hash(value)
  end
  hash
end

#to_sString

Returns the string representation of the object

Returns:

  • (String)

    String presentation of the object



314
315
316
# File 'lib/onesignal/models/journey_condition.rb', line 314

def to_s
  to_hash.to_s
end

#valid?Boolean

Check to see if the all the properties in the model are valid

Returns:

  • (Boolean)

    true if the model is valid



182
183
184
185
186
187
188
189
# File 'lib/onesignal/models/journey_condition.rb', line 182

def valid?
  return false if @kind.nil?
  kind_validator = EnumAttributeValidator.new('String', ["segment_membership", "on_notification_action", "event_trigger"])
  return false unless kind_validator.valid?(@kind)
  action_validator = EnumAttributeValidator.new('String', ["received", "clicked", "opened"])
  return false unless action_validator.valid?(@action)
  true
end