trophy_api_client 1.0.23 → 1.0.25

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: 3e83bc714888213fee4230e282f81c84167b7a06f299bfb64fa88c6f31fdbccf
4
+ data.tar.gz: 8a8fd15093b0f52a3e740eda1c09992fafea425a66a3ec699ce4e4bd335f1a63
5
5
  SHA512:
6
- metadata.gz: b1716545b54c6ba34b2e33306d3ee3a6a2f638597898527c3df0ddeb200bd2a5686801661d41542bd36ebbf4cc005807bdcc81ab8c39f3cfc8de6dfccb423ae5
7
- data.tar.gz: 5f6a490904fb8842edc52c718c3e1559d5c3d048a920cfa5e0d4255f8dce0d9c83b4d4ae3d199513f25cee5c52e38c101fc62b5887b8a6ce58f713a950b7e4aa
6
+ metadata.gz: db6436076a0426b84f0d1db8d6be58d0b37333cc72af12141e0823add83f0688eedb2ae9ab184b43b748daaf34dcc6ca7f35e29fc1aedb8a0caad445f391b038
7
+ data.tar.gz: e3951f80976187af389151dcadef50b80089d30f9525c0f5abecd382538fa2507045f9221b3bddda585979e00fe12fdef6d9b018f8aa465c78f94e14431f680f
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.25"
6
6
  AUTHORS = ["Trophy Labs, Inc"].freeze
7
7
  EMAIL = ""
8
8
  SUMMARY = "Ruby library for the Trophy API."
