Class: TrophyApiClient::UserAchievementWithStatsResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/trophy_api_client/types/user_achievement_with_stats_response.rb

Constant Summary collapse

OMIT =
Object.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(completions:, rarity:, id:, name:, trigger:, user_attributes:, achieved_at: OMIT, description: OMIT, badge_url: OMIT, key: OMIT, streak_length: OMIT, achievement_ids: OMIT, metric_id: OMIT, metric_value: OMIT, metric_name: OMIT, event_attribute: OMIT, event_attributes: OMIT, additional_properties: nil) ⇒ TrophyApiClient::UserAchievementWithStatsResponse

Parameters:

  • achieved_at (DateTime) (defaults to: OMIT)

    The date and time the achievement was completed, in ISO 8601 format. Null if the achievement has not been completed.

  • completions (Integer)

    The number of users who have completed this achievement.

  • rarity (Float)

    The percentage of all users who have completed this achievement.

  • id (String)

    The unique ID of the achievement.

  • name (String)

    The name of this achievement.

  • trigger (TrophyApiClient::AchievementResponseTrigger)

    The trigger of the achievement.

  • description (String) (defaults to: OMIT)

    The description of this achievement.

  • badge_url (String) (defaults to: OMIT)

    The URL of the badge image for the achievement, if one has been uploaded.

  • key (String) (defaults to: OMIT)

    The key used to reference this achievement in the API (only applicable if trigger = ‘api’)

  • streak_length (Integer) (defaults to: OMIT)

    The length of the streak required to complete the achievement (only applicable if trigger = ‘streak’)

  • achievement_ids (Array<String>) (defaults to: OMIT)

    The IDs of the prerequisite achievements that must be completed to earn this achievement (only applicable if trigger = ‘achievement’)

  • metric_id (String) (defaults to: OMIT)

    The ID of the metric associated with this achievement (only applicable if trigger = ‘metric’)

  • metric_value (Float) (defaults to: OMIT)

    The value of the metric required to complete the achievement (only applicable if trigger = ‘metric’)

  • metric_name (String) (defaults to: OMIT)

    The name of the metric associated with this achievement (only applicable if trigger = ‘metric’)

  • user_attributes (Array<TrophyApiClient::AchievementResponseUserAttributesItem>)

    User attribute filters that must be met for this achievement to be completed.

  • event_attribute (TrophyApiClient::AchievementResponseEventAttribute) (defaults to: OMIT)

    Deprecated. Event attribute filter that must be met for this achievement to be completed. Only present if the achievement has an event filter configured.

  • event_attributes (Array<TrophyApiClient::AchievementResponseEventAttributesItem>) (defaults to: OMIT)

    Event attribute filters that must be met for this achievement to be completed. Omitted for non-metric achievements.

  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/trophy_api_client/types/user_achievement_with_stats_response.rb', line 92

def initialize(completions:, rarity:, id:, name:, trigger:, user_attributes:, achieved_at: OMIT, description: OMIT, badge_url: OMIT,
               key: OMIT, streak_length: OMIT, achievement_ids: OMIT, metric_id: OMIT, metric_value: OMIT, metric_name: OMIT, event_attribute: OMIT, event_attributes: OMIT, additional_properties: nil)
  @achieved_at = achieved_at if achieved_at != OMIT
  @completions = completions
  @rarity = rarity
  @id = id
  @name = name
  @trigger = trigger
  @description = description if description != OMIT
  @badge_url = badge_url if badge_url != OMIT
  @key = key if key != OMIT
  @streak_length = streak_length if streak_length != OMIT
  @achievement_ids = achievement_ids if achievement_ids != OMIT
  @metric_id = metric_id if metric_id != OMIT
  @metric_value = metric_value if metric_value != OMIT
  @metric_name = metric_name if metric_name != OMIT
  @user_attributes = user_attributes
  @event_attribute = event_attribute if event_attribute != OMIT
  @event_attributes = event_attributes if event_attributes != OMIT
  @additional_properties = additional_properties
  @_field_set = {
    "achievedAt": achieved_at,
    "completions": completions,
    "rarity": rarity,
    "id": id,
    "name": name,
    "trigger": trigger,
    "description": description,
    "badgeUrl": badge_url,
    "key": key,
    "streakLength": streak_length,
    "achievementIds": achievement_ids,
    "metricId": metric_id,
    "metricValue": metric_value,
    "metricName": metric_name,
    "userAttributes": user_attributes,
    "eventAttribute": event_attribute,
    "eventAttributes": event_attributes
  }.reject do |_k, v|
    v == OMIT
  end
end

Instance Attribute Details

#achieved_atDateTime (readonly)

Returns The date and time the achievement was completed, in ISO 8601 format. Null if the achievement has not been completed.

Returns:

  • (DateTime)

    The date and time the achievement was completed, in ISO 8601 format. Null if the achievement has not been completed.



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

