trophy_api_client 1.27.0 → 1.28.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/trophy/admin/client.rb +5 -0
- data/lib/trophy/admin/rewards/client.rb +207 -0
- data/lib/trophy/admin/rewards/triggers/client.rb +209 -0
- data/lib/trophy/admin/rewards/triggers/types/triggers_delete_request.rb +17 -0
- data/lib/trophy/admin/rewards/triggers/types/triggers_list_request.rb +19 -0
- data/lib/trophy/admin/rewards/types/rewards_delete_request.rb +13 -0
- data/lib/trophy/admin/rewards/types/rewards_list_request.rb +15 -0
- data/lib/trophy/client.rb +6 -1
- data/lib/trophy/rewards/client.rb +57 -0
- data/lib/trophy/rewards/types/rewards_redeem_request.rb +13 -0
- data/lib/trophy/types/achievement_completion_response.rb +4 -0
- data/lib/trophy/types/admin_reward.rb +28 -0
- data/lib/trophy/types/admin_reward_status.rb +12 -0
- data/lib/trophy/types/admin_reward_trigger.rb +30 -0
- data/lib/trophy/types/admin_reward_trigger_event_attributes_item.rb +11 -0
- data/lib/trophy/types/admin_reward_trigger_status.rb +12 -0
- data/lib/trophy/types/admin_reward_trigger_type.rb +14 -0
- data/lib/trophy/types/admin_reward_trigger_user_attributes_item.rb +11 -0
- data/lib/trophy/types/admin_reward_type.rb +12 -0
- data/lib/trophy/types/admin_reward_user_attributes_item.rb +11 -0
- data/lib/trophy/types/create_reward_request_item.rb +28 -0
- data/lib/trophy/types/create_reward_request_item_status.rb +12 -0
- data/lib/trophy/types/create_reward_request_item_type.rb +12 -0
- data/lib/trophy/types/create_reward_request_item_user_attributes_item.rb +11 -0
- data/lib/trophy/types/create_reward_trigger_request_item.rb +28 -0
- data/lib/trophy/types/create_reward_trigger_request_item_event_attributes_item.rb +11 -0
- data/lib/trophy/types/create_reward_trigger_request_item_status.rb +12 -0
- data/lib/trophy/types/create_reward_trigger_request_item_type.rb +14 -0
- data/lib/trophy/types/create_reward_trigger_request_item_user_attributes_item.rb +11 -0
- data/lib/trophy/types/create_reward_triggers_request.rb +23 -0
- data/lib/trophy/types/create_reward_triggers_response.rb +12 -0
- data/lib/trophy/types/create_rewards_request.rb +23 -0
- data/lib/trophy/types/create_rewards_response.rb +12 -0
- data/lib/trophy/types/created_admin_reward.rb +31 -0
- data/lib/trophy/types/delete_reward_triggers_response.rb +12 -0
- data/lib/trophy/types/delete_rewards_response.rb +12 -0
- data/lib/trophy/types/event_response.rb +2 -0
- data/lib/trophy/types/list_reward_triggers_response.rb +23 -0
- data/lib/trophy/types/list_rewards_response.rb +23 -0
- data/lib/trophy/types/points_trigger.rb +4 -0
- data/lib/trophy/types/points_trigger_type.rb +1 -0
- data/lib/trophy/types/redeem_reward_response.rb +15 -0
- data/lib/trophy/types/redeemed_reward.rb +13 -0
- data/lib/trophy/types/reward_summary.rb +23 -0
- data/lib/trophy/types/reward_summary_type.rb +12 -0
- data/lib/trophy/types/reward_webhook_event.rb +17 -0
- data/lib/trophy/types/reward_webhook_event_redemption.rb +17 -0
- data/lib/trophy/types/reward_webhook_event_type.rb +12 -0
- data/lib/trophy/types/update_reward_request_item.rb +27 -0
- data/lib/trophy/types/update_reward_request_item_status.rb +12 -0
- data/lib/trophy/types/update_reward_request_item_type.rb +12 -0
- data/lib/trophy/types/update_reward_request_item_user_attributes_item.rb +11 -0
- data/lib/trophy/types/update_reward_triggers_request.rb +23 -0
- data/lib/trophy/types/update_reward_triggers_request_item.rb +29 -0
- data/lib/trophy/types/update_reward_triggers_request_item_event_attributes_item.rb +11 -0
- data/lib/trophy/types/update_reward_triggers_request_item_status.rb +12 -0
- data/lib/trophy/types/update_reward_triggers_request_item_type.rb +14 -0
- data/lib/trophy/types/update_reward_triggers_request_item_user_attributes_item.rb +11 -0
- data/lib/trophy/types/update_reward_triggers_response.rb +12 -0
- data/lib/trophy/types/update_rewards_request.rb +23 -0
- data/lib/trophy/types/update_rewards_response.rb +12 -0
- data/lib/trophy/types/user_reward_response.rb +19 -0
- data/lib/trophy/types/user_reward_trigger.rb +25 -0
- data/lib/trophy/types/user_reward_trigger_type.rb +14 -0
- data/lib/trophy/users/client.rb +45 -0
- data/lib/trophy/users/types/users_rewards_request.rb +21 -0
- data/lib/trophy/version.rb +1 -1
- data/lib/trophy.rb +59 -0
- data/reference.md +1274 -368
- metadata +60 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8b9b801a55fb30105dc70b819d3889b53c348d6aaef675847912bcf53a6180cb
|
|
4
|
+
data.tar.gz: 7cf24c43b3d632eab7ed9ae5a1acad3285af28ffc673c4b4f92b519dd7d65476
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 49139c5bba99b6f673a4f5065ba44e052ac8ba459237af00c29076be4cf56a9b81302d44a85dec4727973cf9f7681b6b6614486ab58d5c648796f38dc9c1b1e4
|
|
7
|
+
data.tar.gz: aa0864579a800c9c66f2e6ce9671ce04ec208f3005bb7d5f77c10ecddf86fc1b059ceffbb14b0e49f2304c940d49dcb17fdd3d24f69a6691f7deff028d64940d
|
data/lib/trophy/admin/client.rb
CHANGED
|
@@ -24,6 +24,11 @@ module Trophy
|
|
|
24
24
|
@achievements ||= Trophy::Admin::Achievements::Client.new(client: @client, base_url: @base_url, environment: @environment)
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
+
# @return [Trophy::Rewards::Client]
|
|
28
|
+
def rewards
|
|
29
|
+
@rewards ||= Trophy::Admin::Rewards::Client.new(client: @client, base_url: @base_url, environment: @environment)
|
|
30
|
+
end
|
|
31
|
+
|
|
27
32
|
# @return [Trophy::Metrics::Client]
|
|
28
33
|
def metrics
|
|
29
34
|
@metrics ||= Trophy::Admin::Metrics::Client.new(client: @client, base_url: @base_url, environment: @environment)
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Trophy
|
|
4
|
+
module Admin
|
|
5
|
+
module Rewards
|
|
6
|
+
class Client
|
|
7
|
+
# @param client [Trophy::Internal::Http::RawClient]
|
|
8
|
+
# @param base_url [String, nil]
|
|
9
|
+
# @param environment [Hash[Symbol, String], nil]
|
|
10
|
+
#
|
|
11
|
+
# @return [void]
|
|
12
|
+
def initialize(client:, base_url: nil, environment: nil)
|
|
13
|
+
@client = client
|
|
14
|
+
@base_url = base_url
|
|
15
|
+
@environment = environment
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# List rewards.
|
|
19
|
+
#
|
|
20
|
+
# @param request_options [Hash]
|
|
21
|
+
# @param params [Hash]
|
|
22
|
+
# @option request_options [String] :base_url
|
|
23
|
+
# @option request_options [Hash{String => Object}] :additional_headers
|
|
24
|
+
# @option request_options [Hash{String => Object}] :additional_query_parameters
|
|
25
|
+
# @option request_options [Hash{String => Object}] :additional_body_parameters
|
|
26
|
+
# @option request_options [Integer] :timeout_in_seconds
|
|
27
|
+
# @option params [Integer, nil] :limit
|
|
28
|
+
# @option params [Integer, nil] :skip
|
|
29
|
+
#
|
|
30
|
+
# @return [Array[Trophy::Types::AdminReward]]
|
|
31
|
+
def list(request_options: {}, **params)
|
|
32
|
+
params = Trophy::Internal::Types::Utils.normalize_keys(params)
|
|
33
|
+
query_params = {}
|
|
34
|
+
query_params["limit"] = params[:limit] if params.key?(:limit)
|
|
35
|
+
query_params["skip"] = params[:skip] if params.key?(:skip)
|
|
36
|
+
|
|
37
|
+
request = Trophy::Internal::JSON::Request.new(
|
|
38
|
+
base_url: request_options[:base_url] || @base_url || @environment&.dig(:admin),
|
|
39
|
+
method: "GET",
|
|
40
|
+
path: "rewards",
|
|
41
|
+
query: query_params,
|
|
42
|
+
request_options: request_options
|
|
43
|
+
)
|
|
44
|
+
begin
|
|
45
|
+
response = @client.send(request)
|
|
46
|
+
rescue Net::HTTPRequestTimeout
|
|
47
|
+
raise Trophy::Errors::TimeoutError
|
|
48
|
+
end
|
|
49
|
+
code = response.code.to_i
|
|
50
|
+
if code.between?(200, 299)
|
|
51
|
+
Trophy::Types::ListRewardsResponse.load(response.body)
|
|
52
|
+
else
|
|
53
|
+
error_class = Trophy::Errors::ResponseError.subclass_for_code(code)
|
|
54
|
+
raise error_class.new(response.body, code: code)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# Create rewards. Optionally include triggers in each reward payload to create them alongside the reward. A
|
|
59
|
+
# reward with any invalid trigger is not created.
|
|
60
|
+
#
|
|
61
|
+
# @param request_options [Hash]
|
|
62
|
+
# @param params [Trophy::Types::CreateRewardsRequest]
|
|
63
|
+
# @option request_options [String] :base_url
|
|
64
|
+
# @option request_options [Hash{String => Object}] :additional_headers
|
|
65
|
+
# @option request_options [Hash{String => Object}] :additional_query_parameters
|
|
66
|
+
# @option request_options [Hash{String => Object}] :additional_body_parameters
|
|
67
|
+
# @option request_options [Integer] :timeout_in_seconds
|
|
68
|
+
#
|
|
69
|
+
# @return [Trophy::Types::CreateRewardsResponse]
|
|
70
|
+
def create(request_options: {}, **params)
|
|
71
|
+
params = Trophy::Internal::Types::Utils.normalize_keys(params)
|
|
72
|
+
request = Trophy::Internal::JSON::Request.new(
|
|
73
|
+
base_url: request_options[:base_url] || @base_url || @environment&.dig(:admin),
|
|
74
|
+
method: "POST",
|
|
75
|
+
path: "rewards",
|
|
76
|
+
body: params,
|
|
77
|
+
request_options: request_options
|
|
78
|
+
)
|
|
79
|
+
begin
|
|
80
|
+
response = @client.send(request)
|
|
81
|
+
rescue Net::HTTPRequestTimeout
|
|
82
|
+
raise Trophy::Errors::TimeoutError
|
|
83
|
+
end
|
|
84
|
+
code = response.code.to_i
|
|
85
|
+
if code.between?(200, 299)
|
|
86
|
+
Trophy::Types::CreateRewardsResponse.load(response.body)
|
|
87
|
+
else
|
|
88
|
+
error_class = Trophy::Errors::ResponseError.subclass_for_code(code)
|
|
89
|
+
raise error_class.new(response.body, code: code)
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# Delete rewards by ID. Maximum 100 reward IDs per request. A deleted reward's triggers are deleted too.
|
|
94
|
+
#
|
|
95
|
+
# @param request_options [Hash]
|
|
96
|
+
# @param params [Hash]
|
|
97
|
+
# @option request_options [String] :base_url
|
|
98
|
+
# @option request_options [Hash{String => Object}] :additional_headers
|
|
99
|
+
# @option request_options [Hash{String => Object}] :additional_query_parameters
|
|
100
|
+
# @option request_options [Hash{String => Object}] :additional_body_parameters
|
|
101
|
+
# @option request_options [Integer] :timeout_in_seconds
|
|
102
|
+
# @option params [String, nil] :ids
|
|
103
|
+
#
|
|
104
|
+
# @return [Trophy::Types::DeleteRewardsResponse]
|
|
105
|
+
def delete(request_options: {}, **params)
|
|
106
|
+
params = Trophy::Internal::Types::Utils.normalize_keys(params)
|
|
107
|
+
query_params = {}
|
|
108
|
+
query_params["ids"] = params[:ids] if params.key?(:ids)
|
|
109
|
+
|
|
110
|
+
request = Trophy::Internal::JSON::Request.new(
|
|
111
|
+
base_url: request_options[:base_url] || @base_url || @environment&.dig(:admin),
|
|
112
|
+
method: "DELETE",
|
|
113
|
+
path: "rewards",
|
|
114
|
+
query: query_params,
|
|
115
|
+
request_options: request_options
|
|
116
|
+
)
|
|
117
|
+
begin
|
|
118
|
+
response = @client.send(request)
|
|
119
|
+
rescue Net::HTTPRequestTimeout
|
|
120
|
+
raise Trophy::Errors::TimeoutError
|
|
121
|
+
end
|
|
122
|
+
code = response.code.to_i
|
|
123
|
+
if code.between?(200, 299)
|
|
124
|
+
Trophy::Types::DeleteRewardsResponse.load(response.body)
|
|
125
|
+
else
|
|
126
|
+
error_class = Trophy::Errors::ResponseError.subclass_for_code(code)
|
|
127
|
+
raise error_class.new(response.body, code: code)
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
# Update rewards by ID. Maximum 100 rewards per request. Only provided fields are updated; omitted fields are
|
|
132
|
+
# preserved. Use the reward triggers endpoints to change a reward's triggers.
|
|
133
|
+
#
|
|
134
|
+
# @param request_options [Hash]
|
|
135
|
+
# @param params [Trophy::Types::UpdateRewardsRequest]
|
|
136
|
+
# @option request_options [String] :base_url
|
|
137
|
+
# @option request_options [Hash{String => Object}] :additional_headers
|
|
138
|
+
# @option request_options [Hash{String => Object}] :additional_query_parameters
|
|
139
|
+
# @option request_options [Hash{String => Object}] :additional_body_parameters
|
|
140
|
+
# @option request_options [Integer] :timeout_in_seconds
|
|
141
|
+
#
|
|
142
|
+
# @return [Trophy::Types::UpdateRewardsResponse]
|
|
143
|
+
def update(request_options: {}, **params)
|
|
144
|
+
params = Trophy::Internal::Types::Utils.normalize_keys(params)
|
|
145
|
+
request = Trophy::Internal::JSON::Request.new(
|
|
146
|
+
base_url: request_options[:base_url] || @base_url || @environment&.dig(:admin),
|
|
147
|
+
method: "PATCH",
|
|
148
|
+
path: "rewards",
|
|
149
|
+
body: params,
|
|
150
|
+
request_options: request_options
|
|
151
|
+
)
|
|
152
|
+
begin
|
|
153
|
+
response = @client.send(request)
|
|
154
|
+
rescue Net::HTTPRequestTimeout
|
|
155
|
+
raise Trophy::Errors::TimeoutError
|
|
156
|
+
end
|
|
157
|
+
code = response.code.to_i
|
|
158
|
+
if code.between?(200, 299)
|
|
159
|
+
Trophy::Types::UpdateRewardsResponse.load(response.body)
|
|
160
|
+
else
|
|
161
|
+
error_class = Trophy::Errors::ResponseError.subclass_for_code(code)
|
|
162
|
+
raise error_class.new(response.body, code: code)
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
# Get a reward by ID.
|
|
167
|
+
#
|
|
168
|
+
# @param request_options [Hash]
|
|
169
|
+
# @param params [Hash]
|
|
170
|
+
# @option request_options [String] :base_url
|
|
171
|
+
# @option request_options [Hash{String => Object}] :additional_headers
|
|
172
|
+
# @option request_options [Hash{String => Object}] :additional_query_parameters
|
|
173
|
+
# @option request_options [Hash{String => Object}] :additional_body_parameters
|
|
174
|
+
# @option request_options [Integer] :timeout_in_seconds
|
|
175
|
+
# @option params [String] :id
|
|
176
|
+
#
|
|
177
|
+
# @return [Trophy::Types::AdminReward]
|
|
178
|
+
def get(request_options: {}, **params)
|
|
179
|
+
params = Trophy::Internal::Types::Utils.normalize_keys(params)
|
|
180
|
+
request = Trophy::Internal::JSON::Request.new(
|
|
181
|
+
base_url: request_options[:base_url] || @base_url || @environment&.dig(:admin),
|
|
182
|
+
method: "GET",
|
|
183
|
+
path: "rewards/#{URI.encode_uri_component(params[:id].to_s)}",
|
|
184
|
+
request_options: request_options
|
|
185
|
+
)
|
|
186
|
+
begin
|
|
187
|
+
response = @client.send(request)
|
|
188
|
+
rescue Net::HTTPRequestTimeout
|
|
189
|
+
raise Trophy::Errors::TimeoutError
|
|
190
|
+
end
|
|
191
|
+
code = response.code.to_i
|
|
192
|
+
if code.between?(200, 299)
|
|
193
|
+
Trophy::Types::AdminReward.load(response.body)
|
|
194
|
+
else
|
|
195
|
+
error_class = Trophy::Errors::ResponseError.subclass_for_code(code)
|
|
196
|
+
raise error_class.new(response.body, code: code)
|
|
197
|
+
end
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
# @return [Trophy::Triggers::Client]
|
|
201
|
+
def triggers
|
|
202
|
+
@triggers ||= Trophy::Admin::Rewards::Triggers::Client.new(client: @client, base_url: @base_url, environment: @environment)
|
|
203
|
+
end
|
|
204
|
+
end
|
|
205
|
+
end
|
|
206
|
+
end
|
|
207
|
+
end
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Trophy
|
|
4
|
+
module Admin
|
|
5
|
+
module Rewards
|
|
6
|
+
module Triggers
|
|
7
|
+
class Client
|
|
8
|
+
# @param client [Trophy::Internal::Http::RawClient]
|
|
9
|
+
# @param base_url [String, nil]
|
|
10
|
+
# @param environment [Hash[Symbol, String], nil]
|
|
11
|
+
#
|
|
12
|
+
# @return [void]
|
|
13
|
+
def initialize(client:, base_url: nil, environment: nil)
|
|
14
|
+
@client = client
|
|
15
|
+
@base_url = base_url
|
|
16
|
+
@environment = environment
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# List triggers for a reward. Active triggers are listed first.
|
|
20
|
+
#
|
|
21
|
+
# @param request_options [Hash]
|
|
22
|
+
# @param params [Hash]
|
|
23
|
+
# @option request_options [String] :base_url
|
|
24
|
+
# @option request_options [Hash{String => Object}] :additional_headers
|
|
25
|
+
# @option request_options [Hash{String => Object}] :additional_query_parameters
|
|
26
|
+
# @option request_options [Hash{String => Object}] :additional_body_parameters
|
|
27
|
+
# @option request_options [Integer] :timeout_in_seconds
|
|
28
|
+
# @option params [String] :reward_id
|
|
29
|
+
# @option params [Integer, nil] :limit
|
|
30
|
+
# @option params [Integer, nil] :skip
|
|
31
|
+
#
|
|
32
|
+
# @return [Array[Trophy::Types::AdminRewardTrigger]]
|
|
33
|
+
def list(request_options: {}, **params)
|
|
34
|
+
params = Trophy::Internal::Types::Utils.normalize_keys(params)
|
|
35
|
+
query_params = {}
|
|
36
|
+
query_params["limit"] = params[:limit] if params.key?(:limit)
|
|
37
|
+
query_params["skip"] = params[:skip] if params.key?(:skip)
|
|
38
|
+
|
|
39
|
+
request = Trophy::Internal::JSON::Request.new(
|
|
40
|
+
base_url: request_options[:base_url] || @base_url || @environment&.dig(:admin),
|
|
41
|
+
method: "GET",
|
|
42
|
+
path: "rewards/#{URI.encode_uri_component(params[:reward_id].to_s)}/triggers",
|
|
43
|
+
query: query_params,
|
|
44
|
+
request_options: request_options
|
|
45
|
+
)
|
|
46
|
+
begin
|
|
47
|
+
response = @client.send(request)
|
|
48
|
+
rescue Net::HTTPRequestTimeout
|
|
49
|
+
raise Trophy::Errors::TimeoutError
|
|
50
|
+
end
|
|
51
|
+
code = response.code.to_i
|
|
52
|
+
if code.between?(200, 299)
|
|
53
|
+
Trophy::Types::ListRewardTriggersResponse.load(response.body)
|
|
54
|
+
else
|
|
55
|
+
error_class = Trophy::Errors::ResponseError.subclass_for_code(code)
|
|
56
|
+
raise error_class.new(response.body, code: code)
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# Create reward triggers in bulk. Maximum 100 triggers per request.
|
|
61
|
+
#
|
|
62
|
+
# @param request_options [Hash]
|
|
63
|
+
# @param params [Trophy::Types::CreateRewardTriggersRequest]
|
|
64
|
+
# @option request_options [String] :base_url
|
|
65
|
+
# @option request_options [Hash{String => Object}] :additional_headers
|
|
66
|
+
# @option request_options [Hash{String => Object}] :additional_query_parameters
|
|
67
|
+
# @option request_options [Hash{String => Object}] :additional_body_parameters
|
|
68
|
+
# @option request_options [Integer] :timeout_in_seconds
|
|
69
|
+
# @option params [String] :reward_id
|
|
70
|
+
#
|
|
71
|
+
# @return [Trophy::Types::CreateRewardTriggersResponse]
|
|
72
|
+
def create(request_options: {}, **params)
|
|
73
|
+
params = Trophy::Internal::Types::Utils.normalize_keys(params)
|
|
74
|
+
request = Trophy::Internal::JSON::Request.new(
|
|
75
|
+
base_url: request_options[:base_url] || @base_url || @environment&.dig(:admin),
|
|
76
|
+
method: "POST",
|
|
77
|
+
path: "rewards/#{URI.encode_uri_component(params[:reward_id].to_s)}/triggers",
|
|
78
|
+
body: params,
|
|
79
|
+
request_options: request_options
|
|
80
|
+
)
|
|
81
|
+
begin
|
|
82
|
+
response = @client.send(request)
|
|
83
|
+
rescue Net::HTTPRequestTimeout
|
|
84
|
+
raise Trophy::Errors::TimeoutError
|
|
85
|
+
end
|
|
86
|
+
code = response.code.to_i
|
|
87
|
+
if code.between?(200, 299)
|
|
88
|
+
Trophy::Types::CreateRewardTriggersResponse.load(response.body)
|
|
89
|
+
else
|
|
90
|
+
error_class = Trophy::Errors::ResponseError.subclass_for_code(code)
|
|
91
|
+
raise error_class.new(response.body, code: code)
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# Delete reward triggers by ID. Maximum 100 trigger IDs per request. A reward with no triggers is not awarded
|
|
96
|
+
# until a trigger is added.
|
|
97
|
+
#
|
|
98
|
+
# @param request_options [Hash]
|
|
99
|
+
# @param params [Hash]
|
|
100
|
+
# @option request_options [String] :base_url
|
|
101
|
+
# @option request_options [Hash{String => Object}] :additional_headers
|
|
102
|
+
# @option request_options [Hash{String => Object}] :additional_query_parameters
|
|
103
|
+
# @option request_options [Hash{String => Object}] :additional_body_parameters
|
|
104
|
+
# @option request_options [Integer] :timeout_in_seconds
|
|
105
|
+
# @option params [String] :reward_id
|
|
106
|
+
# @option params [String, nil] :ids
|
|
107
|
+
#
|
|
108
|
+
# @return [Trophy::Types::DeleteRewardTriggersResponse]
|
|
109
|
+
def delete(request_options: {}, **params)
|
|
110
|
+
params = Trophy::Internal::Types::Utils.normalize_keys(params)
|
|
111
|
+
query_params = {}
|
|
112
|
+
query_params["ids"] = params[:ids] if params.key?(:ids)
|
|
113
|
+
|
|
114
|
+
request = Trophy::Internal::JSON::Request.new(
|
|
115
|
+
base_url: request_options[:base_url] || @base_url || @environment&.dig(:admin),
|
|
116
|
+
method: "DELETE",
|
|
117
|
+
path: "rewards/#{URI.encode_uri_component(params[:reward_id].to_s)}/triggers",
|
|
118
|
+
query: query_params,
|
|
119
|
+
request_options: request_options
|
|
120
|
+
)
|
|
121
|
+
begin
|
|
122
|
+
response = @client.send(request)
|
|
123
|
+
rescue Net::HTTPRequestTimeout
|
|
124
|
+
raise Trophy::Errors::TimeoutError
|
|
125
|
+
end
|
|
126
|
+
code = response.code.to_i
|
|
127
|
+
if code.between?(200, 299)
|
|
128
|
+
Trophy::Types::DeleteRewardTriggersResponse.load(response.body)
|
|
129
|
+
else
|
|
130
|
+
error_class = Trophy::Errors::ResponseError.subclass_for_code(code)
|
|
131
|
+
raise error_class.new(response.body, code: code)
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
# Update reward triggers in bulk. Maximum 100 triggers per request. Only provided fields are updated; omitted
|
|
136
|
+
# fields are preserved. A trigger keeps its ID when its criteria change.
|
|
137
|
+
#
|
|
138
|
+
# @param request_options [Hash]
|
|
139
|
+
# @param params [Trophy::Types::UpdateRewardTriggersRequest]
|
|
140
|
+
# @option request_options [String] :base_url
|
|
141
|
+
# @option request_options [Hash{String => Object}] :additional_headers
|
|
142
|
+
# @option request_options [Hash{String => Object}] :additional_query_parameters
|
|
143
|
+
# @option request_options [Hash{String => Object}] :additional_body_parameters
|
|
144
|
+
# @option request_options [Integer] :timeout_in_seconds
|
|
145
|
+
# @option params [String] :reward_id
|
|
146
|
+
#
|
|
147
|
+
# @return [Trophy::Types::UpdateRewardTriggersResponse]
|
|
148
|
+
def update(request_options: {}, **params)
|
|
149
|
+
params = Trophy::Internal::Types::Utils.normalize_keys(params)
|
|
150
|
+
request = Trophy::Internal::JSON::Request.new(
|
|
151
|
+
base_url: request_options[:base_url] || @base_url || @environment&.dig(:admin),
|
|
152
|
+
method: "PATCH",
|
|
153
|
+
path: "rewards/#{URI.encode_uri_component(params[:reward_id].to_s)}/triggers",
|
|
154
|
+
body: params,
|
|
155
|
+
request_options: request_options
|
|
156
|
+
)
|
|
157
|
+
begin
|
|
158
|
+
response = @client.send(request)
|
|
159
|
+
rescue Net::HTTPRequestTimeout
|
|
160
|
+
raise Trophy::Errors::TimeoutError
|
|
161
|
+
end
|
|
162
|
+
code = response.code.to_i
|
|
163
|
+
if code.between?(200, 299)
|
|
164
|
+
Trophy::Types::UpdateRewardTriggersResponse.load(response.body)
|
|
165
|
+
else
|
|
166
|
+
error_class = Trophy::Errors::ResponseError.subclass_for_code(code)
|
|
167
|
+
raise error_class.new(response.body, code: code)
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
# Get a single reward trigger by ID.
|
|
172
|
+
#
|
|
173
|
+
# @param request_options [Hash]
|
|
174
|
+
# @param params [Hash]
|
|
175
|
+
# @option request_options [String] :base_url
|
|
176
|
+
# @option request_options [Hash{String => Object}] :additional_headers
|
|
177
|
+
# @option request_options [Hash{String => Object}] :additional_query_parameters
|
|
178
|
+
# @option request_options [Hash{String => Object}] :additional_body_parameters
|
|
179
|
+
# @option request_options [Integer] :timeout_in_seconds
|
|
180
|
+
# @option params [String] :reward_id
|
|
181
|
+
# @option params [String] :id
|
|
182
|
+
#
|
|
183
|
+
# @return [Trophy::Types::AdminRewardTrigger]
|
|
184
|
+
def get(request_options: {}, **params)
|
|
185
|
+
params = Trophy::Internal::Types::Utils.normalize_keys(params)
|
|
186
|
+
request = Trophy::Internal::JSON::Request.new(
|
|
187
|
+
base_url: request_options[:base_url] || @base_url || @environment&.dig(:admin),
|
|
188
|
+
method: "GET",
|
|
189
|
+
path: "rewards/#{URI.encode_uri_component(params[:reward_id].to_s)}/triggers/#{URI.encode_uri_component(params[:id].to_s)}",
|
|
190
|
+
request_options: request_options
|
|
191
|
+
)
|
|
192
|
+
begin
|
|
193
|
+
response = @client.send(request)
|
|
194
|
+
rescue Net::HTTPRequestTimeout
|
|
195
|
+
raise Trophy::Errors::TimeoutError
|
|
196
|
+
end
|
|
197
|
+
code = response.code.to_i
|
|
198
|
+
if code.between?(200, 299)
|
|
199
|
+
Trophy::Types::AdminRewardTrigger.load(response.body)
|
|
200
|
+
else
|
|
201
|
+
error_class = Trophy::Errors::ResponseError.subclass_for_code(code)
|
|
202
|
+
raise error_class.new(response.body, code: code)
|
|
203
|
+
end
|
|
204
|
+
end
|
|
205
|
+
end
|
|
206
|
+
end
|
|
207
|
+
end
|
|
208
|
+
end
|
|
209
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Trophy
|
|
4
|
+
module Admin
|
|
5
|
+
module Rewards
|
|
6
|
+
module Triggers
|
|
7
|
+
module Types
|
|
8
|
+
class TriggersDeleteRequest < Internal::Types::Model
|
|
9
|
+
field :reward_id, -> { String }, optional: false, nullable: false, api_name: "rewardId"
|
|
10
|
+
|
|
11
|
+
field :ids, -> { String }, optional: true, nullable: false
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Trophy
|
|
4
|
+
module Admin
|
|
5
|
+
module Rewards
|
|
6
|
+
module Triggers
|
|
7
|
+
module Types
|
|
8
|
+
class TriggersListRequest < Internal::Types::Model
|
|
9
|
+
field :reward_id, -> { String }, optional: false, nullable: false, api_name: "rewardId"
|
|
10
|
+
|
|
11
|
+
field :limit, -> { Integer }, optional: true, nullable: false
|
|
12
|
+
|
|
13
|
+
field :skip, -> { Integer }, optional: true, nullable: false
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Trophy
|
|
4
|
+
module Admin
|
|
5
|
+
module Rewards
|
|
6
|
+
module Types
|
|
7
|
+
class RewardsListRequest < Internal::Types::Model
|
|
8
|
+
field :limit, -> { Integer }, optional: true, nullable: false
|
|
9
|
+
|
|
10
|
+
field :skip, -> { Integer }, optional: true, nullable: false
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
data/lib/trophy/client.rb
CHANGED
|
@@ -9,7 +9,7 @@ module Trophy
|
|
|
9
9
|
# @param max_retries [Integer]
|
|
10
10
|
#
|
|
11
11
|
# @return [void]
|
|
12
|
-
def initialize(api_key:, base_url: nil, environment: Trophy::Environment::PRODUCTION, sdk_version: "1.
|
|
12
|
+
def initialize(api_key:, base_url: nil, environment: Trophy::Environment::PRODUCTION, sdk_version: "1.28.0", max_retries: 2)
|
|
13
13
|
@base_url = base_url
|
|
14
14
|
@environment = environment
|
|
15
15
|
|
|
@@ -29,6 +29,11 @@ module Trophy
|
|
|
29
29
|
@achievements ||= Trophy::Achievements::Client.new(client: @raw_client, base_url: @base_url, environment: @environment)
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
+
# @return [Trophy::Rewards::Client]
|
|
33
|
+
def rewards
|
|
34
|
+
@rewards ||= Trophy::Rewards::Client.new(client: @raw_client, base_url: @base_url, environment: @environment)
|
|
35
|
+
end
|
|
36
|
+
|
|
32
37
|
# @return [Trophy::Metrics::Client]
|
|
33
38
|
def metrics
|
|
34
39
|
@metrics ||= Trophy::Metrics::Client.new(client: @raw_client, base_url: @base_url, environment: @environment)
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Trophy
|
|
4
|
+
module Rewards
|
|
5
|
+
class Client
|
|
6
|
+
# @param client [Trophy::Internal::Http::RawClient]
|
|
7
|
+
# @param base_url [String, nil]
|
|
8
|
+
# @param environment [Hash[Symbol, String], nil]
|
|
9
|
+
#
|
|
10
|
+
# @return [void]
|
|
11
|
+
def initialize(client:, base_url: nil, environment: nil)
|
|
12
|
+
@client = client
|
|
13
|
+
@base_url = base_url
|
|
14
|
+
@environment = environment
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Redeem a reward for a user.
|
|
18
|
+
#
|
|
19
|
+
# @param request_options [Hash]
|
|
20
|
+
# @param params [Trophy::Rewards::Types::RewardsRedeemRequest]
|
|
21
|
+
# @option request_options [String] :base_url
|
|
22
|
+
# @option request_options [Hash{String => Object}] :additional_headers
|
|
23
|
+
# @option request_options [Hash{String => Object}] :additional_query_parameters
|
|
24
|
+
# @option request_options [Hash{String => Object}] :additional_body_parameters
|
|
25
|
+
# @option request_options [Integer] :timeout_in_seconds
|
|
26
|
+
# @option params [String] :key
|
|
27
|
+
#
|
|
28
|
+
# @return [Trophy::Types::RedeemRewardResponse]
|
|
29
|
+
def redeem(request_options: {}, **params)
|
|
30
|
+
params = Trophy::Internal::Types::Utils.normalize_keys(params)
|
|
31
|
+
request_data = Trophy::Rewards::Types::RewardsRedeemRequest.new(params).to_h
|
|
32
|
+
non_body_param_names = %w[key]
|
|
33
|
+
body = request_data.except(*non_body_param_names)
|
|
34
|
+
|
|
35
|
+
request = Trophy::Internal::JSON::Request.new(
|
|
36
|
+
base_url: request_options[:base_url] || @base_url || @environment&.dig(:api),
|
|
37
|
+
method: "POST",
|
|
38
|
+
path: "rewards/#{URI.encode_uri_component(params[:key].to_s)}/redeem",
|
|
39
|
+
body: body,
|
|
40
|
+
request_options: request_options
|
|
41
|
+
)
|
|
42
|
+
begin
|
|
43
|
+
response = @client.send(request)
|
|
44
|
+
rescue Net::HTTPRequestTimeout
|
|
45
|
+
raise Trophy::Errors::TimeoutError
|
|
46
|
+
end
|
|
47
|
+
code = response.code.to_i
|
|
48
|
+
if code.between?(200, 299)
|
|
49
|
+
Trophy::Types::RedeemRewardResponse.load(response.body)
|
|
50
|
+
else
|
|
51
|
+
error_class = Trophy::Errors::ResponseError.subclass_for_code(code)
|
|
52
|
+
raise error_class.new(response.body, code: code)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Trophy
|
|
4
|
+
module Rewards
|
|
5
|
+
module Types
|
|
6
|
+
class RewardsRedeemRequest < Internal::Types::Model
|
|
7
|
+
field :key, -> { String }, optional: false, nullable: false
|
|
8
|
+
|
|
9
|
+
field :user, -> { Trophy::Types::UpsertedUser }, optional: false, nullable: false
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -8,6 +8,10 @@ module Trophy
|
|
|
8
8
|
field :achievement, -> { Trophy::Types::UserAchievementResponse }, optional: false, nullable: false
|
|
9
9
|
|
|
10
10
|
field :points, -> { Internal::Types::Hash[String, Trophy::Types::MetricEventPointsResponse] }, optional: false, nullable: false
|
|
11
|
+
|
|
12
|
+
field :leaderboards, -> { Internal::Types::Hash[String, Trophy::Types::MetricEventLeaderboardResponse] }, optional: false, nullable: false
|
|
13
|
+
|
|
14
|
+
field :rewards, -> { Internal::Types::Array[Trophy::Types::UserRewardResponse] }, optional: false, nullable: false
|
|
11
15
|
end
|
|
12
16
|
end
|
|
13
17
|
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Trophy
|
|
4
|
+
module Types
|
|
5
|
+
# A reward returned from the admin rewards endpoints.
|
|
6
|
+
class AdminReward < Internal::Types::Model
|
|
7
|
+
field :id, -> { String }, optional: false, nullable: false
|
|
8
|
+
|
|
9
|
+
field :name, -> { String }, optional: false, nullable: false
|
|
10
|
+
|
|
11
|
+
field :key, -> { String }, optional: false, nullable: false
|
|
12
|
+
|
|
13
|
+
field :description, -> { String }, optional: true, nullable: false
|
|
14
|
+
|
|
15
|
+
field :status, -> { Trophy::Types::AdminRewardStatus }, optional: false, nullable: false
|
|
16
|
+
|
|
17
|
+
field :type, -> { Trophy::Types::AdminRewardType }, optional: false, nullable: false
|
|
18
|
+
|
|
19
|
+
field :points_system_id, -> { String }, optional: true, nullable: false, api_name: "pointsSystemId"
|
|
20
|
+
|
|
21
|
+
field :points, -> { Integer }, optional: true, nullable: false
|
|
22
|
+
|
|
23
|
+
field :max_redemptions, -> { Integer }, optional: true, nullable: false, api_name: "maxRedemptions"
|
|
24
|
+
|
|
25
|
+
field :user_attributes, -> { Internal::Types::Array[Trophy::Types::AdminRewardUserAttributesItem] }, optional: false, nullable: false, api_name: "userAttributes"
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|