Skip to content

Commit 5c39ac7

Browse files
Automatically update Ruby SDK
1 parent 631e258 commit 5c39ac7

52 files changed

Lines changed: 2047 additions & 314 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,6 @@ build-iPhoneSimulator/
5454

5555
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
5656
# .rubocop-https?--*
57+
58+
# OSX
59+
.DS_Store

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.29"
5+
VERSION = "1.0.30"
66
AUTHORS = ["Trophy Labs, Inc"].freeze
77
EMAIL = ""
88
SUMMARY = "Ruby library for the Trophy API."

lib/trophy_api_client/achievements/client.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def all(request_options: nil)
7272
# environment: TrophyApiClient::Environment::PRODUCTION,
7373
# api_key: "YOUR_API_KEY"
7474
# )
75-
# api.achievements.complete(key: "finish-onboarding", user: { email: "user@example.com", tz: "Europe/London", id: "user-id" })
75+
# api.achievements.complete(key: "finish-onboarding", user: { email: "user@example.com", name: "User", tz: "Europe/London", device_tokens: ["token1", "token2"], subscribe_to_emails: true, attributes: { "department": "engineering", "role": "developer" }, id: "user-id" })
7676
def complete(key:, user:, request_options: nil)
7777
response = @request_client.conn.post do |req|
7878
req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
@@ -159,7 +159,7 @@ def all(request_options: nil)
159159
# environment: TrophyApiClient::Environment::PRODUCTION,
160160
# api_key: "YOUR_API_KEY"
161161
# )
162-
# api.achievements.complete(key: "finish-onboarding", user: { email: "user@example.com", tz: "Europe/London", id: "user-id" })
162+
# api.achievements.complete(key: "finish-onboarding", user: { email: "user@example.com", name: "User", tz: "Europe/London", device_tokens: ["token1", "token2"], subscribe_to_emails: true, attributes: { "department": "engineering", "role": "developer" }, id: "user-id" })
163163
def complete(key:, user:, request_options: nil)
164164
Async do
165165
response = @request_client.conn.post do |req|

lib/trophy_api_client/leaderboards/client.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
require_relative "../../requests"
4-
require_relative "../types/leaderboard_response"
4+
require_relative "types/leaderboards_all_response_item"
55
require "json"
66
require_relative "../types/leaderboard_response_with_rankings"
77
require "async"
@@ -20,7 +20,7 @@ def initialize(request_client:)
2020
# Get all active leaderboards for your organization.
2121
#
2222
# @param request_options [TrophyApiClient::RequestOptions]
23-
# @return [Array<TrophyApiClient::LeaderboardResponse>]
23+
# @return [Array<TrophyApiClient::Leaderboards::LeaderboardsAllResponseItem>]
2424
# @example
2525
# api = TrophyApiClient::Client.new(
2626
# base_url: "https://api.example.com",
@@ -48,7 +48,7 @@ def all(request_options: nil)
4848
parsed_json = JSON.parse(response.body)
4949
parsed_json&.map do |item|
5050
item = item.to_json
51-
TrophyApiClient::LeaderboardResponse.from_json(json_object: item)
51+
TrophyApiClient::Leaderboards::LeaderboardsAllResponseItem.from_json(json_object: item)
5252
end
5353
end
5454

