Skip to content

Commit a887117

Browse files
Automatically update Ruby SDK
1 parent f4795f5 commit a887117

20 files changed

+1512
-28
lines changed

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

lib/trophy_api_client/admin/client.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,24 @@
66
module TrophyApiClient
77
module Admin
88
class Client
9-
# @return [TrophyApiClient::Admin::Streaks::Client]
10-
attr_reader :admin
9+
# @return [TrophyApiClient::Admin::StreaksClient]
10+
attr_reader :streaks
1111

1212
# @param request_client [TrophyApiClient::RequestClient]
1313
# @return [TrophyApiClient::Admin::Client]
1414
def initialize(request_client:)
15-
@admin = TrophyApiClient::Admin::Streaks::Client.new(request_client: request_client)
15+
@streaks = TrophyApiClient::Admin::StreaksClient.new(request_client: request_client)
1616
end
1717
end
1818

1919
class AsyncClient
20-
# @return [TrophyApiClient::Admin::Streaks::AsyncClient]
21-
attr_reader :admin
20+
# @return [TrophyApiClient::Admin::AsyncStreaksClient]
21+
attr_reader :streaks
2222

2323
# @param request_client [TrophyApiClient::AsyncRequestClient]
2424
# @return [TrophyApiClient::Admin::AsyncClient]
2525
def initialize(request_client:)
26-
@admin = TrophyApiClient::Admin::Streaks::AsyncClient.new(request_client: request_client)
26+
@streaks = TrophyApiClient::Admin::AsyncStreaksClient.new(request_client: request_client)
2727
end
2828
end
2929
end

lib/trophy_api_client/admin/streaks/client.rb

Lines changed: 81 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,95 @@
11
# frozen_string_literal: true
22

33
require_relative "../../../requests"
4-
require_relative "freezes/client"
4+
require_relative "../../types/restore_streaks_response"
5+
require "async"
56

67
module TrophyApiClient
78
module Admin
8-
module Streaks
9-
class Client
10-
# @return [TrophyApiClient::Admin::Streaks::FreezesClient]
11-
attr_reader :freezes
9+
class StreaksClient
10+
# @return [TrophyApiClient::RequestClient]
11+
attr_reader :request_client
1212

13-
# @param request_client [TrophyApiClient::RequestClient]
14-
# @return [TrophyApiClient::Admin::Streaks::Client]
15-
def initialize(request_client:)
16-
@freezes = TrophyApiClient::Admin::Streaks::FreezesClient.new(request_client: request_client)
13+
# @param request_client [TrophyApiClient::RequestClient]
14+
# @return [TrophyApiClient::Admin::StreaksClient]
15+
def initialize(request_client:)
16+
@request_client = request_client
17+
end
18+
19+
# Restore streaks for multiple users to the maximum length in the last 90 days (in
20+
# the case of daily streaks), one year (in the case of weekly streaks), or two
21+
# years (in the case of monthly streaks).
22+
#
23+
# @param user_ids [Array<String>] Array of user IDs to restore streaks for. Maximum 100 users per request.
24+
# @param request_options [TrophyApiClient::RequestOptions]
25+
# @return [TrophyApiClient::RestoreStreaksResponse]
26+
# @example
27+
# api = TrophyApiClient::Client.new(
28+
# base_url: "https://api.example.com",
29+
# environment: TrophyApiClient::Environment::PRODUCTION,
30+
# api_key: "YOUR_API_KEY"
31+
# )
32+
# api.admin.streaks.restore(user_ids: ["user-123", "user-456"])
33+
def restore(user_ids:, request_options: nil)
34+
response = @request_client.conn.post do |req|
35+
req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
36+
req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
37+
req.headers = {
38+
**(req.headers || {}),
39+
**@request_client.get_headers,
40+
**(request_options&.additional_headers || {})
41+
}.compact
42+
unless request_options.nil? || request_options&.additional_query_parameters.nil?
43+
req.params = { **(request_options&.additional_query_parameters || {}) }.compact
44+
end
45+
req.body = { **(request_options&.additional_body_parameters || {}), userIds: user_ids }.compact
46+
req.url "#{@request_client.get_url(environment: admin, request_options: request_options)}/streaks/restore"
1747
end
48+
TrophyApiClient::RestoreStreaksResponse.from_json(json_object: response.body)
1849
end
50+
end
1951

