Skip to content

Commit 2e4c49e

Browse files
Automatically update Ruby SDK
1 parent 177bc2f commit 2e4c49e

24 files changed

Lines changed: 1171 additions & 31 deletions

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.10"
5+
VERSION = "1.0.11"
66
AUTHORS = ["Trophy Labs, Inc"].freeze
77
EMAIL = ""
88
SUMMARY = "Ruby library for the Trophy API."

lib/trophy_api_client.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
require_relative "trophy_api_client/achievements/client"
77
require_relative "trophy_api_client/metrics/client"
88
require_relative "trophy_api_client/users/client"
9+
require_relative "trophy_api_client/points/client"
910

1011
module TrophyApiClient
1112
class Client
@@ -15,6 +16,8 @@ class Client
1516
attr_reader :metrics
1617
# @return [TrophyApiClient::UsersClient]
1718
attr_reader :users
19+
# @return [TrophyApiClient::PointsClient]
20+
attr_reader :points
1821

1922
# @param base_url [String]
2023
# @param environment [TrophyApiClient::Environment]
@@ -34,6 +37,7 @@ def initialize(api_key:, base_url: nil, environment: TrophyApiClient::Environmen
3437
@achievements = TrophyApiClient::AchievementsClient.new(request_client: @request_client)
3538
@metrics = TrophyApiClient::MetricsClient.new(request_client: @request_client)
3639
@users = TrophyApiClient::UsersClient.new(request_client: @request_client)
40+
@points = TrophyApiClient::PointsClient.new(request_client: @request_client)
3741
end
3842
end
3943

@@ -44,6 +48,8 @@ class AsyncClient
4448
attr_reader :metrics
4549
# @return [TrophyApiClient::AsyncUsersClient]
4650
attr_reader :users
51+
# @return [TrophyApiClient::AsyncPointsClient]
52+
attr_reader :points
4753

4854
# @param base_url [String]
4955
# @param environment [TrophyApiClient::Environment]
@@ -63,6 +69,7 @@ def initialize(api_key:, base_url: nil, environment: TrophyApiClient::Environmen
6369
@achievements = TrophyApiClient::AsyncAchievementsClient.new(request_client: @async_request_client)
6470
@metrics = TrophyApiClient::AsyncMetricsClient.new(request_client: @async_request_client)
6571
@users = TrophyApiClient::AsyncUsersClient.new(request_client: @async_request_client)
72+
@points = TrophyApiClient::AsyncPointsClient.new(request_client: @async_request_client)
6673
end
6774
end
6875
end
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
# frozen_string_literal: true
2+
3+
require_relative "../../requests"
4+
require_relative "../types/points_summary_response"
5+
require "json"
6+
require_relative "../types/points_trigger_response"
7+
require "async"
8+
9+
module TrophyApiClient
10+
class PointsClient
11+
# @return [TrophyApiClient::RequestClient]
12+
attr_reader :request_client
13+
14+
# @param request_client [TrophyApiClient::RequestClient]
15+
# @return [TrophyApiClient::PointsClient]
16+
def initialize(request_client:)
17+
@request_client = request_client
18+
end
19+
20+
# Get a breakdown of the number of users with points in each range.
21+
#
22+
# @param request_options [TrophyApiClient::RequestOptions]
23+
# @return [TrophyApiClient::POINTS_SUMMARY_RESPONSE]
24+
# @example
25+
# api = TrophyApiClient::Client.new(
26+
# base_url: "https://api.example.com",
27+
# environment: TrophyApiClient::Environment::DEFAULT,
28+
# api_key: "YOUR_API_KEY"
29+
# )
30+
# api.points.summary
31+
def summary(request_options: nil)
32+
response = @request_client.conn.get do |req|
33+
req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
34+
req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
35+
req.headers = {
36+
**(req.headers || {}),
37+
**@request_client.get_headers,
38+
**(request_options&.additional_headers || {})
39+
}.compact
40+
unless request_options.nil? || request_options&.additional_query_parameters.nil?
41+
req.params = { **(request_options&.additional_query_parameters || {}) }.compact
42+
end
43+
unless request_options.nil? || request_options&.additional_body_parameters.nil?
44+
req.body = { **(request_options&.additional_body_parameters || {}) }.compact
45+
end
46+
req.url "#{@request_client.get_url(request_options: request_options)}/points/summary"
47+
end
48+
parsed_json = JSON.parse(response.body)
49+
parsed_json&.map do |item|
50+
item = item.to_json
51+
TrophyApiClient::PointsRange.from_json(json_object: item)
52+
end
53+
end
54+
55+
# Get all points triggers.
56+
#
57+
# @param request_options [TrophyApiClient::RequestOptions]
58+
# @return [Array<TrophyApiClient::PointsTriggerResponse>]
59+
# @example
60+
# api = TrophyApiClient::Client.new(
61+
# base_url: "https://api.example.com",
62+
# environment: TrophyApiClient::Environment::DEFAULT,
63+
# api_key: "YOUR_API_KEY"
64+
# )
65+
# api.points.triggers
66+
def triggers(request_options: nil)
67+
response = @request_client.conn.get do |req|
68+
req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
69+
req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
70+
req.headers = {
71+
**(req.headers || {}),
72+
**@request_client.get_headers,
73+
**(request_options&.additional_headers || {})
74+
}.compact
75+
unless request_options.nil? || request_options&.additional_query_parameters.nil?
76+
req.params = { **(request_options&.additional_query_parameters || {}) }.compact
77+
end
78+
unless request_options.nil? || request_options&.additional_body_parameters.nil?
79+
req.body = { **(request_options&.additional_body_parameters || {}) }.compact
80+
end
81+
req.url "#{@request_client.get_url(request_options: request_options)}/points/triggers"
82+
end
83+
parsed_json = JSON.parse(response.body)
84+
parsed_json&.map do |item|
85+
item = item.to_json
86+
TrophyApiClient::PointsTriggerResponse.from_json(json_object: item)
87+
end
88+
end
89+
end
90+
91+
class AsyncPointsClient
92+
# @return [TrophyApiClient::AsyncRequestClient]
93+
attr_reader :request_client
94+
95+
# @param request_client [TrophyApiClient::AsyncRequestClient]
96+
# @return [TrophyApiClient::AsyncPointsClient]
97+
def initialize(request_client:)
98+
@request_client = request_client
99+
end
100+
101+
# Get a breakdown of the number of users with points in each range.
102+
#
103+
# @param request_options [TrophyApiClient::RequestOptions]
104+
# @return [TrophyApiClient::POINTS_SUMMARY_RESPONSE]
105+
# @example
106+
# api = TrophyApiClient::Client.new(
107+
# base_url: "https://api.example.com",
108+
# environment: TrophyApiClient::Environment::DEFAULT,
109+
# api_key: "YOUR_API_KEY"
110+
# )
111+
# api.points.summary
112+
def summary(request_options: nil)
113+
Async do
114+
response = @request_client.conn.get do |req|
115+
req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
116+
req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
117+
req.headers = {
118+
**(req.headers || {}),
119+
**@request_client.get_headers,
120+
**(request_options&.additional_headers || {})
121+
}.compact
122+
unless request_options.nil? || request_options&.additional_query_parameters.nil?
123+
req.params = { **(request_options&.additional_query_parameters || {}) }.compact
124+
end
125+
unless request_options.nil? || request_options&.additional_body_parameters.nil?
126+
req.body = { **(request_options&.additional_body_parameters || {}) }.compact
127+
end
128+
req.url "#{@request_client.get_url(request_options: request_options)}/points/summary"
129+
end
130+
parsed_json = JSON.parse(response.body)
131+
parsed_json&.map do |item|
132+
item = item.to_json
133+
TrophyApiClient::PointsRange.from_json(json_object: item)
134+
end
135+
end
136+
end
137+
138+
# Get all points triggers.
139+
#
140+
# @param request_options [TrophyApiClient::RequestOptions]
141+
# @return [Array<TrophyApiClient::PointsTriggerResponse>]
142+
# @example
143+
# api = TrophyApiClient::Client.new(
144+
# base_url: "https://api.example.com",
145+
# environment: TrophyApiClient::Environment::DEFAULT,
146+
# api_key: "YOUR_API_KEY"
147+
# )
148+
# api.points.triggers
149+
def triggers(request_options: nil)
150+
Async do
151+
response = @request_client.conn.get do |req|
152+
req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
153+
req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
154+
req.headers = {
155+
**(req.headers || {}),
156+
**@request_client.get_headers,
157+
**(request_options&.additional_headers || {})
158+
}.compact
159+
unless request_options.nil? || request_options&.additional_query_parameters.nil?
160+
req.params = { **(request_options&.additional_query_parameters || {}) }.compact
161+
end
162+
unless request_options.nil? || request_options&.additional_body_parameters.nil?
163+
req.body = { **(request_options&.additional_body_parameters || {}) }.compact
164+
end
165+
req.url "#{@request_client.get_url(request_options: request_options)}/points/triggers"
166+
end
167+
parsed_json = JSON.parse(response.body)
168+
parsed_json&.map do |item|
169+
item = item.to_json
170+
TrophyApiClient::PointsTriggerResponse.from_json(json_object: item)
171+
end
172+
end
173+
end
174+
end
175+
end

lib/trophy_api_client/types/achievement_response.rb

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# frozen_string_literal: true
22

3+
require_relative "achievement_response_trigger"
4+
require_relative "metric_event_streak_response"
35
require "ostruct"
46
require "json"
57

@@ -9,7 +11,7 @@ class AchievementResponse
911
attr_reader :id
1012
# @return [String] The name of this achievement.
1113
attr_reader :name
12-
# @return [String] The trigger of the achievement, either 'metric', 'streak', or 'api'.
14+
# @return [TrophyApiClient::AchievementResponseTrigger] The trigger of the achievement.
1315
attr_reader :trigger
1416
# @return [String] The description of this achievement.
1517
attr_reader :description
@@ -30,6 +32,8 @@ class AchievementResponse
3032
# @return [String] The name of the metric associated with this achievement (only applicable if
3133
# trigger = 'metric')
3234
attr_reader :metric_name
35+
# @return [TrophyApiClient::MetricEventStreakResponse] The user's current streak for the metric, if the metric has streaks enabled.
36+
attr_reader :current_streak
3337
# @return [OpenStruct] Additional properties unmapped to the current class definition
3438
attr_reader :additional_properties
3539
# @return [Object]
@@ -40,7 +44,7 @@ class AchievementResponse
4044

4145
# @param id [String] The unique ID of the achievement.
4246
# @param name [String] The name of this achievement.
43-
# @param trigger [String] The trigger of the achievement, either 'metric', 'streak', or 'api'.
47+
# @param trigger [TrophyApiClient::AchievementResponseTrigger] The trigger of the achievement.
4448
# @param description [String] The description of this achievement.
4549
# @param badge_url [String] The URL of the badge image for the achievement, if one has been uploaded.
4650
# @param key [String] The key used to reference this achievement in the API (only applicable if
@@ -53,10 +57,11 @@ class AchievementResponse
5357
# trigger = 'metric')
5458
# @param metric_name [String] The name of the metric associated with this achievement (only applicable if
5559
# trigger = 'metric')
60+
# @param current_streak [TrophyApiClient::MetricEventStreakResponse] The user's current streak for the metric, if the metric has streaks enabled.
5661
# @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
5762
# @return [TrophyApiClient::AchievementResponse]
5863
def initialize(id:, name:, trigger:, description: OMIT, badge_url: OMIT, key: OMIT, streak_length: OMIT,
59-
metric_id: OMIT, metric_value: OMIT, metric_name: OMIT, additional_properties: nil)
64+
metric_id: OMIT, metric_value: OMIT, metric_name: OMIT, current_streak: OMIT, additional_properties: nil)
6065
@id = id
6166
@name = name
6267
@trigger = trigger
@@ -67,6 +72,7 @@ def initialize(id:, name:, trigger:, description: OMIT, badge_url: OMIT, key: OM
6772
@metric_id = metric_id if metric_id != OMIT
6873
@metric_value = metric_value if metric_value != OMIT
6974
@metric_name = metric_name if metric_name != OMIT
75+
@current_streak = current_streak if current_streak != OMIT
7076
@additional_properties = additional_properties
7177
@_field_set = {
7278
"id": id,
@@ -78,7 +84,8 @@ def initialize(id:, name:, trigger:, description: OMIT, badge_url: OMIT, key: OM
7884
"streakLength": streak_length,
7985
"metricId": metric_id,
8086
"metricValue": metric_value,
81-
"metricName": metric_name
87+
"metricName": metric_name,
88+
"currentStreak": current_streak
8289
}.reject do |_k, v|
8390
v == OMIT
8491
end
@@ -101,6 +108,12 @@ def self.from_json(json_object:)
101108
metric_id = parsed_json["metricId"]
102109
metric_value = parsed_json["metricValue"]
103110
metric_name = parsed_json["metricName"]
111+
if parsed_json["currentStreak"].nil?
112+
current_streak = nil
113+
else
114+
current_streak = parsed_json["currentStreak"].to_json
115+
current_streak = TrophyApiClient::MetricEventStreakResponse.from_json(json_object: current_streak)
116+
end
104117
new(
105118
id: id,
106119
name: name,
@@ -112,6 +125,7 @@ def self.from_json(json_object:)
112125
metric_id: metric_id,
113126
metric_value: metric_value,
114127
metric_name: metric_name,
128+
current_streak: current_streak,
115129
additional_properties: struct
116130
)
117131
end
@@ -132,14 +146,15 @@ def to_json(*_args)
132146
def self.validate_raw(obj:)
133147
obj.id.is_a?(String) != false || raise("Passed value for field obj.id is not the expected type, validation failed.")
134148
obj.name.is_a?(String) != false || raise("Passed value for field obj.name is not the expected type, validation failed.")
135-
obj.trigger.is_a?(String) != false || raise("Passed value for field obj.trigger is not the expected type, validation failed.")
149+
obj.trigger.is_a?(TrophyApiClient::AchievementResponseTrigger) != false || raise("Passed value for field obj.trigger is not the expected type, validation failed.")
136150
obj.description&.is_a?(String) != false || raise("Passed value for field obj.description is not the expected type, validation failed.")
137151
obj.badge_url&.is_a?(String) != false || raise("Passed value for field obj.badge_url is not the expected type, validation failed.")
138152
obj.key&.is_a?(String) != false || raise("Passed value for field obj.key is not the expected type, validation failed.")
139153
obj.streak_length&.is_a?(Integer) != false || raise("Passed value for field obj.streak_length is not the expected type, validation failed.")
140154
obj.metric_id&.is_a?(String) != false || raise("Passed value for field obj.metric_id is not the expected type, validation failed.")
141155
obj.metric_value&.is_a?(Float) != false || raise("Passed value for field obj.metric_value is not the expected type, validation failed.")
142156
obj.metric_name&.is_a?(String) != false || raise("Passed value for field obj.metric_name is not the expected type, validation failed.")
157+
obj.current_streak.nil? || TrophyApiClient::MetricEventStreakResponse.validate_raw(obj: obj.current_streak)
143158
end
144159
end
145160
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# frozen_string_literal: true
2+
3+
module TrophyApiClient
4+
# The trigger of the achievement.
5+
class AchievementResponseTrigger
6+
METRIC = "metric"
7+
STREAK = "streak"
8+
API = "api"
9+
end
10+
end

0 commit comments

Comments
 (0)