@@ -71,6 +71,8 @@ def all(request_options: nil)
7171
# )
7272
# api.leaderboards.get(
7373
# key: "weekly-words",
74+
# offset: 1,
75+
# limit: 1,
7476
# run: "2025-01-15",
7577
# user_id: "user-123"
7678
# )
@@ -112,7 +114,7 @@ def initialize(request_client:)
112114
# Get all active leaderboards for your organization.
113115
#
114116
# @param request_options [TrophyApiClient::RequestOptions]
115-
# @return [Array<TrophyApiClient::LeaderboardResponse>]
117+
# @return [Array<TrophyApiClient::Leaderboards::LeaderboardsAllResponseItem>]
116118
# @example
117119
# api = TrophyApiClient::Client.new(
118120
# base_url: "https://api.example.com",
@@ -141,7 +143,7 @@ def all(request_options: nil)
141143
parsed_json = JSON.parse(response.body)
142144
parsed_json&.map do |item|
143145
item = item.to_json
144-
TrophyApiClient::LeaderboardResponse.from_json(json_object: item)
146+
TrophyApiClient::Leaderboards::LeaderboardsAllResponseItem.from_json(json_object: item)
145147
end
146148
end
147149
end
@@ -165,6 +167,8 @@ def all(request_options: nil)
165167
# )
166168
# api.leaderboards.get(
167169
# key: "weekly-words",
170+
# offset: 1,
171+
# limit: 1,
168172
# run: "2025-01-15",
169173
# user_id: "user-123"
170174
# )
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
# frozen_string_literal: true
2+
3+
require_relative "leaderboards_all_response_item_status"
4+
require_relative "../../types/leaderboard_response_rank_by"
5+
require_relative "../../types/leaderboard_response_run_unit"
6+
require "ostruct"
7+
require "json"
8+
9+
module TrophyApiClient
10+
class Leaderboards
11+
class LeaderboardsAllResponseItem
12+
# @return [TrophyApiClient::Leaderboards::LeaderboardsAllResponseItemStatus] The status of the leaderboard.
13+
attr_reader :status
14+
# @return [String] The unique ID of the leaderboard.
15+
attr_reader :id
16+
# @return [String] The user-facing name of the leaderboard.
17+
attr_reader :name
18+
# @return [String] The unique key used to reference the leaderboard in APIs.
19+
attr_reader :key
20+
# @return [TrophyApiClient::LeaderboardResponseRankBy] What the leaderboard ranks by.
21+
attr_reader :rank_by
22+
# @return [String] The key of the metric to rank by, if rankBy is 'metric'.
23+
attr_reader :metric_key
24+
# @return [String] The name of the metric to rank by, if rankBy is 'metric'.
25+
attr_reader :metric_name
26+
# @return [String] The key of the points system to rank by, if rankBy is 'points'.
27+
attr_reader :points_system_key
28+
# @return [String] The name of the points system to rank by, if rankBy is 'points'.
29+
attr_reader :points_system_name
30+
# @return [String] The user-facing description of the leaderboard.
31+
attr_reader :description
32+
# @return [String] The start date of the leaderboard in YYYY-MM-DD format.
33+
attr_reader :start
34+
# @return [String] The end date of the leaderboard in YYYY-MM-DD format, or null if it runs
35+
# forever.
36+
attr_reader :end_
37+
# @return [Integer] The maximum number of participants in the leaderboard.
38+
attr_reader :max_participants
39+
# @return [TrophyApiClient::LeaderboardResponseRunUnit] The repetition type for recurring leaderboards, or null for one-time
40+
# leaderboards.
41+
attr_reader :run_unit
42+
# @return [Integer] The interval between repetitions, relative to the start date and repetition
43+
# type.
44+
attr_reader :run_interval
45+
# @return [OpenStruct] Additional properties unmapped to the current class definition
46+
attr_reader :additional_properties
47+
# @return [Object]
48+
attr_reader :_field_set
49+
protected :_field_set
50+
51+
OMIT = Object.new
52+
53+
# @param status [TrophyApiClient::Leaderboards::LeaderboardsAllResponseItemStatus] The status of the leaderboard.
54+
# @param id [String] The unique ID of the leaderboard.
55+
# @param name [String] The user-facing name of the leaderboard.
56+
# @param key [String] The unique key used to reference the leaderboard in APIs.
57+
# @param rank_by [TrophyApiClient::LeaderboardResponseRankBy] What the leaderboard ranks by.
58+
# @param metric_key [String] The key of the metric to rank by, if rankBy is 'metric'.
59+
# @param metric_name [String] The name of the metric to rank by, if rankBy is 'metric'.
60+
# @param points_system_key [String] The key of the points system to rank by, if rankBy is 'points'.
61+
# @param points_system_name [String] The name of the points system to rank by, if rankBy is 'points'.
62+
# @param description [String] The user-facing description of the leaderboard.
63+
# @param start [String] The start date of the leaderboard in YYYY-MM-DD format.
64+
# @param end_ [String] The end date of the leaderboard in YYYY-MM-DD format, or null if it runs
65+
# forever.
66+
# @param max_participants [Integer] The maximum number of participants in the leaderboard.
67+
# @param run_unit [TrophyApiClient::LeaderboardResponseRunUnit] The repetition type for recurring leaderboards, or null for one-time
68+
# leaderboards.
69+
# @param run_interval [Integer] The interval between repetitions, relative to the start date and repetition
70+
# type.
71+
# @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
72+
# @return [TrophyApiClient::Leaderboards::LeaderboardsAllResponseItem]
73+
def initialize(status:, id:, name:, key:, rank_by:, description:, start:, max_participants:, run_interval:, metric_key: OMIT, metric_name: OMIT, points_system_key: OMIT,
74+
points_system_name: OMIT, end_: OMIT, run_unit: OMIT, additional_properties: nil)
75+
@status = status
76+
@id = id
77+
@name = name
78+
@key = key
79+
@rank_by = rank_by
80+
@metric_key = metric_key if metric_key != OMIT
81+
@metric_name = metric_name if metric_name != OMIT
82+
@points_system_key = points_system_key if points_system_key != OMIT
83+
@points_system_name = points_system_name if points_system_name != OMIT
84+
@description = description
85+
@start = start
86+
@end_ = end_ if end_ != OMIT
87+
@max_participants = max_participants
88+
@run_unit = run_unit if run_unit != OMIT
89+
@run_interval = run_interval
90+
@additional_properties = additional_properties
91+
@_field_set = {
92+
"status": status,
93+
"id": id,
94+
"name": name,
95+
"key": key,
96+
"rankBy": rank_by,
97+
"metricKey": metric_key,
98+
"metricName": metric_name,
99+
"pointsSystemKey": points_system_key,
100+
"pointsSystemName": points_system_name,
101+
"description": description,
102+
"start": start,
103+
"end": end_,
104+
"maxParticipants": max_participants,
105+
"runUnit": run_unit,
106+
"runInterval": run_interval
107+
}.reject do |_k, v|
108+
v == OMIT
109+
end
110+
end
111+
112+
# Deserialize a JSON object to an instance of LeaderboardsAllResponseItem
113+
#
114+
# @param json_object [String]
115+
# @return [TrophyApiClient::Leaderboards::LeaderboardsAllResponseItem]
116+
def self.from_json(json_object:)
117+
struct = JSON.parse(json_object, object_class: OpenStruct)
118+
parsed_json = JSON.parse(json_object)
119+
status = parsed_json["status"]
120+
id = parsed_json["id"]
121+
name = parsed_json["name"]
122+
key = parsed_json["key"]
123+
rank_by = parsed_json["rankBy"]
124+
metric_key = parsed_json["metricKey"]
125+
metric_name = parsed_json["metricName"]
126+
points_system_key = parsed_json["pointsSystemKey"]
127+
points_system_name = parsed_json["pointsSystemName"]
128+
description = parsed_json["description"]
129+
start = parsed_json["start"]
130+
end_ = parsed_json["end"]
131+
max_participants = parsed_json["maxParticipants"]
132+
run_unit = parsed_json["runUnit"]
133+
run_interval = parsed_json["runInterval"]
134+
new(
135+
status: status,
136+
id: id,
137+
name: name,
138+
key: key,
139+
rank_by: rank_by,
140+
metric_key: metric_key,
141+
metric_name: metric_name,
142+
points_system_key: points_system_key,
143+
points_system_name: points_system_name,
144+
description: description,
145+
start: start,
146+
end_: end_,
147+
max_participants: max_participants,
148+
run_unit: run_unit,
149+
run_interval: run_interval,
150+
additional_properties: struct
151+
)
152+
end
153+
154+
# Serialize an instance of LeaderboardsAllResponseItem to a JSON object
155+
#
156+
# @return [String]
157+
def to_json(*_args)
158+
@_field_set&.to_json
159+
end
160+
161+
# Leveraged for Union-type generation, validate_raw attempts to parse the given
162+
# hash and check each fields type against the current object's property
163+
# definitions.
164+
#
165+
# @param obj [Object]
166+
# @return [Void]
167+
def self.validate_raw(obj:)
168+
obj.status.is_a?(TrophyApiClient::Leaderboards::LeaderboardsAllResponseItemStatus) != false || raise("Passed value for field obj.status is not the expected type, validation failed.")
169+
obj.id.is_a?(String) != false || raise("Passed value for field obj.id is not the expected type, validation failed.")
170+
obj.name.is_a?(String) != false || raise("Passed value for field obj.name is not the expected type, validation failed.")
171+
obj.key.is_a?(String) != false || raise("Passed value for field obj.key is not the expected type, validation failed.")
172+
obj.rank_by.is_a?(TrophyApiClient::LeaderboardResponseRankBy) != false || raise("Passed value for field obj.rank_by is not the expected type, validation failed.")
173+
obj.metric_key&.is_a?(String) != false || raise("Passed value for field obj.metric_key is not the expected type, validation failed.")
174+
obj.metric_name&.is_a?(String) != false || raise("Passed value for field obj.metric_name is not the expected type, validation failed.")
175+
obj.points_system_key&.is_a?(String) != false || raise("Passed value for field obj.points_system_key is not the expected type, validation failed.")
176+
obj.points_system_name&.is_a?(String) != false || raise("Passed value for field obj.points_system_name is not the expected type, validation failed.")
177+
obj.description.is_a?(String) != false || raise("Passed value for field obj.description is not the expected type, validation failed.")
178+
obj.start.is_a?(String) != false || raise("Passed value for field obj.start is not the expected type, validation failed.")
179+
obj.end_&.is_a?(String) != false || raise("Passed value for field obj.end_ is not the expected type, validation failed.")
180+
obj.max_participants.is_a?(Integer) != false || raise("Passed value for field obj.max_participants is not the expected type, validation failed.")
181+
obj.run_unit&.is_a?(TrophyApiClient::LeaderboardResponseRunUnit) != false || raise("Passed value for field obj.run_unit is not the expected type, validation failed.")
182+
obj.run_interval.is_a?(Integer) != false || raise("Passed value for field obj.run_interval is not the expected type, validation failed.")
183+
end
184+
end
185+
end
186+
end
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# frozen_string_literal: true
2+
3+
module TrophyApiClient
4+
class Leaderboards
5+
# The status of the leaderboard.
6+
class LeaderboardsAllResponseItemStatus
7+
ACTIVE = "active"
8+
SCHEDULED = "scheduled"
9+
FINISHED = "finished"
10+
end
11+
end
12+
end

