Skip to content

Commit c7e3f5f

Browse files
Automatically update Ruby SDK
1 parent 179f143 commit c7e3f5f

8 files changed

Lines changed: 319 additions & 2 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.0.40"
5+
VERSION = "1.0.42"
66
AUTHORS = ["Trophy Labs, Inc"].freeze
77
EMAIL = ""
88
SUMMARY = "Ruby library for the Trophy API."
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
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+
# 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
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

lib/trophy_api_client/users/client.rb

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
require_relative "../types/upserted_user"
55
require_relative "../types/user"
66
require_relative "../types/updated_user"
7+
require_relative "../types/user_preferences_response"
8+
require_relative "../types/notification_preferences"
79
require_relative "../types/metric_response"
810
require "json"
911
require_relative "types/users_metric_event_summary_request_aggregation"
@@ -171,6 +173,73 @@ def update(id:, request:, request_options: nil)
171173
TrophyApiClient::User.from_json(json_object: response.body)
172174
end
173175

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+
174243
# Get a single user's progress against all active metrics.
175244
#
176245
# @param id [String] ID of the user
@@ -697,6 +766,79 @@ def update(id:, request:, request_options: nil)
697766
end
698767
end
699768

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+
700842
# Get a single user's progress against all active metrics.
701843
#
702844
# @param id [String] ID of the user

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.0.40"
2+
VERSION = "1.0.42"
33
end

lib/types_export.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@
5151
require_relative "trophy_api_client/types/updated_user"
5252
require_relative "trophy_api_client/types/upserted_user"
5353
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"
5458
require_relative "trophy_api_client/types/error_body"
5559
require_relative "trophy_api_client/types/achievement_completion_response"
5660
require_relative "trophy_api_client/types/event_response"

0 commit comments

Comments
 (0)