trophy_api_client 1.0.20 → 1.0.21
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/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: 68357394d52195a47c44fc9355befe6eca436547e932e74dd0efa10f7c01821e
|
4
|
+
data.tar.gz: d081f45005de17054f0acefc19e113e0a7788b73e8e3c1e942e66b7dbb4d90ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d955c1f044f150e062e4740398028483d22935eb76a475f45a7fc13118767c6b6c3f2ac4dd032b7cd7a013e8e2aae7113598efe220c4e9f4d1f6fc0b1531894d
|
7
|
+
data.tar.gz: b5b9402673a5981686b77aae50db69e28ddb683dddcd2db4a02471e23299868313361dcaa683d4ce9128cd767476854fe6d6e57bc9d925ac1e9ea9e0c3c7ded9
|
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
|
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.21
|
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
|