trophy_api_client 1.0.23 → 1.0.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 39897ab7658149ab5f3bf2a97e23eb07e0f2a2e2e5efc65e44b3aa70ca4ca36b
4
- data.tar.gz: c202d22246b40b860ea0e201b8f90df0379fbb2c0330913c89b44d969ddafc3c
3
+ metadata.gz: ea40e7beb7fd349e5a92975fd9e202e6e602f9fb2133d35a9e308c2aa987b24f
4
+ data.tar.gz: ed4690822763b7e2e76ad0b8c356cb488f0eafeb39f02551d0b1345bbfa217ca
5
5
  SHA512:
6
- metadata.gz: b1716545b54c6ba34b2e33306d3ee3a6a2f638597898527c3df0ddeb200bd2a5686801661d41542bd36ebbf4cc005807bdcc81ab8c39f3cfc8de6dfccb423ae5
7
- data.tar.gz: 5f6a490904fb8842edc52c718c3e1559d5c3d048a920cfa5e0d4255f8dce0d9c83b4d4ae3d199513f25cee5c52e38c101fc62b5887b8a6ce58f713a950b7e4aa
6
+ metadata.gz: 301e9caf410b6b9ca4be8dbeff563fa49cc1a85232c3ce23c464070cbf36922e80c264f0f9a5066cb277cdf3936121173dc5678d7d38bb1958920c62e0617a3f
7
+ data.tar.gz: ce1884675bc3f55b3cddf5f440e59438f0ed06cd91155a873476c92b056e13494b98f9203287cf8598ec540766abbea988e92da83c31e80803fd87ee43c9f69c
data/lib/gemconfig.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  module TrophyApiClient
4
4
  module Gemconfig
5
- VERSION = "1.0.23"
5
+ VERSION = "1.0.24"
6
6
  AUTHORS = ["Trophy Labs, Inc"].freeze
7
7
  EMAIL = ""
8
8
  SUMMARY = "Ruby library for the Trophy API."
