Class: TrophyApiClient::User
- Inherits:
-
Object
- Object
- TrophyApiClient::User
- Defined in:
- lib/trophy_api_client/types/user.rb
Overview
A user of your application.
Constant Summary collapse
- OMIT =
Object.new
Instance Attribute Summary collapse
-
#additional_properties ⇒ OpenStruct
readonly
Additional properties unmapped to the current class definition.
-
#attributes ⇒ Hash{String => String}
readonly
User attributes as key-value pairs.
-
#control ⇒ Boolean
readonly
Whether the user is in the control group, meaning they do not receive emails or other communications from Trophy.
-
#created ⇒ DateTime
readonly
The date and time the user was created, in ISO 8601 format.
-
#device_tokens ⇒ Array<String>
readonly
The user’s device tokens, used for push notifications.
-
#email ⇒ String
readonly
The user’s email address.
-
#id ⇒ String
readonly
The ID of the user in your database.
-
#name ⇒ String
readonly
The name to refer to the user by in emails.
-
#subscribe_to_emails ⇒ Boolean
readonly
Whether the user should receive Trophy-powered emails.
-
#tz ⇒ String
readonly
The user’s timezone (used for email scheduling).
-
#updated ⇒ DateTime
readonly
The date and time the user was last updated, in ISO 8601 format.
Class Method Summary collapse
-
.from_json(json_object:) ⇒ TrophyApiClient::User
Deserialize a JSON object to an instance of User.
-
.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:, control: OMIT, created: OMIT, updated: OMIT, email: OMIT, name: OMIT, tz: OMIT, device_tokens: OMIT, subscribe_to_emails: OMIT, attributes: OMIT, additional_properties: nil) ⇒ TrophyApiClient::User constructor
-
#to_json(*_args) ⇒ String
Serialize an instance of User to a JSON object.
Constructor Details
#initialize(id:, control: OMIT, created: OMIT, updated: OMIT, email: OMIT, name: OMIT, tz: OMIT, device_tokens: OMIT, subscribe_to_emails: OMIT, attributes: OMIT, additional_properties: nil) ⇒ TrophyApiClient::User
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/trophy_api_client/types/user.rb', line 56 def initialize(id:, control: OMIT, created: OMIT, updated: OMIT, email: OMIT, name: OMIT, tz: OMIT, device_tokens: OMIT, subscribe_to_emails: OMIT, attributes: OMIT, additional_properties: nil) @control = control if control != OMIT @created = created if created != OMIT @updated = updated if updated != OMIT @id = id @email = email if email != OMIT @name = name if name != OMIT @tz = tz if tz != OMIT @device_tokens = device_tokens if device_tokens != OMIT @subscribe_to_emails = subscribe_to_emails if subscribe_to_emails != OMIT @attributes = attributes if attributes != OMIT @additional_properties = additional_properties @_field_set = { "control": control, "created": created, "updated": updated, "id": id, "email": email, "name": name, "tz": tz, "deviceTokens": device_tokens, "subscribeToEmails": subscribe_to_emails, "attributes": attributes }.reject do |_k, v| v == OMIT end end |
Instance Attribute Details
#additional_properties ⇒ OpenStruct (readonly)
Returns Additional properties unmapped to the current class definition.
34 35 36 |
# File 'lib/trophy_api_client/types/user.rb', line 34 def additional_properties @additional_properties end |
#attributes ⇒ Hash{String => String} (readonly)
Returns User attributes as key-value pairs. Keys must match existing user attributes set up in the Trophy dashboard.
32 33 34 |
# File 'lib/trophy_api_client/types/user.rb', line 32 def attributes @attributes end |
#control ⇒ Boolean (readonly)
Returns Whether the user is in the control group, meaning they do not receive emails or other communications from Trophy.
12 13 14 |
# File 'lib/trophy_api_client/types/user.rb', line 12 def control @control end |
#created ⇒ DateTime (readonly)
Returns The date and time the user was created, in ISO 8601 format.
14 15 16 |
# File 'lib/trophy_api_client/types/user.rb', line 14 def created @created end |
#device_tokens ⇒ Array<String> (readonly)
Returns The user’s device tokens, used for push notifications.
26 27 28 |
# File 'lib/trophy_api_client/types/user.rb', line 26 def device_tokens @device_tokens end |
#email ⇒ String (readonly)
Returns The user’s email address. Required if subscribeToEmails is true.
20 21 22 |
# File 'lib/trophy_api_client/types/user.rb', line 20 def email @email end |
#id ⇒ String (readonly)
Returns The ID of the user in your database. Must be a string.
18 19 20 |
# File 'lib/trophy_api_client/types/user.rb', line 18 def id @id end |
#name ⇒ String (readonly)
Returns The name to refer to the user by in emails.
22 23 24 |
# File 'lib/trophy_api_client/types/user.rb', line 22 def name @name end |
#subscribe_to_emails ⇒ Boolean (readonly)
Returns Whether the user should receive Trophy-powered emails. If false, Trophy will not store the user’s email address.
29 30 31 |
# File 'lib/trophy_api_client/types/user.rb', line 29 def subscribe_to_emails @subscribe_to_emails end |
#tz ⇒ String (readonly)
Returns The user’s timezone (used for email scheduling).
24 25 26 |
# File 'lib/trophy_api_client/types/user.rb', line 24 def tz @tz end |
#updated ⇒ DateTime (readonly)
Returns The date and time the user was last updated, in ISO 8601 format.
16 17 18 |
# File 'lib/trophy_api_client/types/user.rb', line 16 def updated @updated end |
Class Method Details
.from_json(json_object:) ⇒ TrophyApiClient::User
Deserialize a JSON object to an instance of User
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/trophy_api_client/types/user.rb', line 89 def self.from_json(json_object:) struct = JSON.parse(json_object, object_class: OpenStruct) parsed_json = JSON.parse(json_object) control = parsed_json["control"] created = (DateTime.parse(parsed_json["created"]) unless parsed_json["created"].nil?) updated = (DateTime.parse(parsed_json["updated"]) unless parsed_json["updated"].nil?) id = parsed_json["id"] email = parsed_json["email"] name = parsed_json["name"] tz = parsed_json["tz"] device_tokens = parsed_json["deviceTokens"] subscribe_to_emails = parsed_json["subscribeToEmails"] attributes = parsed_json["attributes"] new( control: control, created: created, updated: updated, id: id, email: email, name: name, tz: tz, device_tokens: device_tokens, subscribe_to_emails: subscribe_to_emails, attributes: attributes, 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.
130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/trophy_api_client/types/user.rb', line 130 def self.validate_raw(obj:) obj.control&.is_a?(Boolean) != false || raise("Passed value for field obj.control is not the expected type, validation failed.") obj.created&.is_a?(DateTime) != false || raise("Passed value for field obj.created is not the expected type, validation failed.") obj.updated&.is_a?(DateTime) != false || raise("Passed value for field obj.updated is not the expected type, validation failed.") obj.id.is_a?(String) != false || raise("Passed value for field obj.id 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.name&.is_a?(String) != false || raise("Passed value for field obj.name is not the expected type, validation failed.") obj.tz&.is_a?(String) != false || raise("Passed value for field obj.tz is not the expected type, validation failed.") obj.device_tokens&.is_a?(Array) != false || raise("Passed value for field obj.device_tokens is not the expected type, validation failed.") obj.subscribe_to_emails&.is_a?(Boolean) != false || raise("Passed value for field obj.subscribe_to_emails is not the expected type, validation failed.") obj.attributes&.is_a?(Hash) != false || raise("Passed value for field obj.attributes is not the expected type, validation failed.") end |
Instance Method Details
#to_json(*_args) ⇒ String
Serialize an instance of User to a JSON object
120 121 122 |
# File 'lib/trophy_api_client/types/user.rb', line 120 def to_json(*_args) @_field_set&.to_json end |