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.
@@ -0,0 +1,216 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "leaderboard_event"
4
+ require_relative "leaderboard_response_status"
5
+ require_relative "leaderboard_response_rank_by"
6
+ require "ostruct"
7
+ require "json"
8
+
9
+ module TrophyApiClient
10
+ # A user's data for a specific leaderboard including rank, value, and history.
11
+ class UserLeaderboardResponse
12
+ # @return [Integer] The user's current rank in this leaderboard. Null if the user is not on the
13
+ # leaderboard.
14
+ attr_reader :rank
15
+ # @return [Integer] The user's current value in this leaderboard. Null if the user is not on the
16
+ # leaderboard.
17
+ attr_reader :value
18
+ # @return [Array<TrophyApiClient::LeaderboardEvent>] An array of events showing the user's rank and value changes over time.
19
+ attr_reader :history
20
+ # @return [String] The unique ID of the leaderboard.
21
+ attr_reader :id
22
+ # @return [String] The user-facing name of the leaderboard.
23
+ attr_reader :name
24
+ # @return [String] The unique key used to reference the leaderboard in APIs.
25
+ attr_reader :key
26
+ # @return [TrophyApiClient::LeaderboardResponseStatus] The status of the leaderboard.
27
+ attr_reader :status
28
+ # @return [TrophyApiClient::LeaderboardResponseRankBy] What the leaderboard ranks by.
29
+ attr_reader :rank_by
30
+ # @return [String] The key of the metric to rank by, if rankBy is 'metric'.
31
+ attr_reader :metric_key
32
+ # @return [String] The name of the metric to rank by, if rankBy is 'metric'.
33
+ attr_reader :metric_name
34
+ # @return [String] The key of the points system to rank by, if rankBy is 'points'.
35
+ attr_reader :points_system_key
36
+ # @return [String] The name of the points system to rank by, if rankBy is 'points'.
37
+ attr_reader :points_system_name
38
+ # @return [String] The user-facing description of the leaderboard.
39
+ attr_reader :description
40
+ # @return [String] The start date of the leaderboard in YYYY-MM-DD format.
41
+ attr_reader :start
42
+ # @return [String] The end date of the leaderboard in YYYY-MM-DD format, or null if it runs
43
+ # forever.
44
+ attr_reader :end_
45
+ # @return [Integer] The maximum number of participants in the leaderboard.
46
+ attr_reader :max_participants
47
+ # @return [String] The repetition type for recurring leaderboards, or null for one-time
48
+ # leaderboards.
49
+ attr_reader :run_unit
50
+ # @return [Integer] The interval between repetitions, relative to the start date and repetition
51
+ # type.
52
+ attr_reader :run_interval
53
+ # @return [OpenStruct] Additional properties unmapped to the current class definition
54
+ attr_reader :additional_properties
55
+ # @return [Object]
56
+ attr_reader :_field_set
57
+ protected :_field_set
58
+
59
+ OMIT = Object.new
60
+
61
+ # @param rank [Integer] The user's current rank in this leaderboard. Null if the user is not on the
62
+ # leaderboard.
63
+ # @param value [Integer] The user's current value in this leaderboard. Null if the user is not on the
64
+ # leaderboard.
65
+ # @param history [Array<TrophyApiClient::LeaderboardEvent>] An array of events showing the user's rank and value changes over time.
66
+ # @param id [String] The unique ID of the leaderboard.
67
+ # @param name [String] The user-facing name of the leaderboard.
68
+ # @param key [String] The unique key used to reference the leaderboard in APIs.
69
+ # @param status [TrophyApiClient::LeaderboardResponseStatus] The status of the leaderboard.
70
+ # @param rank_by [TrophyApiClient::LeaderboardResponseRankBy] What the leaderboard ranks by.
71
+ # @param metric_key [String] The key of the metric to rank by, if rankBy is 'metric'.
72
+ # @param metric_name [String] The name of the metric to rank by, if rankBy is 'metric'.
73
+ # @param points_system_key [String] The key of the points system to rank by, if rankBy is 'points'.
74
+ # @param points_system_name [String] The name of the points system to rank by, if rankBy is 'points'.
75
+ # @param description [String] The user-facing description of the leaderboard.
76
+ # @param start [String] The start date of the leaderboard in YYYY-MM-DD format.
77
+ # @param end_ [String] The end date of the leaderboard in YYYY-MM-DD format, or null if it runs
78
+ # forever.
79
+ # @param max_participants [Integer] The maximum number of participants in the leaderboard.
80
+ # @param run_unit [String] The repetition type for recurring leaderboards, or null for one-time
81
+ # leaderboards.
82
+ # @param run_interval [Integer] The interval between repetitions, relative to the start date and repetition
83
+ # type.
84
+ # @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
85
+ # @return [TrophyApiClient::UserLeaderboardResponse]
86
+ def initialize(history:, id:, name:, key:, rank_by:, start:, max_participants:, run_interval:, rank: OMIT, value: OMIT, status: OMIT, metric_key: OMIT,
87
+ metric_name: OMIT, points_system_key: OMIT, points_system_name: OMIT, description: OMIT, end_: OMIT, run_unit: OMIT, additional_properties: nil)
88
+ @rank = rank if rank != OMIT
89
+ @value = value if value != OMIT
90
+ @history = history
91
+ @id = id
92
+ @name = name
93
+ @key = key
94
+ @status = status if status != OMIT
95
+ @rank_by = rank_by
96
+ @metric_key = metric_key if metric_key != OMIT
97
+ @metric_name = metric_name if metric_name != OMIT
98
+ @points_system_key = points_system_key if points_system_key != OMIT
99
+ @points_system_name = points_system_name if points_system_name != OMIT
100
+ @description = description if description != OMIT
101
+ @start = start
102
+ @end_ = end_ if end_ != OMIT
103
+ @max_participants = max_participants
104
+ @run_unit = run_unit if run_unit != OMIT
105
+ @run_interval = run_interval
106
+ @additional_properties = additional_properties
107
+ @_field_set = {
108
+ "rank": rank,
109
+ "value": value,
110
+ "history": history,
111
+ "id": id,
112
+ "name": name,
113
+ "key": key,
114
+ "status": status,
115
+ "rankBy": rank_by,
116
+ "metricKey": metric_key,
117
+ "metricName": metric_name,
118
+ "pointsSystemKey": points_system_key,
119
+ "pointsSystemName": points_system_name,
120
+ "description": description,
121
+ "start": start,
122
+ "end": end_,
123
+ "maxParticipants": max_participants,
124
+ "runUnit": run_unit,
125
+ "runInterval": run_interval
126
+ }.reject do |_k, v|
127
+ v == OMIT
128
+ end
129
+ end
130
+
131
+ # Deserialize a JSON object to an instance of UserLeaderboardResponse
132
+ #
133
+ # @param json_object [String]
134
+ # @return [TrophyApiClient::UserLeaderboardResponse]
135
+ def self.from_json(json_object:)
136
+ struct = JSON.parse(json_object, object_class: OpenStruct)
137
+ parsed_json = JSON.parse(json_object)
138
+ rank = parsed_json["rank"]
139
+ value = parsed_json["value"]
140
+ history = parsed_json["history"]&.map do |item|
141
+ item = item.to_json
142
+ TrophyApiClient::LeaderboardEvent.from_json(json_object: item)
143
+ end
144
+ id = parsed_json["id"]
145
+ name = parsed_json["name"]
146
+ key = parsed_json["key"]
147
+ status = parsed_json["status"]
148
+ rank_by = parsed_json["rankBy"]
149
+ metric_key = parsed_json["metricKey"]
150
+ metric_name = parsed_json["metricName"]
151
+ points_system_key = parsed_json["pointsSystemKey"]
152
+ points_system_name = parsed_json["pointsSystemName"]
153
+ description = parsed_json["description"]
154
+ start = parsed_json["start"]
155
+ end_ = parsed_json["end"]
156
+ max_participants = parsed_json["maxParticipants"]
157
+ run_unit = parsed_json["runUnit"]
158
+ run_interval = parsed_json["runInterval"]
159
+ new(
160
+ rank: rank,
161
+ value: value,
162
+ history: history,
163
+ id: id,
164
+ name: name,
165
+ key: key,
166
+ status: status,
167
+ rank_by: rank_by,
168
+ metric_key: metric_key,
169
+ metric_name: metric_name,
170
+ points_system_key: points_system_key,
171
+ points_system_name: points_system_name,
172
+ description: description,
173
+ start: start,
174
+ end_: end_,
175
+ max_participants: max_participants,
176
+ run_unit: run_unit,
177
+ run_interval: run_interval,
178
+ additional_properties: struct
179
+ )
180
+ end
181
+
182
+ # Serialize an instance of UserLeaderboardResponse to a JSON object
183
+ #
184
+ # @return [String]
185
+ def to_json(*_args)
186
+ @_field_set&.to_json
187
+ end
188
+
189
+ # Leveraged for Union-type generation, validate_raw attempts to parse the given
190
+ # hash and check each fields type against the current object's property
191
+ # definitions.
192
+ #
193
+ # @param obj [Object]
194
+ # @return [Void]
195
+ def self.validate_raw(obj:)
196
+ obj.rank&.is_a?(Integer) != false || raise("Passed value for field obj.rank is not the expected type, validation failed.")
197
+ obj.value&.is_a?(Integer) != false || raise("Passed value for field obj.value is not the expected type, validation failed.")
198
+ obj.history.is_a?(Array) != false || raise("Passed value for field obj.history is not the expected type, validation failed.")
199
+ obj.id.is_a?(String) != false || raise("Passed value for field obj.id is not the expected type, validation failed.")
200
+ obj.name.is_a?(String) != false || raise("Passed value for field obj.name is not the expected type, validation failed.")
201
+ obj.key.is_a?(String) != false || raise("Passed value for field obj.key is not the expected type, validation failed.")
202
+ obj.status&.is_a?(TrophyApiClient::LeaderboardResponseStatus) != false || raise("Passed value for field obj.status is not the expected type, validation failed.")
203
+ obj.rank_by.is_a?(TrophyApiClient::LeaderboardResponseRankBy) != false || raise("Passed value for field obj.rank_by is not the expected type, validation failed.")
204
+ obj.metric_key&.is_a?(String) != false || raise("Passed value for field obj.metric_key is not the expected type, validation failed.")
205
+ obj.metric_name&.is_a?(String) != false || raise("Passed value for field obj.metric_name is not the expected type, validation failed.")
206
+ obj.points_system_key&.is_a?(String) != false || raise("Passed value for field obj.points_system_key is not the expected type, validation failed.")
207
+ obj.points_system_name&.is_a?(String) != false || raise("Passed value for field obj.points_system_name is not the expected type, validation failed.")
208
+ obj.description&.is_a?(String) != false || raise("Passed value for field obj.description is not the expected type, validation failed.")
209
+ obj.start.is_a?(String) != false || raise("Passed value for field obj.start is not the expected type, validation failed.")
210
+ obj.end_&.is_a?(String) != false || raise("Passed value for field obj.end_ is not the expected type, validation failed.")
211
+ obj.max_participants.is_a?(Integer) != false || raise("Passed value for field obj.max_participants is not the expected type, validation failed.")
212
+ obj.run_unit&.is_a?(String) != false || raise("Passed value for field obj.run_unit is not the expected type, validation failed.")
213
+ obj.run_interval.is_a?(Integer) != false || raise("Passed value for field obj.run_interval is not the expected type, validation failed.")
214
+ end
215
+ end
216
+ end
@@ -1,3 +1,3 @@
1
1
  module MyGem
