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:, current_streak:, points:, leaderboards:, idempotency_key: OMIT, idempotent_replayed: OMIT, additional_properties: nil) ⇒ TrophyApiClient::EventResponse



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

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

Instance Attribute Details

#achievementsArray<TrophyApiClient::UserAchievementResponse> (readonly)



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

def achievements
  @achievements
end

#additional_propertiesOpenStruct (readonly)



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

def additional_properties
  @additional_properties
end

#current_streakTrophyApiClient::MetricEventStreakResponse (readonly)



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

def current_streak
  @current_streak
end

#event_idString (readonly)



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

def event_id
  @event_id
end

#idempotency_keyString (readonly)



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

def idempotency_key
  @idempotency_key
end

#idempotent_replayedBoolean (readonly)



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

def idempotent_replayed
  @idempotent_replayed
end

#leaderboardsHash{String => TrophyApiClient::MetricEventLeaderboardResponse} (readonly)



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

def leaderboards
  @leaderboards
end

#metric_idString (readonly)



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

def metric_id
  @metric_id
end

#pointsHash{String => TrophyApiClient::MetricEventPointsResponse} (readonly)



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

def points
  @points
end

#totalFloat (readonly)



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

def total
  @total
end

Class Method Details

.from_json(json_object:) ⇒ TrophyApiClient::EventResponse

Deserialize a JSON object to an instance of EventResponse



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
113
114
115
116
117
118
119
120
# File 'lib/trophy_api_client/types/event_response.rb', line 82

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::UserAchievementResponse.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
  points = parsed_json["points"]&.transform_values do |value|
    value = value.to_json
    TrophyApiClient::MetricEventPointsResponse.from_json(json_object: value)
  end
  leaderboards = parsed_json["leaderboards"]&.transform_values do |value|
    value = value.to_json
    TrophyApiClient::MetricEventLeaderboardResponse.from_json(json_object: value)
  end
  idempotency_key = parsed_json["idempotencyKey"]
  idempotent_replayed = parsed_json["idempotentReplayed"]
  new(
    event_id: event_id,
    metric_id: metric_id,
    total: total,
    achievements: achievements,
    current_streak: current_streak,
    points: points,
    leaderboards: leaderboards,
    idempotency_key: idempotency_key,
    idempotent_replayed: idempotent_replayed,
    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.


135
136
137
138
139
140
141
142
143
144
145
# File 'lib/trophy_api_client/types/event_response.rb', line 135

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.")
  TrophyApiClient::MetricEventStreakResponse.validate_raw(obj: obj.current_streak)
  obj.points.is_a?(Hash) != false || raise("Passed value for field obj.points is not the expected type, validation failed.")
  obj.leaderboards.is_a?(Hash) != false || raise("Passed value for field obj.leaderboards is not the expected type, validation failed.")
  obj.idempotency_key&.is_a?(String) != false || raise("Passed value for field obj.idempotency_key is not the expected type, validation failed.")
  obj.idempotent_replayed&.is_a?(Boolean) != false || raise("Passed value for field obj.idempotent_replayed is not the expected type, validation failed.")
end

Instance Method Details

#to_json(*_args) ⇒ String

Serialize an instance of EventResponse to a JSON object



125
126
127
# File 'lib/trophy_api_client/types/event_response.rb', line 125

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