trophy_api_client 1.0.20 → 1.0.22
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/gemconfig.rb +1 -1
- data/lib/trophy_api_client/streaks/client.rb +74 -1
- data/lib/trophy_api_client/types/bulk_streak_response.rb +7 -0
- data/lib/trophy_api_client/types/bulk_streak_response_item.rb +74 -0
- data/lib/trophy_api_client/types/event_response.rb +18 -2
- data/lib/trophy_api_client/version.rb +1 -1
- data/lib/types_export.rb +2 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cab733c24577e49524eb7899160b7c172195e0d2e84b3b6cd11cadb32342ee9a
|
4
|
+
data.tar.gz: a3999029f59148a4208edf380c131f9c9539c51fd9512e3f7f9fdd5e58270b06
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dcb1a2eab70038ac53d6d85ef7f8267a17b29dbba682f4fd44d2af7bb7d88243c85d34adf337775b24d494ee7124e8cdf77d3cba64492908eb03293374821d0a
|
7
|
+
data.tar.gz: c173eacb9c7c5be6cd6cc540c055ecb3f7bfb1c811f20c3f143e838f3a01dd1bd287d2fc920b9e5f2a73547494b6e22b7e28fd6e78339dcdd279acde449c1940
|
data/lib/gemconfig.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative "../../requests"
|
4
|
+
require_relative "../types/bulk_streak_response"
|
5
|
+
require "json"
|
4
6
|
require_relative "types/streaks_rankings_request_type"
|
5
7
|
require_relative "../types/streak_ranking_user"
|
6
|
-
require "json"
|
7
8
|
require "async"
|
8
9
|
|
9
10
|
module TrophyApiClient
|
@@ -17,6 +18,41 @@ module TrophyApiClient
|
|
17
18
|
@request_client = request_client
|
18
19
|
end
|
19
20
|
|
21
|
+
# Get the streak lengths of a list of users, ranked by streak length from longest
|
22
|
+
# to shortest.
|
23
|
+
#
|
24
|
+
# @param user_ids [String] A list of up to 100 user IDs.
|
25
|
+
# @param request_options [TrophyApiClient::RequestOptions]
|
26
|
+
# @return [TrophyApiClient::BULK_STREAK_RESPONSE]
|
27
|
+
# @example
|
28
|
+
# api = TrophyApiClient::Client.new(
|
29
|
+
# base_url: "https://api.example.com",
|
30
|
+
# environment: TrophyApiClient::Environment::DEFAULT,
|
31
|
+
# api_key: "YOUR_API_KEY"
|
32
|
+
# )
|
33
|
+
# api.streaks.list
|
34
|
+
def list(user_ids: nil, request_options: nil)
|
35
|
+
response = @request_client.conn.get do |req|
|
36
|
+
req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
|
37
|
+
req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
|
38
|
+
req.headers = {
|
39
|
+
**(req.headers || {}),
|
40
|
+
**@request_client.get_headers,
|
41
|
+
**(request_options&.additional_headers || {})
|
42
|
+
}.compact
|
43
|
+
req.params = { **(request_options&.additional_query_parameters || {}), "userIds": user_ids }.compact
|
44
|
+
unless request_options.nil? || request_options&.additional_body_parameters.nil?
|
45
|
+
req.body = { **(request_options&.additional_body_parameters || {}) }.compact
|
46
|
+
end
|
47
|
+
req.url "#{@request_client.get_url(request_options: request_options)}/streaks"
|
48
|
+
end
|
49
|
+
parsed_json = JSON.parse(response.body)
|
50
|
+
parsed_json&.map do |item|
|
51
|
+
item = item.to_json
|
52
|
+
TrophyApiClient::BulkStreakResponseItem.from_json(json_object: item)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
20
56
|
# Get the top users by streak length (active or longest).
|
21
57
|
#
|
22
58
|
# @param limit [Integer] Number of users to return. Must be between 1 and 100.
|
@@ -63,6 +99,43 @@ module TrophyApiClient
|
|
63
99
|
@request_client = request_client
|
64
100
|
end
|
65
101
|
|
102
|
+
# Get the streak lengths of a list of users, ranked by streak length from longest
|
103
|
+
# to shortest.
|
104
|
+
#
|
105
|
+
# @param user_ids [String] A list of up to 100 user IDs.
|
106
|
+
# @param request_options [TrophyApiClient::RequestOptions]
|
107
|
+
# @return [TrophyApiClient::BULK_STREAK_RESPONSE]
|
108
|
+
# @example
|
109
|
+
# api = TrophyApiClient::Client.new(
|
110
|
+
# base_url: "https://api.example.com",
|
111
|
+
# environment: TrophyApiClient::Environment::DEFAULT,
|
112
|
+
# api_key: "YOUR_API_KEY"
|
113
|
+
# )
|
114
|
+
# api.streaks.list
|
115
|
+
def list(user_ids: nil, request_options: nil)
|
116
|
+
Async do
|
117
|
+
response = @request_client.conn.get do |req|
|
118
|
+
req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
|
119
|
+
req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
|
120
|
+
req.headers = {
|
121
|
+
**(req.headers || {}),
|
122
|
+
**@request_client.get_headers,
|
123
|
+
**(request_options&.additional_headers || {})
|
124
|
+
}.compact
|
125
|
+
req.params = { **(request_options&.additional_query_parameters || {}), "userIds": user_ids }.compact
|
126
|
+
unless request_options.nil? || request_options&.additional_body_parameters.nil?
|
127
|
+
req.body = { **(request_options&.additional_body_parameters || {}) }.compact
|
128
|
+
end
|
129
|
+
req.url "#{@request_client.get_url(request_options: request_options)}/streaks"
|
130
|
+
end
|
131
|
+
parsed_json = JSON.parse(response.body)
|
132
|
+
parsed_json&.map do |item|
|
133
|
+
item = item.to_json
|
134
|
+
TrophyApiClient::BulkStreakResponseItem.from_json(json_object: item)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
66
139
|
# Get the top users by streak length (active or longest).
|
67
140
|
#
|
68
141
|
# @param limit [Integer] Number of users to return. Must be between 1 and 100.
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "ostruct"
|
4
|
+
require "json"
|
5
|
+
|
6
|
+
module TrophyApiClient
|
7
|
+
class BulkStreakResponseItem
|
8
|
+
# @return [String] The ID of the user.
|
9
|
+
attr_reader :user_id
|
10
|
+
# @return [Integer] The length of the user's streak.
|
11
|
+
attr_reader :streak_length
|
12
|
+
# @return [String] The timestamp the streak was extended, as a string.
|
13
|
+
attr_reader :extended
|
14
|
+
# @return [OpenStruct] Additional properties unmapped to the current class definition
|
15
|
+
attr_reader :additional_properties
|
16
|
+
# @return [Object]
|
17
|
+
attr_reader :_field_set
|
18
|
+
protected :_field_set
|
19
|
+
|
20
|
+
OMIT = Object.new
|
21
|
+
|
22
|
+
# @param user_id [String] The ID of the user.
|
23
|
+
# @param streak_length [Integer] The length of the user's streak.
|
24
|
+
# @param extended [String] The timestamp the streak was extended, as a string.
|
25
|
+
# @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
|
26
|
+
# @return [TrophyApiClient::BulkStreakResponseItem]
|
27
|
+
def initialize(user_id:, streak_length:, extended: OMIT, additional_properties: nil)
|
28
|
+
@user_id = user_id
|
29
|
+
@streak_length = streak_length
|
30
|
+
@extended = extended if extended != OMIT
|
31
|
+
@additional_properties = additional_properties
|
32
|
+
@_field_set = { "userId": user_id, "streakLength": streak_length, "extended": extended }.reject do |_k, v|
|
33
|
+
v == OMIT
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# Deserialize a JSON object to an instance of BulkStreakResponseItem
|
38
|
+
#
|
39
|
+
# @param json_object [String]
|
40
|
+
# @return [TrophyApiClient::BulkStreakResponseItem]
|
41
|
+
def self.from_json(json_object:)
|
42
|
+
struct = JSON.parse(json_object, object_class: OpenStruct)
|
43
|
+
parsed_json = JSON.parse(json_object)
|
44
|
+
user_id = parsed_json["userId"]
|
45
|
+
streak_length = parsed_json["streakLength"]
|
46
|
+
extended = parsed_json["extended"]
|
47
|
+
new(
|
48
|
+
user_id: user_id,
|
49
|
+
streak_length: streak_length,
|
50
|
+
extended: extended,
|
51
|
+
additional_properties: struct
|
52
|
+
)
|
53
|
+
end
|
54
|
+
|
55
|
+
# Serialize an instance of BulkStreakResponseItem to a JSON object
|
56
|
+
#
|
57
|
+
# @return [String]
|
58
|
+
def to_json(*_args)
|
59
|
+
@_field_set&.to_json
|
60
|
+
end
|
61
|
+
|
62
|
+
# Leveraged for Union-type generation, validate_raw attempts to parse the given
|
63
|
+
# hash and check each fields type against the current object's property
|
64
|
+
# definitions.
|
65
|
+
#
|
66
|
+
# @param obj [Object]
|
67
|
+
# @return [Void]
|
68
|
+
def self.validate_raw(obj:)
|
69
|
+
obj.user_id.is_a?(String) != false || raise("Passed value for field obj.user_id is not the expected type, validation failed.")
|
70
|
+
obj.streak_length.is_a?(Integer) != false || raise("Passed value for field obj.streak_length is not the expected type, validation failed.")
|
71
|
+
obj.extended&.is_a?(String) != false || raise("Passed value for field obj.extended is not the expected type, validation failed.")
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -19,6 +19,10 @@ module TrophyApiClient
|
|
19
19
|
attr_reader :current_streak
|
20
20
|
# @return [Hash{String => TrophyApiClient::MetricEventPointsResponse}] A map of points systems by key that were affected by this event.
|
21
21
|
attr_reader :points
|
22
|
+
# @return [String] The idempotency key used for the event, if one was provided.
|
23
|
+
attr_reader :idempotency_key
|
24
|
+
# @return [Boolean] Whether the event was replayed due to idempotency.
|
25
|
+
attr_reader :idempotent_replayed
|
22
26
|
# @return [OpenStruct] Additional properties unmapped to the current class definition
|
23
27
|
attr_reader :additional_properties
|
24
28
|
# @return [Object]
|
@@ -33,16 +37,20 @@ module TrophyApiClient
|
|
33
37
|
# @param achievements [Array<TrophyApiClient::CompletedAchievementResponse>] Achievements completed as a result of this event.
|
34
38
|
# @param current_streak [TrophyApiClient::MetricEventStreakResponse] The user's current streak for the metric, if the metric has streaks enabled.
|
35
39
|
# @param points [Hash{String => TrophyApiClient::MetricEventPointsResponse}] A map of points systems by key that were affected by this event.
|
40
|
+
# @param idempotency_key [String] The idempotency key used for the event, if one was provided.
|
41
|
+
# @param idempotent_replayed [Boolean] Whether the event was replayed due to idempotency.
|
36
42
|
# @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
|
37
43
|
# @return [TrophyApiClient::EventResponse]
|
38
44
|
def initialize(event_id:, metric_id:, total:, achievements: OMIT, current_streak: OMIT, points: OMIT,
|
39
|
-
additional_properties: nil)
|
45
|
+
idempotency_key: OMIT, idempotent_replayed: OMIT, additional_properties: nil)
|
40
46
|
@event_id = event_id
|
41
47
|
@metric_id = metric_id
|
42
48
|
@total = total
|
43
49
|
@achievements = achievements if achievements != OMIT
|
44
50
|
@current_streak = current_streak if current_streak != OMIT
|
45
51
|
@points = points if points != OMIT
|
52
|
+
@idempotency_key = idempotency_key if idempotency_key != OMIT
|
53
|
+
@idempotent_replayed = idempotent_replayed if idempotent_replayed != OMIT
|
46
54
|
@additional_properties = additional_properties
|
47
55
|
@_field_set = {
|
48
56
|
"eventId": event_id,
|
@@ -50,7 +58,9 @@ module TrophyApiClient
|
|
50
58
|
"total": total,
|
51
59
|
"achievements": achievements,
|
52
60
|
"currentStreak": current_streak,
|
53
|
-
"points": points
|
61
|
+
"points": points,
|
62
|
+
"idempotencyKey": idempotency_key,
|
63
|
+
"idempotentReplayed": idempotent_replayed
|
54
64
|
}.reject do |_k, v|
|
55
65
|
v == OMIT
|
56
66
|
end
|
@@ -80,6 +90,8 @@ module TrophyApiClient
|
|
80
90
|
value = value.to_json
|
81
91
|
TrophyApiClient::MetricEventPointsResponse.from_json(json_object: value)
|
82
92
|
end
|
93
|
+
idempotency_key = parsed_json["idempotencyKey"]
|
94
|
+
idempotent_replayed = parsed_json["idempotentReplayed"]
|
83
95
|
new(
|
84
96
|
event_id: event_id,
|
85
97
|
metric_id: metric_id,
|
@@ -87,6 +99,8 @@ module TrophyApiClient
|
|
87
99
|
achievements: achievements,
|
88
100
|
current_streak: current_streak,
|
89
101
|
points: points,
|
102
|
+
idempotency_key: idempotency_key,
|
103
|
+
idempotent_replayed: idempotent_replayed,
|
90
104
|
additional_properties: struct
|
91
105
|
)
|
92
106
|
end
|
@@ -111,6 +125,8 @@ module TrophyApiClient
|
|
111
125
|
obj.achievements&.is_a?(Array) != false || raise("Passed value for field obj.achievements is not the expected type, validation failed.")
|
112
126
|
obj.current_streak.nil? || TrophyApiClient::MetricEventStreakResponse.validate_raw(obj: obj.current_streak)
|
113
127
|
obj.points&.is_a?(Hash) != false || raise("Passed value for field obj.points is not the expected type, validation failed.")
|
128
|
+
obj.idempotency_key&.is_a?(String) != false || raise("Passed value for field obj.idempotency_key is not the expected type, validation failed.")
|
129
|
+
obj.idempotent_replayed&.is_a?(Boolean) != false || raise("Passed value for field obj.idempotent_replayed is not the expected type, validation failed.")
|
114
130
|
end
|
115
131
|
end
|
116
132
|
end
|
data/lib/types_export.rb
CHANGED
@@ -8,6 +8,8 @@ require_relative "trophy_api_client/streaks/types/streaks_rankings_request_type"
|
|
8
8
|
require_relative "trophy_api_client/types/metric_status"
|
9
9
|
require_relative "trophy_api_client/types/streak_frequency"
|
10
10
|
require_relative "trophy_api_client/types/base_streak_response"
|
11
|
+
require_relative "trophy_api_client/types/bulk_streak_response_item"
|
12
|
+
require_relative "trophy_api_client/types/bulk_streak_response"
|
11
13
|
require_relative "trophy_api_client/types/metric_event_streak_response"
|
12
14
|
require_relative "trophy_api_client/types/streak_response_streak_history_item"
|
13
15
|
require_relative "trophy_api_client/types/streak_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.
|
4
|
+
version: 1.0.22
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Trophy Labs, Inc
|
@@ -111,6 +111,8 @@ files:
|
|
111
111
|
- lib/trophy_api_client/types/achievement_with_stats_response_event_attribute.rb
|
112
112
|
- lib/trophy_api_client/types/achievement_with_stats_response_user_attributes_item.rb
|
113
113
|
- lib/trophy_api_client/types/base_streak_response.rb
|
114
|
+
- lib/trophy_api_client/types/bulk_streak_response.rb
|
115
|
+
- lib/trophy_api_client/types/bulk_streak_response_item.rb
|
114
116
|
- lib/trophy_api_client/types/completed_achievement_response.rb
|
115
117
|
- lib/trophy_api_client/types/error_body.rb
|
116
118
|
- lib/trophy_api_client/types/event_response.rb
|