2
- VERSION = "1.0.23"
2
+ VERSION = "1.0.24"
3
3
  end
@@ -8,6 +8,7 @@ require_relative "trophy_api_client/metrics/client"
8
8
  require_relative "trophy_api_client/users/client"
9
9
  require_relative "trophy_api_client/streaks/client"
10
10
  require_relative "trophy_api_client/points/client"
11
+ require_relative "trophy_api_client/leaderboards/client"
11
12
 
12
13
  module TrophyApiClient
13
14
  class Client
@@ -21,6 +22,8 @@ module TrophyApiClient
21
22
  attr_reader :streaks
22
23
  # @return [TrophyApiClient::PointsClient]
23
24
  attr_reader :points
25
+ # @return [TrophyApiClient::LeaderboardsClient]
26
+ attr_reader :leaderboards
24
27
 
25
28
  # @param base_url [String]
26
29
  # @param environment [TrophyApiClient::Environment]
@@ -42,6 +45,7 @@ module TrophyApiClient
42
45
  @users = TrophyApiClient::UsersClient.new(request_client: @request_client)
43
46
  @streaks = TrophyApiClient::StreaksClient.new(request_client: @request_client)
44
47
  @points = TrophyApiClient::PointsClient.new(request_client: @request_client)
48
+ @leaderboards = TrophyApiClient::LeaderboardsClient.new(request_client: @request_client)
45
49
  end
