trophy_api_client 1.0.40 → 1.0.42

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: ccada1b1f574255085097fba1ef98806380bead4795e66a98db917bf82391e4b
4
- data.tar.gz: c27e60901c8bb55bba1b03b62fac00e247bebdbb16bbd64e9049e27cb7a36cab
3
+ metadata.gz: 77265cbb3258c3a5737b4f7649d1b12a3924b65189193ce24a7d7d585c05abbc
4
+ data.tar.gz: d9fe18d5ec1d18e0d4bbb4ceeb03b604f4182dcd3b36061246402cdad68cae01
5
5
  SHA512:
6
- metadata.gz: d8b112fe94fffcf2c31241bcc91279d184d55dd9b95c0ab10f82d3c122ce60b1427b324f76eb895c9b3f3ef00e9a0b8325f8a0f915ea98eaa1e160180e83d1ae
7
- data.tar.gz: 28e86210d2381bf56dfba0c43822085ed6042aa955c2bf462147ef097cf0fe9f852ea99d11bbdbe9a0f0fd5618b3179ba6b3d70eb993d673b735424670a6188e
6
+ metadata.gz: 6d456b11f213ebcade5b49769e45a93c7cfea3f2e2caa26c22cc2f9ae740955bd37c1e4ad36773011386d49765388cca31ac5c4be1470b72b0f7e8eae9895dc7
7
+ data.tar.gz: 19cceac7fbc0c7c077de7c42cc0c12eb11ff85fed52f87548accfc28bc3e39f6dbdaf3d6366b98bea37c472a9f9a6a10c677e03d1f1aac993edbd2df48d9aee6
data/lib/gemconfig.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  module TrophyApiClient
4
4
  module Gemconfig
5
- VERSION = "1.0.40"
5
+ VERSION = "1.0.42"
6
6
  AUTHORS = ["Trophy Labs, Inc"].freeze
7
7
  EMAIL = ""