lib/trophy_api_client/metrics/client.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def initialize(request_client:)
4242
# api.metrics.event(
4343
# idempotency_key: "e4296e4b-8493-4bd1-9c30-5a1a9ac4d78f",
4444
# key: "words-written",
45-
# user: { email: "user@example.com", tz: "Europe/London", attributes: { "department": "engineering", "role": "developer" }, id: "18" },
45+
# user: { email: "user@example.com", name: "User", tz: "Europe/London", device_tokens: ["token1", "token2"], subscribe_to_emails: true, attributes: { "department": "engineering", "role": "developer" }, id: "18" },
4646
# value: 750,
4747
# attributes: { "category": "writing", "source": "mobile-app" }
4848
# )
@@ -107,7 +107,7 @@ def initialize(request_client:)
107107
# api.metrics.event(
108108
# idempotency_key: "e4296e4b-8493-4bd1-9c30-5a1a9ac4d78f",
109109
# key: "words-written",
110-
# user: { email: "user@example.com", tz: "Europe/London", attributes: { "department": "engineering", "role": "developer" }, id: "18" },
110+
# user: { email: "user@example.com", name: "User", tz: "Europe/London", device_tokens: ["token1", "token2"], subscribe_to_emails: true, attributes: { "department": "engineering", "role": "developer" }, id: "18" },
111111
# value: 750,
112112
# attributes: { "category": "writing", "source": "mobile-app" }
113113
# )