46
50
  end
47
51
 
@@ -56,6 +60,8 @@ module TrophyApiClient
56
60
  attr_reader :streaks
57
61
  # @return [TrophyApiClient::AsyncPointsClient]
58
62
  attr_reader :points
63
+ # @return [TrophyApiClient::AsyncLeaderboardsClient]
64
+ attr_reader :leaderboards
59
65
 
60
66
  # @param base_url [String]
61
67
  # @param environment [TrophyApiClient::Environment]
@@ -77,6 +83,7 @@ module TrophyApiClient
77
83
  @users = TrophyApiClient::AsyncUsersClient.new(request_client: @async_request_client)
78
84
  @streaks = TrophyApiClient::AsyncStreaksClient.new(request_client: @async_request_client)
79
85
  @points = TrophyApiClient::AsyncPointsClient.new(request_client: @async_request_client)
86
+ @leaderboards = TrophyApiClient::AsyncLeaderboardsClient.new(request_client: @async_request_client)
80
87
  end
81
88
  end
82
89
  end
data/lib/types_export.rb CHANGED
@@ -17,7 +17,12 @@ require_relative "trophy_api_client/types/points_trigger_type"
17
17
  require_relative "trophy_api_client/types/points_trigger"
18
18
  require_relative "trophy_api_client/types/points_award"