8
8
  SUMMARY = "Ruby library for the Trophy API."
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TrophyApiClient
4
+ # A notification delivery channel.
5
+ class NotificationChannel
6
+ EMAIL = "email"
7
+ PUSH = "push"
8
+ end
9
+ end
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "notification_channel"
4
+ require "ostruct"
5
+ require "json"
6
+
7
+ module TrophyApiClient
8
+ # Notification preferences for each notification type.
9
+ class NotificationPreferences
10
+ # @return [Array<TrophyApiClient::NotificationChannel>] Channels to receive achievement completion notifications on.
11
+ attr_reader :achievement_completed
12
+ # @return [Array<TrophyApiClient::NotificationChannel>] Channels to receive recap notifications on.
13
+ attr_reader :recap
14
+ # @return [Array<TrophyApiClient::NotificationChannel>] Channels to receive reactivation notifications on.
15
+ attr_reader :reactivation
16
+ # @return [Array<TrophyApiClient::NotificationChannel>] Channels to receive streak reminder notifications on.
17
+ attr_reader :streak_reminder
18
+ # @return [OpenStruct] Additional properties unmapped to the current class definition
19
+ attr_reader :additional_properties
20
+ # @return [Object]
21
+ attr_reader :_field_set
22
+ protected :_field_set
23
+
24
+ OMIT = Object.new
25
+
26
+ # @param achievement_completed [Array<TrophyApiClient::NotificationChannel>] Channels to receive achievement completion notifications on.
27
+ # @param recap [Array<TrophyApiClient::NotificationChannel>] Channels to receive recap notifications on.
28
+ # @param reactivation [Array<TrophyApiClient::NotificationChannel>] Channels to receive reactivation notifications on.
29
+ # @param streak_reminder [Array<TrophyApiClient::NotificationChannel>] Channels to receive streak reminder notifications on.
30
+ # @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
31
+ # @return [TrophyApiClient::NotificationPreferences]
32
+ def initialize(achievement_completed: OMIT, recap: OMIT, reactivation: OMIT, streak_reminder: OMIT,
33
+ additional_properties: nil)
34
+ @achievement_completed = achievement_completed if achievement_completed != OMIT
35
+ @recap = recap if recap != OMIT
36
+ @reactivation = reactivation if reactivation != OMIT
37
+ @streak_reminder = streak_reminder if streak_reminder != OMIT
38
+ @additional_properties = additional_properties
39
+ @_field_set = {
40
+ "achievement_completed": achievement_completed,
41
+ "recap": recap,
42
+ "reactivation": reactivation,
43
+ "streak_reminder": streak_reminder
44
+ }.reject do |_k, v|
45
+ v == OMIT
46
+ end
47
+ end
48
+
49
+ # Deserialize a JSON object to an instance of NotificationPreferences
50
+ #
51
+ # @param json_object [String]
52
+ # @return [TrophyApiClient::NotificationPreferences]
53
+ def self.from_json(json_object:)
54
+ struct = JSON.parse(json_object, object_class: OpenStruct)
55
+ parsed_json = JSON.parse(json_object)
56
+ achievement_completed = parsed_json["achievement_completed"]
57
+ recap = parsed_json["recap"]
58
+ reactivation = parsed_json["reactivation"]
59
+ streak_reminder = parsed_json["streak_reminder"]
60
+ new(
61
+ achievement_completed: achievement_completed,
62
+ recap: recap,
63
+ reactivation: reactivation,
64
+ streak_reminder: streak_reminder,
65
+ additional_properties: struct
66
+ )
67
+ end
68
+
69
+ # Serialize an instance of NotificationPreferences to a JSON object
70
+ #
71
+ # @return [String]
72
+ def to_json(*_args)
73
+ @_field_set&.to_json
74
+ end
75
+
76
+ # Leveraged for Union-type generation, validate_raw attempts to parse the given
77
+ # hash and check each fields type against the current object's property
78
+ # definitions.
79
+ #
80
+ # @param obj [Object]
81
+ # @return [Void]
82
+ def self.validate_raw(obj:)
83
+ obj.achievement_completed&.is_a?(Array) != false || raise("Passed value for field obj.achievement_completed is not the expected type, validation failed.")
84
+ obj.recap&.is_a?(Array) != false || raise("Passed value for field obj.recap is not the expected type, validation failed.")
85
+ obj.reactivation&.is_a?(Array) != false || raise("Passed value for field obj.reactivation is not the expected type, validation failed.")
86
+ obj.streak_reminder&.is_a?(Array) != false || raise("Passed value for field obj.streak_reminder is not the expected type, validation failed.")
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TrophyApiClient
4
+ # A type of notification that can be configured.
5
+ class NotificationType
6
+ ACHIEVEMENT_COMPLETED = "achievement_completed"
7
+ RECAP = "recap"
8
+ REACTIVATION = "reactivation"
9
+ STREAK_REMINDER = "streak_reminder"
10
+ end
11
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "notification_preferences"
4
+ require "ostruct"
5
+ require "json"
6
+
7
+ module TrophyApiClient
8
+ # A user's preferences.
9
+ class UserPreferencesResponse
10
+ # @return [TrophyApiClient::NotificationPreferences]
11
+ attr_reader :notifications
12
+ # @return [OpenStruct] Additional properties unmapped to the current class definition
13
+ attr_reader :additional_properties
14
+ # @return [Object]
15
+ attr_reader :_field_set
16
+ protected :_field_set
17
+
18
+ OMIT = Object.new
19
+
20
+ # @param notifications [TrophyApiClient::NotificationPreferences]
21
+ # @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
22
+ # @return [TrophyApiClient::UserPreferencesResponse]
23
+ def initialize(notifications:, additional_properties: nil)
24
+ @notifications = notifications
25
+ @additional_properties = additional_properties
26
+ @_field_set = { "notifications": notifications }
27
+ end
28
+
29
+ # Deserialize a JSON object to an instance of UserPreferencesResponse
30
+ #
31
+ # @param json_object [String]
32
+ # @return [TrophyApiClient::UserPreferencesResponse]
33
+ def self.from_json(json_object:)
34
+ struct = JSON.parse(json_object, object_class: OpenStruct)
35
+ parsed_json = JSON.parse(json_object)
36
+ if parsed_json["notifications"].nil?
37
+ notifications = nil
38
+ else
39
+ notifications = parsed_json["notifications"].to_json
40
+ notifications = TrophyApiClient::NotificationPreferences.from_json(json_object: notifications)
41
+ end
42
+ new(notifications: notifications, additional_properties: struct)
43
+ end
44
+
45
+ # Serialize an instance of UserPreferencesResponse to a JSON object
46
+ #
47
+ # @return [String]
48
+ def to_json(*_args)
49
+ @_field_set&.to_json
50
+ end
51
+
52
+ # Leveraged for Union-type generation, validate_raw attempts to parse the given
53
+ # hash and check each fields type against the current object's property
54
+ # definitions.
55
+ #
56
+ # @param obj [Object]
57
+ # @return [Void]
58
+ def self.validate_raw(obj:)
59
+ TrophyApiClient::NotificationPreferences.validate_raw(obj: obj.notifications)
60
+ end
61
+ end
62
+ end
@@ -4,6 +4,8 @@ require_relative "../../requests"
4
4
  require_relative "../types/upserted_user"