lib/trophy_api_client/streaks/client.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def list(user_ids: nil, request_options: nil)
6565
# environment: TrophyApiClient::Environment::PRODUCTION,
6666
# api_key: "YOUR_API_KEY"
6767
# )
68-
# api.streaks.rankings
68+
# api.streaks.rankings(limit: 1, type: ACTIVE)
6969
def rankings(limit: nil, type: nil, request_options: nil)
7070
response = @request_client.conn.get do |req|
7171
req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
@@ -148,7 +148,7 @@ def list(user_ids: nil, request_options: nil)
148148
# environment: TrophyApiClient::Environment::PRODUCTION,
149149
# api_key: "YOUR_API_KEY"
150150
# )
151-
# api.streaks.rankings
151+
# api.streaks.rankings(limit: 1, type: ACTIVE)
152152
def rankings(limit: nil, type: nil, request_options: nil)
153153
Async do
154154
response = @request_client.conn.get do |req|

lib/trophy_api_client/types/achievement_completion_response.rb

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# frozen_string_literal: true
22

3-
require_relative "completed_achievement_response"
3+
require_relative "achievement_completion_response_achievement"
44
require "ostruct"
55
require "json"
66

77
module TrophyApiClient
88
class AchievementCompletionResponse
99
# @return [String] The unique ID of the completion.
1010
attr_reader :completion_id
11-
# @return [TrophyApiClient::CompletedAchievementResponse]
11+
# @return [TrophyApiClient::AchievementCompletionResponseAchievement]
1212
attr_reader :achievement
1313
# @return [Hash{String => TrophyApiClient::MetricEventPointsResponse}] A map of points systems by key that were affected by this achievement
1414
# completion.
@@ -22,19 +22,17 @@ class AchievementCompletionResponse
2222
OMIT = Object.new
2323

