trophy_api_client 1.12.0 → 1.14.0
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.
- checksums.yaml +4 -4
- data/lib/gemconfig.rb +1 -1
- data/lib/trophy_api_client/types/streak_evaluation_mode_preference.rb +11 -0
- data/lib/trophy_api_client/types/streak_metric_preference.rb +66 -0
- data/lib/trophy_api_client/types/streak_preferences.rb +83 -0
- data/lib/trophy_api_client/types/user_preferences_response.rb +21 -3
- data/lib/trophy_api_client/users/client.rb +25 -6
- data/lib/trophy_api_client/version.rb +1 -1
- data/lib/types_export.rb +3 -0
- metadata +4 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 45068f7d5694f561b61d480fa8e8d89c556f9dfa860f75689cbcf4b4fa2098c3
|
|
4
|
+
data.tar.gz: a86937078e80ad934bcc256ea439cf3403b3ae583e3dbdd2cea5e73e72f5da64
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e8fac77c390e4bc53659399927abd76957c181addeec88f300098fc04fc4a84ac5a6e48284ab00fe05e160db003ef8c9e6efa2c15d10af1bc50327539f77c6cb
|
|
7
|
+
data.tar.gz: 98a01274b0a1003797a4f1bd0f202a8aaeccc2d675be465244749a607461bd888dd825d5734c90960d0f86507b6afc07eac04cba8ffcf5d1e6ffa2fad792e01d
|
data/lib/gemconfig.rb
CHANGED
|
@@ -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
|
|
@@ -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
|
|
@@ -0,0 +1,83 @@
|
|
|
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. Metric and evaluation mode overrides require
|
|
10
|
+
# streak customization to be enabled in dashboard settings.
|
|
11
|
+
class StreakPreferences
|
|
12
|
+
# @return [Boolean] Whether streaks are calculated for this user. When false, the user's streak is
|
|
13
|
+
# always 0 and streak webhooks and notifications are not sent.
|
|
14
|
+
attr_reader :enabled
|
|
15
|
+
# @return [TrophyApiClient::StreakEvaluationModePreference]
|
|
16
|
+
attr_reader :evaluation_mode
|
|
17
|
+
# @return [Array<TrophyApiClient::StreakMetricPreference>] Metrics and thresholds that count toward this user's streak.
|
|
18
|
+
attr_reader :metrics
|
|
19
|
+
# @return [OpenStruct] Additional properties unmapped to the current class definition
|
|
20
|
+
attr_reader :additional_properties
|
|
21
|
+
# @return [Object]
|
|
22
|
+
attr_reader :_field_set
|
|
23
|
+
protected :_field_set
|
|
24
|
+
|
|
25
|
+
OMIT = Object.new
|
|
26
|
+
|
|
27
|
+
# @param enabled [Boolean] Whether streaks are calculated for this user. When false, the user's streak is
|
|
28
|
+
# always 0 and streak webhooks and notifications are not sent.
|
|
29
|
+
# @param evaluation_mode [TrophyApiClient::StreakEvaluationModePreference]
|
|
30
|
+
# @param metrics [Array<TrophyApiClient::StreakMetricPreference>] Metrics and thresholds that count toward this user's streak.
|
|
31
|
+
# @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
|
|
32
|
+
# @return [TrophyApiClient::StreakPreferences]
|
|
33
|
+
def initialize(enabled: OMIT, evaluation_mode: OMIT, metrics: OMIT, additional_properties: nil)
|
|
34
|
+
@enabled = enabled if enabled != OMIT
|
|
35
|
+
@evaluation_mode = evaluation_mode if evaluation_mode != OMIT
|
|
36
|
+
@metrics = metrics if metrics != OMIT
|
|
37
|
+
@additional_properties = additional_properties
|
|
38
|
+
@_field_set = { "enabled": enabled, "evaluationMode": evaluation_mode, "metrics": metrics }.reject do |_k, v|
|
|
39
|
+
v == OMIT
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Deserialize a JSON object to an instance of StreakPreferences
|
|
44
|
+
#
|
|
45
|
+
# @param json_object [String]
|
|
46
|
+
# @return [TrophyApiClient::StreakPreferences]
|
|
47
|
+
def self.from_json(json_object:)
|
|
48
|
+
struct = JSON.parse(json_object, object_class: OpenStruct)
|
|
49
|
+
parsed_json = JSON.parse(json_object)
|
|
50
|
+
enabled = parsed_json["enabled"]
|
|
51
|
+
evaluation_mode = parsed_json["evaluationMode"]
|
|
52
|
+
metrics = parsed_json["metrics"]&.map do |item|
|
|
53
|
+
item = item.to_json
|
|
54
|
+
TrophyApiClient::StreakMetricPreference.from_json(json_object: item)
|
|
55
|
+
end
|
|
56
|
+
new(
|
|
57
|
+
enabled: enabled,
|
|
58
|
+
evaluation_mode: evaluation_mode,
|
|
59
|
+
metrics: metrics,
|
|
60
|
+
additional_properties: struct
|
|
61
|
+
)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# Serialize an instance of StreakPreferences to a JSON object
|
|
65
|
+
#
|
|
66
|
+
# @return [String]
|
|
67
|
+
def to_json(*_args)
|
|
68
|
+
@_field_set&.to_json
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# Leveraged for Union-type generation, validate_raw attempts to parse the given
|
|
72
|
+
# hash and check each fields type against the current object's property
|
|
73
|
+
# definitions.
|
|
74
|
+
#
|
|
75
|
+
# @param obj [Object]
|
|
76
|
+
# @return [Void]
|
|
77
|
+
def self.validate_raw(obj:)
|
|
78
|
+
obj.enabled&.is_a?(Boolean) != false || raise("Passed value for field obj.enabled is not the expected type, validation failed.")
|
|
79
|
+
obj.evaluation_mode&.is_a?(TrophyApiClient::StreakEvaluationModePreference) != false || raise("Passed value for field obj.evaluation_mode is not the expected type, validation failed.")
|
|
80
|
+
obj.metrics&.is_a?(Array) != false || raise("Passed value for field obj.metrics is not the expected type, validation failed.")
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require_relative "notification_preferences"
|
|
4
|
+
require_relative "streak_preferences"
|
|
4
5
|
require "ostruct"
|
|
5
6
|
require "json"
|
|
6
7
|
|
|
@@ -9,6 +10,8 @@ module TrophyApiClient
|
|
|
9
10
|
class UserPreferencesResponse
|
|
10
11
|
# @return [TrophyApiClient::NotificationPreferences]
|
|
11
12
|
attr_reader :notifications
|
|
13
|
+
# @return [TrophyApiClient::StreakPreferences]
|
|
14
|
+
attr_reader :streak
|
|
12
15
|
# @return [OpenStruct] Additional properties unmapped to the current class definition
|
|
13
16
|
attr_reader :additional_properties
|
|
14
17
|
# @return [Object]
|
|
@@ -18,12 +21,16 @@ module TrophyApiClient
|
|
|
18
21
|
OMIT = Object.new
|
|
19
22
|
|
|
20
23
|
# @param notifications [TrophyApiClient::NotificationPreferences]
|
|
24
|
+
# @param streak [TrophyApiClient::StreakPreferences]
|
|
21
25
|
# @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
|
|
22
26
|
# @return [TrophyApiClient::UserPreferencesResponse]
|
|
23
|
-
def initialize(notifications:, additional_properties: nil)
|
|
27
|
+
def initialize(notifications:, streak: OMIT, additional_properties: nil)
|
|
24
28
|
@notifications = notifications
|
|
29
|
+
@streak = streak if streak != OMIT
|
|
25
30
|
@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
|
|
27
34
|
end
|
|
28
35
|
|
|
29
36
|
# Deserialize a JSON object to an instance of UserPreferencesResponse
|
|
@@ -39,7 +46,17 @@ module TrophyApiClient
|
|
|
39
46
|
notifications = parsed_json["notifications"].to_json
|
|
40
47
|
notifications = TrophyApiClient::NotificationPreferences.from_json(json_object: notifications)
|
|
41
48
|
end
|
|
42
|
-
|
|
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
|
+
)
|
|
43
60
|
end
|
|
44
61
|
|
|
45
62
|
# Serialize an instance of UserPreferencesResponse to a JSON object
|
|
@@ -57,6 +74,7 @@ module TrophyApiClient
|
|
|
57
74
|
# @return [Void]
|
|
58
75
|
def self.validate_raw(obj:)
|
|
59
76
|
TrophyApiClient::NotificationPreferences.validate_raw(obj: obj.notifications)
|
|
77
|
+
obj.streak.nil? || TrophyApiClient::StreakPreferences.validate_raw(obj: obj.streak)
|
|
60
78
|
end
|
|
61
79
|
end
|
|
62
80
|
end
|
|
@@ -6,6 +6,7 @@ require_relative "../types/user"
|
|
|
6
6
|
require_relative "../types/updated_user"
|
|
7
7
|
require_relative "../types/user_preferences_response"
|
|
8
8
|
require_relative "../types/notification_preferences"
|
|
9
|
+
require_relative "../types/streak_preferences"
|
|
9
10
|
require_relative "../types/metric_response"
|
|
10
11
|
require "json"
|
|
11
12
|
require_relative "types/users_metric_event_summary_request_aggregation"
|
|
@@ -211,7 +212,8 @@ module TrophyApiClient
|
|
|
211
212
|
TrophyApiClient::UserPreferencesResponse.from_json(json_object: response.body)
|
|
212
213
|
end
|
|
213
214
|
|
|
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.
|
|
215
217
|
#
|
|
216
218
|
# @param id [String] The user's ID in your database.
|
|
217
219
|
# @param notifications [Hash] Request of type TrophyApiClient::NotificationPreferences, as a Hash
|
|
@@ -219,6 +221,10 @@ module TrophyApiClient
|
|
|
219
221
|
# * :recap (Array<TrophyApiClient::NotificationChannel>)
|
|
220
222
|
# * :reactivation (Array<TrophyApiClient::NotificationChannel>)
|
|
221
223
|
# * :streak_reminder (Array<TrophyApiClient::NotificationChannel>)
|
|
224
|
+
# @param streak [Hash] Request of type TrophyApiClient::StreakPreferences, as a Hash
|
|
225
|
+
# * :enabled (Boolean)
|
|
226
|
+
# * :evaluation_mode (TrophyApiClient::StreakEvaluationModePreference)
|
|
227
|
+
# * :metrics (Array<TrophyApiClient::StreakMetricPreference>)
|
|
222
228
|
# @param request_options [TrophyApiClient::RequestOptions]
|
|
223
229
|
# @return [TrophyApiClient::UserPreferencesResponse]
|
|
224
230
|
# @example
|
|
@@ -228,7 +234,7 @@ module TrophyApiClient
|
|
|
228
234
|
# api_key: "YOUR_API_KEY"
|
|
229
235
|
# )
|
|
230
236
|
# api.users.update_preferences(id: "user-123", notifications: { streak_reminder: [EMAIL] })
|
|
231
|
-
def update_preferences(id:, notifications: nil, request_options: nil)
|
|
237
|
+
def update_preferences(id:, notifications: nil, streak: nil, request_options: nil)
|
|
232
238
|
response = @request_client.conn.patch do |req|
|
|
233
239
|
req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
|
|
234
240
|
req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
|
|
@@ -241,7 +247,11 @@ module TrophyApiClient
|
|
|
241
247
|
unless request_options.nil? || request_options&.additional_query_parameters.nil?
|
|
242
248
|
req.params = { **(request_options&.additional_query_parameters || {}) }.compact
|
|
243
249
|
end
|
|
244
|
-
req.body = {
|
|
250
|
+
req.body = {
|
|
251
|
+
**(request_options&.additional_body_parameters || {}),
|
|
252
|
+
notifications: notifications,
|
|
253
|
+
streak: streak
|
|
254
|
+
}.compact
|
|
245
255
|
req.url "#{@request_client.get_url(environment: api, request_options: request_options)}/users/#{id}/preferences"
|
|
246
256
|
end
|
|
247
257
|
TrophyApiClient::UserPreferencesResponse.from_json(json_object: response.body)
|
|
@@ -862,7 +872,8 @@ module TrophyApiClient
|
|
|
862
872
|
end
|
|
863
873
|
end
|
|
864
874
|
|
|
865
|
-
# Update a user's notification preferences.
|
|
875
|
+
# Update a user's notification and streak preferences. Streak preferences require
|
|
876
|
+
# streak customization to be enabled in your Trophy dashboard settings.
|
|
866
877
|
#
|
|
867
878
|
# @param id [String] The user's ID in your database.
|
|
868
879
|
# @param notifications [Hash] Request of type TrophyApiClient::NotificationPreferences, as a Hash
|
|
@@ -870,6 +881,10 @@ module TrophyApiClient
|
|
|
870
881
|
# * :recap (Array<TrophyApiClient::NotificationChannel>)
|
|
871
882
|
# * :reactivation (Array<TrophyApiClient::NotificationChannel>)
|
|
872
883
|
# * :streak_reminder (Array<TrophyApiClient::NotificationChannel>)
|
|
884
|
+
# @param streak [Hash] Request of type TrophyApiClient::StreakPreferences, as a Hash
|
|
885
|
+
# * :enabled (Boolean)
|
|
886
|
+
# * :evaluation_mode (TrophyApiClient::StreakEvaluationModePreference)
|
|
887
|
+
# * :metrics (Array<TrophyApiClient::StreakMetricPreference>)
|
|
873
888
|
# @param request_options [TrophyApiClient::RequestOptions]
|
|
874
889
|
# @return [TrophyApiClient::UserPreferencesResponse]
|
|
875
890
|
# @example
|
|
@@ -879,7 +894,7 @@ module TrophyApiClient
|
|
|
879
894
|
# api_key: "YOUR_API_KEY"
|
|
880
895
|
# )
|
|
881
896
|
# api.users.update_preferences(id: "user-123", notifications: { streak_reminder: [EMAIL] })
|
|
882
|
-
def update_preferences(id:, notifications: nil, request_options: nil)
|
|
897
|
+
def update_preferences(id:, notifications: nil, streak: nil, request_options: nil)
|
|
883
898
|
Async do
|
|
884
899
|
response = @request_client.conn.patch do |req|
|
|
885
900
|
req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
|
|
@@ -893,7 +908,11 @@ module TrophyApiClient
|
|
|
893
908
|
unless request_options.nil? || request_options&.additional_query_parameters.nil?
|
|
894
909
|
req.params = { **(request_options&.additional_query_parameters || {}) }.compact
|
|
895
910
|
end
|
|
896
|
-
req.body = {
|
|
911
|
+
req.body = {
|
|
912
|
+
**(request_options&.additional_body_parameters || {}),
|
|
913
|
+
notifications: notifications,
|
|
914
|
+
streak: streak
|
|
915
|
+
}.compact
|
|
897
916
|
req.url "#{@request_client.get_url(environment: api,
|
|
898
917
|
request_options: request_options)}/users/#{id}/preferences"
|
|
899
918
|
end
|
data/lib/types_export.rb
CHANGED
|
@@ -71,6 +71,9 @@ require_relative "trophy_api_client/types/upserted_user"
|
|
|
71
71
|
require_relative "trophy_api_client/types/user"
|
|
72
72
|
require_relative "trophy_api_client/types/notification_channel"
|
|
73
73
|
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"
|
|
74
77
|
require_relative "trophy_api_client/types/user_preferences_response"
|
|
75
78
|
require_relative "trophy_api_client/types/error_body"
|
|
76
79
|
require_relative "trophy_api_client/types/achievement_completion_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.
|
|
4
|
+
version: 1.14.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Trophy Labs, Inc
|
|
@@ -270,7 +270,10 @@ files:
|
|
|
270
270
|
- lib/trophy_api_client/types/points_trigger_type.rb
|
|
271
271
|
- lib/trophy_api_client/types/points_trigger_user_attributes_item.rb
|
|
272
272
|
- lib/trophy_api_client/types/restore_streaks_response.rb
|
|
273
|
+
- lib/trophy_api_client/types/streak_evaluation_mode_preference.rb
|
|
273
274
|
- lib/trophy_api_client/types/streak_frequency.rb
|
|
275
|
+
- lib/trophy_api_client/types/streak_metric_preference.rb
|
|
276
|
+
- lib/trophy_api_client/types/streak_preferences.rb
|
|
274
277
|
- lib/trophy_api_client/types/streak_response.rb
|
|
275
278
|
- lib/trophy_api_client/types/streak_response_streak_history_item.rb
|
|
276
279
|
- lib/trophy_api_client/types/update_attribute_request_item.rb
|