5
5
  require_relative "../types/user"
6
6
  require_relative "../types/updated_user"
7
+ require_relative "../types/user_preferences_response"
8
+ require_relative "../types/notification_preferences"
7
9
  require_relative "../types/metric_response"
8
10
  require "json"
9
11
  require_relative "types/users_metric_event_summary_request_aggregation"
@@ -171,6 +173,73 @@ module TrophyApiClient
171
173
  TrophyApiClient::User.from_json(json_object: response.body)
172
174
  end
173
175
 
176
+ # Get a user's notification preferences.
177
+ #
178
+ # @param id [String] The user's ID in your database.
179
+ # @param request_options [TrophyApiClient::RequestOptions]
180
+ # @return [TrophyApiClient::UserPreferencesResponse]
181
+ # @example
182
+ # api = TrophyApiClient::Client.new(
183
+ # base_url: "https://api.example.com",
184
+ # environment: TrophyApiClient::Environment::PRODUCTION,
185
+ # api_key: "YOUR_API_KEY"
186
+ # )
187
+ # api.users.get_preferences(id: "user-123")
188
+ def get_preferences(id:, request_options: nil)
189
+ response = @request_client.conn.get do |req|
190
+ req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
191
+ req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
192
+ req.headers = {
193
+ **(req.headers || {}),
194
+ **@request_client.get_headers,
195
+ **(request_options&.additional_headers || {})
196
+ }.compact
197
+ unless request_options.nil? || request_options&.additional_query_parameters.nil?
198
+ req.params = { **(request_options&.additional_query_parameters || {}) }.compact
199
+ end
200
+ unless request_options.nil? || request_options&.additional_body_parameters.nil?
201
+ req.body = { **(request_options&.additional_body_parameters || {}) }.compact
202
+ end
203
+ req.url "#{@request_client.get_url(environment: api, request_options: request_options)}/users/#{id}/preferences"
204
+ end
205
+ TrophyApiClient::UserPreferencesResponse.from_json(json_object: response.body)
206
+ end
207
+
208
+ # Update a user's notification preferences.
209
+ #
210
+ # @param id [String] The user's ID in your database.
211
+ # @param notifications [Hash] Request of type TrophyApiClient::NotificationPreferences, as a Hash
212
+ # * :achievement_completed (Array<TrophyApiClient::NotificationChannel>)
213
+ # * :recap (Array<TrophyApiClient::NotificationChannel>)
214
+ # * :reactivation (Array<TrophyApiClient::NotificationChannel>)
215
+ # * :streak_reminder (Array<TrophyApiClient::NotificationChannel>)
216
+ # @param request_options [TrophyApiClient::RequestOptions]
217
+ # @return [TrophyApiClient::UserPreferencesResponse]
218
+ # @example
219
+ # api = TrophyApiClient::Client.new(
220
+ # base_url: "https://api.example.com",
221
+ # environment: TrophyApiClient::Environment::PRODUCTION,
222
+ # api_key: "YOUR_API_KEY"
223
+ # )
224
+ # api.users.update_preferences(id: "user-123", notifications: { streak_reminder: [EMAIL] })
225
+ def update_preferences(id:, notifications: nil, request_options: nil)
226
+ response = @request_client.conn.patch do |req|
227
+ req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
228
+ req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
229
+ req.headers = {
230
+ **(req.headers || {}),
231
+ **@request_client.get_headers,
232
+ **(request_options&.additional_headers || {})
233
+ }.compact
234
+ unless request_options.nil? || request_options&.additional_query_parameters.nil?
235
+ req.params = { **(request_options&.additional_query_parameters || {}) }.compact
236
+ end
237
+ req.body = { **(request_options&.additional_body_parameters || {}), notifications: notifications }.compact
238
+ req.url "#{@request_client.get_url(environment: api, request_options: request_options)}/users/#{id}/preferences"
239
+ end
240
+ TrophyApiClient::UserPreferencesResponse.from_json(json_object: response.body)
241
+ end
242
+
174
243
  # Get a single user's progress against all active metrics.