@@ -0,0 +1,274 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../../requests"
4
+ require_relative "../types/leaderboard_response"
5
+ require "json"
6
+ require_relative "../types/leaderboard_response_with_rankings"
7
+ require_relative "../types/user_leaderboard_response"
8
+ require "async"
9
+
10
+ module TrophyApiClient
11
+ class LeaderboardsClient
12
+ # @return [TrophyApiClient::RequestClient]
13
+ attr_reader :request_client
14
+
15
+ # @param request_client [TrophyApiClient::RequestClient]
16
+ # @return [TrophyApiClient::LeaderboardsClient]
17
+ def initialize(request_client:)
18
+ @request_client = request_client
19
+ end
20
+
21
+ # Get all active leaderboards for your organization.
22
+ #
23
+ # @param request_options [TrophyApiClient::RequestOptions]
24
+ # @return [Array<TrophyApiClient::LeaderboardResponse>]
25
+ # @example
26
+ # api = TrophyApiClient::Client.new(
27
+ # base_url: "https://api.example.com",
28
+ # environment: TrophyApiClient::Environment::DEFAULT,
29
+ # api_key: "YOUR_API_KEY"
30
+ # )
31
+ # api.leaderboards.all
32
+ def all(request_options: nil)
33
+ response = @request_client.conn.get do |req|
34
+ req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
35
+ req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
36
+ req.headers = {
37
+ **(req.headers || {}),
38
+ **@request_client.get_headers,
39
+ **(request_options&.additional_headers || {})
40
+ }.compact
41
+ unless request_options.nil? || request_options&.additional_query_parameters.nil?
42
+ req.params = { **(request_options&.additional_query_parameters || {}) }.compact
43
+ end
44
+ unless request_options.nil? || request_options&.additional_body_parameters.nil?
45
+ req.body = { **(request_options&.additional_body_parameters || {}) }.compact
46
+ end
47
+ req.url "#{@request_client.get_url(request_options: request_options)}/leaderboards"
48
+ end
49
+ parsed_json = JSON.parse(response.body)
50
+ parsed_json&.map do |item|
51
+ item = item.to_json
52
+ TrophyApiClient::LeaderboardResponse.from_json(json_object: item)
53
+ end
54
+ end
55
+
56
+ # Get a specific leaderboard by its key.
57
+ #
58
+ # @param key [String] Unique key of the leaderboard as set when created.
59
+ # @param offset [Integer] Number of rankings to skip for pagination.
60
+ # @param limit [Integer] Maximum number of rankings to return.
61
+ # @param run [String] Specific run date in YYYY-MM-DD format. If not provided, returns the current
62
+ # run.
63
+ # @param user_id [String] When provided, offset is relative to this user's position on the leaderboard. If
64
+ # the user is not found in the leaderboard, returns empty rankings array.
65
+ # @param request_options [TrophyApiClient::RequestOptions]
66
+ # @return [TrophyApiClient::LeaderboardResponseWithRankings]
67
+ # @example
68
+ # api = TrophyApiClient::Client.new(
69
+ # base_url: "https://api.example.com",
70
+ # environment: TrophyApiClient::Environment::DEFAULT,
71
+ # api_key: "YOUR_API_KEY"
72
+ # )
73
+ # api.leaderboards.get(
74
+ # key: "weekly-words",
75
+ # run: "2025-01-15",
76
+ # user_id: "user-123"
77
+ # )
78
+ def get(key:, offset: nil, limit: nil, run: nil, user_id: nil, request_options: nil)
79
+ response = @request_client.conn.get do |req|
80
+ req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
81
+ req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
82
+ req.headers = {
83
+ **(req.headers || {}),
84
+ **@request_client.get_headers,
85
+ **(request_options&.additional_headers || {})
86
+ }.compact
87
+ req.params = {
88
+ **(request_options&.additional_query_parameters || {}),
89
+ "offset": offset,
90
+ "limit": limit,
91
+ "run": run,
92
+ "userId": user_id
93
+ }.compact
94
+ unless request_options.nil? || request_options&.additional_body_parameters.nil?
95
+ req.body = { **(request_options&.additional_body_parameters || {}) }.compact
96
+ end
97
+ req.url "#{@request_client.get_url(request_options: request_options)}/leaderboards/#{key}"
98
+ end
99
+ TrophyApiClient::LeaderboardResponseWithRankings.from_json(json_object: response.body)
100
+ end
101
+
102
+ # Get a user's rank, value, and history for a specific leaderboard.
103
+ #
104
+ # @param user_id [String] The user's ID in your database.
105
+ # @param key [String] Unique key of the leaderboard as set when created.
106
+ # @param run [String] Specific run date in YYYY-MM-DD format. If not provided, returns the current
107
+ # run.
108
+ # @param request_options [TrophyApiClient::RequestOptions]
109
+ # @return [TrophyApiClient::UserLeaderboardResponse]
110
+ # @example
111
+ # api = TrophyApiClient::Client.new(
112
+ # base_url: "https://api.example.com",
113
+ # environment: TrophyApiClient::Environment::DEFAULT,
114
+ # api_key: "YOUR_API_KEY"
115
+ # )
116
+ # api.leaderboards.users_leaderboards(
117
+ # user_id: "user-123",
118
+ # key: "weekly-words",
119
+ # run: "2025-01-15"
120
+ # )
121
+ def users_leaderboards(user_id:, key:, run: nil, request_options: nil)
122
+ response = @request_client.conn.get do |req|
123
+ req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
124
+ req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
125
+ req.headers = {
126
+ **(req.headers || {}),
127
+ **@request_client.get_headers,
128
+ **(request_options&.additional_headers || {})
129
+ }.compact
130
+ req.params = { **(request_options&.additional_query_parameters || {}), "run": run }.compact
131
+ unless request_options.nil? || request_options&.additional_body_parameters.nil?
132
+ req.body = { **(request_options&.additional_body_parameters || {}) }.compact
133
+ end
134
+ req.url "#{@request_client.get_url(request_options: request_options)}/users/#{user_id}/leaderboards/#{key}"
135
+ end
136
+ TrophyApiClient::UserLeaderboardResponse.from_json(json_object: response.body)
137
+ end
138
+ end
139
+
140
+ class AsyncLeaderboardsClient
141
+ # @return [TrophyApiClient::AsyncRequestClient]
142
+ attr_reader :request_client
143
+
144
+ # @param request_client [TrophyApiClient::AsyncRequestClient]
145
+ # @return [TrophyApiClient::AsyncLeaderboardsClient]
146
+ def initialize(request_client:)
147
+ @request_client = request_client
148
+ end
149
+
150
+ # Get all active leaderboards for your organization.
151
+ #
152
+ # @param request_options [TrophyApiClient::RequestOptions]
153
+ # @return [Array<TrophyApiClient::LeaderboardResponse>]
154
+ # @example
155
+ # api = TrophyApiClient::Client.new(
156
+ # base_url: "https://api.example.com",
157
+ # environment: TrophyApiClient::Environment::DEFAULT,
158
+ # api_key: "YOUR_API_KEY"
159
+ # )
160
+ # api.leaderboards.all
161
+ def all(request_options: nil)
162
+ Async do
163
+ response = @request_client.conn.get do |req|
164
+ req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
165
+ req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
166
+ req.headers = {
167
+ **(req.headers || {}),
168
+ **@request_client.get_headers,
169
+ **(request_options&.additional_headers || {})
170
+ }.compact
171
+ unless request_options.nil? || request_options&.additional_query_parameters.nil?
172
+ req.params = { **(request_options&.additional_query_parameters || {}) }.compact
173
+ end
174
+ unless request_options.nil? || request_options&.additional_body_parameters.nil?
175
+ req.body = { **(request_options&.additional_body_parameters || {}) }.compact
176
+ end
177
+ req.url "#{@request_client.get_url(request_options: request_options)}/leaderboards"
178
+ end
179
+ parsed_json = JSON.parse(response.body)
180
+ parsed_json&.map do |item|
181
+ item = item.to_json
182
+ TrophyApiClient::LeaderboardResponse.from_json(json_object: item)
183
+ end
184
+ end
185
+ end
186
+
187
+ # Get a specific leaderboard by its key.
188
+ #
189
+ # @param key [String] Unique key of the leaderboard as set when created.
190
+ # @param offset [Integer] Number of rankings to skip for pagination.
191
+ # @param limit [Integer] Maximum number of rankings to return.
192
+ # @param run [String] Specific run date in YYYY-MM-DD format. If not provided, returns the current
193
+ # run.
194
+ # @param user_id [String] When provided, offset is relative to this user's position on the leaderboard. If
195
+ # the user is not found in the leaderboard, returns empty rankings array.
196
+ # @param request_options [TrophyApiClient::RequestOptions]
197
+ # @return [TrophyApiClient::LeaderboardResponseWithRankings]
198
+ # @example
199
+ # api = TrophyApiClient::Client.new(
200
+ # base_url: "https://api.example.com",
201
+ # environment: TrophyApiClient::Environment::DEFAULT,
202
+ # api_key: "YOUR_API_KEY"
203
+ # )
204
+ # api.leaderboards.get(
205
+ # key: "weekly-words",
206
+ # run: "2025-01-15",
207
+ # user_id: "user-123"
208
+ # )
209
+ def get(key:, offset: nil, limit: nil, run: nil, user_id: nil, request_options: nil)
210
+ Async do
211
+ response = @request_client.conn.get do |req|
212
+ req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
213
+ req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
214
+ req.headers = {
215
+ **(req.headers || {}),
216
+ **@request_client.get_headers,
217
+ **(request_options&.additional_headers || {})
218
+ }.compact
219
+ req.params = {
220
+ **(request_options&.additional_query_parameters || {}),
221
+ "offset": offset,
222
+ "limit": limit,
223
+ "run": run,
224
+ "userId": user_id
225
+ }.compact
226
+ unless request_options.nil? || request_options&.additional_body_parameters.nil?
227
+ req.body = { **(request_options&.additional_body_parameters || {}) }.compact
228
+ end
229
+ req.url "#{@request_client.get_url(request_options: request_options)}/leaderboards/#{key}"
230
+ end
231
+ TrophyApiClient::LeaderboardResponseWithRankings.from_json(json_object: response.body)
232
+ end
233
+ end
234
+
235
+ # Get a user's rank, value, and history for a specific leaderboard.
236
+ #
237
+ # @param user_id [String] The user's ID in your database.
238
+ # @param key [String] Unique key of the leaderboard as set when created.
239
+ # @param run [String] Specific run date in YYYY-MM-DD format. If not provided, returns the current
240
+ # run.
241
+ # @param request_options [TrophyApiClient::RequestOptions]
242
+ # @return [TrophyApiClient::UserLeaderboardResponse]
243
+ # @example
244
+ # api = TrophyApiClient::Client.new(
245
+ # base_url: "https://api.example.com",
246
+ # environment: TrophyApiClient::Environment::DEFAULT,
247
+ # api_key: "YOUR_API_KEY"
248
+ # )
249
+ # api.leaderboards.users_leaderboards(
250
+ # user_id: "user-123",
251
+ # key: "weekly-words",
252
+ # run: "2025-01-15"
253
+ # )
254
+ def users_leaderboards(user_id:, key:, run: nil, request_options: nil)
255
+ Async do
256
+ response = @request_client.conn.get do |req|
257
+ req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
258
+ req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
259
+ req.headers = {
260
+ **(req.headers || {}),
261
+ **@request_client.get_headers,
262
+ **(request_options&.additional_headers || {})
263
+ }.compact
264
+ req.params = { **(request_options&.additional_query_parameters || {}), "run": run }.compact
265
+ unless request_options.nil? || request_options&.additional_body_parameters.nil?
266
+ req.body = { **(request_options&.additional_body_parameters || {}) }.compact
267
+ end
268
+ req.url "#{@request_client.get_url(request_options: request_options)}/users/#{user_id}/leaderboards/#{key}"
269
+ end
270
+ TrophyApiClient::UserLeaderboardResponse.from_json(json_object: response.body)
271
+ end
272
+ end
273
+ end
274
+ end
@@ -15,10 +15,12 @@ module TrophyApiClient
15
15
  attr_reader :total
