Class: TrophyApiClient::EventResponseMetricsItem

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

Constant Summary collapse

OMIT =
Object.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(completed:, trigger: OMIT, metric_id: OMIT, additional_properties: nil) ⇒ TrophyApiClient::EventResponseMetricsItem

Parameters:

  • trigger (String) (defaults to: OMIT)

    The trigger of the achievement, in this case either ‘metric’ or ‘streak’.

  • metric_id (String) (defaults to: OMIT)

    The ID of the metric that these achievements are associated with, if any.

  • completed (Array<TrophyApiClient::EventResponseMetricsItemCompletedItem>)

    A list of any new achievements that the user has now completed as a result of this event being submitted.

  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



30
31
32
33
34
35
36
37
38
# File 'lib/trophy_api_client/types/event_response_metrics_item.rb', line 30

def initialize(completed:, trigger: OMIT, metric_id: OMIT, additional_properties: nil)
  @trigger = trigger if trigger != OMIT
  @metric_id = metric_id if metric_id != OMIT
  @completed = completed
  @additional_properties = additional_properties
  @_field_set = { "trigger": trigger, "metricId": metric_id, "completed": completed }.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



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

def additional_properties
  @additional_properties
end

#completedArray<TrophyApiClient::EventResponseMetricsItemCompletedItem> (readonly)

Returns A list of any new achievements that the user has now completed as a result of this event being submitted.

Returns:



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

def completed
  @completed
end

#metric_idString (readonly)

Returns The ID of the metric that these achievements are associated with, if any.

Returns:

  • (String)

    The ID of the metric that these achievements are associated with, if any.



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

def metric_id
  @metric_id
end

#triggerString (readonly)

Returns The trigger of the achievement, in this case either ‘metric’ or ‘streak’.

Returns:

  • (String)

    The trigger of the achievement, in this case either ‘metric’ or ‘streak’.



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

def trigger
  @trigger
end

Class Method Details

.from_json(json_object:) ⇒ TrophyApiClient::EventResponseMetricsItem

Deserialize a JSON object to an instance of EventResponseMetricsItem

Parameters:

  • json_object (String)

Returns:



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/trophy_api_client/types/event_response_metrics_item.rb', line 44

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  trigger = parsed_json["trigger"]
  metric_id = parsed_json["metricId"]
  completed = parsed_json["completed"]&.map do |item|
    item = item.to_json
    TrophyApiClient::EventResponseMetricsItemCompletedItem.from_json(json_object: item)
  end
  new(
    trigger: trigger,
    metric_id: metric_id,
    completed: completed,
    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)


74
75
76
77
78
# File 'lib/trophy_api_client/types/event_response_metrics_item.rb', line 74

def self.validate_raw(obj:)
  obj.trigger&.is_a?(String) != false || raise("Passed value for field obj.trigger 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.completed.is_a?(Array) != false || raise("Passed value for field obj.completed is not the expected type, validation failed.")
end

Instance Method Details

#to_json(*_args) ⇒ String

Serialize an instance of EventResponseMetricsItem to a JSON object

Returns:

  • (String)


64
65
66
# File 'lib/trophy_api_client/types/event_response_metrics_item.rb', line 64

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