Skip to content

Commit c3fb1f9

Browse files
Automatically update Ruby SDK
1 parent 69d9248 commit c3fb1f9

8 files changed

Lines changed: 200 additions & 11 deletions

File tree

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.12.0"
5+
VERSION = "1.13.0"
66
AUTHORS = ["Trophy Labs, Inc"].freeze
77
EMAIL = ""
88
SUMMARY = "Ruby library for the Trophy API."
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# frozen_string_literal: true
2+
3+
module TrophyApiClient
4+
# Whether meeting any single metric threshold (`OR`) or all configured metric
5+
# thresholds (`AND`) extends the user's streak. Matches the evaluation mode
6+
# configured in dashboard streak settings.
7+
class StreakEvaluationModePreference
8+
OR = "OR"
9+
AND = "AND"
10+
end
11+
end
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# frozen_string_literal: true
2+
3+
require "ostruct"
4+
require "json"
5+
6+
module TrophyApiClient
7+
# Per-metric streak threshold override for a user.
8+
class StreakMetricPreference
9+
# @return [String] The metric key.
10+
attr_reader :key
11+
# @return [Float] Minimum metric change in a streak period to count toward the streak.
12+
attr_reader :threshold
13+
# @return [OpenStruct] Additional properties unmapped to the current class definition
14+
attr_reader :additional_properties
15+
# @return [Object]
16+
attr_reader :_field_set
17+
protected :_field_set
18+
19+
OMIT = Object.new
20+
21+
# @param key [String] The metric key.
22+
# @param threshold [Float] Minimum metric change in a streak period to count toward the streak.
23+
# @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
24+
# @return [TrophyApiClient::StreakMetricPreference]
25+
def initialize(key:, threshold:, additional_properties: nil)
26+
@key = key
27+
@threshold = threshold
28+
@additional_properties = additional_properties
29+
@_field_set = { "key": key, "threshold": threshold }
30+
end
31+
32+
# Deserialize a JSON object to an instance of StreakMetricPreference
33+
#
34+
# @param json_object [String]
35+
# @return [TrophyApiClient::StreakMetricPreference]
36+
def self.from_json(json_object:)
37+
struct = JSON.parse(json_object, object_class: OpenStruct)
38+
parsed_json = JSON.parse(json_object)
39+
key = parsed_json["key"]
40+
threshold = parsed_json["threshold"]
41+
new(
42+
key: key,
43+
threshold: threshold,
44+
additional_properties: struct
45+
)
46+
end
47+
48+
# Serialize an instance of StreakMetricPreference to a JSON object
49+
#
50+
# @return [String]
51+
def to_json(*_args)
52+
@_field_set&.to_json
53+
end
54+
55+
# Leveraged for Union-type generation, validate_raw attempts to parse the given
56+
# hash and check each fields type against the current object's property
57+
# definitions.
58+
#
59+
# @param obj [Object]
60+
# @return [Void]
61+
def self.validate_raw(obj:)
62+
obj.key.is_a?(String) != false || raise("Passed value for field obj.key is not the expected type, validation failed.")
63+
obj.threshold.is_a?(Float) != false || raise("Passed value for field obj.threshold is not the expected type, validation failed.")
64+
end
65+
end
66+
end
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# frozen_string_literal: true
2+
3+
require_relative "streak_evaluation_mode_preference"
4+
require_relative "streak_metric_preference"
5+
require "ostruct"
6+
require "json"
7+
8+
module TrophyApiClient
9+
# Per-user streak configuration. Requires streak customization to be enabled in
10+
# dashboard settings.
11+
class StreakPreferences
12+
# @return [TrophyApiClient::StreakEvaluationModePreference]
13+
attr_reader :evaluation_mode
14+
# @return [Array<TrophyApiClient::StreakMetricPreference>] Metrics and thresholds that count toward this user's streak.
15+
attr_reader :metrics
16+
# @return [OpenStruct] Additional properties unmapped to the current class definition
17+
attr_reader :additional_properties
18+
# @return [Object]
19+
attr_reader :_field_set
20+
protected :_field_set
21+
22+
OMIT = Object.new
23+
24+
# @param evaluation_mode [TrophyApiClient::StreakEvaluationModePreference]
25+
# @param metrics [Array<TrophyApiClient::StreakMetricPreference>] Metrics and thresholds that count toward this user's streak.
26+
# @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
27+
# @return [TrophyApiClient::StreakPreferences]
28+
def initialize(evaluation_mode: OMIT, metrics: OMIT, additional_properties: nil)
29+
@evaluation_mode = evaluation_mode if evaluation_mode != OMIT
30+
@metrics = metrics if metrics != OMIT
31+
@additional_properties = additional_properties
32+
@_field_set = { "evaluationMode": evaluation_mode, "metrics": metrics }.reject do |_k, v|
33+
v == OMIT
34+
end
35+
end
36+
37+
# Deserialize a JSON object to an instance of StreakPreferences
38+
#
39+
# @param json_object [String]
40+
# @return [TrophyApiClient::StreakPreferences]
41+
def self.from_json(json_object:)
42+
struct = JSON.parse(json_object, object_class: OpenStruct)
43+
parsed_json = JSON.parse(json_object)
44+
evaluation_mode = parsed_json["evaluationMode"]
45+
metrics = parsed_json["metrics"]&.map do |item|
46+
item = item.to_json
47+
TrophyApiClient::StreakMetricPreference.from_json(json_object: item)
48+
end
49+
new(
50+
evaluation_mode: evaluation_mode,
51+
metrics: metrics,
52+
additional_properties: struct
53+
)
54+
end
55+
56+
# Serialize an instance of StreakPreferences to a JSON object
57+
#
58+
# @return [String]
59+
def to_json(*_args)
60+
@_field_set&.to_json
61+
end
62+
63+
# Leveraged for Union-type generation, validate_raw attempts to parse the given
64+
# hash and check each fields type against the current object's property
65+
# definitions.
66+
#
67+
# @param obj [Object]
68+
# @return [Void]
69+
def self.validate_raw(obj:)
70+
obj.evaluation_mode&.is_a?(TrophyApiClient::StreakEvaluationModePreference) != false || raise("Passed value for field obj.evaluation_mode is not the expected type, validation failed.")
71+
obj.metrics&.is_a?(Array) != false || raise("Passed value for field obj.metrics is not the expected type, validation failed.")
72+
end
73+
end
74+
end

