Skip to content

Commit 45f0c32

Browse files
Automatically update Ruby SDK
1 parent a01dcd6 commit 45f0c32

14 files changed

Lines changed: 1318 additions & 7 deletions

lib/gemconfig.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
module TrophyApiClient
44
module Gemconfig
5-
VERSION = "1.0.23"
5+
VERSION = "1.0.24"
66
AUTHORS = ["Trophy Labs, Inc"].freeze
77
EMAIL = ""
88
SUMMARY = "Ruby library for the Trophy API."

lib/trophy_api_client.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
require_relative "trophy_api_client/users/client"
99
require_relative "trophy_api_client/streaks/client"
1010
require_relative "trophy_api_client/points/client"
11+
require_relative "trophy_api_client/leaderboards/client"
1112

1213
module TrophyApiClient
1314
class Client
@@ -21,6 +22,8 @@ class Client
2122
attr_reader :streaks
2223
# @return [TrophyApiClient::PointsClient]
2324
attr_reader :points
25+
# @return [TrophyApiClient::LeaderboardsClient]
26+
attr_reader :leaderboards
2427

2528
# @param base_url [String]
2629
# @param environment [TrophyApiClient::Environment]
@@ -42,6 +45,7 @@ def initialize(api_key:, base_url: nil, environment: TrophyApiClient::Environmen
4245
@users = TrophyApiClient::UsersClient.new(request_client: @request_client)
4346
@streaks = TrophyApiClient::StreaksClient.new(request_client: @request_client)
4447
@points = TrophyApiClient::PointsClient.new(request_client: @request_client)
48+
@leaderboards = TrophyApiClient::LeaderboardsClient.new(request_client: @request_client)
4549
end
4650
end
4751

@@ -56,6 +60,8 @@ class AsyncClient
5660
attr_reader :streaks
5761
# @return [TrophyApiClient::AsyncPointsClient]
5862
attr_reader :points
63+
# @return [TrophyApiClient::AsyncLeaderboardsClient]
64+
attr_reader :leaderboards
5965

6066
# @param base_url [String]
6167
# @param environment [TrophyApiClient::Environment]
@@ -77,6 +83,7 @@ def initialize(api_key:, base_url: nil, environment: TrophyApiClient::Environmen
7783
@users = TrophyApiClient::AsyncUsersClient.new(request_client: @async_request_client)
7884
@streaks = TrophyApiClient::AsyncStreaksClient.new(request_client: @async_request_client)
7985
@points = TrophyApiClient::AsyncPointsClient.new(request_client: @async_request_client)
86+
@leaderboards = TrophyApiClient::AsyncLeaderboardsClient.new(request_client: @async_request_client)
8087
end
8188
end
8289
end
Lines changed: 274 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

0 commit comments

Comments
 (0)