19
19
  require_relative "trophy_api_client/types/get_user_points_response"
20
+ require_relative "trophy_api_client/types/leaderboard_response_status"
21
+ require_relative "trophy_api_client/types/leaderboard_response_rank_by"
22
+ require_relative "trophy_api_client/types/leaderboard_response"
23
+ require_relative "trophy_api_client/types/leaderboard_response_with_rankings"
20
24
  require_relative "trophy_api_client/types/metric_event_points_response"
25
+ require_relative "trophy_api_client/types/metric_event_leaderboard_response"
21
26
  require_relative "trophy_api_client/types/achievement_response_trigger"
22
27
  require_relative "trophy_api_client/types/achievement_response"
23
28
  require_relative "trophy_api_client/types/completed_achievement_response"
@@ -40,3 +45,6 @@ require_relative "trophy_api_client/types/points_trigger_response_event_attribut
40
45
  require_relative "trophy_api_client/types/points_trigger_response"
41
46
  require_relative "trophy_api_client/types/points_system_response"
42
47
  require_relative "trophy_api_client/types/streak_ranking_user"
48
+ require_relative "trophy_api_client/types/leaderboard_ranking"
49
+ require_relative "trophy_api_client/types/leaderboard_event"
50
+ require_relative "trophy_api_client/types/user_leaderboard_response"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trophy_api_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.23
4
+ version: 1.0.24
5
5
  platform: ruby
6
6
  authors:
7
7
  - Trophy Labs, Inc
@@ -100,6 +100,7 @@ files:
100
100
  - lib/requests.rb
101
101
  - lib/trophy_api_client.rb
102
102
  - lib/trophy_api_client/achievements/client.rb
103
+ - lib/trophy_api_client/leaderboards/client.rb
103
104
  - lib/trophy_api_client/metrics/client.rb
104
105
  - lib/trophy_api_client/points/client.rb
105
106
  - lib/trophy_api_client/streaks/client.rb
@@ -117,6 +118,13 @@ files:
117
118
  - lib/trophy_api_client/types/error_body.rb
118
119
  - lib/trophy_api_client/types/event_response.rb
119
120
  - lib/trophy_api_client/types/get_user_points_response.rb
121
+ - lib/trophy_api_client/types/leaderboard_event.rb
122
+ - lib/trophy_api_client/types/leaderboard_ranking.rb
123
+ - lib/trophy_api_client/types/leaderboard_response.rb
124
+ - lib/trophy_api_client/types/leaderboard_response_rank_by.rb
125
+ - lib/trophy_api_client/types/leaderboard_response_status.rb
126
+ - lib/trophy_api_client/types/leaderboard_response_with_rankings.rb
127
+ - lib/trophy_api_client/types/metric_event_leaderboard_response.rb
120
128
  - lib/trophy_api_client/types/metric_event_points_response.rb
121
129
  - lib/trophy_api_client/types/metric_event_streak_response.rb
122
130
  - lib/trophy_api_client/types/metric_response.rb
@@ -139,6 +147,7 @@ files:
139
147
  - lib/trophy_api_client/types/updated_user.rb
140
148
  - lib/trophy_api_client/types/upserted_user.rb
141
149
  - lib/trophy_api_client/types/user.rb
150
+ - lib/trophy_api_client/types/user_leaderboard_response.rb
142
151
  - lib/trophy_api_client/users/client.rb
143
152
  - lib/trophy_api_client/users/types/users_metric_event_summary_request_aggregation.rb
144
153
  - lib/trophy_api_client/users/types/users_metric_event_summary_response_item.rb