trophy_api_client 1.0.9 → 1.0.10
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/achievements/client.rb +79 -7
- data/lib/trophy_api_client/types/achievement_completion_response.rb +5 -5
- data/lib/trophy_api_client/types/achievement_response.rb +9 -10
- data/lib/trophy_api_client/types/achievement_with_stats_response.rb +161 -0
- data/lib/trophy_api_client/types/completed_achievement_response.rb +154 -0
- data/lib/trophy_api_client/types/event_response.rb +4 -4
- data/lib/trophy_api_client/types/metric_response.rb +4 -4
- data/lib/trophy_api_client/users/client.rb +111 -5
- data/lib/trophy_api_client/users/types/users_metric_event_summary_request_aggregation.rb +11 -0
- data/lib/trophy_api_client/users/types/users_metric_event_summary_response_item.rb +76 -0
- data/lib/trophy_api_client/version.rb +1 -1
- data/lib/types_export.rb +4 -0
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df830b1cd9f510c3ceea2cecb04f72e8ba30bbd051bc2ea461afb732ef8fc9fa
|
4
|
+
data.tar.gz: ac3d49eddd8de38fb751382004c2cb61f531680d71c84b57ecc76c159037a055
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e37e143621c9865d90ec6d0795bcf9326f917f11d158cb935ab987c40343cdebc6b2bbe624655900af61c920e2237c3ebaff25aaed3496ed1dec8f8b1a6c30d4
|
7
|
+
data.tar.gz: ca9628341f670ba78710751172cea75eab3d975df35c171be3dd361903322d191e8bbf71ce168bd26851f0b76a3a8d6c98268a1411fa2088970a8ef5ee4c4db0
|
data/lib/gemconfig.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative "../../requests"
|
4
|
-
require_relative "../types/
|
4
|
+
require_relative "../types/achievement_with_stats_response"
|
5
|
+
require "json"
|
6
|
+
require_relative "../types/updated_user"
|
5
7
|
require_relative "../types/achievement_completion_response"
|
6
8
|
require "async"
|
7
9
|
|
@@ -16,11 +18,45 @@ module TrophyApiClient
|
|
16
18
|
@request_client = request_client
|
17
19
|
end
|
18
20
|
|
21
|
+
# Get all achievements and their completion stats.
|
22
|
+
#
|
23
|
+
# @param request_options [TrophyApiClient::RequestOptions]
|
24
|
+
# @return [Array<TrophyApiClient::AchievementWithStatsResponse>]
|
25
|
+
# @example
|
26
|
+
# api = TrophyApiClient::Client.new(
|
27
|
+
# base_url: "https://api.example.com",
|
28
|
+
# environment: TrophyApiClient::Environment::DEFAULT,
|
29
|
+
# api_key: "YOUR_API_KEY"
|
30
|
+
# )
|
31
|
+
# api.achievements.all
|
32
|
+
def all(request_options: nil)
|
33
|
+
response = @request_client.conn.get do |req|
|
34
|
+
req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
|
35
|
+
req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
|
36
|
+
req.headers = {
|
37
|
+
**(req.headers || {}),
|
38
|
+
**@request_client.get_headers,
|
39
|
+
**(request_options&.additional_headers || {})
|
40
|
+
}.compact
|
41
|
+
unless request_options.nil? || request_options&.additional_query_parameters.nil?
|
42
|
+
req.params = { **(request_options&.additional_query_parameters || {}) }.compact
|
43
|
+
end
|
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)}/achievements"
|
48
|
+
end
|
49
|
+
parsed_json = JSON.parse(response.body)
|
50
|
+
parsed_json&.map do |item|
|
51
|
+
item = item.to_json
|
52
|
+
TrophyApiClient::AchievementWithStatsResponse.from_json(json_object: item)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
19
56
|
# Mark an achievement as completed for a user.
|
20
57
|
#
|
21
58
|
# @param key [String] Unique reference of the achievement as set when created.
|
22
|
-
# @param user [Hash] The user that completed the achievement.Request of type TrophyApiClient::
|
23
|
-
# * :id (String)
|
59
|
+
# @param user [Hash] The user that completed the achievement.Request of type TrophyApiClient::UpdatedUser, as a Hash
|
24
60
|
# * :email (String)
|
25
61
|
# * :name (String)
|
26
62
|
# * :tz (String)
|
@@ -33,7 +69,7 @@ module TrophyApiClient
|
|
33
69
|
# environment: TrophyApiClient::Environment::DEFAULT,
|
34
70
|
# api_key: "YOUR_API_KEY"
|
35
71
|
# )
|
36
|
-
# api.achievements.complete(key: "finish-onboarding", user: {
|
72
|
+
# api.achievements.complete(key: "finish-onboarding", user: { email: "user@example.com", tz: "Europe/London" })
|
37
73
|
def complete(key:, user:, request_options: nil)
|
38
74
|
response = @request_client.conn.post do |req|
|
39
75
|
req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
|
@@ -63,11 +99,47 @@ module TrophyApiClient
|
|
63
99
|
@request_client = request_client
|
64
100
|
end
|
65
101
|
|
102
|
+
# Get all achievements and their completion stats.
|
103
|
+
#
|
104
|
+
# @param request_options [TrophyApiClient::RequestOptions]
|
105
|
+
# @return [Array<TrophyApiClient::AchievementWithStatsResponse>]
|
106
|
+
# @example
|
107
|
+
# api = TrophyApiClient::Client.new(
|
108
|
+
# base_url: "https://api.example.com",
|
109
|
+
# environment: TrophyApiClient::Environment::DEFAULT,
|
110
|
+
# api_key: "YOUR_API_KEY"
|
111
|
+
# )
|
112
|
+
# api.achievements.all
|
113
|
+
def all(request_options: nil)
|
114
|
+
Async do
|
115
|
+
response = @request_client.conn.get do |req|
|
116
|
+
req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
|
117
|
+
req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
|
118
|
+
req.headers = {
|
119
|
+
**(req.headers || {}),
|
120
|
+
**@request_client.get_headers,
|
121
|
+
**(request_options&.additional_headers || {})
|
122
|
+
}.compact
|
123
|
+
unless request_options.nil? || request_options&.additional_query_parameters.nil?
|
124
|
+
req.params = { **(request_options&.additional_query_parameters || {}) }.compact
|
125
|
+
end
|
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)}/achievements"
|
130
|
+
end
|
131
|
+
parsed_json = JSON.parse(response.body)
|
132
|
+
parsed_json&.map do |item|
|
133
|
+
item = item.to_json
|
134
|
+
TrophyApiClient::AchievementWithStatsResponse.from_json(json_object: item)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
66
139
|
# Mark an achievement as completed for a user.
|
67
140
|
#
|
68
141
|
# @param key [String] Unique reference of the achievement as set when created.
|
69
|
-
# @param user [Hash] The user that completed the achievement.Request of type TrophyApiClient::
|
70
|
-
# * :id (String)
|
142
|
+
# @param user [Hash] The user that completed the achievement.Request of type TrophyApiClient::UpdatedUser, as a Hash
|
71
143
|
# * :email (String)
|
72
144
|
# * :name (String)
|
73
145
|
# * :tz (String)
|
@@ -80,7 +152,7 @@ module TrophyApiClient
|
|
80
152
|
# environment: TrophyApiClient::Environment::DEFAULT,
|
81
153
|
# api_key: "YOUR_API_KEY"
|
82
154
|
# )
|
83
|
-
# api.achievements.complete(key: "finish-onboarding", user: {
|
155
|
+
# api.achievements.complete(key: "finish-onboarding", user: { email: "user@example.com", tz: "Europe/London" })
|
84
156
|
def complete(key:, user:, request_options: nil)
|
85
157
|
Async do
|
86
158
|
response = @request_client.conn.post do |req|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "
|
3
|
+
require_relative "completed_achievement_response"
|
4
4
|
require "ostruct"
|
5
5
|
require "json"
|
6
6
|
|
@@ -8,7 +8,7 @@ module TrophyApiClient
|
|
8
8
|
class AchievementCompletionResponse
|
9
9
|
# @return [String] The unique ID of the completion.
|
10
10
|
attr_reader :completion_id
|
11
|
-
# @return [TrophyApiClient::
|
11
|
+
# @return [TrophyApiClient::CompletedAchievementResponse]
|
12
12
|
attr_reader :achievement
|
13
13
|
# @return [OpenStruct] Additional properties unmapped to the current class definition
|
14
14
|
attr_reader :additional_properties
|
@@ -19,7 +19,7 @@ module TrophyApiClient
|
|
19
19
|
OMIT = Object.new
|
20
20
|
|
21
21
|
# @param completion_id [String] The unique ID of the completion.
|
22
|
-
# @param achievement [TrophyApiClient::
|
22
|
+
# @param achievement [TrophyApiClient::CompletedAchievementResponse]
|
23
23
|
# @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
|
24
24
|
# @return [TrophyApiClient::AchievementCompletionResponse]
|
25
25
|
def initialize(completion_id:, achievement:, additional_properties: nil)
|
@@ -41,7 +41,7 @@ module TrophyApiClient
|
|
41
41
|
achievement = nil
|
42
42
|
else
|
43
43
|
achievement = parsed_json["achievement"].to_json
|
44
|
-
achievement = TrophyApiClient::
|
44
|
+
achievement = TrophyApiClient::CompletedAchievementResponse.from_json(json_object: achievement)
|
45
45
|
end
|
46
46
|
new(
|
47
47
|
completion_id: completion_id,
|
@@ -65,7 +65,7 @@ module TrophyApiClient
|
|
65
65
|
# @return [Void]
|
66
66
|
def self.validate_raw(obj:)
|
67
67
|
obj.completion_id.is_a?(String) != false || raise("Passed value for field obj.completion_id is not the expected type, validation failed.")
|
68
|
-
TrophyApiClient::
|
68
|
+
TrophyApiClient::CompletedAchievementResponse.validate_raw(obj: obj.achievement)
|
69
69
|
end
|
70
70
|
end
|
71
71
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "date"
|
4
3
|
require "ostruct"
|
5
4
|
require "json"
|
6
5
|
|
@@ -12,10 +11,10 @@ module TrophyApiClient
|
|
12
11
|
attr_reader :name
|
13
12
|
# @return [String] The trigger of the achievement, either 'metric', 'streak', or 'api'.
|
14
13
|
attr_reader :trigger
|
14
|
+
# @return [String] The description of this achievement.
|
15
|
+
attr_reader :description
|
15
16
|
# @return [String] The URL of the badge image for the achievement, if one has been uploaded.
|
16
17
|
attr_reader :badge_url
|
17
|
-
# @return [DateTime] The date and time the achievement was completed, in ISO 8601 format.
|
18
|
-
attr_reader :achieved_at
|
19
18
|
# @return [String] The key used to reference this achievement in the API (only applicable if
|
20
19
|
# trigger = 'api')
|
21
20
|
attr_reader :key
|
@@ -42,8 +41,8 @@ module TrophyApiClient
|
|
42
41
|
# @param id [String] The unique ID of the achievement.
|
43
42
|
# @param name [String] The name of this achievement.
|
44
43
|
# @param trigger [String] The trigger of the achievement, either 'metric', 'streak', or 'api'.
|
44
|
+
# @param description [String] The description of this achievement.
|
45
45
|
# @param badge_url [String] The URL of the badge image for the achievement, if one has been uploaded.
|
46
|
-
# @param achieved_at [DateTime] The date and time the achievement was completed, in ISO 8601 format.
|
47
46
|
# @param key [String] The key used to reference this achievement in the API (only applicable if
|
48
47
|
# trigger = 'api')
|
49
48
|
# @param streak_length [Integer] The length of the streak required to complete the achievement (only applicable
|
@@ -56,13 +55,13 @@ module TrophyApiClient
|
|
56
55
|
# trigger = 'metric')
|
57
56
|
# @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
|
58
57
|
# @return [TrophyApiClient::AchievementResponse]
|
59
|
-
def initialize(id:, name:, trigger:,
|
58
|
+
def initialize(id:, name:, trigger:, description: OMIT, badge_url: OMIT, key: OMIT, streak_length: OMIT,
|
60
59
|
metric_id: OMIT, metric_value: OMIT, metric_name: OMIT, additional_properties: nil)
|
61
60
|
@id = id
|
62
61
|
@name = name
|
63
62
|
@trigger = trigger
|
63
|
+
@description = description if description != OMIT
|
64
64
|
@badge_url = badge_url if badge_url != OMIT
|
65
|
-
@achieved_at = achieved_at if achieved_at != OMIT
|
66
65
|
@key = key if key != OMIT
|
67
66
|
@streak_length = streak_length if streak_length != OMIT
|
68
67
|
@metric_id = metric_id if metric_id != OMIT
|
@@ -73,8 +72,8 @@ module TrophyApiClient
|
|
73
72
|
"id": id,
|
74
73
|
"name": name,
|
75
74
|
"trigger": trigger,
|
75
|
+
"description": description,
|
76
76
|
"badgeUrl": badge_url,
|
77
|
-
"achievedAt": achieved_at,
|
78
77
|
"key": key,
|
79
78
|
"streakLength": streak_length,
|
80
79
|
"metricId": metric_id,
|
@@ -95,8 +94,8 @@ module TrophyApiClient
|
|
95
94
|
id = parsed_json["id"]
|
96
95
|
name = parsed_json["name"]
|
97
96
|
trigger = parsed_json["trigger"]
|
97
|
+
description = parsed_json["description"]
|
98
98
|
badge_url = parsed_json["badgeUrl"]
|
99
|
-
achieved_at = (DateTime.parse(parsed_json["achievedAt"]) unless parsed_json["achievedAt"].nil?)
|
100
99
|
key = parsed_json["key"]
|
101
100
|
streak_length = parsed_json["streakLength"]
|
102
101
|
metric_id = parsed_json["metricId"]
|
@@ -106,8 +105,8 @@ module TrophyApiClient
|
|
106
105
|
id: id,
|
107
106
|
name: name,
|
108
107
|
trigger: trigger,
|
108
|
+
description: description,
|
109
109
|
badge_url: badge_url,
|
110
|
-
achieved_at: achieved_at,
|
111
110
|
key: key,
|
112
111
|
streak_length: streak_length,
|
113
112
|
metric_id: metric_id,
|
@@ -134,8 +133,8 @@ module TrophyApiClient
|
|
134
133
|
obj.id.is_a?(String) != false || raise("Passed value for field obj.id is not the expected type, validation failed.")
|
135
134
|
obj.name.is_a?(String) != false || raise("Passed value for field obj.name is not the expected type, validation failed.")
|
136
135
|
obj.trigger.is_a?(String) != false || raise("Passed value for field obj.trigger is not the expected type, validation failed.")
|
136
|
+
obj.description&.is_a?(String) != false || raise("Passed value for field obj.description is not the expected type, validation failed.")
|
137
137
|
obj.badge_url&.is_a?(String) != false || raise("Passed value for field obj.badge_url is not the expected type, validation failed.")
|
138
|
-
obj.achieved_at&.is_a?(DateTime) != false || raise("Passed value for field obj.achieved_at is not the expected type, validation failed.")
|
139
138
|
obj.key&.is_a?(String) != false || raise("Passed value for field obj.key is not the expected type, validation failed.")
|
140
139
|
obj.streak_length&.is_a?(Integer) != false || raise("Passed value for field obj.streak_length is not the expected type, validation failed.")
|
141
140
|
obj.metric_id&.is_a?(String) != false || raise("Passed value for field obj.metric_id is not the expected type, validation failed.")
|
@@ -0,0 +1,161 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "ostruct"
|
4
|
+
require "json"
|
5
|
+
|
6
|
+
module TrophyApiClient
|
7
|
+
class AchievementWithStatsResponse
|
8
|
+
# @return [Integer] The number of users who have completed this achievement.
|
9
|
+
attr_reader :completions
|
10
|
+
# @return [Float] The percentage of all users who have completed this achievement.
|
11
|
+
attr_reader :completed_percentage
|
12
|
+
# @return [String] The unique ID of the achievement.
|
13
|
+
attr_reader :id
|
14
|
+
# @return [String] The name of this achievement.
|
15
|
+
attr_reader :name
|
16
|
+
# @return [String] The trigger of the achievement, either 'metric', 'streak', or 'api'.
|
17
|
+
attr_reader :trigger
|
18
|
+
# @return [String] The description of this achievement.
|
19
|
+
attr_reader :description
|
20
|
+
# @return [String] The URL of the badge image for the achievement, if one has been uploaded.
|
21
|
+
attr_reader :badge_url
|
22
|
+
# @return [String] The key used to reference this achievement in the API (only applicable if
|
23
|
+
# trigger = 'api')
|
24
|
+
attr_reader :key
|
25
|
+
# @return [Integer] The length of the streak required to complete the achievement (only applicable
|
26
|
+
# if trigger = 'streak')
|
27
|
+
attr_reader :streak_length
|
28
|
+
# @return [String] The ID of the metric associated with this achievement (only applicable if
|
29
|
+
# trigger = 'metric')
|
30
|
+
attr_reader :metric_id
|
31
|
+
# @return [Float] The value of the metric required to complete the achievement (only applicable if
|
32
|
+
# trigger = 'metric')
|
33
|
+
attr_reader :metric_value
|
34
|
+
# @return [String] The name of the metric associated with this achievement (only applicable if
|
35
|
+
# trigger = 'metric')
|
36
|
+
attr_reader :metric_name
|
37
|
+
# @return [OpenStruct] Additional properties unmapped to the current class definition
|
38
|
+
attr_reader :additional_properties
|
39
|
+
# @return [Object]
|
40
|
+
attr_reader :_field_set
|
41
|
+
protected :_field_set
|
42
|
+
|
43
|
+
OMIT = Object.new
|
44
|
+
|
45
|
+
# @param completions [Integer] The number of users who have completed this achievement.
|
46
|
+
# @param completed_percentage [Float] The percentage of all users who have completed this achievement.
|
47
|
+
# @param id [String] The unique ID of the achievement.
|
48
|
+
# @param name [String] The name of this achievement.
|
49
|
+
# @param trigger [String] The trigger of the achievement, either 'metric', 'streak', or 'api'.
|
50
|
+
# @param description [String] The description of this achievement.
|
51
|
+
# @param badge_url [String] The URL of the badge image for the achievement, if one has been uploaded.
|
52
|
+
# @param key [String] The key used to reference this achievement in the API (only applicable if
|
53
|
+
# trigger = 'api')
|
54
|
+
# @param streak_length [Integer] The length of the streak required to complete the achievement (only applicable
|
55
|
+
# if trigger = 'streak')
|
56
|
+
# @param metric_id [String] The ID of the metric associated with this achievement (only applicable if
|
57
|
+
# trigger = 'metric')
|
58
|
+
# @param metric_value [Float] The value of the metric required to complete the achievement (only applicable if
|
59
|
+
# trigger = 'metric')
|
60
|
+
# @param metric_name [String] The name of the metric associated with this achievement (only applicable if
|
61
|
+
# trigger = 'metric')
|
62
|
+
# @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
|
63
|
+
# @return [TrophyApiClient::AchievementWithStatsResponse]
|
64
|
+
def initialize(id:, name:, trigger:, completions: OMIT, completed_percentage: OMIT, description: OMIT,
|
65
|
+
badge_url: OMIT, key: OMIT, streak_length: OMIT, metric_id: OMIT, metric_value: OMIT, metric_name: OMIT, additional_properties: nil)
|
66
|
+
@completions = completions if completions != OMIT
|
67
|
+
@completed_percentage = completed_percentage if completed_percentage != OMIT
|
68
|
+
@id = id
|
69
|
+
@name = name
|
70
|
+
@trigger = trigger
|
71
|
+
@description = description if description != OMIT
|
72
|
+
@badge_url = badge_url if badge_url != OMIT
|
73
|
+
@key = key if key != OMIT
|
74
|
+
@streak_length = streak_length if streak_length != OMIT
|
75
|
+
@metric_id = metric_id if metric_id != OMIT
|
76
|
+
@metric_value = metric_value if metric_value != OMIT
|
77
|
+
@metric_name = metric_name if metric_name != OMIT
|
78
|
+
@additional_properties = additional_properties
|
79
|
+
@_field_set = {
|
80
|
+
"completions": completions,
|
81
|
+
"completedPercentage": completed_percentage,
|
82
|
+
"id": id,
|
83
|
+
"name": name,
|
84
|
+
"trigger": trigger,
|
85
|
+
"description": description,
|
86
|
+
"badgeUrl": badge_url,
|
87
|
+
"key": key,
|
88
|
+
"streakLength": streak_length,
|
89
|
+
"metricId": metric_id,
|
90
|
+
"metricValue": metric_value,
|
91
|
+
"metricName": metric_name
|
92
|
+
}.reject do |_k, v|
|
93
|
+
v == OMIT
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
# Deserialize a JSON object to an instance of AchievementWithStatsResponse
|
98
|
+
#
|
99
|
+
# @param json_object [String]
|
100
|
+
# @return [TrophyApiClient::AchievementWithStatsResponse]
|
101
|
+
def self.from_json(json_object:)
|
102
|
+
struct = JSON.parse(json_object, object_class: OpenStruct)
|
103
|
+
parsed_json = JSON.parse(json_object)
|
104
|
+
completions = parsed_json["completions"]
|
105
|
+
completed_percentage = parsed_json["completedPercentage"]
|
106
|
+
id = parsed_json["id"]
|
107
|
+
name = parsed_json["name"]
|
108
|
+
trigger = parsed_json["trigger"]
|
109
|
+
description = parsed_json["description"]
|
110
|
+
badge_url = parsed_json["badgeUrl"]
|
111
|
+
key = parsed_json["key"]
|
112
|
+
streak_length = parsed_json["streakLength"]
|
113
|
+
metric_id = parsed_json["metricId"]
|
114
|
+
metric_value = parsed_json["metricValue"]
|
115
|
+
metric_name = parsed_json["metricName"]
|
116
|
+
new(
|
117
|
+
completions: completions,
|
118
|
+
completed_percentage: completed_percentage,
|
119
|
+
id: id,
|
120
|
+
name: name,
|
121
|
+
trigger: trigger,
|
122
|
+
description: description,
|
123
|
+
badge_url: badge_url,
|
124
|
+
key: key,
|
125
|
+
streak_length: streak_length,
|
126
|
+
metric_id: metric_id,
|
127
|
+
metric_value: metric_value,
|
128
|
+
metric_name: metric_name,
|
129
|
+
additional_properties: struct
|
130
|
+
)
|
131
|
+
end
|
132
|
+
|
133
|
+
# Serialize an instance of AchievementWithStatsResponse to a JSON object
|
134
|
+
#
|
135
|
+
# @return [String]
|
136
|
+
def to_json(*_args)
|
137
|
+
@_field_set&.to_json
|
138
|
+
end
|
139
|
+
|
140
|
+
# Leveraged for Union-type generation, validate_raw attempts to parse the given
|
141
|
+
# hash and check each fields type against the current object's property
|
142
|
+
# definitions.
|
143
|
+
#
|
144
|
+
# @param obj [Object]
|
145
|
+
# @return [Void]
|
146
|
+
def self.validate_raw(obj:)
|
147
|
+
obj.completions&.is_a?(Integer) != false || raise("Passed value for field obj.completions is not the expected type, validation failed.")
|
148
|
+
obj.completed_percentage&.is_a?(Float) != false || raise("Passed value for field obj.completed_percentage is not the expected type, validation failed.")
|
149
|
+
obj.id.is_a?(String) != false || raise("Passed value for field obj.id is not the expected type, validation failed.")
|
150
|
+
obj.name.is_a?(String) != false || raise("Passed value for field obj.name is not the expected type, validation failed.")
|
151
|
+
obj.trigger.is_a?(String) != false || raise("Passed value for field obj.trigger is not the expected type, validation failed.")
|
152
|
+
obj.description&.is_a?(String) != false || raise("Passed value for field obj.description is not the expected type, validation failed.")
|
153
|
+
obj.badge_url&.is_a?(String) != false || raise("Passed value for field obj.badge_url is not the expected type, validation failed.")
|
154
|
+
obj.key&.is_a?(String) != false || raise("Passed value for field obj.key is not the expected type, validation failed.")
|
155
|
+
obj.streak_length&.is_a?(Integer) != false || raise("Passed value for field obj.streak_length is not the expected type, validation failed.")
|
156
|
+
obj.metric_id&.is_a?(String) != false || raise("Passed value for field obj.metric_id is not the expected type, validation failed.")
|
157
|
+
obj.metric_value&.is_a?(Float) != false || raise("Passed value for field obj.metric_value is not the expected type, validation failed.")
|
158
|
+
obj.metric_name&.is_a?(String) != false || raise("Passed value for field obj.metric_name is not the expected type, validation failed.")
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
@@ -0,0 +1,154 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "date"
|
4
|
+
require "ostruct"
|
5
|
+
require "json"
|
6
|
+
|
7
|
+
module TrophyApiClient
|
8
|
+
class CompletedAchievementResponse
|
9
|
+
# @return [DateTime] The date and time the achievement was completed, in ISO 8601 format.
|
10
|
+
attr_reader :achieved_at
|
11
|
+
# @return [String] The unique ID of the achievement.
|
12
|
+
attr_reader :id
|
13
|
+
# @return [String] The name of this achievement.
|
14
|
+
attr_reader :name
|
15
|
+
# @return [String] The trigger of the achievement, either 'metric', 'streak', or 'api'.
|
16
|
+
attr_reader :trigger
|
17
|
+
# @return [String] The description of this achievement.
|
18
|
+
attr_reader :description
|
19
|
+
# @return [String] The URL of the badge image for the achievement, if one has been uploaded.
|
20
|
+
attr_reader :badge_url
|
21
|
+
# @return [String] The key used to reference this achievement in the API (only applicable if
|
22
|
+
# trigger = 'api')
|
23
|
+
attr_reader :key
|
24
|
+
# @return [Integer] The length of the streak required to complete the achievement (only applicable
|
25
|
+
# if trigger = 'streak')
|
26
|
+
attr_reader :streak_length
|
27
|
+
# @return [String] The ID of the metric associated with this achievement (only applicable if
|
28
|
+
# trigger = 'metric')
|
29
|
+
attr_reader :metric_id
|
30
|
+
# @return [Float] The value of the metric required to complete the achievement (only applicable if
|
31
|
+
# trigger = 'metric')
|
32
|
+
attr_reader :metric_value
|
33
|
+
# @return [String] The name of the metric associated with this achievement (only applicable if
|
34
|
+
# trigger = 'metric')
|
35
|
+
attr_reader :metric_name
|
36
|
+
# @return [OpenStruct] Additional properties unmapped to the current class definition
|
37
|
+
attr_reader :additional_properties
|
38
|
+
# @return [Object]
|
39
|
+
attr_reader :_field_set
|
40
|
+
protected :_field_set
|
41
|
+
|
42
|
+
OMIT = Object.new
|
43
|
+
|
44
|
+
# @param achieved_at [DateTime] The date and time the achievement was completed, in ISO 8601 format.
|
45
|
+
# @param id [String] The unique ID of the achievement.
|
46
|
+
# @param name [String] The name of this achievement.
|
47
|
+
# @param trigger [String] The trigger of the achievement, either 'metric', 'streak', or 'api'.
|
48
|
+
# @param description [String] The description of this achievement.
|
49
|
+
# @param badge_url [String] The URL of the badge image for the achievement, if one has been uploaded.
|
50
|
+
# @param key [String] The key used to reference this achievement in the API (only applicable if
|
51
|
+
# trigger = 'api')
|
52
|
+
# @param streak_length [Integer] The length of the streak required to complete the achievement (only applicable
|
53
|
+
# if trigger = 'streak')
|
54
|
+
# @param metric_id [String] The ID of the metric associated with this achievement (only applicable if
|
55
|
+
# trigger = 'metric')
|
56
|
+
# @param metric_value [Float] The value of the metric required to complete the achievement (only applicable if
|
57
|
+
# trigger = 'metric')
|
58
|
+
# @param metric_name [String] The name of the metric associated with this achievement (only applicable if
|
59
|
+
# trigger = 'metric')
|
60
|
+
# @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
|
61
|
+
# @return [TrophyApiClient::CompletedAchievementResponse]
|
62
|
+
def initialize(id:, name:, trigger:, achieved_at: OMIT, description: OMIT, badge_url: OMIT, key: OMIT,
|
63
|
+
streak_length: OMIT, metric_id: OMIT, metric_value: OMIT, metric_name: OMIT, additional_properties: nil)
|
64
|
+
@achieved_at = achieved_at if achieved_at != OMIT
|
65
|
+
@id = id
|
66
|
+
@name = name
|
67
|
+
@trigger = trigger
|
68
|
+
@description = description if description != OMIT
|
69
|
+
@badge_url = badge_url if badge_url != OMIT
|
70
|
+
@key = key if key != OMIT
|
71
|
+
@streak_length = streak_length if streak_length != OMIT
|
72
|
+
@metric_id = metric_id if metric_id != OMIT
|
73
|
+
@metric_value = metric_value if metric_value != OMIT
|
74
|
+
@metric_name = metric_name if metric_name != OMIT
|
75
|
+
@additional_properties = additional_properties
|
76
|
+
@_field_set = {
|
77
|
+
"achievedAt": achieved_at,
|
78
|
+
"id": id,
|
79
|
+
"name": name,
|
80
|
+
"trigger": trigger,
|
81
|
+
"description": description,
|
82
|
+
"badgeUrl": badge_url,
|
83
|
+
"key": key,
|
84
|
+
"streakLength": streak_length,
|
85
|
+
"metricId": metric_id,
|
86
|
+
"metricValue": metric_value,
|
87
|
+
"metricName": metric_name
|
88
|
+
}.reject do |_k, v|
|
89
|
+
v == OMIT
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
# Deserialize a JSON object to an instance of CompletedAchievementResponse
|
94
|
+
#
|
95
|
+
# @param json_object [String]
|
96
|
+
# @return [TrophyApiClient::CompletedAchievementResponse]
|
97
|
+
def self.from_json(json_object:)
|
98
|
+
struct = JSON.parse(json_object, object_class: OpenStruct)
|
99
|
+
parsed_json = JSON.parse(json_object)
|
100
|
+
achieved_at = (DateTime.parse(parsed_json["achievedAt"]) unless parsed_json["achievedAt"].nil?)
|
101
|
+
id = parsed_json["id"]
|
102
|
+
name = parsed_json["name"]
|
103
|
+
trigger = parsed_json["trigger"]
|
104
|
+
description = parsed_json["description"]
|
105
|
+
badge_url = parsed_json["badgeUrl"]
|
106
|
+
key = parsed_json["key"]
|
107
|
+
streak_length = parsed_json["streakLength"]
|
108
|
+
metric_id = parsed_json["metricId"]
|
109
|
+
metric_value = parsed_json["metricValue"]
|
110
|
+
metric_name = parsed_json["metricName"]
|
111
|
+
new(
|
112
|
+
achieved_at: achieved_at,
|
113
|
+
id: id,
|
114
|
+
name: name,
|
115
|
+
trigger: trigger,
|
116
|
+
description: description,
|
117
|
+
badge_url: badge_url,
|
118
|
+
key: key,
|
119
|
+
streak_length: streak_length,
|
120
|
+
metric_id: metric_id,
|
121
|
+
metric_value: metric_value,
|
122
|
+
metric_name: metric_name,
|
123
|
+
additional_properties: struct
|
124
|
+
)
|
125
|
+
end
|
126
|
+
|
127
|
+
# Serialize an instance of CompletedAchievementResponse to a JSON object
|
128
|
+
#
|
129
|
+
# @return [String]
|
130
|
+
def to_json(*_args)
|
131
|
+
@_field_set&.to_json
|
132
|
+
end
|
133
|
+
|
134
|
+
# Leveraged for Union-type generation, validate_raw attempts to parse the given
|
135
|
+
# hash and check each fields type against the current object's property
|
136
|
+
# definitions.
|
137
|
+
#
|
138
|
+
# @param obj [Object]
|
139
|
+
# @return [Void]
|
140
|
+
def self.validate_raw(obj:)
|
141
|
+
obj.achieved_at&.is_a?(DateTime) != false || raise("Passed value for field obj.achieved_at is not the expected type, validation failed.")
|
142
|
+
obj.id.is_a?(String) != false || raise("Passed value for field obj.id is not the expected type, validation failed.")
|
143
|
+
obj.name.is_a?(String) != false || raise("Passed value for field obj.name is not the expected type, validation failed.")
|
144
|
+
obj.trigger.is_a?(String) != false || raise("Passed value for field obj.trigger is not the expected type, validation failed.")
|
145
|
+
obj.description&.is_a?(String) != false || raise("Passed value for field obj.description is not the expected type, validation failed.")
|
146
|
+
obj.badge_url&.is_a?(String) != false || raise("Passed value for field obj.badge_url is not the expected type, validation failed.")
|
147
|
+
obj.key&.is_a?(String) != false || raise("Passed value for field obj.key is not the expected type, validation failed.")
|
148
|
+
obj.streak_length&.is_a?(Integer) != false || raise("Passed value for field obj.streak_length is not the expected type, validation failed.")
|
149
|
+
obj.metric_id&.is_a?(String) != false || raise("Passed value for field obj.metric_id is not the expected type, validation failed.")
|
150
|
+
obj.metric_value&.is_a?(Float) != false || raise("Passed value for field obj.metric_value is not the expected type, validation failed.")
|
151
|
+
obj.metric_name&.is_a?(String) != false || raise("Passed value for field obj.metric_name is not the expected type, validation failed.")
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "
|
3
|
+
require_relative "completed_achievement_response"
|
4
4
|
require_relative "increment_metric_streak_response"
|
5
5
|
require "ostruct"
|
6
6
|
require "json"
|
@@ -13,7 +13,7 @@ module TrophyApiClient
|
|
13
13
|
attr_reader :metric_id
|
14
14
|
# @return [Float] The user's new total progress against the metric.
|
15
15
|
attr_reader :total
|
16
|
-
# @return [Array<TrophyApiClient::
|
16
|
+
# @return [Array<TrophyApiClient::CompletedAchievementResponse>] Achievements completed as a result of this event.
|
17
17
|
attr_reader :achievements
|
18
18
|
# @return [TrophyApiClient::IncrementMetricStreakResponse] The user's current streak for the metric, if the metric has streaks enabled.
|
19
19
|
attr_reader :current_streak
|
@@ -28,7 +28,7 @@ module TrophyApiClient
|
|
28
28
|
# @param event_id [String] The unique ID of the event.
|
29
29
|
# @param metric_id [String] The unique ID of the metric that was updated.
|
30
30
|
# @param total [Float] The user's new total progress against the metric.
|
31
|
-
# @param achievements [Array<TrophyApiClient::
|
31
|
+
# @param achievements [Array<TrophyApiClient::CompletedAchievementResponse>] Achievements completed as a result of this event.
|
32
32
|
# @param current_streak [TrophyApiClient::IncrementMetricStreakResponse] The user's current streak for the metric, if the metric has streaks enabled.
|
33
33
|
# @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
|
34
34
|
# @return [TrophyApiClient::EventResponse]
|
@@ -62,7 +62,7 @@ module TrophyApiClient
|
|
62
62
|
total = parsed_json["total"]
|
63
63
|
achievements = parsed_json["achievements"]&.map do |item|
|
64
64
|
item = item.to_json
|
65
|
-
TrophyApiClient::
|
65
|
+
TrophyApiClient::CompletedAchievementResponse.from_json(json_object: item)
|
66
66
|
end
|
67
67
|
if parsed_json["currentStreak"].nil?
|
68
68
|
current_streak = nil
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative "metric_status"
|
4
|
-
require_relative "
|
4
|
+
require_relative "completed_achievement_response"
|
5
5
|
require "ostruct"
|
6
6
|
require "json"
|
7
7
|
|
@@ -17,7 +17,7 @@ module TrophyApiClient
|
|
17
17
|
attr_reader :status
|
18
18
|
# @return [Float] The user's current total for the metric.
|
19
19
|
attr_reader :current
|
20
|
-
# @return [Array<TrophyApiClient::
|
20
|
+
# @return [Array<TrophyApiClient::CompletedAchievementResponse>] A list of the metric's achievements and the user's progress towards each.
|
21
21
|
attr_reader :achievements
|
22
22
|
# @return [OpenStruct] Additional properties unmapped to the current class definition
|
23
23
|
attr_reader :additional_properties
|
@@ -32,7 +32,7 @@ module TrophyApiClient
|
|
32
32
|
# @param name [String] The name of the metric.
|
33
33
|
# @param status [TrophyApiClient::MetricStatus] The status of the metric.
|
34
34
|
# @param current [Float] The user's current total for the metric.
|
35
|
-
# @param achievements [Array<TrophyApiClient::
|
35
|
+
# @param achievements [Array<TrophyApiClient::CompletedAchievementResponse>] A list of the metric's achievements and the user's progress towards each.
|
36
36
|
# @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
|
37
37
|
# @return [TrophyApiClient::MetricResponse]
|
38
38
|
def initialize(id:, key:, name:, status:, current:, achievements:, additional_properties: nil)
|
@@ -67,7 +67,7 @@ module TrophyApiClient
|
|
67
67
|
current = parsed_json["current"]
|
68
68
|
achievements = parsed_json["achievements"]&.map do |item|
|
69
69
|
item = item.to_json
|
70
|
-
TrophyApiClient::
|
70
|
+
TrophyApiClient::CompletedAchievementResponse.from_json(json_object: item)
|
71
71
|
end
|
72
72
|
new(
|
73
73
|
id: id,
|
@@ -6,7 +6,9 @@ require_relative "../types/user"
|
|
6
6
|
require_relative "../types/updated_user"
|
7
7
|
require_relative "../types/metric_response"
|
8
8
|
require "json"
|
9
|
-
require_relative "
|
9
|
+
require_relative "types/users_metric_event_summary_request_aggregation"
|
10
|
+
require_relative "types/users_metric_event_summary_response_item"
|
11
|
+
require_relative "../types/completed_achievement_response"
|
10
12
|
require_relative "../types/streak_response"
|
11
13
|
require "async"
|
12
14
|
|
@@ -192,11 +194,62 @@ module TrophyApiClient
|
|
192
194
|
TrophyApiClient::MetricResponse.from_json(json_object: response.body)
|
193
195
|
end
|
194
196
|
|
197
|
+
# Get a summary of metric events over time for a user.
|
198
|
+
#
|
199
|
+
# @param id [String] ID of the user.
|
200
|
+
# @param key [String] Unique key of the metric.
|
201
|
+
# @param aggregation [TrophyApiClient::Users::UsersMetricEventSummaryRequestAggregation] The time period over which to aggregate the event data.
|
202
|
+
# @param start_date [String] The start date for the data range in YYYY-MM-DD format. The startDate must be
|
203
|
+
# before the endDate, and the date range must not exceed 400 days.
|
204
|
+
# @param end_date [String] The end date for the data range in YYYY-MM-DD format. The endDate must be after
|
205
|
+
# the startDate, and the date range must not exceed 400 days.
|
206
|
+
# @param request_options [TrophyApiClient::RequestOptions]
|
207
|
+
# @return [Array<TrophyApiClient::Users::UsersMetricEventSummaryResponseItem>]
|
208
|
+
# @example
|
209
|
+
# api = TrophyApiClient::Client.new(
|
210
|
+
# base_url: "https://api.example.com",
|
211
|
+
# environment: TrophyApiClient::Environment::DEFAULT,
|
212
|
+
# api_key: "YOUR_API_KEY"
|
213
|
+
# )
|
214
|
+
# api.users.metric_event_summary(
|
215
|
+
# id: "userId",
|
216
|
+
# key: "words-written",
|
217
|
+
# aggregation: DAILY,
|
218
|
+
# start_date: "2024-01-01",
|
219
|
+
# end_date: "2024-01-31"
|
220
|
+
# )
|
221
|
+
def metric_event_summary(id:, key:, aggregation:, start_date:, end_date:, request_options: nil)
|
222
|
+
response = @request_client.conn.get do |req|
|
223
|
+
req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
|
224
|
+
req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
|
225
|
+
req.headers = {
|
226
|
+
**(req.headers || {}),
|
227
|
+
**@request_client.get_headers,
|
228
|
+
**(request_options&.additional_headers || {})
|
229
|
+
}.compact
|
230
|
+
req.params = {
|
231
|
+
**(request_options&.additional_query_parameters || {}),
|
232
|
+
"aggregation": aggregation,
|
233
|
+
"startDate": start_date,
|
234
|
+
"endDate": end_date
|
235
|
+
}.compact
|
236
|
+
unless request_options.nil? || request_options&.additional_body_parameters.nil?
|
237
|
+
req.body = { **(request_options&.additional_body_parameters || {}) }.compact
|
238
|
+
end
|
239
|
+
req.url "#{@request_client.get_url(request_options: request_options)}/users/#{id}/metrics/#{key}/event-summary"
|
240
|
+
end
|
241
|
+
parsed_json = JSON.parse(response.body)
|
242
|
+
parsed_json&.map do |item|
|
243
|
+
item = item.to_json
|
244
|
+
TrophyApiClient::Users::UsersMetricEventSummaryResponseItem.from_json(json_object: item)
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
195
248
|
# Get all of a user's completed achievements.
|
196
249
|
#
|
197
250
|
# @param id [String] ID of the user.
|
198
251
|
# @param request_options [TrophyApiClient::RequestOptions]
|
199
|
-
# @return [Array<TrophyApiClient::
|
252
|
+
# @return [Array<TrophyApiClient::CompletedAchievementResponse>]
|
200
253
|
# @example
|
201
254
|
# api = TrophyApiClient::Client.new(
|
202
255
|
# base_url: "https://api.example.com",
|
@@ -224,7 +277,7 @@ module TrophyApiClient
|
|
224
277
|
parsed_json = JSON.parse(response.body)
|
225
278
|
parsed_json&.map do |item|
|
226
279
|
item = item.to_json
|
227
|
-
TrophyApiClient::
|
280
|
+
TrophyApiClient::CompletedAchievementResponse.from_json(json_object: item)
|
228
281
|
end
|
229
282
|
end
|
230
283
|
|
@@ -455,11 +508,64 @@ module TrophyApiClient
|
|
455
508
|
end
|
456
509
|
end
|
457
510
|
|
511
|
+
# Get a summary of metric events over time for a user.
|
512
|
+
#
|
513
|
+
# @param id [String] ID of the user.
|
514
|
+
# @param key [String] Unique key of the metric.
|
515
|
+
# @param aggregation [TrophyApiClient::Users::UsersMetricEventSummaryRequestAggregation] The time period over which to aggregate the event data.
|
516
|
+
# @param start_date [String] The start date for the data range in YYYY-MM-DD format. The startDate must be
|
517
|
+
# before the endDate, and the date range must not exceed 400 days.
|
518
|
+
# @param end_date [String] The end date for the data range in YYYY-MM-DD format. The endDate must be after
|
519
|
+
# the startDate, and the date range must not exceed 400 days.
|
520
|
+
# @param request_options [TrophyApiClient::RequestOptions]
|
521
|
+
# @return [Array<TrophyApiClient::Users::UsersMetricEventSummaryResponseItem>]
|
522
|
+
# @example
|
523
|
+
# api = TrophyApiClient::Client.new(
|
524
|
+
# base_url: "https://api.example.com",
|
525
|
+
# environment: TrophyApiClient::Environment::DEFAULT,
|
526
|
+
# api_key: "YOUR_API_KEY"
|
527
|
+
# )
|
528
|
+
# api.users.metric_event_summary(
|
529
|
+
# id: "userId",
|
530
|
+
# key: "words-written",
|
531
|
+
# aggregation: DAILY,
|
532
|
+
# start_date: "2024-01-01",
|
533
|
+
# end_date: "2024-01-31"
|
534
|
+
# )
|
535
|
+
def metric_event_summary(id:, key:, aggregation:, start_date:, end_date:, request_options: nil)
|
536
|
+
Async do
|
537
|
+
response = @request_client.conn.get do |req|
|
538
|
+
req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
|
539
|
+
req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
|
540
|
+
req.headers = {
|
541
|
+
**(req.headers || {}),
|
542
|
+
**@request_client.get_headers,
|
543
|
+
**(request_options&.additional_headers || {})
|
544
|
+
}.compact
|
545
|
+
req.params = {
|
546
|
+
**(request_options&.additional_query_parameters || {}),
|
547
|
+
"aggregation": aggregation,
|
548
|
+
"startDate": start_date,
|
549
|
+
"endDate": end_date
|
550
|
+
}.compact
|
551
|
+
unless request_options.nil? || request_options&.additional_body_parameters.nil?
|
552
|
+
req.body = { **(request_options&.additional_body_parameters || {}) }.compact
|
553
|
+
end
|
554
|
+
req.url "#{@request_client.get_url(request_options: request_options)}/users/#{id}/metrics/#{key}/event-summary"
|
555
|
+
end
|
556
|
+
parsed_json = JSON.parse(response.body)
|
557
|
+
parsed_json&.map do |item|
|
558
|
+
item = item.to_json
|
559
|
+
TrophyApiClient::Users::UsersMetricEventSummaryResponseItem.from_json(json_object: item)
|
560
|
+
end
|
561
|
+
end
|
562
|
+
end
|
563
|
+
|
458
564
|
# Get all of a user's completed achievements.
|
459
565
|
#
|
460
566
|
# @param id [String] ID of the user.
|
461
567
|
# @param request_options [TrophyApiClient::RequestOptions]
|
462
|
-
# @return [Array<TrophyApiClient::
|
568
|
+
# @return [Array<TrophyApiClient::CompletedAchievementResponse>]
|
463
569
|
# @example
|
464
570
|
# api = TrophyApiClient::Client.new(
|
465
571
|
# base_url: "https://api.example.com",
|
@@ -488,7 +594,7 @@ module TrophyApiClient
|
|
488
594
|
parsed_json = JSON.parse(response.body)
|
489
595
|
parsed_json&.map do |item|
|
490
596
|
item = item.to_json
|
491
|
-
TrophyApiClient::
|
597
|
+
TrophyApiClient::CompletedAchievementResponse.from_json(json_object: item)
|
492
598
|
end
|
493
599
|
end
|
494
600
|
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "ostruct"
|
4
|
+
require "json"
|
5
|
+
|
6
|
+
module TrophyApiClient
|
7
|
+
class Users
|
8
|
+
class UsersMetricEventSummaryResponseItem
|
9
|
+
# @return [String] The date of the data point. For weekly or monthly aggregations, this is the
|
10
|
+
# first date of the period.
|
11
|
+
attr_reader :date
|
12
|
+
# @return [Float] The user's total for this metric at the end of this date.
|
13
|
+
attr_reader :total
|
14
|
+
# @return [Float] The change in the user's total for this metric during this period.
|
15
|
+
attr_reader :change
|
16
|
+
# @return [OpenStruct] Additional properties unmapped to the current class definition
|
17
|
+
attr_reader :additional_properties
|
18
|
+
# @return [Object]
|
19
|
+
attr_reader :_field_set
|
20
|
+
protected :_field_set
|
21
|
+
|
22
|
+
OMIT = Object.new
|
23
|
+
|
24
|
+
# @param date [String] The date of the data point. For weekly or monthly aggregations, this is the
|
25
|
+
# first date of the period.
|
26
|
+
# @param total [Float] The user's total for this metric at the end of this date.
|
27
|
+
# @param change [Float] The change in the user's total for this metric during this period.
|
28
|
+
# @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
|
29
|
+
# @return [TrophyApiClient::Users::UsersMetricEventSummaryResponseItem]
|
30
|
+
def initialize(date:, total:, change:, additional_properties: nil)
|
31
|
+
@date = date
|
32
|
+
@total = total
|
33
|
+
@change = change
|
34
|
+
@additional_properties = additional_properties
|
35
|
+
@_field_set = { "date": date, "total": total, "change": change }
|
36
|
+
end
|
37
|
+
|
38
|
+
# Deserialize a JSON object to an instance of UsersMetricEventSummaryResponseItem
|
39
|
+
#
|
40
|
+
# @param json_object [String]
|
41
|
+
# @return [TrophyApiClient::Users::UsersMetricEventSummaryResponseItem]
|
42
|
+
def self.from_json(json_object:)
|
43
|
+
struct = JSON.parse(json_object, object_class: OpenStruct)
|
44
|
+
parsed_json = JSON.parse(json_object)
|
45
|
+
date = parsed_json["date"]
|
46
|
+
total = parsed_json["total"]
|
47
|
+
change = parsed_json["change"]
|
48
|
+
new(
|
49
|
+
date: date,
|
50
|
+
total: total,
|
51
|
+
change: change,
|
52
|
+
additional_properties: struct
|
53
|
+
)
|
54
|
+
end
|
55
|
+
|
56
|
+
# Serialize an instance of UsersMetricEventSummaryResponseItem 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.date.is_a?(String) != false || raise("Passed value for field obj.date is not the expected type, validation failed.")
|
71
|
+
obj.total.is_a?(Float) != false || raise("Passed value for field obj.total is not the expected type, validation failed.")
|
72
|
+
obj.change.is_a?(Float) != false || raise("Passed value for field obj.change is not the expected type, validation failed.")
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
data/lib/types_export.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative "trophy_api_client/users/types/users_metric_event_summary_request_aggregation"
|
4
|
+
require_relative "trophy_api_client/users/types/users_metric_event_summary_response_item"
|
3
5
|
require_relative "trophy_api_client/types/metric_status"
|
4
6
|
require_relative "trophy_api_client/types/streak_frequency"
|
5
7
|
require_relative "trophy_api_client/types/base_streak_response"
|
@@ -7,6 +9,8 @@ require_relative "trophy_api_client/types/increment_metric_streak_response"
|
|
7
9
|
require_relative "trophy_api_client/types/streak_response_streak_history_item"
|
8
10
|
require_relative "trophy_api_client/types/streak_response"
|
9
11
|
require_relative "trophy_api_client/types/achievement_response"
|
12
|
+
require_relative "trophy_api_client/types/completed_achievement_response"
|
13
|
+
require_relative "trophy_api_client/types/achievement_with_stats_response"
|
10
14
|
require_relative "trophy_api_client/types/metric_response"
|
11
15
|
require_relative "trophy_api_client/types/updated_user"
|
12
16
|
require_relative "trophy_api_client/types/upserted_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.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Trophy Labs, Inc
|
@@ -103,7 +103,9 @@ files:
|
|
103
103
|
- lib/trophy_api_client/metrics/client.rb
|
104
104
|
- lib/trophy_api_client/types/achievement_completion_response.rb
|
105
105
|
- lib/trophy_api_client/types/achievement_response.rb
|
106
|
+
- lib/trophy_api_client/types/achievement_with_stats_response.rb
|
106
107
|
- lib/trophy_api_client/types/base_streak_response.rb
|
108
|
+
- lib/trophy_api_client/types/completed_achievement_response.rb
|
107
109
|
- lib/trophy_api_client/types/error_body.rb
|
108
110
|
- lib/trophy_api_client/types/event_response.rb
|
109
111
|
- lib/trophy_api_client/types/increment_metric_streak_response.rb
|
@@ -116,6 +118,8 @@ files:
|
|
116
118
|
- lib/trophy_api_client/types/upserted_user.rb
|
117
119
|
- lib/trophy_api_client/types/user.rb
|
118
120
|
- lib/trophy_api_client/users/client.rb
|
121
|
+
- lib/trophy_api_client/users/types/users_metric_event_summary_request_aggregation.rb
|
122
|
+
- lib/trophy_api_client/users/types/users_metric_event_summary_response_item.rb
|
119
123
|
- lib/trophy_api_client/version.rb
|
120
124
|
- lib/types_export.rb
|
121
125
|
homepage: https://github.com/trophyso/trophy-ruby
|