Class: TrophyApiClient::MetricResponse

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

Constant Summary collapse

OMIT =
Object.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, key:, name:, emoji:, streak_frequency:, status:, current:, achievements:, current_streak: OMIT, additional_properties: nil) ⇒ TrophyApiClient::MetricResponse

Parameters:

  • id (String)

    The unique ID of the metric.

  • key (String)

    The unique key of the metric.

  • name (String)

    The name of the metric.

  • emoji (String)

    The emoji to represent the metric.

  • streak_frequency (TrophyApiClient::StreakFrequency)

    The frequency of the streak.

  • status (TrophyApiClient::MetricStatus)

    The status of the metric.

  • current (Float)

    The user’s current total for the metric.

  • achievements (Array<TrophyApiClient::AchievementResponse>)

    A list of the metric’s achievements and the user’s progress towards each.

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

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

  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/trophy_api_client/types/metric_response.rb', line 49

def initialize(id:, key:, name:, emoji:, streak_frequency:, status:, current:, achievements:, current_streak: OMIT,
               additional_properties: nil)
  @id = id
  @key = key
  @name = name
  @emoji = emoji
  @streak_frequency = streak_frequency
  @status = status
  @current = current
  @achievements = achievements
  @current_streak = current_streak if current_streak != OMIT
  @additional_properties = additional_properties
  @_field_set = {
    "id": id,
    "key": key,
    "name": name,
    "emoji": emoji,
    "streakFrequency": streak_frequency,
    "status": status,
    "current": current,
    "achievements": achievements,
    "currentStreak": current_streak
  }.reject do |_k, v|
    v == OMIT
  end
end

Instance Attribute Details

#achievementsArray<TrophyApiClient::AchievementResponse> (readonly)

Returns A list of the metric’s achievements and the user’s progress towards each.

Returns:



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

def achievements
  @achievements
end

#additional_propertiesOpenStruct (readonly)

Returns Additional properties unmapped to the current class definition.

Returns:

  • (OpenStruct)

    Additional properties unmapped to the current class definition



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

def additional_properties
  @additional_properties
end

#currentFloat (readonly)

Returns The user’s current total for the metric.

Returns:

  • (Float)

    The user’s current total for the metric.



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

def current
  @current
end

#current_streakTrophyApiClient::StreakResponse (readonly)

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

Returns:



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

def current_streak
  @current_streak
end

#emojiString (readonly)

Returns The emoji to represent the metric.

Returns:

  • (String)

    The emoji to represent the metric.



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

def emoji
  @emoji
end

#idString (readonly)

Returns The unique ID of the metric.

Returns:

  • (String)

    The unique ID of the metric.



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

def id
  @id
end

#keyString (readonly)

Returns The unique key of the metric.

Returns:

  • (String)

    The unique key of the metric.



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

def key
  @key
end

#nameString (readonly)

Returns The name of the metric.

Returns:

  • (String)

    The name of the metric.



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

def name
  @name
end

#statusTrophyApiClient::MetricStatus (readonly)

Returns The status of the metric.

Returns:



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

def status
  @status
end

#streak_frequencyTrophyApiClient::StreakFrequency (readonly)

Returns The frequency of the streak.

Returns:



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

def streak_frequency
  @streak_frequency
end

Class Method Details

.from_json(json_object:) ⇒ TrophyApiClient::MetricResponse

Deserialize a JSON object to an instance of MetricResponse

Parameters:

  • json_object (String)

Returns:



80
81
82
83
84
85
86
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
# File 'lib/trophy_api_client/types/metric_response.rb', line 80

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  id = parsed_json["id"]
  key = parsed_json["key"]
  name = parsed_json["name"]
  emoji = parsed_json["emoji"]
  streak_frequency = parsed_json["streakFrequency"]
  status = parsed_json["status"]
  current = parsed_json["current"]
  achievements = parsed_json["achievements"]&.map do |item|
    item = item.to_json
    TrophyApiClient::AchievementResponse.from_json(json_object: item)
  end
  if parsed_json["currentStreak"].nil?
    current_streak = nil
  else
    current_streak = parsed_json["currentStreak"].to_json
    current_streak = TrophyApiClient::StreakResponse.from_json(json_object: current_streak)
  end
  new(
    id: id,
    key: key,
    name: name,
    emoji: emoji,
    streak_frequency: streak_frequency,
    status: status,
    current: current,
    achievements: achievements,
    current_streak: current_streak,
    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)


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

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.key.is_a?(String) != false || raise("Passed value for field obj.key 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.emoji.is_a?(String) != false || raise("Passed value for field obj.emoji is not the expected type, validation failed.")
  obj.streak_frequency.is_a?(TrophyApiClient::StreakFrequency) != false || raise("Passed value for field obj.streak_frequency is not the expected type, validation failed.")
  obj.status.is_a?(TrophyApiClient::MetricStatus) != false || raise("Passed value for field obj.status is not the expected type, validation failed.")
  obj.current.is_a?(Float) != false || raise("Passed value for field obj.current is not the expected type, validation failed.")
  obj.achievements.is_a?(Array) != false || raise("Passed value for field obj.achievements is not the expected type, validation failed.")
  obj.current_streak.nil? || TrophyApiClient::StreakResponse.validate_raw(obj: obj.current_streak)
end

Instance Method Details

#to_json(*_args) ⇒ String

Serialize an instance of MetricResponse to a JSON object

Returns:

  • (String)


117
118
119
# File 'lib/trophy_api_client/types/metric_response.rb', line 117

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