trophy_api_client 1.0.19 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c8d767c67c359d85255fda71dfc5b23dfdbd7ec7703a02843e025c593da2604a
4
- data.tar.gz: d661b2fb934daeb5f28d2189646fb3c09294f3f05db4b3454f3f4c2cc337babd
3
+ metadata.gz: 68357394d52195a47c44fc9355befe6eca436547e932e74dd0efa10f7c01821e
4
+ data.tar.gz: d081f45005de17054f0acefc19e113e0a7788b73e8e3c1e942e66b7dbb4d90ee
5
5
  SHA512:
6
- metadata.gz: 6310df4c2f5a5fcf9a10a1134bbe38860c32fb0ab7af8715c07335152461d8bf8fd1cd1026dd3286a28e80ac31d4e3f9e3d06413ad91d138ba834d26d1773cbb
7
- data.tar.gz: 41ec09de29b07a35735a5f188aabcf7cf29e0e14f9c661caf0f15138efc8c153403edec02346e05d89d2fd3b095367f83f7c747c1ef81920355f9e98b33eb902
6
+ metadata.gz: d955c1f044f150e062e4740398028483d22935eb76a475f45a7fc13118767c6b6c3f2ac4dd032b7cd7a013e8e2aae7113598efe220c4e9f4d1f6fc0b1531894d
7
+ data.tar.gz: b5b9402673a5981686b77aae50db69e28ddb683dddcd2db4a02471e23299868313361dcaa683d4ce9128cd767476854fe6d6e57bc9d925ac1e9ea9e0c3c7ded9
data/lib/gemconfig.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  module TrophyApiClient
4
4
  module Gemconfig
5
- VERSION = "1.0.19"
5
+ VERSION = "1.0.21"
6
6
  AUTHORS = ["Trophy Labs, Inc"].freeze
7
7
  EMAIL = ""
8
8
  SUMMARY = "Ruby library for the Trophy API."
@@ -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,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "bulk_streak_response_item"
4
+
5
+ module TrophyApiClient
6
+ BULK_STREAK_RESPONSE = Array
7
+ end
@@ -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
@@ -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.19"
2
+ VERSION = "1.0.21"
3
3
  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.19
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