Class: Courier::Send::UserRecipient

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(account_id: nil, context: nil, data: nil, email: nil, locale: nil, user_id: nil, phone_number: nil, preferences: nil, tenant_id: nil, additional_properties: nil) ⇒ Send::UserRecipient

Parameters:

  • account_id (String) (defaults to: nil)

    Use ‘tenant_id` instad.

  • context (Send::MessageContext) (defaults to: nil)

    Context information such as tenant_id to send the notification with.

  • data (Send::MESSAGE_DATA) (defaults to: nil)
  • email (String) (defaults to: nil)
  • locale (String) (defaults to: nil)

    The user’s preferred ISO 639-1 language code.

  • user_id (String) (defaults to: nil)
  • phone_number (String) (defaults to: nil)
  • preferences (Send::IProfilePreferences) (defaults to: nil)
  • tenant_id (String) (defaults to: nil)

    An id of a tenant, [see tenants api docs](www.courier.com/docs/reference/tenants). Will load brand, default preferences and any other base context data associated with this tenant.

  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/trycourier/send/types/user_recipient.rb', line 26

def initialize(account_id: nil, context: nil, data: nil, email: nil, locale: nil, user_id: nil,
               phone_number: nil, preferences: nil, tenant_id: nil, additional_properties: nil)
  # @type [String] Use `tenant_id` instad.
  @account_id = 
  # @type [Send::MessageContext] Context information such as tenant_id to send the notification with.
  @context = context
  # @type [Send::MESSAGE_DATA]
  @data = data
  # @type [String]
  @email = email
  # @type [String] The user's preferred ISO 639-1 language code.
  @locale = locale
  # @type [String]
  @user_id = user_id
  # @type [String]
  @phone_number = phone_number
  # @type [Send::IProfilePreferences]
  @preferences = preferences
  # @type [String] An id of a tenant, [see tenants api docs](https://www.courier.com/docs/reference/tenants).
  #   Will load brand, default preferences and any other base context data associated with this tenant.
  @tenant_id = tenant_id
  # @type [OpenStruct] Additional properties unmapped to the current class definition
  @additional_properties = additional_properties
end

Instance Attribute Details

#account_idObject (readonly)

Returns the value of attribute account_id.



11
12
13
# File 'lib/trycourier/send/types/user_recipient.rb', line 11

def 
  @account_id
end

#additional_propertiesObject (readonly)

Returns the value of attribute additional_properties.



11
12
13
# File 'lib/trycourier/send/types/user_recipient.rb', line 11

def additional_properties
  @additional_properties
end

#contextObject (readonly)

Returns the value of attribute context.



11
12
13
# File 'lib/trycourier/send/types/user_recipient.rb', line 11

def context
  @context
end

#dataObject (readonly)

Returns the value of attribute data.



11
12
13
# File 'lib/trycourier/send/types/user_recipient.rb', line 11

def data
  @data
end

#emailObject (readonly)

Returns the value of attribute email.



11
12
13
# File 'lib/trycourier/send/types/user_recipient.rb', line 11

def email
  @email
end

#localeObject (readonly)

Returns the value of attribute locale.



11
12
13
# File 'lib/trycourier/send/types/user_recipient.rb', line 11

def locale
  @locale
end

#phone_numberObject (readonly)

Returns the value of attribute phone_number.



11
12
13
# File 'lib/trycourier/send/types/user_recipient.rb', line 11

def phone_number
  @phone_number
end

#preferencesObject (readonly)

Returns the value of attribute preferences.



11
12
13
# File 'lib/trycourier/send/types/user_recipient.rb', line 11

def preferences
  @preferences
end

#tenant_idObject (readonly)

Returns the value of attribute tenant_id.



11
12
13
# File 'lib/trycourier/send/types/user_recipient.rb', line 11

def tenant_id
  @tenant_id
end

#user_idObject (readonly)

Returns the value of attribute user_id.



11
12
13
# File 'lib/trycourier/send/types/user_recipient.rb', line 11

def user_id
  @user_id
end

Class Method Details

.from_json(json_object:) ⇒ Send::UserRecipient

Deserialize a JSON object to an instance of UserRecipient

Parameters:

  • json_object (JSON)

Returns:



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/trycourier/send/types/user_recipient.rb', line 55

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
   = struct.
  if parsed_json["context"].nil?
    context = nil
  else
    context = parsed_json["context"].to_json
    context = Send::MessageContext.from_json(json_object: context)
  end
  data = struct.data
  email = struct.email
  locale = struct.locale
  user_id = struct.user_id
  phone_number = struct.phone_number
  if parsed_json["preferences"].nil?
    preferences = nil
  else
    preferences = parsed_json["preferences"].to_json
    preferences = Send::IProfilePreferences.from_json(json_object: preferences)
  end
  tenant_id = struct.tenant_id
  new(account_id: , context: context, data: data, email: email, locale: locale, user_id: user_id,
      phone_number: phone_number, preferences: preferences, tenant_id: tenant_id, 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)


102
103
104
105
106
107
108
109
110
111
112
# File 'lib/trycourier/send/types/user_recipient.rb', line 102

def self.validate_raw(obj:)
  obj.&.is_a?(String) != false || raise("Passed value for field obj.account_id is not the expected type, validation failed.")
  obj.context.nil? || Send::MessageContext.validate_raw(obj: obj.context)
  obj.data&.is_a?(Hash) != false || raise("Passed value for field obj.data is not the expected type, validation failed.")
  obj.email&.is_a?(String) != false || raise("Passed value for field obj.email is not the expected type, validation failed.")
  obj.locale&.is_a?(String) != false || raise("Passed value for field obj.locale is not the expected type, validation failed.")
  obj.user_id&.is_a?(String) != false || raise("Passed value for field obj.user_id is not the expected type, validation failed.")
  obj.phone_number&.is_a?(String) != false || raise("Passed value for field obj.phone_number is not the expected type, validation failed.")
  obj.preferences.nil? || Send::IProfilePreferences.validate_raw(obj: obj.preferences)
  obj.tenant_id&.is_a?(String) != false || raise("Passed value for field obj.tenant_id is not the expected type, validation failed.")
end

Instance Method Details

#to_json(*_args) ⇒ JSON

Serialize an instance of UserRecipient to a JSON object

Returns:

  • (JSON)


84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/trycourier/send/types/user_recipient.rb', line 84

def to_json(*_args)
  {
    "account_id": @account_id,
    "context": @context,
    "data": @data,
    "email": @email,
    "locale": @locale,
    "user_id": @user_id,
    "phone_number": @phone_number,
    "preferences": @preferences,
    "tenant_id": @tenant_id
  }.to_json
end