trophy_api_client 1.0.18 → 1.0.20

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 73fb32551a294b3d18f85f1fcd4d88a77f0981605abe9319246dce45f74aabc6
4
- data.tar.gz: da3fb8ff4822577a125253cfc6f31320d10fc1ca70168ca80e086178fb8a642f
3
+ metadata.gz: a79a94b140eb840c0a0b4f40f855c69fbb66bb429977154f144ef1e5f1b37729
4
+ data.tar.gz: d712f9760544029301467b699433584ceaddf2faf12a3122475d1de9630ca7ae
5
5
  SHA512:
6
- metadata.gz: 86f558440df2068208b19471bbe251efac6b87a3ee6caf3572210065fa07671f14dd65170453aabef59f27c638b00073e8e3adc12563d0736dd8a7a5034a2ff5
7
- data.tar.gz: e43df82d944f6cebbee8ab85e2e38eb8dba9cc21d879e32d0cd8d88d2874b2435153ac961b319670138dcbc139f20ab1d074bf47cb520b422ea3c282cc4d19cc
6
+ metadata.gz: 23d14322f1451cc839c440cb727a5549439ae5c09f5869e09519db7a6bc0f562426acb200d67b1a11390d8b0a2af047ab60a1e7aea1de59c43a747db7f2c7b20
7
+ data.tar.gz: 53ea20d8432d15b2b64834927d74c1eba36b2912f10654325fbf81456ee68460442f523cc82af9b5077bcb0cc154d27cbac901c58e224e7a2255aa18da1d3d01
data/lib/gemconfig.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  module TrophyApiClient
4
4
  module Gemconfig
5
- VERSION = "1.0.18"
5
+ VERSION = "1.0.20"
6
6
  AUTHORS = ["Trophy Labs, Inc"].freeze
7
7
  EMAIL = ""
8
8
  SUMMARY = "Ruby library for the Trophy API."
@@ -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,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TrophyApiClient
4
+ class Streaks
5
+ class StreaksRankingsRequestType
6
+ ACTIVE = "active"
7
+ LONGEST = "longest"
8
+ end
9
+ end
10
+ 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
@@ -11,6 +11,8 @@ module TrophyApiClient
11
11
  # @return [Array<TrophyApiClient::StreakResponseStreakHistoryItem>] A list of the user's past streak periods up through the current period. Each
12
12
  # period includes the start and end dates and the length of the streak.
13
13
  attr_reader :streak_history
14
+ # @return [Integer] The user's rank across all users. Null if the user has no active streak.
15
+ attr_reader :rank
14
16
  # @return [Integer] The length of the user's current streak.
15
17
  attr_reader :length
16
18
  # @return [TrophyApiClient::StreakFrequency] The frequency of the streak.
@@ -33,6 +35,7 @@ module TrophyApiClient
33
35
 
34
36
  # @param streak_history [Array<TrophyApiClient::StreakResponseStreakHistoryItem>] A list of the user's past streak periods up through the current period. Each
35
37
  # period includes the start and end dates and the length of the streak.
38
+ # @param rank [Integer] The user's rank across all users. Null if the user has no active streak.
36
39
  # @param length [Integer] The length of the user's current streak.
37
40
  # @param frequency [TrophyApiClient::StreakFrequency] The frequency of the streak.
38
41
  # @param started [String] The date the streak started.
@@ -41,9 +44,10 @@ module TrophyApiClient
41
44
  # @param expires [String] The date the streak will expire if the user does not increment a metric.
42
45
  # @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
43
46
  # @return [TrophyApiClient::StreakResponse]
44
- def initialize(length:, frequency:, streak_history: OMIT, started: OMIT, period_start: OMIT, period_end: OMIT,
45
- expires: OMIT, additional_properties: nil)
47
+ def initialize(length:, frequency:, streak_history: OMIT, rank: OMIT, started: OMIT, period_start: OMIT,
48
+ period_end: OMIT, expires: OMIT, additional_properties: nil)
46
49
  @streak_history = streak_history if streak_history != OMIT
50
+ @rank = rank if rank != OMIT
47
51
  @length = length
48
52
  @frequency = frequency
49
53
  @started = started if started != OMIT
@@ -53,6 +57,7 @@ module TrophyApiClient
53
57
  @additional_properties = additional_properties
54
58
  @_field_set = {
55
59
  "streakHistory": streak_history,
60
+ "rank": rank,
56
61
  "length": length,
57
62
  "frequency": frequency,
58
63
  "started": started,
@@ -75,6 +80,7 @@ module TrophyApiClient
75
80
  item = item.to_json
76
81
  TrophyApiClient::StreakResponseStreakHistoryItem.from_json(json_object: item)
77
82
  end
83
+ rank = parsed_json["rank"]
78
84
  length = parsed_json["length"]
79
85
  frequency = parsed_json["frequency"]
80
86
  started = parsed_json["started"]
@@ -83,6 +89,7 @@ module TrophyApiClient
83
89
  expires = parsed_json["expires"]
84
90
  new(
85
91
  streak_history: streak_history,
92
+ rank: rank,
86
93
  length: length,
87
94
  frequency: frequency,
88
95
  started: started,
@@ -108,6 +115,7 @@ module TrophyApiClient
108
115
  # @return [Void]
109
116
  def self.validate_raw(obj:)
110
117
  obj.streak_history&.is_a?(Array) != false || raise("Passed value for field obj.streak_history is not the expected type, validation failed.")
118
+ obj.rank&.is_a?(Integer) != false || raise("Passed value for field obj.rank is not the expected type, validation failed.")
111
119
  obj.length.is_a?(Integer) != false || raise("Passed value for field obj.length is not the expected type, validation failed.")
112
120
  obj.frequency.is_a?(TrophyApiClient::StreakFrequency) != false || raise("Passed value for field obj.frequency is not the expected type, validation failed.")
113
121
  obj.started&.is_a?(String) != false || raise("Passed value for field obj.started is not the expected type, validation failed.")
@@ -1,3 +1,3 @@
1
1
  module MyGem
2
- VERSION = "1.0.18"
2
+ VERSION = "1.0.20"
3
3
  end
@@ -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.18
4
+ version: 1.0.20
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