def achieved_at
  @achieved_at
end

#achievement_idsArray<String> (readonly)

Returns The IDs of the prerequisite achievements that must be completed to earn this achievement (only applicable if trigger = ‘achievement’).

Returns:

  • (Array<String>)

    The IDs of the prerequisite achievements that must be completed to earn this achievement (only applicable if trigger = ‘achievement’)



38
39
40
# File 'lib/trophy_api_client/types/user_achievement_with_stats_response.rb', line 38

def achievement_ids
  @achievement_ids
end

#additional_propertiesOpenStruct (readonly)

Returns Additional properties unmapped to the current class definition.

Returns:

  • (OpenStruct)

    Additional properties unmapped to the current class definition



57
58
59
# File 'lib/trophy_api_client/types/user_achievement_with_stats_response.rb', line 57

def additional_properties
  @additional_properties
end

#badge_urlString (readonly)

Returns The URL of the badge image for the achievement, if one has been uploaded.

Returns:

  • (String)

    The URL of the badge image for the achievement, if one has been uploaded.



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

def badge_url
  @badge_url
end

#completionsInteger (readonly)

Returns The number of users who have completed this achievement.

Returns:

  • (Integer)

    The number of users who have completed this achievement.



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

def completions
  @completions
end

#descriptionString (readonly)

Returns The description of this achievement.

Returns:

  • (String)

    The description of this achievement.



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

def description
  @description
end

#event_attributeTrophyApiClient::AchievementResponseEventAttribute (readonly)

Returns Deprecated. Event attribute filter that must be met for this achievement to be completed. Only present if the achievement has an event filter configured.

Returns:



52
53
54
# File 'lib/trophy_api_client/types/user_achievement_with_stats_response.rb', line 52

def event_attribute
  @event_attribute
end

#event_attributesArray<TrophyApiClient::AchievementResponseEventAttributesItem> (readonly)

Returns Event attribute filters that must be met for this achievement to be completed. Omitted for non-metric achievements.

Returns:



55
56
57
# File 'lib/trophy_api_client/types/user_achievement_with_stats_response.rb', line 55

def event_attributes
  @event_attributes
end

#idString (readonly)

Returns The unique ID of the achievement.

Returns:

  • (String)

    The unique ID of the achievement.



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

def id
  @id
end

#keyString (readonly)

Returns The key used to reference this achievement in the API (only applicable if trigger = ‘api’).

Returns:

  • (String)

    The key used to reference this achievement in the API (only applicable if trigger = ‘api’)



32
33
34
# File 'lib/trophy_api_client/types/user_achievement_with_stats_response.rb', line 32

def key
  @key
end

#metric_idString (readonly)

Returns The ID of the metric associated with this achievement (only applicable if trigger = ‘metric’).

Returns:

  • (String)

    The ID of the metric associated with this achievement (only applicable if trigger = ‘metric’)



41
42
43
# File 'lib/trophy_api_client/types/user_achievement_with_stats_response.rb', line 41

def metric_id
  @metric_id
end

#metric_nameString (readonly)

Returns The name of the metric associated with this achievement (only applicable if trigger = ‘metric’).

Returns:

  • (String)

    The name of the metric associated with this achievement (only applicable if trigger = ‘metric’)



47
48
49
# File 'lib/trophy_api_client/types/user_achievement_with_stats_response.rb', line 47

def metric_name
  @metric_name
end

#metric_valueFloat (readonly)

Returns The value of the metric required to complete the achievement (only applicable if trigger = ‘metric’).

Returns:

  • (Float)

    The value of the metric required to complete the achievement (only applicable if trigger = ‘metric’)



44
45
46
# File 'lib/trophy_api_client/types/user_achievement_with_stats_response.rb', line 44

def metric_value
  @metric_value
end

#nameString (readonly)

Returns The name of this achievement.

Returns:

  • (String)

    The name of this achievement.



23
24
25
# File 'lib/trophy_api_client/types/user_achievement_with_stats_response.rb', line 23

def name
  @name
end

#rarityFloat (readonly)

Returns The percentage of all users who have completed this achievement.

Returns:

  • (Float)

    The percentage of all users who have completed this achievement.



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

def rarity
  @rarity
end

#streak_lengthInteger (readonly)

Returns The length of the streak required to complete the achievement (only applicable if trigger = ‘streak’).

Returns:

  • (Integer)

    The length of the streak required to complete the achievement (only applicable if trigger = ‘streak’)



35
36
37
# File 'lib/trophy_api_client/types/user_achievement_with_stats_response.rb', line 35

def streak_length
  @streak_length
end

#triggerTrophyApiClient::AchievementResponseTrigger (readonly)

Returns The trigger of the achievement.

Returns:



25
26
27
# File 'lib/trophy_api_client/types/user_achievement_with_stats_response.rb', line 25

def trigger
  @trigger
end