20-
class AsyncClient
21-
# @return [TrophyApiClient::Admin::Streaks::AsyncFreezesClient]
22-
attr_reader :freezes
52+
class AsyncStreaksClient
53+
# @return [TrophyApiClient::AsyncRequestClient]
54+
attr_reader :request_client
55+
56+
# @param request_client [TrophyApiClient::AsyncRequestClient]
57+
# @return [TrophyApiClient::Admin::AsyncStreaksClient]
58+
def initialize(request_client:)
59+
@request_client = request_client
60+
end
2361

24-
# @param request_client [TrophyApiClient::AsyncRequestClient]
25-
# @return [TrophyApiClient::Admin::Streaks::AsyncClient]
26-
def initialize(request_client:)
27-
@freezes = TrophyApiClient::Admin::Streaks::AsyncFreezesClient.new(request_client: request_client)
62+
# Restore streaks for multiple users to the maximum length in the last 90 days (in
63+
# the case of daily streaks), one year (in the case of weekly streaks), or two
64+
# years (in the case of monthly streaks).
65+
#
66+
# @param user_ids [Array<String>] Array of user IDs to restore streaks for. Maximum 100 users per request.
67+
# @param request_options [TrophyApiClient::RequestOptions]
68+
# @return [TrophyApiClient::RestoreStreaksResponse]
69+
# @example
70+
# api = TrophyApiClient::Client.new(
71+
# base_url: "https://api.example.com",
72+
# environment: TrophyApiClient::Environment::PRODUCTION,
73+
# api_key: "YOUR_API_KEY"
74+
# )
75+
# api.admin.streaks.restore(user_ids: ["user-123", "user-456"])
76+
def restore(user_ids:, request_options: nil)
77+
Async do
78+
response = @request_client.conn.post 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+
unless request_options.nil? || request_options&.additional_query_parameters.nil?
87+
req.params = { **(request_options&.additional_query_parameters || {}) }.compact
88+
end
89+
req.body = { **(request_options&.additional_body_parameters || {}), userIds: user_ids }.compact
90+
req.url "#{@request_client.get_url(environment: admin, request_options: request_options)}/streaks/restore"
91+
end
92+
TrophyApiClient::RestoreStreaksResponse.from_json(json_object: response.body)
2893
end
2994
end
3095
end