lib/trophy_api_client/types/user_preferences_response.rb

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

33
require_relative "notification_preferences"
4+
require_relative "streak_preferences"
45
require "ostruct"
56
require "json"
67

@@ -9,6 +10,8 @@ module TrophyApiClient
910
class UserPreferencesResponse
1011
# @return [TrophyApiClient::NotificationPreferences]
1112
attr_reader :notifications
13+
# @return [TrophyApiClient::StreakPreferences]
14+
attr_reader :streak
1215
# @return [OpenStruct] Additional properties unmapped to the current class definition
1316
attr_reader :additional_properties
1417
# @return [Object]
@@ -18,12 +21,16 @@ class UserPreferencesResponse
1821
OMIT = Object.new
1922

2023
# @param notifications [TrophyApiClient::NotificationPreferences]
24+
# @param streak [TrophyApiClient::StreakPreferences]
2125
# @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
2226
# @return [TrophyApiClient::UserPreferencesResponse]
23-
def initialize(notifications:, additional_properties: nil)
27+
def initialize(notifications:, streak: OMIT, additional_properties: nil)
2428
@notifications = notifications
29+
@streak = streak if streak != OMIT
2530
@additional_properties = additional_properties
26-
@_field_set = { "notifications": notifications }
31+
@_field_set = { "notifications": notifications, "streak": streak }.reject do |_k, v|
32+
v == OMIT
33+
end
2734
end
2835

2936
# Deserialize a JSON object to an instance of UserPreferencesResponse
@@ -39,7 +46,17 @@ def self.from_json(json_object:)
3946
notifications = parsed_json["notifications"].to_json
4047
notifications = TrophyApiClient::NotificationPreferences.from_json(json_object: notifications)
4148
end
42-
new(notifications: notifications, additional_properties: struct)
49+
if parsed_json["streak"].nil?
50+
streak = nil
51+
else
52+
streak = parsed_json["streak"].to_json
53+
streak = TrophyApiClient::StreakPreferences.from_json(json_object: streak)
54+
end
55+
new(
56+
notifications: notifications,
57+
streak: streak,
58+
additional_properties: struct
59+
)
4360
end
4461

4562
# Serialize an instance of UserPreferencesResponse to a JSON object
@@ -57,6 +74,7 @@ def to_json(*_args)
5774
# @return [Void]
5875
def self.validate_raw(obj:)
5976
TrophyApiClient::NotificationPreferences.validate_raw(obj: obj.notifications)
77+
obj.streak.nil? || TrophyApiClient::StreakPreferences.validate_raw(obj: obj.streak)
6078
end
6179
end
6280
end

lib/trophy_api_client/users/client.rb

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
require_relative "../types/updated_user"
77
require_relative "../types/user_preferences_response"
88
require_relative "../types/notification_preferences"
9+
require_relative "../types/streak_preferences"
910
require_relative "../types/metric_response"
1011
require "json"
1112
require_relative "types/users_metric_event_summary_request_aggregation"
@@ -211,14 +212,18 @@ def get_preferences(id:, request_options: nil)
211212
TrophyApiClient::UserPreferencesResponse.from_json(json_object: response.body)
212213
end
213214