16
16
  # @return [Array<TrophyApiClient::CompletedAchievementResponse>] Achievements completed as a result of this event.
17
17
  attr_reader :achievements
18
- # @return [TrophyApiClient::MetricEventStreakResponse] The user's current streak for the metric, if the metric has streaks enabled.
18
+ # @return [TrophyApiClient::MetricEventStreakResponse] The user's current streak.
19
19
  attr_reader :current_streak
20
- # @return [Hash{String => TrophyApiClient::MetricEventPointsResponse}] A map of points systems by key that were affected by this event.
20
+ # @return [Hash{String => TrophyApiClient::MetricEventPointsResponse}] A map of points systems by key.
21
21
  attr_reader :points
22
+ # @return [Hash{String => TrophyApiClient::MetricEventLeaderboardResponse}] A map of leaderboards by key.
23
+ attr_reader :leaderboards
22
24
  # @return [String] The idempotency key used for the event, if one was provided.
23
25
  attr_reader :idempotency_key
24
26
  # @return [Boolean] Whether the event was replayed due to idempotency.
@@ -35,20 +37,22 @@ module TrophyApiClient
35
37
  # @param metric_id [String] The unique ID of the metric that was updated.
36
38
  # @param total [Float] The user's new total progress against the metric.
37
39
  # @param achievements [Array<TrophyApiClient::CompletedAchievementResponse>] Achievements completed as a result of this event.
