trophy_api_client 1.11.0 → 1.13.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/streaks/client.rb +0 -76
- 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 +74 -0
- data/lib/trophy_api_client/types/streak_response.rb +14 -13
- data/lib/trophy_api_client/types/user_preferences_response.rb +21 -3
- data/lib/trophy_api_client/users/client.rb +23 -6
- data/lib/trophy_api_client/version.rb +1 -1
- data/lib/types_export.rb +3 -2
- metadata +4 -3
- data/lib/trophy_api_client/streaks/types/streaks_rankings_request_type.rb +0 -10
- data/lib/trophy_api_client/types/streak_ranking_user.rb +0 -75
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 63cf1c72d377d4e597ede4a41d8114467eb3234e3aa16322447a03ea2a27fc0a
|
|
4
|
+
data.tar.gz: 17dd217600b02a7ec867e9a2ffed08baafa6761d159638c1ae9058994848920f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7e7a475bcefa4b4935e398395e7a0fd365006a170442ca1f86534f28d26a229d46336f967a4877eab8fda1092241e818d50cb32d6c916a8d92f370c153a0f3bb
|
|
7
|
+
data.tar.gz: 74b391c48f09d09b03f4fa6b7b2da9e47869b831bb4a5842a67eef233a89bf0132975ccf6d4e4e4e5d55aaa64d7ddc643ef59c3291e8fd2a0ce448e3b2910405
|
data/lib/gemconfig.rb
CHANGED
|
@@ -3,8 +3,6 @@
|
|
|
3
3
|
require_relative "../../requests"
|
|
4
4
|
require_relative "../types/bulk_streak_response"
|
|
5
5
|
require "json"
|
|
6
|
-
require_relative "types/streaks_rankings_request_type"
|
|
7
|
-
require_relative "../types/streak_ranking_user"
|
|
8
6
|
require "async"
|
|
9
7
|
|
|
10
8
|
module TrophyApiClient
|
|
@@ -53,42 +51,6 @@ module TrophyApiClient
|
|
|
53
51
|
TrophyApiClient::BulkStreakResponseItem.from_json(json_object: item)
|
|
54
52
|
end
|
|
55
53
|
end
|
|
56
|
-
|
|
57
|
-
# Get the top users by streak length (active or longest).
|
|
58
|
-
#
|
|
59
|
-
# @param limit [Integer] Number of users to return. Must be between 1 and 100.
|
|
60
|
-
# @param type [TrophyApiClient::Streaks::StreaksRankingsRequestType] Whether to rank users by active streaks or longest streaks ever achieved.
|
|
61
|
-
# @param request_options [TrophyApiClient::RequestOptions]
|
|
62
|
-
# @return [Array<TrophyApiClient::StreakRankingUser>]
|
|
63
|
-
# @example
|
|
64
|
-
# api = TrophyApiClient::Client.new(
|
|
65
|
-
# base_url: "https://api.example.com",
|
|
66
|
-
# environment: TrophyApiClient::Environment::PRODUCTION,
|
|
67
|
-
# api_key: "YOUR_API_KEY"
|
|
68
|
-
# )
|
|
69
|
-
# api.streaks.rankings(limit: 1, type: ACTIVE)
|
|
70
|
-
def rankings(limit: nil, type: nil, request_options: nil)
|
|
71
|
-
response = @request_client.conn.get do |req|
|
|
72
|
-
req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
|
|
73
|
-
req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
|
|
74
|
-
req.headers["Tenant-ID"] = request_options.tenant_id unless request_options&.tenant_id.nil?
|
|
75
|
-
req.headers = {
|
|
76
|
-
**(req.headers || {}),
|
|
77
|
-
**@request_client.get_headers,
|
|
78
|
-
**(request_options&.additional_headers || {})
|
|
79
|
-
}.compact
|
|
80
|
-
req.params = { **(request_options&.additional_query_parameters || {}), "limit": limit, "type": type }.compact
|
|
81
|
-
unless request_options.nil? || request_options&.additional_body_parameters.nil?
|
|
82
|
-
req.body = { **(request_options&.additional_body_parameters || {}) }.compact
|
|
83
|
-
end
|
|
84
|
-
req.url "#{@request_client.get_url(environment: api, request_options: request_options)}/streaks/rankings"
|
|
85
|
-
end
|
|
86
|
-
parsed_json = JSON.parse(response.body)
|
|
87
|
-
parsed_json&.map do |item|
|
|
88
|
-
item = item.to_json
|
|
89
|
-
TrophyApiClient::StreakRankingUser.from_json(json_object: item)
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
54
|
end
|
|
93
55
|
|
|
94
56
|
class AsyncStreaksClient
|
|
@@ -138,43 +100,5 @@ module TrophyApiClient
|
|
|
138
100
|
end
|
|
139
101
|
end
|
|
140
102
|
end
|
|
141
|
-
|
|
142
|
-
# Get the top users by streak length (active or longest).
|
|
143
|
-
#
|
|
144
|
-
# @param limit [Integer] Number of users to return. Must be between 1 and 100.
|
|
145
|
-
# @param type [TrophyApiClient::Streaks::StreaksRankingsRequestType] Whether to rank users by active streaks or longest streaks ever achieved.
|
|
146
|
-
# @param request_options [TrophyApiClient::RequestOptions]
|
|
147
|
-
# @return [Array<TrophyApiClient::StreakRankingUser>]
|
|
148
|
-
# @example
|
|
149
|
-
# api = TrophyApiClient::Client.new(
|
|
150
|
-
# base_url: "https://api.example.com",
|
|
151
|
-
# environment: TrophyApiClient::Environment::PRODUCTION,
|
|
152
|
-
# api_key: "YOUR_API_KEY"
|
|
153
|
-
# )
|
|
154
|
-
# api.streaks.rankings(limit: 1, type: ACTIVE)
|
|
155
|
-
def rankings(limit: nil, type: nil, request_options: nil)
|
|
156
|
-
Async do
|
|
157
|
-
response = @request_client.conn.get do |req|
|
|
158
|
-
req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
|
|
159
|
-
req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
|
|
160
|
-
req.headers["Tenant-ID"] = request_options.tenant_id unless request_options&.tenant_id.nil?
|
|
161
|
-
req.headers = {
|
|
162
|
-
**(req.headers || {}),
|
|
163
|
-
**@request_client.get_headers,
|
|
164
|
-
**(request_options&.additional_headers || {})
|
|
165
|
-
}.compact
|
|
166
|
-
req.params = { **(request_options&.additional_query_parameters || {}), "limit": limit, "type": type }.compact
|
|
167
|
-
unless request_options.nil? || request_options&.additional_body_parameters.nil?
|
|
168
|
-
req.body = { **(request_options&.additional_body_parameters || {}) }.compact
|
|
169
|
-
end
|
|
170
|
-
req.url "#{@request_client.get_url(environment: api, request_options: request_options)}/streaks/rankings"
|
|
171
|
-
end
|
|
172
|
-
parsed_json = JSON.parse(response.body)
|
|
173
|
-
parsed_json&.map do |item|
|
|
174
|
-
item = item.to_json
|
|
175
|
-
TrophyApiClient::StreakRankingUser.from_json(json_object: item)
|
|
176
|
-
end
|
|
177
|
-
end
|
|
178
|
-
end
|
|
179
103
|
end
|
|
180
104
|
end
|
|
@@ -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,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
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "date"
|
|
3
4
|
require_relative "streak_response_streak_history_item"
|
|
4
5
|
require_relative "streak_frequency"
|
|
5
6
|
require "ostruct"
|
|
@@ -8,12 +9,12 @@ require "json"
|
|
|
8
9
|
module TrophyApiClient
|
|
9
10
|
# An object representing the user's streak.
|
|
10
11
|
class StreakResponse
|
|
12
|
+
# @return [DateTime] The timestamp the streak was most recently extended. Null if the streak is not
|
|
13
|
+
# active.
|
|
14
|
+
attr_reader :extended
|
|
11
15
|
# @return [Array<TrophyApiClient::StreakResponseStreakHistoryItem>] A list of the user's past streak periods up through the current period. Each
|
|
12
16
|
# period includes the start and end dates and the length of the streak.
|
|
13
17
|
attr_reader :streak_history
|
|
14
|
-
# @return [Integer] Deprecated. The user's rank across all users. Null if the user has no active
|
|
15
|
-
# streak.
|
|
16
|
-
attr_reader :rank
|
|
17
18
|
# @return [Integer] The length of the user's current streak.
|
|
18
19
|
attr_reader :length
|
|
19
20
|
# @return [TrophyApiClient::StreakFrequency] The frequency of the streak.
|
|
@@ -46,10 +47,10 @@ module TrophyApiClient
|
|
|
46
47
|
|
|
47
48
|
OMIT = Object.new
|
|
48
49
|
|
|
50
|
+
# @param extended [DateTime] The timestamp the streak was most recently extended. Null if the streak is not
|
|
51
|
+
# active.
|
|
49
52
|
# @param streak_history [Array<TrophyApiClient::StreakResponseStreakHistoryItem>] A list of the user's past streak periods up through the current period. Each
|
|
50
53
|
# period includes the start and end dates and the length of the streak.
|
|
51
|
-
# @param rank [Integer] Deprecated. The user's rank across all users. Null if the user has no active
|
|
52
|
-
# streak.
|
|
53
54
|
# @param length [Integer] The length of the user's current streak.
|
|
54
55
|
# @param frequency [TrophyApiClient::StreakFrequency] The frequency of the streak.
|
|
55
56
|
# @param started [String] The date the streak started.
|
|
@@ -66,10 +67,10 @@ module TrophyApiClient
|
|
|
66
67
|
# the organization has enabled streak freeze auto-earn.
|
|
67
68
|
# @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
|
|
68
69
|
# @return [TrophyApiClient::StreakResponse]
|
|
69
|
-
def initialize(length:, frequency:,
|
|
70
|
+
def initialize(streak_history:, length:, frequency:, extended: OMIT, started: OMIT, period_start: OMIT,
|
|
70
71
|
period_end: OMIT, expires: OMIT, freezes: OMIT, max_freezes: OMIT, freeze_auto_earn_interval: OMIT, freeze_auto_earn_amount: OMIT, additional_properties: nil)
|
|
71
|
-
@
|
|
72
|
-
@
|
|
72
|
+
@extended = extended if extended != OMIT
|
|
73
|
+
@streak_history = streak_history
|
|
73
74
|
@length = length
|
|
74
75
|
@frequency = frequency
|
|
75
76
|
@started = started if started != OMIT
|
|
@@ -82,8 +83,8 @@ module TrophyApiClient
|
|
|
82
83
|
@freeze_auto_earn_amount = freeze_auto_earn_amount if freeze_auto_earn_amount != OMIT
|
|
83
84
|
@additional_properties = additional_properties
|
|
84
85
|
@_field_set = {
|
|
86
|
+
"extended": extended,
|
|
85
87
|
"streakHistory": streak_history,
|
|
86
|
-
"rank": rank,
|
|
87
88
|
"length": length,
|
|
88
89
|
"frequency": frequency,
|
|
89
90
|
"started": started,
|
|
@@ -106,11 +107,11 @@ module TrophyApiClient
|
|
|
106
107
|
def self.from_json(json_object:)
|
|
107
108
|
struct = JSON.parse(json_object, object_class: OpenStruct)
|
|
108
109
|
parsed_json = JSON.parse(json_object)
|
|
110
|
+
extended = (DateTime.parse(parsed_json["extended"]) unless parsed_json["extended"].nil?)
|
|
109
111
|
streak_history = parsed_json["streakHistory"]&.map do |item|
|
|
110
112
|
item = item.to_json
|
|
111
113
|
TrophyApiClient::StreakResponseStreakHistoryItem.from_json(json_object: item)
|
|
112
114
|
end
|
|
113
|
-
rank = parsed_json["rank"]
|
|
114
115
|
length = parsed_json["length"]
|
|
115
116
|
frequency = parsed_json["frequency"]
|
|
116
117
|
started = parsed_json["started"]
|
|
@@ -122,8 +123,8 @@ module TrophyApiClient
|
|
|
122
123
|
freeze_auto_earn_interval = parsed_json["freezeAutoEarnInterval"]
|
|
123
124
|
freeze_auto_earn_amount = parsed_json["freezeAutoEarnAmount"]
|
|
124
125
|
new(
|
|
126
|
+
extended: extended,
|
|
125
127
|
streak_history: streak_history,
|
|
126
|
-
rank: rank,
|
|
127
128
|
length: length,
|
|
128
129
|
frequency: frequency,
|
|
129
130
|
started: started,
|
|
@@ -152,8 +153,8 @@ module TrophyApiClient
|
|
|
152
153
|
# @param obj [Object]
|
|
153
154
|
# @return [Void]
|
|
154
155
|
def self.validate_raw(obj:)
|
|
155
|
-
obj.
|
|
156
|
-
obj.
|
|
156
|
+
obj.extended&.is_a?(DateTime) != false || raise("Passed value for field obj.extended is not the expected type, validation failed.")
|
|
157
|
+
obj.streak_history.is_a?(Array) != false || raise("Passed value for field obj.streak_history is not the expected type, validation failed.")
|
|
157
158
|
obj.length.is_a?(Integer) != false || raise("Passed value for field obj.length is not the expected type, validation failed.")
|
|
158
159
|
obj.frequency.is_a?(TrophyApiClient::StreakFrequency) != false || raise("Passed value for field obj.frequency is not the expected type, validation failed.")
|
|
159
160
|
obj.started&.is_a?(String) != false || raise("Passed value for field obj.started is not the expected type, validation failed.")
|
|
@@ -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,9 @@ 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
|
+
# * :evaluation_mode (TrophyApiClient::StreakEvaluationModePreference)
|
|
226
|
+
# * :metrics (Array<TrophyApiClient::StreakMetricPreference>)
|
|
222
227
|
# @param request_options [TrophyApiClient::RequestOptions]
|
|
223
228
|
# @return [TrophyApiClient::UserPreferencesResponse]
|
|
224
229
|
# @example
|
|
@@ -228,7 +233,7 @@ module TrophyApiClient
|
|
|
228
233
|
# api_key: "YOUR_API_KEY"
|
|
229
234
|
# )
|
|
230
235
|
# 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)
|
|
232
237
|
response = @request_client.conn.patch do |req|
|
|
233
238
|
req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
|
|
234
239
|
req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
|
|
@@ -241,7 +246,11 @@ module TrophyApiClient
|
|
|
241
246
|
unless request_options.nil? || request_options&.additional_query_parameters.nil?
|
|
242
247
|
req.params = { **(request_options&.additional_query_parameters || {}) }.compact
|
|
243
248
|
end
|
|
244
|
-
req.body = {
|
|
249
|
+
req.body = {
|
|
250
|
+
**(request_options&.additional_body_parameters || {}),
|
|
251
|
+
notifications: notifications,
|
|
252
|
+
streak: streak
|
|
253
|
+
}.compact
|
|
245
254
|
req.url "#{@request_client.get_url(environment: api, request_options: request_options)}/users/#{id}/preferences"
|
|
246
255
|
end
|
|
247
256
|
TrophyApiClient::UserPreferencesResponse.from_json(json_object: response.body)
|
|
@@ -862,7 +871,8 @@ module TrophyApiClient
|
|
|
862
871
|
end
|
|
863
872
|
end
|
|
864
873
|
|
|
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.
|
|
866
876
|
#
|
|
867
877
|
# @param id [String] The user's ID in your database.
|
|
868
878
|
# @param notifications [Hash] Request of type TrophyApiClient::NotificationPreferences, as a Hash
|
|
@@ -870,6 +880,9 @@ module TrophyApiClient
|
|
|
870
880
|
# * :recap (Array<TrophyApiClient::NotificationChannel>)
|
|
871
881
|
# * :reactivation (Array<TrophyApiClient::NotificationChannel>)
|
|
872
882
|
# * :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>)
|
|
873
886
|
# @param request_options [TrophyApiClient::RequestOptions]
|
|
874
887
|
# @return [TrophyApiClient::UserPreferencesResponse]
|
|
875
888
|
# @example
|
|
@@ -879,7 +892,7 @@ module TrophyApiClient
|
|
|
879
892
|
# api_key: "YOUR_API_KEY"
|
|
880
893
|
# )
|
|
881
894
|
# 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)
|
|
883
896
|
Async do
|
|
884
897
|
response = @request_client.conn.patch do |req|
|
|
885
898
|
req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
|
|
@@ -893,7 +906,11 @@ module TrophyApiClient
|
|
|
893
906
|
unless request_options.nil? || request_options&.additional_query_parameters.nil?
|
|
894
907
|
req.params = { **(request_options&.additional_query_parameters || {}) }.compact
|
|
895
908
|
end
|
|
896
|
-
req.body = {
|
|
909
|
+
req.body = {
|
|
910
|
+
**(request_options&.additional_body_parameters || {}),
|
|
911
|
+
notifications: notifications,
|
|
912
|
+
streak: streak
|
|
913
|
+
}.compact
|
|
897
914
|
req.url "#{@request_client.get_url(environment: api,
|
|
898
915
|
request_options: request_options)}/users/#{id}/preferences"
|
|
899
916
|
end
|
data/lib/types_export.rb
CHANGED
|
@@ -4,7 +4,6 @@ require_relative "trophy_api_client/users/types/users_metric_event_summary_reque
|
|
|
4
4
|
require_relative "trophy_api_client/users/types/users_metric_event_summary_response_item"
|
|
5
5
|
require_relative "trophy_api_client/users/types/users_points_event_summary_request_aggregation"
|
|
6
6
|
require_relative "trophy_api_client/users/types/users_points_event_summary_response_item"
|
|
7
|
-
require_relative "trophy_api_client/streaks/types/streaks_rankings_request_type"
|
|
8
7
|
require_relative "trophy_api_client/leaderboards/types/leaderboards_all_response_item_status"
|
|
9
8
|
require_relative "trophy_api_client/leaderboards/types/leaderboards_all_response_item"
|
|
10
9
|
require_relative "trophy_api_client/admin/streaks/types/restore_streaks_request_users_item"
|
|
@@ -72,6 +71,9 @@ require_relative "trophy_api_client/types/upserted_user"
|
|
|
72
71
|
require_relative "trophy_api_client/types/user"
|
|
73
72
|
require_relative "trophy_api_client/types/notification_channel"
|
|
74
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"
|
|
75
77
|
require_relative "trophy_api_client/types/user_preferences_response"
|
|
76
78
|
require_relative "trophy_api_client/types/error_body"
|
|
77
79
|
require_relative "trophy_api_client/types/achievement_completion_response"
|
|
@@ -79,7 +81,6 @@ require_relative "trophy_api_client/types/event_response"
|
|
|
79
81
|
require_relative "trophy_api_client/types/points_range"
|
|
80
82
|
require_relative "trophy_api_client/types/points_summary_response"
|
|
81
83
|
require_relative "trophy_api_client/types/points_system_response"
|
|
82
|
-
require_relative "trophy_api_client/types/streak_ranking_user"
|
|
83
84
|
require_relative "trophy_api_client/types/leaderboard_ranking"
|
|
84
85
|
require_relative "trophy_api_client/types/leaderboard_event"
|
|
85
86
|
require_relative "trophy_api_client/types/user_leaderboard_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.13.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Trophy Labs, Inc
|
|
@@ -120,7 +120,6 @@ files:
|
|
|
120
120
|
- lib/trophy_api_client/metrics/client.rb
|
|
121
121
|
- lib/trophy_api_client/points/client.rb
|
|
122
122
|
- lib/trophy_api_client/streaks/client.rb
|
|
123
|
-
- lib/trophy_api_client/streaks/types/streaks_rankings_request_type.rb
|
|
124
123
|
- lib/trophy_api_client/types/achievement_completion_response.rb
|
|
125
124
|
- lib/trophy_api_client/types/achievement_response.rb
|
|
126
125
|
- lib/trophy_api_client/types/achievement_response_event_attribute.rb
|
|
@@ -271,8 +270,10 @@ files:
|
|
|
271
270
|
- lib/trophy_api_client/types/points_trigger_type.rb
|
|
272
271
|
- lib/trophy_api_client/types/points_trigger_user_attributes_item.rb
|
|
273
272
|
- lib/trophy_api_client/types/restore_streaks_response.rb
|
|
273
|
+
- lib/trophy_api_client/types/streak_evaluation_mode_preference.rb
|
|
274
274
|
- lib/trophy_api_client/types/streak_frequency.rb
|
|
275
|
-
- lib/trophy_api_client/types/
|
|
275
|
+
- lib/trophy_api_client/types/streak_metric_preference.rb
|
|
276
|
+
- lib/trophy_api_client/types/streak_preferences.rb
|
|
276
277
|
- lib/trophy_api_client/types/streak_response.rb
|
|
277
278
|
- lib/trophy_api_client/types/streak_response_streak_history_item.rb
|
|
278
279
|
- lib/trophy_api_client/types/update_attribute_request_item.rb
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "ostruct"
|
|
4
|
-
require "json"
|
|
5
|
-
|
|
6
|
-
module TrophyApiClient
|
|
7
|
-
# A user with their streak length in the rankings.
|
|
8
|
-
class StreakRankingUser
|
|
9
|
-
# @return [String] The ID of the user.
|
|
10
|
-
attr_reader :user_id
|
|
11
|
-
# @return [String] The name of the user. May be null if no name is set.
|
|
12
|
-
attr_reader :name
|
|
13
|
-
# @return [Integer] The user's streak length (active or longest depending on query parameter).
|
|
14
|
-
attr_reader :streak_length
|
|
15
|
-
# @return [OpenStruct] Additional properties unmapped to the current class definition
|
|
16
|
-
attr_reader :additional_properties
|
|
17
|
-
# @return [Object]
|
|
18
|
-
attr_reader :_field_set
|
|
19
|
-
protected :_field_set
|
|
20
|
-
|
|
21
|
-
OMIT = Object.new
|
|
22
|
-
|
|
23
|
-
# @param user_id [String] The ID of the user.
|
|
24
|
-
# @param name [String] The name of the user. May be null if no name is set.
|
|
25
|
-
# @param streak_length [Integer] The user's streak length (active or longest depending on query parameter).
|
|
26
|
-
# @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
|
|
27
|
-
# @return [TrophyApiClient::StreakRankingUser]
|
|
28
|
-
def initialize(user_id:, streak_length:, name: OMIT, additional_properties: nil)
|
|
29
|
-
@user_id = user_id
|
|
30
|
-
@name = name if name != OMIT
|
|
31
|
-
@streak_length = streak_length
|
|
32
|
-
@additional_properties = additional_properties
|
|
33
|
-
@_field_set = { "userId": user_id, "name": name, "streakLength": streak_length }.reject do |_k, v|
|
|
34
|
-
v == OMIT
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
# Deserialize a JSON object to an instance of StreakRankingUser
|
|
39
|
-
#
|
|
40
|
-
# @param json_object [String]
|
|
41
|
-
# @return [TrophyApiClient::StreakRankingUser]
|
|
42
|
-
def self.from_json(json_object:)
|
|
43
|
-
struct = JSON.parse(json_object, object_class: OpenStruct)
|
|
44
|
-
parsed_json = JSON.parse(json_object)
|
|
45
|
-
user_id = parsed_json["userId"]
|
|
46
|
-
name = parsed_json["name"]
|
|
47
|
-
streak_length = parsed_json["streakLength"]
|
|
48
|
-
new(
|
|
49
|
-
user_id: user_id,
|
|
50
|
-
name: name,
|
|
51
|
-
streak_length: streak_length,
|
|
52
|
-
additional_properties: struct
|
|
53
|
-
)
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
# Serialize an instance of StreakRankingUser 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.user_id.is_a?(String) != false || raise("Passed value for field obj.user_id is not the expected type, validation failed.")
|
|
71
|
-
obj.name&.is_a?(String) != false || raise("Passed value for field obj.name is not the expected type, validation failed.")
|
|
72
|
-
obj.streak_length.is_a?(Integer) != false || raise("Passed value for field obj.streak_length is not the expected type, validation failed.")
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
end
|