Class: TrophyApiClient::AchievementCompletionResponseAchievement

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

Constant Summary collapse

OMIT =
Object.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(achieved_at:, id:, name:, trigger:, key:, current_streak: OMIT, description: OMIT, badge_url: OMIT, streak_length: OMIT, metric_id: OMIT, metric_value: OMIT, metric_name: OMIT, additional_properties: nil) ⇒ TrophyApiClient::AchievementCompletionResponseAchievement

Parameters:

  • current_streak (TrophyApiClient::MetricEventStreakResponse) (defaults to: OMIT)

    The user’s current streak for the metric, if the metric has streaks enabled.

  • achieved_at (DateTime)

    The date and time the achievement was completed, in ISO 8601 format.

  • 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)

    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’)

  • 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’)

  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/trophy_api_client/types/achievement_completion_response_achievement.rb', line 67

def initialize(achieved_at:, id:, name:, trigger:, key:, current_streak: OMIT, description: OMIT, badge_url: OMIT,
               streak_length: OMIT, metric_id: OMIT, metric_value: OMIT, metric_name: OMIT, additional_properties: nil)
  @current_streak = current_streak if current_streak != OMIT
  @achieved_at = achieved_at
  @id = id
  @name = name
  @trigger = trigger
  @description = description if description != OMIT
  @badge_url = badge_url if badge_url != OMIT
  @key = key
  @streak_length = streak_length if streak_length != 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
  @additional_properties = additional_properties
  @_field_set = {
    "currentStreak": current_streak,
    "achievedAt": achieved_at,
    "id": id,
    "name": name,
    "trigger": trigger,
    "description": description,
    "badgeUrl": badge_url,
    "key": key,
    "streakLength": streak_length,
    "metricId": metric_id,
    "metricValue": metric_value,
    "metricName": metric_name
  }.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.

Returns:

  • (DateTime)

    The date and time the achievement was completed, in ISO 8601 format.



14
15
16
# File 'lib/trophy_api_client/types/achievement_completion_response_achievement.rb', line 14

def achieved_at
  @achieved_at
end

#additional_propertiesOpenStruct (readonly)

Returns Additional properties unmapped to the current class definition.

Returns:

  • (OpenStruct)

    Additional properties unmapped to the current class definition



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

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.



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

def badge_url
  @badge_url
end

#current_streakTrophyApiClient::MetricEventStreakResponse (readonly)

Returns The user’s current streak for the metric, if the metric has streaks enabled.

Returns:



12
13
14
# File 'lib/trophy_api_client/types/achievement_completion_response_achievement.rb', line 12

def current_streak
  @current_streak
end

#descriptionString (readonly)

Returns The description of this achievement.

Returns:

  • (String)

    The description of this achievement.



22
23
24
# File 'lib/trophy_api_client/types/achievement_completion_response_achievement.rb', line 22

def description
  @description
end

#idString (readonly)

Returns The unique ID of the achievement.

Returns:

  • (String)

    The unique ID of the achievement.



16
17
18
# File 'lib/trophy_api_client/types/achievement_completion_response_achievement.rb', line 16

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’)



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

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’)



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

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’)



39
40
41
# File 'lib/trophy_api_client/types/achievement_completion_response_achievement.rb', line 39

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’)



36
37
38
# File 'lib/trophy_api_client/types/achievement_completion_response_achievement.rb', line 36

def metric_value
  @metric_value
end

#nameString (readonly)

Returns The name of this achievement.

Returns:

  • (String)

    The name of this achievement.



18
19
20
# File 'lib/trophy_api_client/types/achievement_completion_response_achievement.rb', line 18

def name
  @name
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’)



30
31
32
# File 'lib/trophy_api_client/types/achievement_completion_response_achievement.rb', line 30

def streak_length
  @streak_length
end

#triggerTrophyApiClient::AchievementResponseTrigger (readonly)

Returns The trigger of the achievement.

Returns:



20
21
22
# File 'lib/trophy_api_client/types/achievement_completion_response_achievement.rb', line 20

def trigger
  @trigger
end

Class Method Details

.from_json(json_object:) ⇒ TrophyApiClient::AchievementCompletionResponseAchievement

Deserialize a JSON object to an instance of

AchievementCompletionResponseAchievement

Parameters:

  • json_object (String)

Returns:



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
134
135
136
137
138
139
140
# File 'lib/trophy_api_client/types/achievement_completion_response_achievement.rb', line 105

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  if parsed_json["currentStreak"].nil?
    current_streak = nil
  else
    current_streak = parsed_json["currentStreak"].to_json
    current_streak = TrophyApiClient::MetricEventStreakResponse.from_json(json_object: current_streak)
  end
  achieved_at = (DateTime.parse(parsed_json["achievedAt"]) unless parsed_json["achievedAt"].nil?)
  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"]
  metric_id = parsed_json["metricId"]
  metric_value = parsed_json["metricValue"]
  metric_name = parsed_json["metricName"]
  new(
    current_streak: current_streak,
    achieved_at: achieved_at,
    id: id,
    name: name,
    trigger: trigger,
    description: description,
    badge_url: badge_url,
    key: key,
    streak_length: streak_length,
    metric_id: metric_id,
    metric_value: metric_value,
    metric_name: metric_name,
    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)


156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/trophy_api_client/types/achievement_completion_response_achievement.rb', line 156

def self.validate_raw(obj:)
  obj.current_streak.nil? || TrophyApiClient::MetricEventStreakResponse.validate_raw(obj: obj.current_streak)
  obj.achieved_at.is_a?(DateTime) != false || raise("Passed value for field obj.achieved_at 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.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.")
end

Instance Method Details

#to_json(*_args) ⇒ String

Serialize an instance of AchievementCompletionResponseAchievement to a JSON

object

Returns:

  • (String)


146
147
148
# File 'lib/trophy_api_client/types/achievement_completion_response_achievement.rb', line 146

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