@@ -0,0 +1,197 @@
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 "async"
8
+
9
+ module TrophyApiClient
10
+ class LeaderboardsClient
11
+ # @return [TrophyApiClient::RequestClient]
12
+ attr_reader :request_client
13
+
14
+ # @param request_client [TrophyApiClient::RequestClient]
15
+ # @return [TrophyApiClient::LeaderboardsClient]
16
+ def initialize(request_client:)
17
+ @request_client = request_client
18
+ end
19
+
20
+ # Get all active leaderboards for your organization.
21
+ #
22
+ # @param request_options [TrophyApiClient::RequestOptions]
23
+ # @return [Array<TrophyApiClient::LeaderboardResponse>]
24
+ # @example
25
+ # api = TrophyApiClient::Client.new(
26
+ # base_url: "https://api.example.com",
27
+ # environment: TrophyApiClient::Environment::DEFAULT,
28
+ # api_key: "YOUR_API_KEY"
29
+ # )
30
+ # api.leaderboards.all
31
+ def all(request_options: nil)
32
+ response = @request_client.conn.get do |req|
33
+ req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
34
+ req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
35
+ req.headers = {
36
+ **(req.headers || {}),
37
+ **@request_client.get_headers,
38
+ **(request_options&.additional_headers || {})
39
+ }.compact
40
+ unless request_options.nil? || request_options&.additional_query_parameters.nil?
41
+ req.params = { **(request_options&.additional_query_parameters || {}) }.compact
42
+ end
43
+ unless request_options.nil? || request_options&.additional_body_parameters.nil?
44
+ req.body = { **(request_options&.additional_body_parameters || {}) }.compact
45
+ end
46
+ req.url "#{@request_client.get_url(request_options: request_options)}/leaderboards"
47
+ end
48
+ parsed_json = JSON.parse(response.body)
49
+ parsed_json&.map do |item|
50
+ item = item.to_json
51
+ TrophyApiClient::LeaderboardResponse.from_json(json_object: item)
52
+ end
53
+ end
54
+
55
+ # Get a specific leaderboard by its key.
56
+ #
57
+ # @param key [String] Unique key of the leaderboard as set when created.
58
+ # @param offset [Integer] Number of rankings to skip for pagination.
59
+ # @param limit [Integer] Maximum number of rankings to return.
60
+ # @param run [String] Specific run date in YYYY-MM-DD format. If not provided, returns the current
61
+ # run.
62
+ # @param user_id [String] When provided, offset is relative to this user's position on the leaderboard. If
63
+ # the user is not found in the leaderboard, returns empty rankings array.
64
+ # @param request_options [TrophyApiClient::RequestOptions]
65
+ # @return [TrophyApiClient::LeaderboardResponseWithRankings]
66
+ # @example
67
+ # api = TrophyApiClient::Client.new(
68
+ # base_url: "https://api.example.com",
69
+ # environment: TrophyApiClient::Environment::DEFAULT,
70
+ # api_key: "YOUR_API_KEY"
71
+ # )
72
+ # api.leaderboards.get(
73
+ # key: "weekly-words",
74
+ # run: "2025-01-15",
75
+ # user_id: "user-123"
76
+ # )
77
+ def get(key:, offset: nil, limit: nil, run: nil, user_id: nil, request_options: nil)
78
+ response = @request_client.conn.get do |req|
79
+ req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
80
+ req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
81
+ req.headers = {
82
+ **(req.headers || {}),
83
+ **@request_client.get_headers,
84
+ **(request_options&.additional_headers || {})
85
+ }.compact
86
+ req.params = {
87
+ **(request_options&.additional_query_parameters || {}),
88
+ "offset": offset,
89
+ "limit": limit,
90
+ "run": run,
91
+ "userId": user_id
92
+ }.compact
93
+ unless request_options.nil? || request_options&.additional_body_parameters.nil?
94
+ req.body = { **(request_options&.additional_body_parameters || {}) }.compact
95
+ end
96
+ req.url "#{@request_client.get_url(request_options: request_options)}/leaderboards/#{key}"
97
+ end
98
+ TrophyApiClient::LeaderboardResponseWithRankings.from_json(json_object: response.body)
99
+ end
100
+ end
101
+
102
+ class AsyncLeaderboardsClient
103
+ # @return [TrophyApiClient::AsyncRequestClient]
104
+ attr_reader :request_client
105
+
106
+ # @param request_client [TrophyApiClient::AsyncRequestClient]
107
+ # @return [TrophyApiClient::AsyncLeaderboardsClient]
108
+ def initialize(request_client:)
109
+ @request_client = request_client
110
+ end
111
+
112
+ # Get all active leaderboards for your organization.
113
+ #
114
+ # @param request_options [TrophyApiClient::RequestOptions]
115
+ # @return [Array<TrophyApiClient::LeaderboardResponse>]
116
+ # @example
117
+ # api = TrophyApiClient::Client.new(
118
+ # base_url: "https://api.example.com",
119
+ # environment: TrophyApiClient::Environment::DEFAULT,
120
+ # api_key: "YOUR_API_KEY"
121
+ # )
122
+ # api.leaderboards.all
123
+ def all(request_options: nil)
124
+ Async do
125
+ response = @request_client.conn.get do |req|
126
+ req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
127
+ req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
128
+ req.headers = {
129
+ **(req.headers || {}),
130
+ **@request_client.get_headers,
131
+ **(request_options&.additional_headers || {})
132
+ }.compact
133
+ unless request_options.nil? || request_options&.additional_query_parameters.nil?
134
+ req.params = { **(request_options&.additional_query_parameters || {}) }.compact
135
+ end
136
+ unless request_options.nil? || request_options&.additional_body_parameters.nil?
137
+ req.body = { **(request_options&.additional_body_parameters || {}) }.compact
138
+ end
139
+ req.url "#{@request_client.get_url(request_options: request_options)}/leaderboards"
140
+ end
141
+ parsed_json = JSON.parse(response.body)
142
+ parsed_json&.map do |item|
143
+ item = item.to_json
144
+ TrophyApiClient::LeaderboardResponse.from_json(json_object: item)
145
+ end
146
+ end
147
+ end
148
+
149
+ # Get a specific leaderboard by its key.
150
+ #
151
+ # @param key [String] Unique key of the leaderboard as set when created.
152
+ # @param offset [Integer] Number of rankings to skip for pagination.
153
+ # @param limit [Integer] Maximum number of rankings to return.
154
+ # @param run [String] Specific run date in YYYY-MM-DD format. If not provided, returns the current
155
+ # run.
156
+ # @param user_id [String] When provided, offset is relative to this user's position on the leaderboard. If
157
+ # the user is not found in the leaderboard, returns empty rankings array.
158
+ # @param request_options [TrophyApiClient::RequestOptions]
159
+ # @return [TrophyApiClient::LeaderboardResponseWithRankings]
160
+ # @example
161
+ # api = TrophyApiClient::Client.new(
162
+ # base_url: "https://api.example.com",
163
+ # environment: TrophyApiClient::Environment::DEFAULT,
164
+ # api_key: "YOUR_API_KEY"
165
+ # )
166
+ # api.leaderboards.get(
167
+ # key: "weekly-words",
168
+ # run: "2025-01-15",
169
+ # user_id: "user-123"
170
+ # )
171
+ def get(key:, offset: nil, limit: nil, run: nil, user_id: nil, request_options: nil)
172
+ Async do
173
+ response = @request_client.conn.get do |req|
174
+ req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
175
+ req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
176
+ req.headers = {
177
+ **(req.headers || {}),
178
+ **@request_client.get_headers,
179
+ **(request_options&.additional_headers || {})
180
+ }.compact
181
+ req.params = {
182
+ **(request_options&.additional_query_parameters || {}),
183
+ "offset": offset,
184
+ "limit": limit,
185
+ "run": run,
186
+ "userId": user_id
187
+ }.compact
188
+ unless request_options.nil? || request_options&.additional_body_parameters.nil?
189
+ req.body = { **(request_options&.additional_body_parameters || {}) }.compact
190
+ end
191
+ req.url "#{@request_client.get_url(request_options: request_options)}/leaderboards/#{key}"
192
+ end
193
+ TrophyApiClient::LeaderboardResponseWithRankings.from_json(json_object: response.body)
194
+ end
195
+ end
196
+ end
197
+ 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
@@ -0,0 +1,184 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "leaderboard_response_status"
4
+ require_relative "leaderboard_response_rank_by"
5
+ require "ostruct"
6
+ require "json"
7
+
8
+ module TrophyApiClient
9
+ # A leaderboard with its configuration details.
10
+ class LeaderboardResponse
11
+ # @return [String] The unique ID of the leaderboard.
12
+ attr_reader :id
13
+ # @return [String] The user-facing name of the leaderboard.
14
+ attr_reader :name
15
+ # @return [String] The unique key used to reference the leaderboard in APIs.
16
+ attr_reader :key
17
+ # @return [TrophyApiClient::LeaderboardResponseStatus] The status of the leaderboard.
18
+ attr_reader :status
19
+ # @return [TrophyApiClient::LeaderboardResponseRankBy] What the leaderboard ranks by.
20
+ attr_reader :rank_by
21
+ # @return [String] The key of the metric to rank by, if rankBy is 'metric'.
22
+ attr_reader :metric_key
23
+ # @return [String] The name of the metric to rank by, if rankBy is 'metric'.
24
+ attr_reader :metric_name
25
+ # @return [String] The key of the points system to rank by, if rankBy is 'points'.
26
+ attr_reader :points_system_key
27
+ # @return [String] The name of the points system to rank by, if rankBy is 'points'.
28
+ attr_reader :points_system_name
29
+ # @return [String] The user-facing description of the leaderboard.
30
+ attr_reader :description
31
+ # @return [String] The start date of the leaderboard in YYYY-MM-DD format.
32
+ attr_reader :start
33
+ # @return [String] The end date of the leaderboard in YYYY-MM-DD format, or null if it runs
34
+ # forever.
35
+ attr_reader :end_
36
+ # @return [Integer] The maximum number of participants in the leaderboard.
37
+ attr_reader :max_participants
38
+ # @return [String] The repetition type for recurring leaderboards, or null for one-time
39
+ # leaderboards.
40
+ attr_reader :run_unit
41
+ # @return [Integer] The interval between repetitions, relative to the start date and repetition
42
+ # type.
43
+ attr_reader :run_interval
44
+ # @return [OpenStruct] Additional properties unmapped to the current class definition
45
+ attr_reader :additional_properties
46
+ # @return [Object]
47
+ attr_reader :_field_set
48
+ protected :_field_set
49
+
50
+ OMIT = Object.new
51
+
52
+ # @param id [String] The unique ID of the leaderboard.
53
+ # @param name [String] The user-facing name of the leaderboard.
54
+ # @param key [String] The unique key used to reference the leaderboard in APIs.
55
+ # @param status [TrophyApiClient::LeaderboardResponseStatus] The status of the leaderboard.
56
+ # @param rank_by [TrophyApiClient::LeaderboardResponseRankBy] What the leaderboard ranks by.
57
+ # @param metric_key [String] The key of the metric to rank by, if rankBy is 'metric'.
58
+ # @param metric_name [String] The name of the metric to rank by, if rankBy is 'metric'.
59
+ # @param points_system_key [String] The key of the points system to rank by, if rankBy is 'points'.
60
+ # @param points_system_name [String] The name of the points system to rank by, if rankBy is 'points'.
61
+ # @param description [String] The user-facing description of the leaderboard.
62
+ # @param start [String] The start date of the leaderboard in YYYY-MM-DD format.
63
+ # @param end_ [String] The end date of the leaderboard in YYYY-MM-DD format, or null if it runs
64
+ # forever.
65
+ # @param max_participants [Integer] The maximum number of participants in the leaderboard.
66
+ # @param run_unit [String] The repetition type for recurring leaderboards, or null for one-time
67
+ # leaderboards.
68
+ # @param run_interval [Integer] The interval between repetitions, relative to the start date and repetition
69
+ # type.
70
+ # @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
71
+ # @return [TrophyApiClient::LeaderboardResponse]
72
+ def initialize(id:, name:, key:, rank_by:, start:, max_participants:, run_interval:, status: OMIT, metric_key: OMIT, metric_name: OMIT,
73
+ points_system_key: OMIT, points_system_name: OMIT, description: OMIT, end_: OMIT, run_unit: OMIT, additional_properties: nil)
74
+ @id = id
75
+ @name = name
76
+ @key = key
77
+ @status = status if status != OMIT
78
+ @rank_by = rank_by
79
+ @metric_key = metric_key if metric_key != OMIT
80
+ @metric_name = metric_name if metric_name != OMIT
81
+ @points_system_key = points_system_key if points_system_key != OMIT
82
+ @points_system_name = points_system_name if points_system_name != OMIT
83
+ @description = description if description != OMIT
84
+ @start = start
85
+ @end_ = end_ if end_ != OMIT
86
+ @max_participants = max_participants
87
+ @run_unit = run_unit if run_unit != OMIT
88
+ @run_interval = run_interval
89
+ @additional_properties = additional_properties
90
+ @_field_set = {
91
+ "id": id,
92
+ "name": name,
93
+ "key": key,
94
+ "status": status,
95
+ "rankBy": rank_by,
96
+ "metricKey": metric_key,
97
+ "metricName": metric_name,
98
+ "pointsSystemKey": points_system_key,
99
+ "pointsSystemName": points_system_name,
100
+ "description": description,
101
+ "start": start,
102
+ "end": end_,
103
+ "maxParticipants": max_participants,
104
+ "runUnit": run_unit,
105
+ "runInterval": run_interval
106
+ }.reject do |_k, v|
107
+ v == OMIT
108
+ end
109
+ end
110
+
111
+ # Deserialize a JSON object to an instance of LeaderboardResponse
112
+ #
113
+ # @param json_object [String]
114
+ # @return [TrophyApiClient::LeaderboardResponse]
115
+ def self.from_json(json_object:)
116
+ struct = JSON.parse(json_object, object_class: OpenStruct)
117
+ parsed_json = JSON.parse(json_object)
118
+ id = parsed_json["id"]
119
+ name = parsed_json["name"]
120
+ key = parsed_json["key"]
121
+ status = parsed_json["status"]
122
+ rank_by = parsed_json["rankBy"]
123
+ metric_key = parsed_json["metricKey"]
124
+ metric_name = parsed_json["metricName"]
125
+ points_system_key = parsed_json["pointsSystemKey"]
126
+ points_system_name = parsed_json["pointsSystemName"]
127
+ description = parsed_json["description"]
128
+ start = parsed_json["start"]
129
+ end_ = parsed_json["end"]
130
+ max_participants = parsed_json["maxParticipants"]
131
+ run_unit = parsed_json["runUnit"]
132
+ run_interval = parsed_json["runInterval"]
133
+ new(
134
+ id: id,
135
+ name: name,
136
+ key: key,
137
+ status: status,
138
+ rank_by: rank_by,
139
+ metric_key: metric_key,
140
+ metric_name: metric_name,
141
+ points_system_key: points_system_key,
142
+ points_system_name: points_system_name,
143
+ description: description,
144
+ start: start,
145
+ end_: end_,
146
+ max_participants: max_participants,
147
+ run_unit: run_unit,
148
+ run_interval: run_interval,
149
+ additional_properties: struct
150
+ )
151
+ end
152
+
153
+ # Serialize an instance of LeaderboardResponse to a JSON object
154
+ #
155
+ # @return [String]
156
+ def to_json(*_args)
157
+ @_field_set&.to_json
158
+ end
159
+
160
+ # Leveraged for Union-type generation, validate_raw attempts to parse the given
161
+ # hash and check each fields type against the current object's property
162
+ # definitions.
163
+ #
164
+ # @param obj [Object]
165
+ # @return [Void]
166
+ def self.validate_raw(obj:)
167
+ obj.id.is_a?(String) != false || raise("Passed value for field obj.id is not the expected type, validation failed.")
168
+ obj.name.is_a?(String) != false || raise("Passed value for field obj.name is not the expected type, validation failed.")
169
+ obj.key.is_a?(String) != false || raise("Passed value for field obj.key is not the expected type, validation failed.")
170
+ obj.status&.is_a?(TrophyApiClient::LeaderboardResponseStatus) != false || raise("Passed value for field obj.status is not the expected type, validation failed.")
171
+ obj.rank_by.is_a?(TrophyApiClient::LeaderboardResponseRankBy) != false || raise("Passed value for field obj.rank_by is not the expected type, validation failed.")
172
+ obj.metric_key&.is_a?(String) != false || raise("Passed value for field obj.metric_key is not the expected type, validation failed.")
173
+ obj.metric_name&.is_a?(String) != false || raise("Passed value for field obj.metric_name is not the expected type, validation failed.")
174
+ obj.points_system_key&.is_a?(String) != false || raise("Passed value for field obj.points_system_key is not the expected type, validation failed.")
175
+ obj.points_system_name&.is_a?(String) != false || raise("Passed value for field obj.points_system_name is not the expected type, validation failed.")
176
+ obj.description&.is_a?(String) != false || raise("Passed value for field obj.description is not the expected type, validation failed.")
177
+ obj.start.is_a?(String) != false || raise("Passed value for field obj.start is not the expected type, validation failed.")
178
+ obj.end_&.is_a?(String) != false || raise("Passed value for field obj.end_ is not the expected type, validation failed.")
179
+ obj.max_participants.is_a?(Integer) != false || raise("Passed value for field obj.max_participants is not the expected type, validation failed.")
180
+ obj.run_unit&.is_a?(String) != false || raise("Passed value for field obj.run_unit is not the expected type, validation failed.")
181
+ obj.run_interval.is_a?(Integer) != false || raise("Passed value for field obj.run_interval is not the expected type, validation failed.")
182
+ end
183
+ end
184
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TrophyApiClient
4
+ # What the leaderboard ranks by.
5
+ class LeaderboardResponseRankBy
6
+ POINTS = "points"
7
+ STREAK = "streak"
8
+ METRIC = "metric"
9
+ end
10
+ end