trophy_api_client 1.12.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 53980f53595d29d00f98c8417ae38f192c42eb899139036238aff75acd9a8b5a
4
- data.tar.gz: fd0a8b34d06eea9ea76d68278384a6dff6189543d8288679b8965632ac3f8bde
3
+ metadata.gz: 63cf1c72d377d4e597ede4a41d8114467eb3234e3aa16322447a03ea2a27fc0a
4
+ data.tar.gz: 17dd217600b02a7ec867e9a2ffed08baafa6761d159638c1ae9058994848920f
5
5
  SHA512:
6
- metadata.gz: a05179e86d3577f0ac681e87434b3c8260bd46de6f0233b69a65afc2802330fe6421c5cdb5f54e7dad967c7528381b9cd66291f9de833f38c2161430e8aba87a
7
- data.tar.gz: 8821f372ad08068762223ba56af83134916e901f653988ce816626cbdf5f39c403be07d99f9736bab53a8f8621e531742a3c241219030b453642941ca120cd13
6
+ metadata.gz: 7e7a475bcefa4b4935e398395e7a0fd365006a170442ca1f86534f28d26a229d46336f967a4877eab8fda1092241e818d50cb32d6c916a8d92f370c153a0f3bb
7
+ data.tar.gz: 74b391c48f09d09b03f4fa6b7b2da9e47869b831bb4a5842a67eef233a89bf0132975ccf6d4e4e4e5d55aaa64d7ddc643ef59c3291e8fd2a0ce448e3b2910405
data/lib/gemconfig.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  module TrophyApiClient
4
4
  module Gemconfig
5
- VERSION = "1.12.0"
5
+ VERSION = "1.13.0"
6
6
  AUTHORS = ["Trophy Labs, Inc"].freeze
7
7
  EMAIL = ""
8
8
  SUMMARY = "Ruby library for the Trophy API."
@@ -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,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
- 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
+ )
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 = { **(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
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 = { **(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
897
914
  req.url "#{@request_client.get_url(environment: api,
898
915
  request_options: request_options)}/users/#{id}/preferences"
899
916
  end
@@ -1,3 +1,3 @@
1
1
  module MyGem
2
- VERSION = "1.12.0"
2
+ VERSION = "1.13.0"
3
3
  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.12.0
4
+ version: 1.13.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