Class: Courier::Tenants::Tenant
- Inherits:
-
Object
- Object
- Courier::Tenants::Tenant
- Defined in:
- lib/trycourier/tenants/types/tenant.rb
Instance Attribute Summary collapse
-
#additional_properties ⇒ Object
readonly
Returns the value of attribute additional_properties.
-
#brand_id ⇒ Object
readonly
Returns the value of attribute brand_id.
-
#default_preferences ⇒ Object
readonly
Returns the value of attribute default_preferences.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent_tenant_id ⇒ Object
readonly
Returns the value of attribute parent_tenant_id.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
-
#user_profile ⇒ Object
readonly
Returns the value of attribute user_profile.
Class Method Summary collapse
-
.from_json(json_object:) ⇒ Tenants::Tenant
Deserialize a JSON object to an instance of Tenant.
-
.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.
Instance Method Summary collapse
- #initialize(id:, name:, parent_tenant_id: nil, default_preferences: nil, properties: nil, user_profile: nil, brand_id: nil, additional_properties: nil) ⇒ Tenants::Tenant constructor
-
#to_json(*_args) ⇒ JSON
Serialize an instance of Tenant to a JSON object.
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
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 = 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_properties ⇒ Object (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_id ⇒ Object (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_preferences ⇒ Object (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 |
#id ⇒ Object (readonly)
Returns the value of attribute id.
10 11 12 |
# File 'lib/trycourier/tenants/types/tenant.rb', line 10 def id @id end |
#name ⇒ Object (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_id ⇒ Object (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 |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
10 11 12 |
# File 'lib/trycourier/tenants/types/tenant.rb', line 10 def properties @properties end |
#user_profile ⇒ Object (readonly)
Returns the value of attribute user_profile.
10 11 12 |
# File 'lib/trycourier/tenants/types/tenant.rb', line 10 def user_profile @user_profile end |
Class Method Details
.from_json(json_object:) ⇒ Tenants::Tenant
Deserialize a JSON object to an instance of Tenant
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 user_profile = struct.user_profile brand_id = struct.brand_id new(id: id, name: name, parent_tenant_id: parent_tenant_id, default_preferences: default_preferences, properties: properties, user_profile: 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.
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.user_profile&.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
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 |