214-
# Update a user's notification preferences.
215+
# Update a user's notification and streak preferences. Streak preferences require
216+
# streak customization to be enabled in your Trophy dashboard settings.
215217
#
216218
# @param id [String] The user's ID in your database.
217219
# @param notifications [Hash] Request of type TrophyApiClient::NotificationPreferences, as a Hash
218220
# * :achievement_completed (Array<TrophyApiClient::NotificationChannel>)
219221
# * :recap (Array<TrophyApiClient::NotificationChannel>)
220222
# * :reactivation (Array<TrophyApiClient::NotificationChannel>)
221223
# * :streak_reminder (Array<TrophyApiClient::NotificationChannel>)
224+
# @param streak [Hash] Request of type TrophyApiClient::StreakPreferences, as a Hash
225+
# * :evaluation_mode (TrophyApiClient::StreakEvaluationModePreference)
226+
# * :metrics (Array<TrophyApiClient::StreakMetricPreference>)
222227
# @param request_options [TrophyApiClient::RequestOptions]
223228
# @return [TrophyApiClient::UserPreferencesResponse]
224229
# @example
@@ -228,7 +233,7 @@ def get_preferences(id:, request_options: nil)
228233
# api_key: "YOUR_API_KEY"
229234
# )
230235
# api.users.update_preferences(id: "user-123", notifications: { streak_reminder: [EMAIL] })
231-
def update_preferences(id:, notifications: nil, request_options: nil)
236+
def update_preferences(id:, notifications: nil, streak: nil, request_options: nil)
232237
response = @request_client.conn.patch do |req|
233238
req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
234239
req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
@@ -241,7 +246,11 @@ def update_preferences(id:, notifications: nil, request_options: nil)
241246
unless request_options.nil? || request_options&.additional_query_parameters.nil?
242247
req.params = { **(request_options&.additional_query_parameters || {}) }.compact
243248
end
244-
req.body = { **(request_options&.additional_body_parameters || {}), notifications: notifications }.compact
249+
req.body = {
250+
**(request_options&.additional_body_parameters || {}),
251+
notifications: notifications,
252+
streak: streak
253+
}.compact
245254
req.url "#{@request_client.get_url(environment: api, request_options: request_options)}/users/#{id}/preferences"
246255
end
247256
TrophyApiClient::UserPreferencesResponse.from_json(json_object: response.body)
@@ -862,14 +871,18 @@ def get_preferences(id:, request_options: nil)
862871
end
863872
end
864873

865-
# Update a user's notification preferences.
874+
# Update a user's notification and streak preferences. Streak preferences require
875+
# streak customization to be enabled in your Trophy dashboard settings.
866876
#
867877
# @param id [String] The user's ID in your database.
868878
# @param notifications [Hash] Request of type TrophyApiClient::NotificationPreferences, as a Hash
869879
# * :achievement_completed (Array<TrophyApiClient::NotificationChannel>)
870880
# * :recap (Array<TrophyApiClient::NotificationChannel>)
871881
# * :reactivation (Array<TrophyApiClient::NotificationChannel>)
872882
# * :streak_reminder (Array<TrophyApiClient::NotificationChannel>)
883+
# @param streak [Hash] Request of type TrophyApiClient::StreakPreferences, as a Hash
884+
# * :evaluation_mode (TrophyApiClient::StreakEvaluationModePreference)
885+
# * :metrics (Array<TrophyApiClient::StreakMetricPreference>)
873886
# @param request_options [TrophyApiClient::RequestOptions]
874887
# @return [TrophyApiClient::UserPreferencesResponse]
875888
# @example
@@ -879,7 +892,7 @@ def get_preferences(id:, request_options: nil)
879892
# api_key: "YOUR_API_KEY"
880893
# )
881894
# api.users.update_preferences(id: "user-123", notifications: { streak_reminder: [EMAIL] })
882-
def update_preferences(id:, notifications: nil, request_options: nil)
895+
def update_preferences(id:, notifications: nil, streak: nil, request_options: nil)
883896
Async do
884897
response = @request_client.conn.patch do |req|
885898
req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
@@ -893,7 +906,11 @@ def update_preferences(id:, notifications: nil, request_options: nil)
893906
unless request_options.nil? || request_options&.additional_query_parameters.nil?
894907
req.params = { **(request_options&.additional_query_parameters || {}) }.compact
895908
end
896-
req.body = { **(request_options&.additional_body_parameters || {}), notifications: notifications }.compact
909+
req.body = {
910+
**(request_options&.additional_body_parameters || {}),
911+
notifications: notifications,
912+
streak: streak
913+
}.compact
897914
req.url "#{@request_client.get_url(environment: api,
898915
request_options: request_options)}/users/#{id}/preferences"
899916
end

lib/trophy_api_client/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module MyGem
2-
VERSION = "1.12.0"
2+
VERSION = "1.13.0"
33
end

lib/types_export.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@
7171
require_relative "trophy_api_client/types/user"
7272
require_relative "trophy_api_client/types/notification_channel"
7373
require_relative "trophy_api_client/types/notification_preferences"
74+
require_relative "trophy_api_client/types/streak_evaluation_mode_preference"
75+
require_relative "trophy_api_client/types/streak_metric_preference"
76+
require_relative "trophy_api_client/types/streak_preferences"
7477
require_relative "trophy_api_client/types/user_preferences_response"
7578
require_relative "trophy_api_client/types/error_body"
7679
require_relative "trophy_api_client/types/achievement_completion_response"

0 commit comments

Comments
 (0)