lib/trophy_api_client/types/achievement_completion_response_achievement.rb

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
require_relative "metric_event_streak_response"
44
require "date"
5+
require_relative "achievement_with_stats_response_user_attributes_item"
6+
require_relative "achievement_with_stats_response_event_attribute"
57
require_relative "achievement_response_trigger"
68
require "ostruct"
79
require "json"
@@ -13,6 +15,16 @@ class AchievementCompletionResponseAchievement
1315
# @return [DateTime] The date and time the achievement was completed, in ISO 8601 format. Null if the
1416
# achievement has not been completed.
1517
attr_reader :achieved_at
18+
# @return [Integer] The number of users who have completed this achievement.
19+
attr_reader :completions
20+
# @return [Float] The percentage of all users who have completed this achievement.
21+
attr_reader :rarity
22+
# @return [Array<TrophyApiClient::AchievementWithStatsResponseUserAttributesItem>] User attribute filters that must be met for this achievement to be completed.
23+
# Only present if the achievement has user attribute filters configured.
24+
attr_reader :user_attributes
25+
# @return [TrophyApiClient::AchievementWithStatsResponseEventAttribute] Event attribute filter that must be met for this achievement to be completed.
26+
# Only present if the achievement has an event filter configured.
27+
attr_reader :event_attribute
1628
# @return [String] The unique ID of the achievement.
1729
attr_reader :id
1830
# @return [String] The name of this achievement.
@@ -49,6 +61,12 @@ class AchievementCompletionResponseAchievement
4961
# @param current_streak [TrophyApiClient::MetricEventStreakResponse] The user's current streak for the metric, if the metric has streaks enabled.
5062
# @param achieved_at [DateTime] The date and time the achievement was completed, in ISO 8601 format. Null if the
5163
# achievement has not been completed.
64+
# @param completions [Integer] The number of users who have completed this achievement.
65+
# @param rarity [Float] The percentage of all users who have completed this achievement.
66+
# @param user_attributes [Array<TrophyApiClient::AchievementWithStatsResponseUserAttributesItem>] User attribute filters that must be met for this achievement to be completed.
67+
# Only present if the achievement has user attribute filters configured.
68+
# @param event_attribute [TrophyApiClient::AchievementWithStatsResponseEventAttribute] Event attribute filter that must be met for this achievement to be completed.
69+
# Only present if the achievement has an event filter configured.
5270
# @param id [String] The unique ID of the achievement.
5371
# @param name [String] The name of this achievement.
5472
# @param trigger [TrophyApiClient::AchievementResponseTrigger] The trigger of the achievement.
@@ -66,10 +84,14 @@ class AchievementCompletionResponseAchievement
6684
# trigger = 'metric')
6785
# @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
6886
# @return [TrophyApiClient::AchievementCompletionResponseAchievement]
69-
def initialize(id:, name:, trigger:, key:, current_streak: OMIT, achieved_at: OMIT, description: OMIT,
70-
badge_url: OMIT, streak_length: OMIT, metric_id: OMIT, metric_value: OMIT, metric_name: OMIT, additional_properties: nil)
87+
def initialize(completions:, rarity:, id:, name:, trigger:, key:, current_streak: OMIT, achieved_at: OMIT, user_attributes: OMIT,
88+
event_attribute: OMIT, description: OMIT, badge_url: OMIT, streak_length: OMIT, metric_id: OMIT, metric_value: OMIT, metric_name: OMIT, additional_properties: nil)
7189
@current_streak = current_streak if current_streak != OMIT
7290
@achieved_at = achieved_at if achieved_at != OMIT
91+
@completions = completions
92+
@rarity = rarity
93+
@user_attributes = user_attributes if user_attributes != OMIT
94+
@event_attribute = event_attribute if event_attribute != OMIT
7395
@id = id
7496
@name = name
7597
@trigger = trigger
@@ -84,6 +106,10 @@ def initialize(id:, name:, trigger:, key:, current_streak: OMIT, achieved_at: OM
84106
@_field_set = {
85107
"currentStreak": current_streak,
86108
"achievedAt": achieved_at,
109+
"completions": completions,
110+
"rarity": rarity,
111+
"userAttributes": user_attributes,
112+
"eventAttribute": event_attribute,
87113
"id": id,
88114
"name": name,
89115
"trigger": trigger,
@@ -114,6 +140,18 @@ def self.from_json(json_object:)
114140
current_streak = TrophyApiClient::MetricEventStreakResponse.from_json(json_object: current_streak)
115141
end
116142
achieved_at = (DateTime.parse(parsed_json["achievedAt"]) unless parsed_json["achievedAt"].nil?)
143+
completions = parsed_json["completions"]
144+
rarity = parsed_json["rarity"]
145+
user_attributes = parsed_json["userAttributes"]&.map do |item|
146+
item = item.to_json
147+
TrophyApiClient::AchievementWithStatsResponseUserAttributesItem.from_json(json_object: item)
148+
end
149+
if parsed_json["eventAttribute"].nil?
150+
event_attribute = nil
151+
else
152+
event_attribute = parsed_json["eventAttribute"].to_json
153+
event_attribute = TrophyApiClient::AchievementWithStatsResponseEventAttribute.from_json(json_object: event_attribute)
154+
end
117155
id = parsed_json["id"]
118156
name = parsed_json["name"]
119157
trigger = parsed_json["trigger"]
@@ -127,6 +165,10 @@ def self.from_json(json_object:)
127165
new(
128166
current_streak: current_streak,
129167
achieved_at: achieved_at,
168+
completions: completions,
169+
rarity: rarity,
170+
user_attributes: user_attributes,
171+
event_attribute: event_attribute,
130172
id: id,
131173
name: name,
132174
trigger: trigger,
@@ -158,6 +200,10 @@ def to_json(*_args)
158200
def self.validate_raw(obj:)
159201
obj.current_streak.nil? || TrophyApiClient::MetricEventStreakResponse.validate_raw(obj: obj.current_streak)
160202
obj.achieved_at&.is_a?(DateTime) != false || raise("Passed value for field obj.achieved_at is not the expected type, validation failed.")
203+
obj.completions.is_a?(Integer) != false || raise("Passed value for field obj.completions is not the expected type, validation failed.")
204+
obj.rarity.is_a?(Float) != false || raise("Passed value for field obj.rarity is not the expected type, validation failed.")
205+
obj.user_attributes&.is_a?(Array) != false || raise("Passed value for field obj.user_attributes is not the expected type, validation failed.")
206+
obj.event_attribute.nil? || TrophyApiClient::AchievementWithStatsResponseEventAttribute.validate_raw(obj: obj.event_attribute)
161207
obj.id.is_a?(String) != false || raise("Passed value for field obj.id is not the expected type, validation failed.")
162208
obj.name.is_a?(String) != false || raise("Passed value for field obj.name is not the expected type, validation failed.")
163209
obj.trigger.is_a?(TrophyApiClient::AchievementResponseTrigger) != false || raise("Passed value for field obj.trigger is not the expected type, validation failed.")

0 commit comments

Comments
 (0)