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:, current:, achievements:, 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.

  • current (Float)

    The user’s current total for the metric.

  • achievements (Array<TrophyApiClient::UserAchievementResponse>)

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

  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



34
35
36
37
38
39
40
41
42
# File 'lib/trophy_api_client/types/metric_response.rb', line 34

def initialize(id:, key:, name:, current:, achievements:, additional_properties: nil)
  @id = id
  @key = key
  @name = name
  @current = current
  @achievements = achievements
  @additional_properties = additional_properties
  @_field_set = { "id": id, "key": key, "name": name, "current": current, "achievements": achievements }
end

Instance Attribute Details

#achievementsArray<TrophyApiClient::UserAchievementResponse> (readonly)

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

Returns:



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

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



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

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.



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

def current
  @current
end

#idString (readonly)

Returns The unique ID of the metric.

Returns:

  • (String)

    The unique ID of the metric.



10
11
12
# File 'lib/trophy_api_client/types/metric_response.rb', line 10

def id
  @id
end

#keyString (readonly)

Returns The unique key of the metric.

Returns:

  • (String)

    The unique key of the metric.



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

def key
  @key
end

#nameString (readonly)

Returns The name of the metric.

Returns:

  • (String)

    The name of the metric.



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

def name
  @name
end

Class Method Details

.from_json(json_object:) ⇒ TrophyApiClient::MetricResponse

Deserialize a JSON object to an instance of MetricResponse

Parameters:

  • json_object (String)

Returns:



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/trophy_api_client/types/metric_response.rb', line 48

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"]
  current = parsed_json["current"]
  achievements = parsed_json["achievements"]&.map do |item|
    item = item.to_json
    TrophyApiClient::UserAchievementResponse.from_json(json_object: item)
  end
  new(
    id: id,
    key: key,
    name: name,
    current: current,
    achievements: achievements,
    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)


82
83
84
85
86
87
88
# File 'lib/trophy_api_client/types/metric_response.rb', line 82

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

Instance Method Details

#to_json(*_args) ⇒ String

Serialize an instance of MetricResponse to a JSON object

Returns:

  • (String)


72
73
74
# File 'lib/trophy_api_client/types/metric_response.rb', line 72

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