Class: Courier::Send::Preference

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status:, rules: nil, channel_preferences: nil, source: nil, additional_properties: nil) ⇒ Send::Preference

Parameters:



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

#rulesObject (readonly)

Returns the value of attribute rules.



12
13
14
# File 'lib/trycourier/send/types/preference.rb', line 12

def rules
  @rules
end

#sourceObject (readonly)

Returns the value of attribute source.



12
13
14
# File 'lib/trycourier/send/types/preference.rb', line 12

def source
  @source
end

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

Parameters:

  • json_object (JSON)

Returns:



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.

Parameters:

  • obj (Object)

Returns:

  • (Void)


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

Returns:

  • (JSON)


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