38
- # @param current_streak [TrophyApiClient::MetricEventStreakResponse] The user's current streak for the metric, if the metric has streaks enabled.
39
- # @param points [Hash{String => TrophyApiClient::MetricEventPointsResponse}] A map of points systems by key that were affected by this event.
40
+ # @param current_streak [TrophyApiClient::MetricEventStreakResponse] The user's current streak.
41
+ # @param points [Hash{String => TrophyApiClient::MetricEventPointsResponse}] A map of points systems by key.
42
+ # @param leaderboards [Hash{String => TrophyApiClient::MetricEventLeaderboardResponse}] A map of leaderboards by key.
40
43
  # @param idempotency_key [String] The idempotency key used for the event, if one was provided.
41
44
  # @param idempotent_replayed [Boolean] Whether the event was replayed due to idempotency.
42
45
  # @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
43
46
  # @return [TrophyApiClient::EventResponse]
44
47
  def initialize(event_id:, metric_id:, total:, achievements: OMIT, current_streak: OMIT, points: OMIT,
45
- idempotency_key: OMIT, idempotent_replayed: OMIT, additional_properties: nil)
48
+ leaderboards: OMIT, idempotency_key: OMIT, idempotent_replayed: OMIT, additional_properties: nil)
46
49
  @event_id = event_id