175
244
  #
176
245
  # @param id [String] ID of the user
@@ -697,6 +766,79 @@ module TrophyApiClient
697
766
  end
698
767
  end
699
768
 
769
+ # Get a user's notification preferences.
770
+ #
771
+ # @param id [String] The user's ID in your database.
772
+ # @param request_options [TrophyApiClient::RequestOptions]
773
+ # @return [TrophyApiClient::UserPreferencesResponse]
774
+ # @example
775
+ # api = TrophyApiClient::Client.new(
776
+ # base_url: "https://api.example.com",
777
+ # environment: TrophyApiClient::Environment::PRODUCTION,
778
+ # api_key: "YOUR_API_KEY"
779
+ # )
780
+ # api.users.get_preferences(id: "user-123")
781
+ def get_preferences(id:, request_options: nil)
782
+ Async do
783
+ response = @request_client.conn.get do |req|
784
+ req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
785
+ req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
786
+ req.headers = {
787
+ **(req.headers || {}),
788
+ **@request_client.get_headers,
789
+ **(request_options&.additional_headers || {})
790
+ }.compact
791
+ unless request_options.nil? || request_options&.additional_query_parameters.nil?
792
+ req.params = { **(request_options&.additional_query_parameters || {}) }.compact
793
+ end
794
+ unless request_options.nil? || request_options&.additional_body_parameters.nil?
795
+ req.body = { **(request_options&.additional_body_parameters || {}) }.compact
796
+ end
797
+ req.url "#{@request_client.get_url(environment: api,
798
+ request_options: request_options)}/users/#{id}/preferences"
799
+ end
800
+ TrophyApiClient::UserPreferencesResponse.from_json(json_object: response.body)
801
+ end
802
+ end
803
+
804
+ # Update a user's notification preferences.
805
+ #
806
+ # @param id [String] The user's ID in your database.
807
+ # @param notifications [Hash] Request of type TrophyApiClient::NotificationPreferences, as a Hash
808
+ # * :achievement_completed (Array<TrophyApiClient::NotificationChannel>)
809
+ # * :recap (Array<TrophyApiClient::NotificationChannel>)
810
+ # * :reactivation (Array<TrophyApiClient::NotificationChannel>)
811
+ # * :streak_reminder (Array<TrophyApiClient::NotificationChannel>)
812
+ # @param request_options [TrophyApiClient::RequestOptions]
813
+ # @return [TrophyApiClient::UserPreferencesResponse]
814
+ # @example
815
+ # api = TrophyApiClient::Client.new(
816
+ # base_url: "https://api.example.com",
817
+ # environment: TrophyApiClient::Environment::PRODUCTION,
818
+ # api_key: "YOUR_API_KEY"
819
+ # )
820
+ # api.users.update_preferences(id: "user-123", notifications: { streak_reminder: [EMAIL] })
821
+ def update_preferences(id:, notifications: nil, request_options: nil)
822
+ Async do
823
+ response = @request_client.conn.patch do |req|
824
+ req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
825
+ req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
826
+ req.headers = {
827
+ **(req.headers || {}),
828
+ **@request_client.get_headers,
829
+ **(request_options&.additional_headers || {})
830
+ }.compact
831
+ unless request_options.nil? || request_options&.additional_query_parameters.nil?
832
+ req.params = { **(request_options&.additional_query_parameters || {}) }.compact
833
+ end
834
+ req.body = { **(request_options&.additional_body_parameters || {}), notifications: notifications }.compact
835
+ req.url "#{@request_client.get_url(environment: api,
836
+ request_options: request_options)}/users/#{id}/preferences"
837
+ end
838
+ TrophyApiClient::UserPreferencesResponse.from_json(json_object: response.body)
839
+ end
840
+ end
841
+
700
842
  # Get a single user's progress against all active metrics.