#user_attributesArray<TrophyApiClient::AchievementResponseUserAttributesItem> (readonly)

Returns User attribute filters that must be met for this achievement to be completed.

Returns:



49
50
51
# File 'lib/trophy_api_client/types/user_achievement_with_stats_response.rb', line 49

def user_attributes
  @user_attributes
end

Class Method Details

.from_json(json_object:) ⇒ TrophyApiClient::UserAchievementWithStatsResponse

Deserialize a JSON object to an instance of UserAchievementWithStatsResponse

Parameters:

  • json_object (String)

Returns:



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/trophy_api_client/types/user_achievement_with_stats_response.rb', line 139

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  achieved_at = (DateTime.parse(parsed_json["achievedAt"]) unless parsed_json["achievedAt"].nil?)
  completions = parsed_json["completions"]
  rarity = parsed_json["rarity"]
  id = parsed_json["id"]
  name = parsed_json["name"]
  trigger = parsed_json["trigger"]
  description = parsed_json["description"]
  badge_url = parsed_json["badgeUrl"]
  key = parsed_json["key"]
  streak_length = parsed_json["streakLength"]
  achievement_ids = parsed_json["achievementIds"]
  metric_id = parsed_json["metricId"]
  metric_value = parsed_json["metricValue"]
  metric_name = parsed_json["metricName"]
  user_attributes = parsed_json["userAttributes"]&.map do |item|
    item = item.to_json
    TrophyApiClient::AchievementResponseUserAttributesItem.from_json(json_object: item)
  end
  if parsed_json["eventAttribute"].nil?
    event_attribute = nil
  else
    event_attribute = parsed_json["eventAttribute"].to_json
    event_attribute = TrophyApiClient::AchievementResponseEventAttribute.from_json(json_object: event_attribute)
  end
  event_attributes = parsed_json["eventAttributes"]&.map do |item|
    item = item.to_json
    TrophyApiClient::AchievementResponseEventAttributesItem.from_json(json_object: item)
  end
  new(
    achieved_at: achieved_at,
    completions: completions,
    rarity: rarity,
    id: id,
    name: name,
    trigger: trigger,
    description: description,
    badge_url: badge_url,
    key: key,
    streak_length: streak_length,
    achievement_ids: achievement_ids,
    metric_id: metric_id,
    metric_value: metric_value,
    metric_name: metric_name,
    user_attributes: user_attributes,
    event_attribute: event_attribute,
    event_attributes: event_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.

Parameters:

  • obj (Object)

Returns:

  • (Void)


205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/trophy_api_client/types/user_achievement_with_stats_response.rb', line 205

def self.validate_raw(obj:)
  obj.achieved_at&.is_a?(DateTime) != false || raise("Passed value for field obj.achieved_at is not the expected type, validation failed.")
  obj.completions.is_a?(Integer) != false || raise("Passed value for field obj.completions is not the expected type, validation failed.")
  obj.rarity.is_a?(Float) != false || raise("Passed value for field obj.rarity 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.name.is_a?(String) != false || raise("Passed value for field obj.name is not the expected type, validation failed.")
  obj.trigger.is_a?(TrophyApiClient::AchievementResponseTrigger) != false || raise("Passed value for field obj.trigger is not the expected type, validation failed.")
  obj.description&.is_a?(String) != false || raise("Passed value for field obj.description is not the expected type, validation failed.")
  obj.badge_url&.is_a?(String) != false || raise("Passed value for field obj.badge_url is not the expected type, validation failed.")
  obj.key&.is_a?(String) != false || raise("Passed value for field obj.key is not the expected type, validation failed.")
  obj.streak_length&.is_a?(Integer) != false || raise("Passed value for field obj.streak_length is not the expected type, validation failed.")
  obj.achievement_ids&.is_a?(Array) != false || raise("Passed value for field obj.achievement_ids is not the expected type, validation failed.")
  obj.metric_id&.is_a?(String) != false || raise("Passed value for field obj.metric_id is not the expected type, validation failed.")
  obj.metric_value&.is_a?(Float) != false || raise("Passed value for field obj.metric_value is not the expected type, validation failed.")
  obj.metric_name&.is_a?(String) != false || raise("Passed value for field obj.metric_name is not the expected type, validation failed.")
  obj.user_attributes.is_a?(Array) != false || raise("Passed value for field obj.user_attributes is not the expected type, validation failed.")
  obj.event_attribute.nil? || TrophyApiClient::AchievementResponseEventAttribute.validate_raw(obj: obj.event_attribute)
  obj.event_attributes&.is_a?(Array) != false || raise("Passed value for field obj.event_attributes is not the expected type, validation failed.")
end

Instance Method Details

#to_json(*_args) ⇒ String

Serialize an instance of UserAchievementWithStatsResponse to a JSON object

Returns:

  • (String)


195
196
197
# File 'lib/trophy_api_client/types/user_achievement_with_stats_response.rb', line 195

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