47
50
  @metric_id = metric_id
48
51
  @total = total
49
52
  @achievements = achievements if achievements != OMIT
50
53
  @current_streak = current_streak if current_streak != OMIT
51
54
  @points = points if points != OMIT
55
+ @leaderboards = leaderboards if leaderboards != OMIT
52
56
  @idempotency_key = idempotency_key if idempotency_key != OMIT
53
57
  @idempotent_replayed = idempotent_replayed if idempotent_replayed != OMIT
54
58
  @additional_properties = additional_properties
@@ -59,6 +63,7 @@ module TrophyApiClient
59
63
  "achievements": achievements,
60
64
  "currentStreak": current_streak,
61
65
  "points": points,
66
+ "leaderboards": leaderboards,
62
67
  "idempotencyKey": idempotency_key,
63
68
  "idempotentReplayed": idempotent_replayed
64
69
  }.reject do |_k, v|
@@ -90,6 +95,10 @@ module TrophyApiClient
90
95
  value = value.to_json
91
96
  TrophyApiClient::MetricEventPointsResponse.from_json(json_object: value)
92
97
  end
98
+ leaderboards = parsed_json["leaderboards"]&.transform_values do |value|
99
+ value = value.to_json
100
+ TrophyApiClient::MetricEventLeaderboardResponse.from_json(json_object: value)
101
+ end
93
102
  idempotency_key = parsed_json["idempotencyKey"]
94
103
  idempotent_replayed = parsed_json["idempotentReplayed"]