701
843
  #
702
844
  # @param id [String] ID of the user
@@ -1,3 +1,3 @@
1
1
  module MyGem
2
- VERSION = "1.0.40"
2
+ VERSION = "1.0.42"
3
3
  end
data/lib/types_export.rb CHANGED
@@ -51,6 +51,10 @@ require_relative "trophy_api_client/types/metric_response"
51
51
  require_relative "trophy_api_client/types/updated_user"
52
52
  require_relative "trophy_api_client/types/upserted_user"
53
53
  require_relative "trophy_api_client/types/user"
54
+ require_relative "trophy_api_client/types/notification_channel"
55
+ require_relative "trophy_api_client/types/notification_type"
56
+ require_relative "trophy_api_client/types/notification_preferences"
57
+ require_relative "trophy_api_client/types/user_preferences_response"
54
58
  require_relative "trophy_api_client/types/error_body"
55
59
  require_relative "trophy_api_client/types/achievement_completion_response"
56
60
  require_relative "trophy_api_client/types/event_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.0.40
4
+ version: 1.0.42
5
5
  platform: ruby
6
6
  authors:
7
7
  - Trophy Labs, Inc
@@ -139,6 +139,9 @@ files:
139
139
  - lib/trophy_api_client/types/metric_event_streak_response.rb
140
140
  - lib/trophy_api_client/types/metric_response.rb
141
141
  - lib/trophy_api_client/types/metric_status.rb
142
+ - lib/trophy_api_client/types/notification_channel.rb
143
+ - lib/trophy_api_client/types/notification_preferences.rb
144
+ - lib/trophy_api_client/types/notification_type.rb
142
145
  - lib/trophy_api_client/types/points_award.rb
143
146
  - lib/trophy_api_client/types/points_range.rb
144
147
  - lib/trophy_api_client/types/points_summary_response.rb
@@ -164,6 +167,7 @@ files:
164
167
  - lib/trophy_api_client/types/user_achievement_with_stats_response.rb
165
168
  - lib/trophy_api_client/types/user_leaderboard_response.rb
166
169
  - lib/trophy_api_client/types/user_leaderboard_response_with_history.rb
170
+ - lib/trophy_api_client/types/user_preferences_response.rb
167
171
  - lib/trophy_api_client/types/webhook_user_leaderboard_response.rb
168
172
  - lib/trophy_api_client/types/webhooks_achievement_completed_payload.rb
169
173
  - lib/trophy_api_client/types/webhooks_leaderboard_changed_payload.rb
@@ -214,7 +218,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
214
218
  - !ruby/object:Gem::Version
215
219
  version: '0'
216
220
  requirements: []
217
- rubygems_version: 3.6.9
221
+ rubygems_version: 4.0.3
218
222
  specification_version: 4
219
223
  summary: Ruby library for the Trophy API.
220
224
  test_files: []