Class: Courier::Lists::ListSubscriptionRecipient

Inherits:
Object
  • Object
show all
Defined in:
lib/trycourier/lists/types/list_subscription_recipient.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(recipient_id:, created: nil, preferences: nil, additional_properties: nil) ⇒ Lists::ListSubscriptionRecipient

Parameters:

  • recipient_id (String)
  • created (String) (defaults to: nil)
  • preferences (Commons::RecipientPreferences) (defaults to: nil)
  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



16
17
18
19
20
21
22
23
24
25
# File 'lib/trycourier/lists/types/list_subscription_recipient.rb', line 16

def initialize(recipient_id:, created: nil, preferences: nil, additional_properties: nil)
  # @type [String]
  @recipient_id = recipient_id
  # @type [String]
  @created = created
  # @type [Commons::RecipientPreferences]
  @preferences = preferences
  # @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.



9
10
11
# File 'lib/trycourier/lists/types/list_subscription_recipient.rb', line 9

def additional_properties
  @additional_properties
end

#createdObject (readonly)

Returns the value of attribute created.



9
10
11
# File 'lib/trycourier/lists/types/list_subscription_recipient.rb', line 9

def created
  @created
end

#preferencesObject (readonly)

Returns the value of attribute preferences.



9
10
11
# File 'lib/trycourier/lists/types/list_subscription_recipient.rb', line 9

def preferences
  @preferences
end

#recipient_idObject (readonly)

Returns the value of attribute recipient_id.



9
10
11
# File 'lib/trycourier/lists/types/list_subscription_recipient.rb', line 9

def recipient_id
  @recipient_id
end

Class Method Details

.from_json(json_object:) ⇒ Lists::ListSubscriptionRecipient

Deserialize a JSON object to an instance of ListSubscriptionRecipient

Parameters:

  • json_object (JSON)

Returns:



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/trycourier/lists/types/list_subscription_recipient.rb', line 31

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  recipient_id = struct.recipientId
  created = struct.created
  if parsed_json["preferences"].nil?
    preferences = nil
  else
    preferences = parsed_json["preferences"].to_json
    preferences = Commons::RecipientPreferences.from_json(json_object: preferences)
  end
  new(recipient_id: recipient_id, created: created, preferences: preferences, 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)


56
57
58
59
60
# File 'lib/trycourier/lists/types/list_subscription_recipient.rb', line 56

def self.validate_raw(obj:)
  obj.recipient_id.is_a?(String) != false || raise("Passed value for field obj.recipient_id is not the expected type, validation failed.")
  obj.created&.is_a?(String) != false || raise("Passed value for field obj.created is not the expected type, validation failed.")
  obj.preferences.nil? || Commons::RecipientPreferences.validate_raw(obj: obj.preferences)
end

Instance Method Details

#to_json(*_args) ⇒ JSON

Serialize an instance of ListSubscriptionRecipient to a JSON object

Returns:

  • (JSON)


48
49
50
# File 'lib/trycourier/lists/types/list_subscription_recipient.rb', line 48

def to_json(*_args)
  { "recipientId": @recipient_id, "created": @created, "preferences": @preferences }.to_json
end