Class: Courier::Tenants::Tenant

Inherits:
Object
  • Object
show all
Defined in:
lib/trycourier/tenants/types/tenant.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, name:, parent_tenant_id: nil, default_preferences: nil, properties: nil, user_profile: nil, brand_id: nil, additional_properties: nil) ⇒ Tenants::Tenant

Parameters:

  • id (String)

    Id of the tenant.

  • name (String)

    Name of the tenant.

  • parent_tenant_id (String) (defaults to: nil)

    Tenant’s parent id (if any).

  • default_preferences (Tenants::DefaultPreferences) (defaults to: nil)

    Defines the preferences used for the account when the user hasn’t specified their own.

  • properties (Tenants::TEMPLATE_PROPERTY) (defaults to: nil)

    Arbitrary properties accessible to a template.

  • user_profile (Hash{String => String}) (defaults to: nil)

    A user profile object merged with user profile on send.

  • brand_id (String) (defaults to: nil)

    Brand to be used for the account when one is not specified by the send call.

  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/trycourier/tenants/types/tenant.rb', line 22

def initialize(id:, name:, parent_tenant_id: nil, default_preferences: nil, properties: nil, user_profile: nil,
               brand_id: nil, additional_properties: nil)
  # @type [String] Id of the tenant.
  @id = id
  # @type [String] Name of the tenant.
  @name = name
  # @type [String] Tenant's parent id (if any).
  @parent_tenant_id = parent_tenant_id
  # @type [Tenants::DefaultPreferences] Defines the preferences used for the account when the user hasn't specified their own.
  @default_preferences = default_preferences
  # @type [Tenants::TEMPLATE_PROPERTY] Arbitrary properties accessible to a template.
  @properties = properties
  # @type [Hash{String => String}] A user profile object merged with user profile on send.
  @user_profile = 
  # @type [String] Brand to be used for the account when one is not specified by the send call.
  @brand_id = brand_id
  # @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.



10
11
12
# File 'lib/trycourier/tenants/types/tenant.rb', line 10

def additional_properties
  @additional_properties
end

#brand_idObject (readonly)

Returns the value of attribute brand_id.



10
11
12
# File 'lib/trycourier/tenants/types/tenant.rb', line 10

def brand_id
  @brand_id
end

#default_preferencesObject (readonly)

Returns the value of attribute default_preferences.



10
11
12
# File 'lib/trycourier/tenants/types/tenant.rb', line 10

def default_preferences
  @default_preferences
end

#idObject (readonly)

Returns the value of attribute id.



10
11
12
# File 'lib/trycourier/tenants/types/tenant.rb', line 10

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/trycourier/tenants/types/tenant.rb', line 10

def name
  @name
end

#parent_tenant_idObject (readonly)

Returns the value of attribute parent_tenant_id.



10
11
12
# File 'lib/trycourier/tenants/types/tenant.rb', line 10

def parent_tenant_id
  @parent_tenant_id
end

#propertiesObject (readonly)

Returns the value of attribute properties.



10
11
12
# File 'lib/trycourier/tenants/types/tenant.rb', line 10

def properties
  @properties
end

#user_profileObject (readonly)

Returns the value of attribute user_profile.



10
11
12
# File 'lib/trycourier/tenants/types/tenant.rb', line 10

def 
  @user_profile
end

Class Method Details

.from_json(json_object:) ⇒ Tenants::Tenant

Deserialize a JSON object to an instance of Tenant

Parameters:

  • json_object (JSON)

Returns:



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/trycourier/tenants/types/tenant.rb', line 46

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  id = struct.id
  name = struct.name
  parent_tenant_id = struct.parent_tenant_id
  if parsed_json["default_preferences"].nil?
    default_preferences = nil
  else
    default_preferences = parsed_json["default_preferences"].to_json
    default_preferences = Tenants::DefaultPreferences.from_json(json_object: default_preferences)
  end
  properties = struct.properties
   = struct.
  brand_id = struct.brand_id
  new(id: id, name: name, parent_tenant_id: parent_tenant_id, default_preferences: default_preferences,
      properties: properties, user_profile: , brand_id: brand_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)


84
85
86
87
88
89
90
91
92
# File 'lib/trycourier/tenants/types/tenant.rb', line 84

def self.validate_raw(obj:)
  obj.id.is_a?(String) != false || raise("Passed value for field obj.id is not the expected type, validation failed.")
  obj.name.is_a?(String) != false || raise("Passed value for field obj.name is not the expected type, validation failed.")
  obj.parent_tenant_id&.is_a?(String) != false || raise("Passed value for field obj.parent_tenant_id is not the expected type, validation failed.")
  obj.default_preferences.nil? || Tenants::DefaultPreferences.validate_raw(obj: obj.default_preferences)
  obj.properties&.is_a?(Object) != false || raise("Passed value for field obj.properties is not the expected type, validation failed.")
  obj.&.is_a?(Hash) != false || raise("Passed value for field obj.user_profile is not the expected type, validation failed.")
  obj.brand_id&.is_a?(String) != false || raise("Passed value for field obj.brand_id is not the expected type, validation failed.")
end

Instance Method Details

#to_json(*_args) ⇒ JSON

Serialize an instance of Tenant to a JSON object

Returns:

  • (JSON)


68
69
70
71
72
73
74
75
76
77
78
# File 'lib/trycourier/tenants/types/tenant.rb', line 68

def to_json(*_args)
  {
    "id": @id,
    "name": @name,
    "parent_tenant_id": @parent_tenant_id,
    "default_preferences": @default_preferences,
    "properties": @properties,
    "user_profile": @user_profile,
    "brand_id": @brand_id
  }.to_json
end