Class: TrophyApiClient::User

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, device_tokens:, subscribe_to_emails:, attributes:, control:, created:, updated:, email: OMIT, name: OMIT, tz: OMIT, additional_properties: nil) ⇒ TrophyApiClient::User

Parameters:

  • id (String)

    The ID of the user in your database. Must be a string.

  • email (String) (defaults to: OMIT)

    The user’s email address.

  • name (String) (defaults to: OMIT)

    The name of the user.

  • tz (String) (defaults to: OMIT)

    The user’s timezone.

  • device_tokens (Array<String>)

    The user’s device tokens.

  • subscribe_to_emails (Boolean)

    Whether the user is opted into receiving Trophy-powered emails.

  • attributes (Hash{String => String})

    User attributes as key-value pairs. Keys must match existing user attributes set up in the Trophy dashboard.

  • control (Boolean)

    Whether the user is in the control group, meaning they do not receive emails or other communications from Trophy.

  • created (DateTime)

    The date and time the user was created, in ISO 8601 format.

  • updated (DateTime)

    The date and time the user was last updated, in ISO 8601 format.

  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



54
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
80
81
# File 'lib/trophy_api_client/types/user.rb', line 54

def initialize(id:, device_tokens:, subscribe_to_emails:, attributes:, control:, created:, updated:, email: OMIT,
               name: OMIT, tz: OMIT, additional_properties: nil)
  @id = id
  @email = email if email != OMIT
  @name = name if name != OMIT
  @tz = tz if tz != OMIT
  @device_tokens = device_tokens
  @subscribe_to_emails = subscribe_to_emails
  @attributes = attributes
  @control = control
  @created = created
  @updated = updated
  @additional_properties = additional_properties
  @_field_set = {
    "id": id,
    "email": email,
    "name": name,
    "tz": tz,
    "deviceTokens": device_tokens,
    "subscribeToEmails": subscribe_to_emails,
    "attributes": attributes,
    "control": control,
    "created": created,
    "updated": updated
  }.reject do |_k, v|
    v == OMIT
  end
end

Instance Attribute Details

#additional_propertiesOpenStruct (readonly)

Returns Additional properties unmapped to the current class definition.

Returns:

  • (OpenStruct)

    Additional properties unmapped to the current class definition



33
34
35
# File 'lib/trophy_api_client/types/user.rb', line 33

def additional_properties
  @additional_properties
end

#attributesHash{String => String} (readonly)

Returns User attributes as key-value pairs. Keys must match existing user attributes set up in the Trophy dashboard.

Returns:

  • (Hash{String => String})

    User attributes as key-value pairs. Keys must match existing user attributes set up in the Trophy dashboard.



24
25
26
# File 'lib/trophy_api_client/types/user.rb', line 24

def attributes
  @attributes
end

#controlBoolean (readonly)

Returns Whether the user is in the control group, meaning they do not receive emails or other communications from Trophy.

Returns:

  • (Boolean)

    Whether the user is in the control group, meaning they do not receive emails or other communications from Trophy.



27
28
29
# File 'lib/trophy_api_client/types/user.rb', line 27

def control
  @control
end

#createdDateTime (readonly)

Returns The date and time the user was created, in ISO 8601 format.

Returns:

  • (DateTime)

    The date and time the user was created, in ISO 8601 format.



29
30
31
# File 'lib/trophy_api_client/types/user.rb', line 29

def created
  @created
end

#device_tokensArray<String> (readonly)

Returns The user’s device tokens.

Returns:

  • (Array<String>)

    The user’s device tokens.



19
20
21
# File 'lib/trophy_api_client/types/user.rb', line 19

def device_tokens
  @device_tokens
end

#emailString (readonly)

Returns The user’s email address.

Returns:

  • (String)

    The user’s email address.



13
14
15
# File 'lib/trophy_api_client/types/user.rb', line 13

def email
  @email
end

#idString (readonly)

Returns The ID of the user in your database. Must be a string.

Returns:

  • (String)

    The ID of the user in your database. Must be a string.



11
12
13
# File 'lib/trophy_api_client/types/user.rb', line 11

def id
  @id
end

#nameString (readonly)

Returns The name of the user.

Returns:

  • (String)

    The name of the user.



15
16
17
# File 'lib/trophy_api_client/types/user.rb', line 15

def name
  @name
end

#subscribe_to_emailsBoolean (readonly)

Returns Whether the user is opted into receiving Trophy-powered emails.

Returns:

  • (Boolean)

    Whether the user is opted into receiving Trophy-powered emails.



21
22
23
# File 'lib/trophy_api_client/types/user.rb', line 21

def subscribe_to_emails
  @subscribe_to_emails
end

#tzString (readonly)

Returns The user’s timezone.

Returns:

  • (String)

    The user’s timezone.



17
18
19
# File 'lib/trophy_api_client/types/user.rb', line 17

def tz
  @tz
end

#updatedDateTime (readonly)

Returns The date and time the user was last updated, in ISO 8601 format.

Returns:

  • (DateTime)

    The date and time the user was last updated, in ISO 8601 format.



31
32
33
# File 'lib/trophy_api_client/types/user.rb', line 31

def updated
  @updated
end

Class Method Details

.from_json(json_object:) ⇒ TrophyApiClient::User

Deserialize a JSON object to an instance of User

Parameters:

  • json_object (String)

Returns:



87
88
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
# File 'lib/trophy_api_client/types/user.rb', line 87

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  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"]
  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?)
  new(
    id: id,
    email: email,
    name: name,
    tz: tz,
    device_tokens: device_tokens,
    subscribe_to_emails: subscribe_to_emails,
    attributes: attributes,
    control: control,
    created: created,
    updated: updated,
    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)


128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/trophy_api_client/types/user.rb', line 128

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.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.")
  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.")
end

Instance Method Details

#to_json(*_args) ⇒ String

Serialize an instance of User to a JSON object

Returns:

  • (String)


118
119
120
# File 'lib/trophy_api_client/types/user.rb', line 118

def to_json(*_args)
  @_field_set&.to_json
end