Class: TrophyApiClient::EventResponse

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

Constant Summary collapse

OMIT =
Object.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event_id:, metric_id:, total:, achievements: OMIT, current_streak: OMIT, points: OMIT, additional_properties: nil) ⇒ TrophyApiClient::EventResponse

Parameters:

  • event_id (String)

    The unique ID of the event.

  • metric_id (String)

    The unique ID of the metric that was updated.

  • total (Float)

    The user’s new total progress against the metric.

  • achievements (Array<TrophyApiClient::CompletedAchievementResponse>) (defaults to: OMIT)

    Achievements completed as a result of this event.

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

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

  • points (TrophyApiClient::MetricEventPointsResponse) (defaults to: OMIT)

    The points added by this event, and a breakdown of the points awards that added points.

  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



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

def initialize(event_id:, metric_id:, total:, achievements: OMIT, current_streak: OMIT, points: OMIT,
               additional_properties: nil)
  @event_id = event_id
  @metric_id = metric_id
  @total = total
  @achievements = achievements if achievements != OMIT
  @current_streak = current_streak if current_streak != OMIT
  @points = points if points != OMIT
  @additional_properties = additional_properties
  @_field_set = {
    "eventId": event_id,
    "metricId": metric_id,
    "total": total,
    "achievements": achievements,
    "currentStreak": current_streak,
    "points": points
  }.reject do |_k, v|
    v == OMIT
  end
end

Instance Attribute Details

#achievementsArray<TrophyApiClient::CompletedAchievementResponse> (readonly)

Returns Achievements completed as a result of this event.

Returns:



18
19
20
# File 'lib/trophy_api_client/types/event_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



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

def additional_properties
  @additional_properties
end

#current_streakTrophyApiClient::MetricEventStreakResponse (readonly)

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

Returns:



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

def current_streak
  @current_streak
end

#event_idString (readonly)

Returns The unique ID of the event.

Returns:

  • (String)

    The unique ID of the event.



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

def event_id
  @event_id
end

#metric_idString (readonly)

Returns The unique ID of the metric that was updated.

Returns:

  • (String)

    The unique ID of the metric that was updated.



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

def metric_id
  @metric_id
end

#pointsTrophyApiClient::MetricEventPointsResponse (readonly)

Returns The points added by this event, and a breakdown of the points awards that added points.

Returns:



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

def points
  @points
end

#totalFloat (readonly)

Returns The user’s new total progress against the metric.

Returns:

  • (Float)

    The user’s new total progress against the metric.



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

def total
  @total
end

Class Method Details

.from_json(json_object:) ⇒ TrophyApiClient::EventResponse

Deserialize a JSON object to an instance of EventResponse

Parameters:

  • json_object (String)

Returns:



66
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
# File 'lib/trophy_api_client/types/event_response.rb', line 66

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  event_id = parsed_json["eventId"]
  metric_id = parsed_json["metricId"]
  total = parsed_json["total"]
  achievements = parsed_json["achievements"]&.map do |item|
    item = item.to_json
    TrophyApiClient::CompletedAchievementResponse.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::MetricEventStreakResponse.from_json(json_object: current_streak)
  end
  if parsed_json["points"].nil?
    points = nil
  else
    points = parsed_json["points"].to_json
    points = TrophyApiClient::MetricEventPointsResponse.from_json(json_object: points)
  end
  new(
    event_id: event_id,
    metric_id: metric_id,
    total: total,
    achievements: achievements,
    current_streak: current_streak,
    points: points,
    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)


112
113
114
115
116
117
118
119
# File 'lib/trophy_api_client/types/event_response.rb', line 112

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

Instance Method Details

#to_json(*_args) ⇒ String

Serialize an instance of EventResponse to a JSON object

Returns:

  • (String)


102
103
104
# File 'lib/trophy_api_client/types/event_response.rb', line 102

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