95
104
  new(
@@ -99,6 +108,7 @@ module TrophyApiClient
99
108
  achievements: achievements,
100
109
  current_streak: current_streak,
101
110
  points: points,
111
+ leaderboards: leaderboards,
102
112
  idempotency_key: idempotency_key,
103
113
  idempotent_replayed: idempotent_replayed,
104
114
  additional_properties: struct
@@ -125,6 +135,7 @@ module TrophyApiClient
125
135
  obj.achievements&.is_a?(Array) != false || raise("Passed value for field obj.achievements is not the expected type, validation failed.")
126
136
  obj.current_streak.nil? || TrophyApiClient::MetricEventStreakResponse.validate_raw(obj: obj.current_streak)
127
137
  obj.points&.is_a?(Hash) != false || raise("Passed value for field obj.points is not the expected type, validation failed.")
138
+ obj.leaderboards&.is_a?(Hash) != false || raise("Passed value for field obj.leaderboards is not the expected type, validation failed.")
128
139
  obj.idempotency_key&.is_a?(String) != false || raise("Passed value for field obj.idempotency_key is not the expected type, validation failed.")
129
140
  obj.idempotent_replayed&.is_a?(Boolean) != false || raise("Passed value for field obj.idempotent_replayed is not the expected type, validation failed.")
130
141
  end
@@ -0,0 +1,101 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "date"
4
+ require "ostruct"
5
+ require "json"
6
+
7
+ module TrophyApiClient
8
+ # A leaderboard event representing a change in a user's rank or value.
9
+ class LeaderboardEvent
10
+ # @return [DateTime] The timestamp when the event occurred.
11
+ attr_reader :time
12
+ # @return [Integer] The user's rank before this event, or null if they were not on the leaderboard.
13
+ attr_reader :previous_rank
14
+ # @return [Integer] The user's rank after this event, or null if they are no longer on the
15
+ # leaderboard.
16
+ attr_reader :rank
17
+ # @return [Integer] The user's value before this event, or null if they were not on the leaderboard.
18
+ attr_reader :previous_value
19
+ # @return [Integer] The user's value after this event, or null if they are no longer on the
20
+ # leaderboard.
21
+ attr_reader :value
22
+ # @return [OpenStruct] Additional properties unmapped to the current class definition
23
+ attr_reader :additional_properties
24
+ # @return [Object]
25
+ attr_reader :_field_set
26
+ protected :_field_set
27
+
28
+ OMIT = Object.new
29
+
30
+ # @param time [DateTime] The timestamp when the event occurred.
31
+ # @param previous_rank [Integer] The user's rank before this event, or null if they were not on the leaderboard.
32
+ # @param rank [Integer] The user's rank after this event, or null if they are no longer on the
33
+ # leaderboard.
34
+ # @param previous_value [Integer] The user's value before this event, or null if they were not on the leaderboard.
35
+ # @param value [Integer] The user's value after this event, or null if they are no longer on the
36
+ # leaderboard.
37
+ # @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
38
+ # @return [TrophyApiClient::LeaderboardEvent]
39
+ def initialize(time:, previous_rank: OMIT, rank: OMIT, previous_value: OMIT, value: OMIT,
40
+ additional_properties: nil)
41
+ @time = time
42
+ @previous_rank = previous_rank if previous_rank != OMIT
43
+ @rank = rank if rank != OMIT
44
+ @previous_value = previous_value if previous_value != OMIT
45
+ @value = value if value != OMIT
46
+ @additional_properties = additional_properties
47
+ @_field_set = {
48
+ "time": time,
49
+ "previousRank": previous_rank,
50
+ "rank": rank,
51
+ "previousValue": previous_value,
52
+ "value": value
53
+ }.reject do |_k, v|
54
+ v == OMIT
55
+ end
56
+ end
57
+
58
+ # Deserialize a JSON object to an instance of LeaderboardEvent
59
+ #
60
+ # @param json_object [String]
61
+ # @return [TrophyApiClient::LeaderboardEvent]
62
+ def self.from_json(json_object:)
63
+ struct = JSON.parse(json_object, object_class: OpenStruct)
64
+ parsed_json = JSON.parse(json_object)
65
+ time = (DateTime.parse(parsed_json["time"]) unless parsed_json["time"].nil?)
66
+ previous_rank = parsed_json["previousRank"]
67
+ rank = parsed_json["rank"]
68
+ previous_value = parsed_json["previousValue"]
69
+ value = parsed_json["value"]
70
+ new(
71
+ time: time,
72
+ previous_rank: previous_rank,
73
+ rank: rank,
74
+ previous_value: previous_value,
75
+ value: value,
76
+ additional_properties: struct
77
+ )
78
+ end
79
+
80
+ # Serialize an instance of LeaderboardEvent to a JSON object
81
+ #
82
+ # @return [String]
83
+ def to_json(*_args)
84
+ @_field_set&.to_json
85
+ end
86
+
87
+ # Leveraged for Union-type generation, validate_raw attempts to parse the given
88
+ # hash and check each fields type against the current object's property
89
+ # definitions.
90
+ #
91
+ # @param obj [Object]
92
+ # @return [Void]
93
+ def self.validate_raw(obj:)
94
+ obj.time.is_a?(DateTime) != false || raise("Passed value for field obj.time is not the expected type, validation failed.")
95
+ obj.previous_rank&.is_a?(Integer) != false || raise("Passed value for field obj.previous_rank is not the expected type, validation failed.")
96
+ obj.rank&.is_a?(Integer) != false || raise("Passed value for field obj.rank is not the expected type, validation failed.")
97
+ obj.previous_value&.is_a?(Integer) != false || raise("Passed value for field obj.previous_value is not the expected type, validation failed.")
98
+ obj.value&.is_a?(Integer) != false || raise("Passed value for field obj.value is not the expected type, validation failed.")
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,82 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "ostruct"
4
+ require "json"
5
+
6
+ module TrophyApiClient
7
+ # A user's ranking in a leaderboard.
8
+ class LeaderboardRanking
9
+ # @return [String] The ID of the user.
10
+ attr_reader :user_id
11
+ # @return [String] The name of the user. May be null if no name is set.
12
+ attr_reader :user_name
13
+ # @return [Integer] The user's rank in the leaderboard.
14
+ attr_reader :rank
15
+ # @return [Integer] The user's value for this leaderboard (points, metric value, etc.).
16
+ attr_reader :value
17
+ # @return [OpenStruct] Additional properties unmapped to the current class definition
18
+ attr_reader :additional_properties
19
+ # @return [Object]
20
+ attr_reader :_field_set
21
+ protected :_field_set
22
+
23
+ OMIT = Object.new
24
+
25
+ # @param user_id [String] The ID of the user.
26
+ # @param user_name [String] The name of the user. May be null if no name is set.
27
+ # @param rank [Integer] The user's rank in the leaderboard.
28
+ # @param value [Integer] The user's value for this leaderboard (points, metric value, etc.).
29
+ # @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
30
+ # @return [TrophyApiClient::LeaderboardRanking]
31
+ def initialize(user_id:, rank:, value:, user_name: OMIT, additional_properties: nil)
32
+ @user_id = user_id
33
+ @user_name = user_name if user_name != OMIT
34
+ @rank = rank
35
+ @value = value
36
+ @additional_properties = additional_properties
37
+ @_field_set = { "userId": user_id, "userName": user_name, "rank": rank, "value": value }.reject do |_k, v|
38
+ v == OMIT
39
+ end
40
+ end
41
+
42
+ # Deserialize a JSON object to an instance of LeaderboardRanking
43
+ #
44
+ # @param json_object [String]
45
+ # @return [TrophyApiClient::LeaderboardRanking]
46
+ def self.from_json(json_object:)
47
+ struct = JSON.parse(json_object, object_class: OpenStruct)
48
+ parsed_json = JSON.parse(json_object)
49
+ user_id = parsed_json["userId"]
50
+ user_name = parsed_json["userName"]
51
+ rank = parsed_json["rank"]
52
+ value = parsed_json["value"]
53
+ new(
54
+ user_id: user_id,
55
+ user_name: user_name,
56
+ rank: rank,
57
+ value: value,
58
+ additional_properties: struct
59
+ )
60
+ end
61
+
62
+ # Serialize an instance of LeaderboardRanking to a JSON object
63
+ #
64
+ # @return [String]
65
+ def to_json(*_args)
66
+ @_field_set&.to_json
67
+ end
68
+
69
+ # Leveraged for Union-type generation, validate_raw attempts to parse the given
70
+ # hash and check each fields type against the current object's property
71
+ # definitions.
72
+ #
73
+ # @param obj [Object]
74
+ # @return [Void]
75
+ def self.validate_raw(obj:)
76
+ obj.user_id.is_a?(String) != false || raise("Passed value for field obj.user_id is not the expected type, validation failed.")
77
+ obj.user_name&.is_a?(String) != false || raise("Passed value for field obj.user_name is not the expected type, validation failed.")
78
+ obj.rank.is_a?(Integer) != false || raise("Passed value for field obj.rank is not the expected type, validation failed.")
79
+ obj.value.is_a?(Integer) != false || raise("Passed value for field obj.value is not the expected type, validation failed.")
80
+ end
81
+ end
82
+ end