trophy_api_client 1.0.17 → 1.0.19
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 +103 -0
- data/lib/trophy_api_client/streaks/types/streaks_rankings_request_type.rb +10 -0
- data/lib/trophy_api_client/types/streak_ranking_user.rb +75 -0
- data/lib/trophy_api_client/version.rb +1 -1
- data/lib/trophy_api_client.rb +7 -0
- data/lib/types_export.rb +2 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8d767c67c359d85255fda71dfc5b23dfdbd7ec7703a02843e025c593da2604a
|
4
|
+
data.tar.gz: d661b2fb934daeb5f28d2189646fb3c09294f3f05db4b3454f3f4c2cc337babd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6310df4c2f5a5fcf9a10a1134bbe38860c32fb0ab7af8715c07335152461d8bf8fd1cd1026dd3286a28e80ac31d4e3f9e3d06413ad91d138ba834d26d1773cbb
|
7
|
+
data.tar.gz: 41ec09de29b07a35735a5f188aabcf7cf29e0e14f9c661caf0f15138efc8c153403edec02346e05d89d2fd3b095367f83f7c747c1ef81920355f9e98b33eb902
|
data/lib/gemconfig.rb
CHANGED
@@ -0,0 +1,103 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../../requests"
|
4
|
+
require_relative "types/streaks_rankings_request_type"
|
5
|
+
require_relative "../types/streak_ranking_user"
|
6
|
+
require "json"
|
7
|
+
require "async"
|
8
|
+
|
9
|
+
module TrophyApiClient
|
10
|
+
class StreaksClient
|
11
|
+
# @return [TrophyApiClient::RequestClient]
|
12
|
+
attr_reader :request_client
|
13
|
+
|
14
|
+
# @param request_client [TrophyApiClient::RequestClient]
|
15
|
+
# @return [TrophyApiClient::StreaksClient]
|
16
|
+
def initialize(request_client:)
|
17
|
+
@request_client = request_client
|
18
|
+
end
|
19
|
+
|
20
|
+
# Get the top users by streak length (active or longest).
|
21
|
+
#
|
22
|
+
# @param limit [Integer] Number of users to return. Must be between 1 and 100.
|
23
|
+
# @param type [TrophyApiClient::Streaks::StreaksRankingsRequestType] Whether to rank users by active streaks or longest streaks ever achieved.
|
24
|
+
# @param request_options [TrophyApiClient::RequestOptions]
|
25
|
+
# @return [Array<TrophyApiClient::StreakRankingUser>]
|
26
|
+
# @example
|
27
|
+
# api = TrophyApiClient::Client.new(
|
28
|
+
# base_url: "https://api.example.com",
|
29
|
+
# environment: TrophyApiClient::Environment::DEFAULT,
|
30
|
+
# api_key: "YOUR_API_KEY"
|
31
|
+
# )
|
32
|
+
# api.streaks.rankings
|
33
|
+
def rankings(limit: nil, type: nil, request_options: nil)
|
34
|
+
response = @request_client.conn.get do |req|
|
35
|
+
req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
|
36
|
+
req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
|
37
|
+
req.headers = {
|
38
|
+
**(req.headers || {}),
|
39
|
+
**@request_client.get_headers,
|
40
|
+
**(request_options&.additional_headers || {})
|
41
|
+
}.compact
|
42
|
+
req.params = { **(request_options&.additional_query_parameters || {}), "limit": limit, "type": type }.compact
|
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)}/streaks/rankings"
|
47
|
+
end
|
48
|
+
parsed_json = JSON.parse(response.body)
|
49
|
+
parsed_json&.map do |item|
|
50
|
+
item = item.to_json
|
51
|
+
TrophyApiClient::StreakRankingUser.from_json(json_object: item)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
class AsyncStreaksClient
|
57
|
+
# @return [TrophyApiClient::AsyncRequestClient]
|
58
|
+
attr_reader :request_client
|
59
|
+
|
60
|
+
# @param request_client [TrophyApiClient::AsyncRequestClient]
|
61
|
+
# @return [TrophyApiClient::AsyncStreaksClient]
|
62
|
+
def initialize(request_client:)
|
63
|
+
@request_client = request_client
|
64
|
+
end
|
65
|
+
|
66
|
+
# Get the top users by streak length (active or longest).
|
67
|
+
#
|
68
|
+
# @param limit [Integer] Number of users to return. Must be between 1 and 100.
|
69
|
+
# @param type [TrophyApiClient::Streaks::StreaksRankingsRequestType] Whether to rank users by active streaks or longest streaks ever achieved.
|
70
|
+
# @param request_options [TrophyApiClient::RequestOptions]
|
71
|
+
# @return [Array<TrophyApiClient::StreakRankingUser>]
|
72
|
+
# @example
|
73
|
+
# api = TrophyApiClient::Client.new(
|
74
|
+
# base_url: "https://api.example.com",
|
75
|
+
# environment: TrophyApiClient::Environment::DEFAULT,
|
76
|
+
# api_key: "YOUR_API_KEY"
|
77
|
+
# )
|
78
|
+
# api.streaks.rankings
|
79
|
+
def rankings(limit: nil, type: nil, request_options: nil)
|
80
|
+
Async do
|
81
|
+
response = @request_client.conn.get do |req|
|
82
|
+
req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
|
83
|
+
req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
|
84
|
+
req.headers = {
|
85
|
+
**(req.headers || {}),
|
86
|
+
**@request_client.get_headers,
|
87
|
+
**(request_options&.additional_headers || {})
|
88
|
+
}.compact
|
89
|
+
req.params = { **(request_options&.additional_query_parameters || {}), "limit": limit, "type": type }.compact
|
90
|
+
unless request_options.nil? || request_options&.additional_body_parameters.nil?
|
91
|
+
req.body = { **(request_options&.additional_body_parameters || {}) }.compact
|
92
|
+
end
|
93
|
+
req.url "#{@request_client.get_url(request_options: request_options)}/streaks/rankings"
|
94
|
+
end
|
95
|
+
parsed_json = JSON.parse(response.body)
|
96
|
+
parsed_json&.map do |item|
|
97
|
+
item = item.to_json
|
98
|
+
TrophyApiClient::StreakRankingUser.from_json(json_object: item)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "ostruct"
|
4
|
+
require "json"
|
5
|
+
|
6
|
+
module TrophyApiClient
|
7
|
+
# A user with their streak length in the rankings.
|
8
|
+
class StreakRankingUser
|
9
|
+
# @return [String] The ID of the user.
|
10
|
+
attr_reader :user_id
|
11
|
+
# @return [String] The name of the user. May be null if no name is set.
|
12
|
+
attr_reader :name
|
13
|
+
# @return [Integer] The user's streak length (active or longest depending on query parameter).
|
14
|
+
attr_reader :streak_length
|
15
|
+
# @return [OpenStruct] Additional properties unmapped to the current class definition
|
16
|
+
attr_reader :additional_properties
|
17
|
+
# @return [Object]
|
18
|
+
attr_reader :_field_set
|
19
|
+
protected :_field_set
|
20
|
+
|
21
|
+
OMIT = Object.new
|
22
|
+
|
23
|
+
# @param user_id [String] The ID of the user.
|
24
|
+
# @param name [String] The name of the user. May be null if no name is set.
|
25
|
+
# @param streak_length [Integer] The user's streak length (active or longest depending on query parameter).
|
26
|
+
# @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
|
27
|
+
# @return [TrophyApiClient::StreakRankingUser]
|
28
|
+
def initialize(user_id:, streak_length:, name: OMIT, additional_properties: nil)
|
29
|
+
@user_id = user_id
|
30
|
+
@name = name if name != OMIT
|
31
|
+
@streak_length = streak_length
|
32
|
+
@additional_properties = additional_properties
|
33
|
+
@_field_set = { "userId": user_id, "name": name, "streakLength": streak_length }.reject do |_k, v|
|
34
|
+
v == OMIT
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Deserialize a JSON object to an instance of StreakRankingUser
|
39
|
+
#
|
40
|
+
# @param json_object [String]
|
41
|
+
# @return [TrophyApiClient::StreakRankingUser]
|
42
|
+
def self.from_json(json_object:)
|
43
|
+
struct = JSON.parse(json_object, object_class: OpenStruct)
|
44
|
+
parsed_json = JSON.parse(json_object)
|
45
|
+
user_id = parsed_json["userId"]
|
46
|
+
name = parsed_json["name"]
|
47
|
+
streak_length = parsed_json["streakLength"]
|
48
|
+
new(
|
49
|
+
user_id: user_id,
|
50
|
+
name: name,
|
51
|
+
streak_length: streak_length,
|
52
|
+
additional_properties: struct
|
53
|
+
)
|
54
|
+
end
|
55
|
+
|
56
|
+
# Serialize an instance of StreakRankingUser to a JSON object
|
57
|
+
#
|
58
|
+
# @return [String]
|
59
|
+
def to_json(*_args)
|
60
|
+
@_field_set&.to_json
|
61
|
+
end
|
62
|
+
|
63
|
+
# Leveraged for Union-type generation, validate_raw attempts to parse the given
|
64
|
+
# hash and check each fields type against the current object's property
|
65
|
+
# definitions.
|
66
|
+
#
|
67
|
+
# @param obj [Object]
|
68
|
+
# @return [Void]
|
69
|
+
def self.validate_raw(obj:)
|
70
|
+
obj.user_id.is_a?(String) != false || raise("Passed value for field obj.user_id is not the expected type, validation failed.")
|
71
|
+
obj.name&.is_a?(String) != false || raise("Passed value for field obj.name is not the expected type, validation failed.")
|
72
|
+
obj.streak_length.is_a?(Integer) != false || raise("Passed value for field obj.streak_length is not the expected type, validation failed.")
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
data/lib/trophy_api_client.rb
CHANGED
@@ -6,6 +6,7 @@ require_relative "requests"
|
|
6
6
|
require_relative "trophy_api_client/achievements/client"
|
7
7
|
require_relative "trophy_api_client/metrics/client"
|
8
8
|
require_relative "trophy_api_client/users/client"
|
9
|
+
require_relative "trophy_api_client/streaks/client"
|
9
10
|
require_relative "trophy_api_client/points/client"
|
10
11
|
|
11
12
|
module TrophyApiClient
|
@@ -16,6 +17,8 @@ module TrophyApiClient
|
|
16
17
|
attr_reader :metrics
|
17
18
|
# @return [TrophyApiClient::UsersClient]
|
18
19
|
attr_reader :users
|
20
|
+
# @return [TrophyApiClient::StreaksClient]
|
21
|
+
attr_reader :streaks
|
19
22
|
# @return [TrophyApiClient::PointsClient]
|
20
23
|
attr_reader :points
|
21
24
|
|
@@ -37,6 +40,7 @@ module TrophyApiClient
|
|
37
40
|
@achievements = TrophyApiClient::AchievementsClient.new(request_client: @request_client)
|
38
41
|
@metrics = TrophyApiClient::MetricsClient.new(request_client: @request_client)
|
39
42
|
@users = TrophyApiClient::UsersClient.new(request_client: @request_client)
|
43
|
+
@streaks = TrophyApiClient::StreaksClient.new(request_client: @request_client)
|
40
44
|
@points = TrophyApiClient::PointsClient.new(request_client: @request_client)
|
41
45
|
end
|
42
46
|
end
|
@@ -48,6 +52,8 @@ module TrophyApiClient
|
|
48
52
|
attr_reader :metrics
|
49
53
|
# @return [TrophyApiClient::AsyncUsersClient]
|
50
54
|
attr_reader :users
|
55
|
+
# @return [TrophyApiClient::AsyncStreaksClient]
|
56
|
+
attr_reader :streaks
|
51
57
|
# @return [TrophyApiClient::AsyncPointsClient]
|
52
58
|
attr_reader :points
|
53
59
|
|
@@ -69,6 +75,7 @@ module TrophyApiClient
|
|
69
75
|
@achievements = TrophyApiClient::AsyncAchievementsClient.new(request_client: @async_request_client)
|
70
76
|
@metrics = TrophyApiClient::AsyncMetricsClient.new(request_client: @async_request_client)
|
71
77
|
@users = TrophyApiClient::AsyncUsersClient.new(request_client: @async_request_client)
|
78
|
+
@streaks = TrophyApiClient::AsyncStreaksClient.new(request_client: @async_request_client)
|
72
79
|
@points = TrophyApiClient::AsyncPointsClient.new(request_client: @async_request_client)
|
73
80
|
end
|
74
81
|
end
|
data/lib/types_export.rb
CHANGED
@@ -4,6 +4,7 @@ require_relative "trophy_api_client/users/types/users_metric_event_summary_reque
|
|
4
4
|
require_relative "trophy_api_client/users/types/users_metric_event_summary_response_item"
|
5
5
|
require_relative "trophy_api_client/users/types/users_points_event_summary_request_aggregation"
|
6
6
|
require_relative "trophy_api_client/users/types/users_points_event_summary_response_item"
|
7
|
+
require_relative "trophy_api_client/streaks/types/streaks_rankings_request_type"
|
7
8
|
require_relative "trophy_api_client/types/metric_status"
|
8
9
|
require_relative "trophy_api_client/types/streak_frequency"
|
9
10
|
require_relative "trophy_api_client/types/base_streak_response"
|
@@ -36,3 +37,4 @@ require_relative "trophy_api_client/types/points_trigger_response_user_attribute
|
|
36
37
|
require_relative "trophy_api_client/types/points_trigger_response_event_attribute"
|
37
38
|
require_relative "trophy_api_client/types/points_trigger_response"
|
38
39
|
require_relative "trophy_api_client/types/points_system_response"
|
40
|
+
require_relative "trophy_api_client/types/streak_ranking_user"
|
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.19
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Trophy Labs, Inc
|
@@ -102,6 +102,8 @@ files:
|
|
102
102
|
- lib/trophy_api_client/achievements/client.rb
|
103
103
|
- lib/trophy_api_client/metrics/client.rb
|
104
104
|
- lib/trophy_api_client/points/client.rb
|
105
|
+
- lib/trophy_api_client/streaks/client.rb
|
106
|
+
- lib/trophy_api_client/streaks/types/streaks_rankings_request_type.rb
|
105
107
|
- lib/trophy_api_client/types/achievement_completion_response.rb
|
106
108
|
- lib/trophy_api_client/types/achievement_response.rb
|
107
109
|
- lib/trophy_api_client/types/achievement_response_trigger.rb
|
@@ -129,6 +131,7 @@ files:
|
|
129
131
|
- lib/trophy_api_client/types/points_trigger_response_user_attributes_item.rb
|
130
132
|
- lib/trophy_api_client/types/points_trigger_type.rb
|
131
133
|
- lib/trophy_api_client/types/streak_frequency.rb
|
134
|
+
- lib/trophy_api_client/types/streak_ranking_user.rb
|
132
135
|
- lib/trophy_api_client/types/streak_response.rb
|
133
136
|
- lib/trophy_api_client/types/streak_response_streak_history_item.rb
|
134
137
|
- lib/trophy_api_client/types/updated_user.rb
|