2424
# @param completion_id [String] The unique ID of the completion.
25-
# @param achievement [TrophyApiClient::CompletedAchievementResponse]
25+
# @param achievement [TrophyApiClient::AchievementCompletionResponseAchievement]
2626
# @param points [Hash{String => TrophyApiClient::MetricEventPointsResponse}] A map of points systems by key that were affected by this achievement
2727
# completion.
2828
# @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
2929
# @return [TrophyApiClient::AchievementCompletionResponse]
30-
def initialize(completion_id:, achievement:, points: OMIT, additional_properties: nil)
30+
def initialize(completion_id:, achievement:, points:, additional_properties: nil)
3131
@completion_id = completion_id
3232
@achievement = achievement
33-
@points = points if points != OMIT
33+
@points = points
3434
@additional_properties = additional_properties
35-
@_field_set = { "completionId": completion_id, "achievement": achievement, "points": points }.reject do |_k, v|
36-
v == OMIT
37-
end
35+
@_field_set = { "completionId": completion_id, "achievement": achievement, "points": points }
3836
end
3937

4038
# Deserialize a JSON object to an instance of AchievementCompletionResponse
@@ -49,7 +47,7 @@ def self.from_json(json_object:)
4947
achievement = nil
5048
else
5149
achievement = parsed_json["achievement"].to_json
52-
achievement = TrophyApiClient::CompletedAchievementResponse.from_json(json_object: achievement)
50+
achievement = TrophyApiClient::AchievementCompletionResponseAchievement.from_json(json_object: achievement)
5351
end
5452
points = parsed_json["points"]&.transform_values do |value|
5553
value = value.to_json
@@ -78,8 +76,8 @@ def to_json(*_args)
7876
# @return [Void]
7977
def self.validate_raw(obj:)
8078
obj.completion_id.is_a?(String) != false || raise("Passed value for field obj.completion_id is not the expected type, validation failed.")
81-
TrophyApiClient::CompletedAchievementResponse.validate_raw(obj: obj.achievement)
82-
obj.points&.is_a?(Hash) != false || raise("Passed value for field obj.points is not the expected type, validation failed.")
79+
TrophyApiClient::AchievementCompletionResponseAchievement.validate_raw(obj: obj.achievement)
80+
obj.points.is_a?(Hash) != false || raise("Passed value for field obj.points is not the expected type, validation failed.")
8381
end
8482
end
8583
end

0 commit comments

Comments
 (0)