trophy_api_client 1.0.2 → 1.0.4
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/types/achievement_completion_response.rb +5 -5
- data/lib/trophy_api_client/types/base_streak_response.rb +104 -0
- data/lib/trophy_api_client/types/event_response.rb +5 -5
- data/lib/trophy_api_client/types/event_response_metrics_item.rb +4 -4
- data/lib/trophy_api_client/types/increment_metric_streak_response.rb +113 -0
- data/lib/trophy_api_client/types/metric_response.rb +7 -33
- data/lib/trophy_api_client/types/{achievement_response.rb → multi_stage_achievement_response.rb} +5 -5
- data/lib/trophy_api_client/types/one_off_achievement_response.rb +95 -0
- data/lib/trophy_api_client/types/streak_response.rb +55 -2
- data/lib/trophy_api_client/types/streak_response_streak_history_item.rb +73 -0
- data/lib/trophy_api_client/users/client.rb +80 -7
- data/lib/trophy_api_client/version.rb +1 -1
- data/lib/types_export.rb +5 -1
- metadata +8 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b24d28841d30125051d3eb1effdadbbac7ba3b1fb1c912bc37f3975d72c7dac0
|
4
|
+
data.tar.gz: e6dfbc42d4a6df6edbc44b0305139c25cc9f1d66368c5a59aac1ee93a2c8c54d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ffef758de2594e6462fa5cbb5af4db9c091d7474e983d780b65edc62f36bc3415849581b4c0274b819250906caabdae1fae8c5f0553c516e03cbb698dca2def3
|
7
|
+
data.tar.gz: 9ecb5035b6d3370d34ca537ec41f60a53bf83e3f2e5dae911bb8d3b8c56f2601008b2e68adc9cbaa632418171144658f944d49c23629961984e8875f7b1755b8
|
data/lib/gemconfig.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "
|
3
|
+
require_relative "one_off_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::OneOffAchievementResponse]
|
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::OneOffAchievementResponse]
|
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::OneOffAchievementResponse.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::OneOffAchievementResponse.validate_raw(obj: obj.achievement)
|
69
69
|
end
|
70
70
|
end
|
71
71
|
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "streak_frequency"
|
4
|
+
require "ostruct"
|
5
|
+
require "json"
|
6
|
+
|
7
|
+
module TrophyApiClient
|
8
|
+
class BaseStreakResponse
|
9
|
+
# @return [Integer] The length of the user's current streak.
|
10
|
+
attr_reader :length
|
11
|
+
# @return [TrophyApiClient::StreakFrequency] The frequency of the streak.
|
12
|
+
attr_reader :frequency
|
13
|
+
# @return [String] The date the streak started.
|
14
|
+
attr_reader :started
|
15
|
+
# @return [String] The start date of the current streak period.
|
16
|
+
attr_reader :period_start
|
17
|
+
# @return [String] The end date of the current streak period.
|
18
|
+
attr_reader :period_end
|
19
|
+
# @return [String] The date the streak will expire if the user does not increment a metric.
|
20
|
+
attr_reader :expires
|
21
|
+
# @return [OpenStruct] Additional properties unmapped to the current class definition
|
22
|
+
attr_reader :additional_properties
|
23
|
+
# @return [Object]
|
24
|
+
attr_reader :_field_set
|
25
|
+
protected :_field_set
|
26
|
+
|
27
|
+
OMIT = Object.new
|
28
|
+
|
29
|
+
# @param length [Integer] The length of the user's current streak.
|
30
|
+
# @param frequency [TrophyApiClient::StreakFrequency] The frequency of the streak.
|
31
|
+
# @param started [String] The date the streak started.
|
32
|
+
# @param period_start [String] The start date of the current streak period.
|
33
|
+
# @param period_end [String] The end date of the current streak period.
|
34
|
+
# @param expires [String] The date the streak will expire if the user does not increment a metric.
|
35
|
+
# @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
|
36
|
+
# @return [TrophyApiClient::BaseStreakResponse]
|
37
|
+
def initialize(length:, frequency:, started: OMIT, period_start: OMIT, period_end: OMIT, expires: OMIT,
|
38
|
+
additional_properties: nil)
|
39
|
+
@length = length
|
40
|
+
@frequency = frequency
|
41
|
+
@started = started if started != OMIT
|
42
|
+
@period_start = period_start if period_start != OMIT
|
43
|
+
@period_end = period_end if period_end != OMIT
|
44
|
+
@expires = expires if expires != OMIT
|
45
|
+
@additional_properties = additional_properties
|
46
|
+
@_field_set = {
|
47
|
+
"length": length,
|
48
|
+
"frequency": frequency,
|
49
|
+
"started": started,
|
50
|
+
"periodStart": period_start,
|
51
|
+
"periodEnd": period_end,
|
52
|
+
"expires": expires
|
53
|
+
}.reject do |_k, v|
|
54
|
+
v == OMIT
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# Deserialize a JSON object to an instance of BaseStreakResponse
|
59
|
+
#
|
60
|
+
# @param json_object [String]
|
61
|
+
# @return [TrophyApiClient::BaseStreakResponse]
|
62
|
+
def self.from_json(json_object:)
|
63
|
+
struct = JSON.parse(json_object, object_class: OpenStruct)
|
64
|
+
parsed_json = JSON.parse(json_object)
|
65
|
+
length = parsed_json["length"]
|
66
|
+
frequency = parsed_json["frequency"]
|
67
|
+
started = parsed_json["started"]
|
68
|
+
period_start = parsed_json["periodStart"]
|
69
|
+
period_end = parsed_json["periodEnd"]
|
70
|
+
expires = parsed_json["expires"]
|
71
|
+
new(
|
72
|
+
length: length,
|
73
|
+
frequency: frequency,
|
74
|
+
started: started,
|
75
|
+
period_start: period_start,
|
76
|
+
period_end: period_end,
|
77
|
+
expires: expires,
|
78
|
+
additional_properties: struct
|
79
|
+
)
|
80
|
+
end
|
81
|
+
|
82
|
+
# Serialize an instance of BaseStreakResponse to a JSON object
|
83
|
+
#
|
84
|
+
# @return [String]
|
85
|
+
def to_json(*_args)
|
86
|
+
@_field_set&.to_json
|
87
|
+
end
|
88
|
+
|
89
|
+
# Leveraged for Union-type generation, validate_raw attempts to parse the given
|
90
|
+
# hash and check each fields type against the current object's property
|
91
|
+
# definitions.
|
92
|
+
#
|
93
|
+
# @param obj [Object]
|
94
|
+
# @return [Void]
|
95
|
+
def self.validate_raw(obj:)
|
96
|
+
obj.length.is_a?(Integer) != false || raise("Passed value for field obj.length is not the expected type, validation failed.")
|
97
|
+
obj.frequency.is_a?(TrophyApiClient::StreakFrequency) != false || raise("Passed value for field obj.frequency is not the expected type, validation failed.")
|
98
|
+
obj.started&.is_a?(String) != false || raise("Passed value for field obj.started is not the expected type, validation failed.")
|
99
|
+
obj.period_start&.is_a?(String) != false || raise("Passed value for field obj.period_start is not the expected type, validation failed.")
|
100
|
+
obj.period_end&.is_a?(String) != false || raise("Passed value for field obj.period_end is not the expected type, validation failed.")
|
101
|
+
obj.expires&.is_a?(String) != false || raise("Passed value for field obj.expires is not the expected type, validation failed.")
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative "event_response_metrics_item"
|
4
|
-
require_relative "
|
4
|
+
require_relative "increment_metric_streak_response"
|
5
5
|
require "ostruct"
|
6
6
|
require "json"
|
7
7
|
|
@@ -15,7 +15,7 @@ module TrophyApiClient
|
|
15
15
|
attr_reader :total
|
16
16
|
# @return [Array<TrophyApiClient::EventResponseMetricsItem>] Changes to achievements as a result of this event.
|
17
17
|
attr_reader :achievements
|
18
|
-
# @return [TrophyApiClient::
|
18
|
+
# @return [TrophyApiClient::IncrementMetricStreakResponse] The user's current streak for the metric, if the metric has streaks enabled.
|
19
19
|
attr_reader :current_streak
|
20
20
|
# @return [OpenStruct] Additional properties unmapped to the current class definition
|
21
21
|
attr_reader :additional_properties
|
@@ -29,7 +29,7 @@ module TrophyApiClient
|
|
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
31
|
# @param achievements [Array<TrophyApiClient::EventResponseMetricsItem>] Changes to achievements as a result of this event.
|
32
|
-
# @param current_streak [TrophyApiClient::
|
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]
|
35
35
|
def initialize(event_id:, metric_id:, total:, achievements: OMIT, current_streak: OMIT, additional_properties: nil)
|
@@ -68,7 +68,7 @@ module TrophyApiClient
|
|
68
68
|
current_streak = nil
|
69
69
|
else
|
70
70
|
current_streak = parsed_json["currentStreak"].to_json
|
71
|
-
current_streak = TrophyApiClient::
|
71
|
+
current_streak = TrophyApiClient::IncrementMetricStreakResponse.from_json(json_object: current_streak)
|
72
72
|
end
|
73
73
|
new(
|
74
74
|
event_id: event_id,
|
@@ -98,7 +98,7 @@ module TrophyApiClient
|
|
98
98
|
obj.metric_id.is_a?(String) != false || raise("Passed value for field obj.metric_id is not the expected type, validation failed.")
|
99
99
|
obj.total.is_a?(Float) != false || raise("Passed value for field obj.total is not the expected type, validation failed.")
|
100
100
|
obj.achievements&.is_a?(Array) != false || raise("Passed value for field obj.achievements is not the expected type, validation failed.")
|
101
|
-
obj.current_streak.nil? || TrophyApiClient::
|
101
|
+
obj.current_streak.nil? || TrophyApiClient::IncrementMetricStreakResponse.validate_raw(obj: obj.current_streak)
|
102
102
|
end
|
103
103
|
end
|
104
104
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "
|
3
|
+
require_relative "multi_stage_achievement_response"
|
4
4
|
require "ostruct"
|
5
5
|
require "json"
|
6
6
|
|
@@ -8,7 +8,7 @@ module TrophyApiClient
|
|
8
8
|
class EventResponseMetricsItem
|
9
9
|
# @return [String] The ID of the metric.
|
10
10
|
attr_reader :metric_id
|
11
|
-
# @return [Array<TrophyApiClient::
|
11
|
+
# @return [Array<TrophyApiClient::MultiStageAchievementResponse>] A list of any new achievements that the user has now completed as a result of
|
12
12
|
# this event being submitted.
|
13
13
|
attr_reader :completed
|
14
14
|
# @return [OpenStruct] Additional properties unmapped to the current class definition
|
@@ -20,7 +20,7 @@ module TrophyApiClient
|
|
20
20
|
OMIT = Object.new
|
21
21
|
|
22
22
|
# @param metric_id [String] The ID of the metric.
|
23
|
-
# @param completed [Array<TrophyApiClient::
|
23
|
+
# @param completed [Array<TrophyApiClient::MultiStageAchievementResponse>] A list of any new achievements that the user has now completed as a result of
|
24
24
|
# this event being submitted.
|
25
25
|
# @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
|
26
26
|
# @return [TrophyApiClient::EventResponseMetricsItem]
|
@@ -43,7 +43,7 @@ module TrophyApiClient
|
|
43
43
|
metric_id = parsed_json["metricId"]
|
44
44
|
completed = parsed_json["completed"]&.map do |item|
|
45
45
|
item = item.to_json
|
46
|
-
TrophyApiClient::
|
46
|
+
TrophyApiClient::MultiStageAchievementResponse.from_json(json_object: item)
|
47
47
|
end
|
48
48
|
new(
|
49
49
|
metric_id: metric_id,
|
@@ -0,0 +1,113 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "streak_frequency"
|
4
|
+
require "ostruct"
|
5
|
+
require "json"
|
6
|
+
|
7
|
+
module TrophyApiClient
|
8
|
+
# An object representing the user's streak after incrementing a metric.
|
9
|
+
class IncrementMetricStreakResponse
|
10
|
+
# @return [Boolean] Whether this metric event increased the user's streak length.
|
11
|
+
attr_reader :extended
|
12
|
+
# @return [Integer] The length of the user's current streak.
|
13
|
+
attr_reader :length
|
14
|
+
# @return [TrophyApiClient::StreakFrequency] The frequency of the streak.
|
15
|
+
attr_reader :frequency
|
16
|
+
# @return [String] The date the streak started.
|
17
|
+
attr_reader :started
|
18
|
+
# @return [String] The start date of the current streak period.
|
19
|
+
attr_reader :period_start
|
20
|
+
# @return [String] The end date of the current streak period.
|
21
|
+
attr_reader :period_end
|
22
|
+
# @return [String] The date the streak will expire if the user does not increment a metric.
|
23
|
+
attr_reader :expires
|
24
|
+
# @return [OpenStruct] Additional properties unmapped to the current class definition
|
25
|
+
attr_reader :additional_properties
|
26
|
+
# @return [Object]
|
27
|
+
attr_reader :_field_set
|
28
|
+
protected :_field_set
|
29
|
+
|
30
|
+
OMIT = Object.new
|
31
|
+
|
32
|
+
# @param extended [Boolean] Whether this metric event increased the user's streak length.
|
33
|
+
# @param length [Integer] The length of the user's current streak.
|
34
|
+
# @param frequency [TrophyApiClient::StreakFrequency] The frequency of the streak.
|
35
|
+
# @param started [String] The date the streak started.
|
36
|
+
# @param period_start [String] The start date of the current streak period.
|
37
|
+
# @param period_end [String] The end date of the current streak period.
|
38
|
+
# @param expires [String] The date the streak will expire if the user does not increment a metric.
|
39
|
+
# @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
|
40
|
+
# @return [TrophyApiClient::IncrementMetricStreakResponse]
|
41
|
+
def initialize(length:, frequency:, extended: OMIT, started: OMIT, period_start: OMIT, period_end: OMIT,
|
42
|
+
expires: OMIT, additional_properties: nil)
|
43
|
+
@extended = extended if extended != OMIT
|
44
|
+
@length = length
|
45
|
+
@frequency = frequency
|
46
|
+
@started = started if started != OMIT
|
47
|
+
@period_start = period_start if period_start != OMIT
|
48
|
+
@period_end = period_end if period_end != OMIT
|
49
|
+
@expires = expires if expires != OMIT
|
50
|
+
@additional_properties = additional_properties
|
51
|
+
@_field_set = {
|
52
|
+
"extended": extended,
|
53
|
+
"length": length,
|
54
|
+
"frequency": frequency,
|
55
|
+
"started": started,
|
56
|
+
"periodStart": period_start,
|
57
|
+
"periodEnd": period_end,
|
58
|
+
"expires": expires
|
59
|
+
}.reject do |_k, v|
|
60
|
+
v == OMIT
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# Deserialize a JSON object to an instance of IncrementMetricStreakResponse
|
65
|
+
#
|
66
|
+
# @param json_object [String]
|
67
|
+
# @return [TrophyApiClient::IncrementMetricStreakResponse]
|
68
|
+
def self.from_json(json_object:)
|
69
|
+
struct = JSON.parse(json_object, object_class: OpenStruct)
|
70
|
+
parsed_json = JSON.parse(json_object)
|
71
|
+
extended = parsed_json["extended"]
|
72
|
+
length = parsed_json["length"]
|
73
|
+
frequency = parsed_json["frequency"]
|
74
|
+
started = parsed_json["started"]
|
75
|
+
period_start = parsed_json["periodStart"]
|
76
|
+
period_end = parsed_json["periodEnd"]
|
77
|
+
expires = parsed_json["expires"]
|
78
|
+
new(
|
79
|
+
extended: extended,
|
80
|
+
length: length,
|
81
|
+
frequency: frequency,
|
82
|
+
started: started,
|
83
|
+
period_start: period_start,
|
84
|
+
period_end: period_end,
|
85
|
+
expires: expires,
|
86
|
+
additional_properties: struct
|
87
|
+
)
|
88
|
+
end
|
89
|
+
|
90
|
+
# Serialize an instance of IncrementMetricStreakResponse to a JSON object
|
91
|
+
#
|
92
|
+
# @return [String]
|
93
|
+
def to_json(*_args)
|
94
|
+
@_field_set&.to_json
|
95
|
+
end
|
96
|
+
|
97
|
+
# Leveraged for Union-type generation, validate_raw attempts to parse the given
|
98
|
+
# hash and check each fields type against the current object's property
|
99
|
+
# definitions.
|
100
|
+
#
|
101
|
+
# @param obj [Object]
|
102
|
+
# @return [Void]
|
103
|
+
def self.validate_raw(obj:)
|
104
|
+
obj.extended&.is_a?(Boolean) != false || raise("Passed value for field obj.extended is not the expected type, validation failed.")
|
105
|
+
obj.length.is_a?(Integer) != false || raise("Passed value for field obj.length is not the expected type, validation failed.")
|
106
|
+
obj.frequency.is_a?(TrophyApiClient::StreakFrequency) != false || raise("Passed value for field obj.frequency is not the expected type, validation failed.")
|
107
|
+
obj.started&.is_a?(String) != false || raise("Passed value for field obj.started is not the expected type, validation failed.")
|
108
|
+
obj.period_start&.is_a?(String) != false || raise("Passed value for field obj.period_start is not the expected type, validation failed.")
|
109
|
+
obj.period_end&.is_a?(String) != false || raise("Passed value for field obj.period_end is not the expected type, validation failed.")
|
110
|
+
obj.expires&.is_a?(String) != false || raise("Passed value for field obj.expires is not the expected type, validation failed.")
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -1,9 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "streak_frequency"
|
4
3
|
require_relative "metric_status"
|
5
|
-
require_relative "
|
6
|
-
require_relative "streak_response"
|
4
|
+
require_relative "multi_stage_achievement_response"
|
7
5
|
require "ostruct"
|
8
6
|
require "json"
|
9
7
|
|
@@ -17,16 +15,12 @@ module TrophyApiClient
|
|
17
15
|
attr_reader :name
|
18
16
|
# @return [String] The emoji to represent the metric.
|
19
17
|
attr_reader :emoji
|
20
|
-
# @return [TrophyApiClient::StreakFrequency] The frequency of the streak.
|
21
|
-
attr_reader :streak_frequency
|
22
18
|
# @return [TrophyApiClient::MetricStatus] The status of the metric.
|
23
19
|
attr_reader :status
|
24
20
|
# @return [Float] The user's current total for the metric.
|
25
21
|
attr_reader :current
|
26
|
-
# @return [Array<TrophyApiClient::
|
22
|
+
# @return [Array<TrophyApiClient::MultiStageAchievementResponse>] A list of the metric's achievements and the user's progress towards each.
|
27
23
|
attr_reader :achievements
|
28
|
-
# @return [TrophyApiClient::StreakResponse] The user's current streak for the metric, if the metric has streaks enabled.
|
29
|
-
attr_reader :current_streak
|
30
24
|
# @return [OpenStruct] Additional properties unmapped to the current class definition
|
31
25
|
attr_reader :additional_properties
|
32
26
|
# @return [Object]
|
@@ -39,38 +33,29 @@ module TrophyApiClient
|
|
39
33
|
# @param key [String] The unique key of the metric.
|
40
34
|
# @param name [String] The name of the metric.
|
41
35
|
# @param emoji [String] The emoji to represent the metric.
|
42
|
-
# @param streak_frequency [TrophyApiClient::StreakFrequency] The frequency of the streak.
|
43
36
|
# @param status [TrophyApiClient::MetricStatus] The status of the metric.
|
44
37
|
# @param current [Float] The user's current total for the metric.
|
45
|
-
# @param achievements [Array<TrophyApiClient::
|
46
|
-
# @param current_streak [TrophyApiClient::StreakResponse] The user's current streak for the metric, if the metric has streaks enabled.
|
38
|
+
# @param achievements [Array<TrophyApiClient::MultiStageAchievementResponse>] A list of the metric's achievements and the user's progress towards each.
|
47
39
|
# @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
|
48
40
|
# @return [TrophyApiClient::MetricResponse]
|
49
|
-
def initialize(id:, key:, name:, emoji:,
|
50
|
-
additional_properties: nil)
|
41
|
+
def initialize(id:, key:, name:, emoji:, status:, current:, achievements:, additional_properties: nil)
|
51
42
|
@id = id
|
52
43
|
@key = key
|
53
44
|
@name = name
|
54
45
|
@emoji = emoji
|
55
|
-
@streak_frequency = streak_frequency
|
56
46
|
@status = status
|
57
47
|
@current = current
|
58
48
|
@achievements = achievements
|
59
|
-
@current_streak = current_streak if current_streak != OMIT
|
60
49
|
@additional_properties = additional_properties
|
61
50
|
@_field_set = {
|
62
51
|
"id": id,
|
63
52
|
"key": key,
|
64
53
|
"name": name,
|
65
54
|
"emoji": emoji,
|
66
|
-
"streakFrequency": streak_frequency,
|
67
55
|
"status": status,
|
68
56
|
"current": current,
|
69
|
-
"achievements": achievements
|
70
|
-
|
71
|
-
}.reject do |_k, v|
|
72
|
-
v == OMIT
|
73
|
-
end
|
57
|
+
"achievements": achievements
|
58
|
+
}
|
74
59
|
end
|
75
60
|
|
76
61
|
# Deserialize a JSON object to an instance of MetricResponse
|
@@ -84,29 +69,20 @@ module TrophyApiClient
|
|
84
69
|
key = parsed_json["key"]
|
85
70
|
name = parsed_json["name"]
|
86
71
|
emoji = parsed_json["emoji"]
|
87
|
-
streak_frequency = parsed_json["streakFrequency"]
|
88
72
|
status = parsed_json["status"]
|
89
73
|
current = parsed_json["current"]
|
90
74
|
achievements = parsed_json["achievements"]&.map do |item|
|
91
75
|
item = item.to_json
|
92
|
-
TrophyApiClient::
|
93
|
-
end
|
94
|
-
if parsed_json["currentStreak"].nil?
|
95
|
-
current_streak = nil
|
96
|
-
else
|
97
|
-
current_streak = parsed_json["currentStreak"].to_json
|
98
|
-
current_streak = TrophyApiClient::StreakResponse.from_json(json_object: current_streak)
|
76
|
+
TrophyApiClient::MultiStageAchievementResponse.from_json(json_object: item)
|
99
77
|
end
|
100
78
|
new(
|
101
79
|
id: id,
|
102
80
|
key: key,
|
103
81
|
name: name,
|
104
82
|
emoji: emoji,
|
105
|
-
streak_frequency: streak_frequency,
|
106
83
|
status: status,
|
107
84
|
current: current,
|
108
85
|
achievements: achievements,
|
109
|
-
current_streak: current_streak,
|
110
86
|
additional_properties: struct
|
111
87
|
)
|
112
88
|
end
|
@@ -129,11 +105,9 @@ module TrophyApiClient
|
|
129
105
|
obj.key.is_a?(String) != false || raise("Passed value for field obj.key is not the expected type, validation failed.")
|
130
106
|
obj.name.is_a?(String) != false || raise("Passed value for field obj.name is not the expected type, validation failed.")
|
131
107
|
obj.emoji.is_a?(String) != false || raise("Passed value for field obj.emoji is not the expected type, validation failed.")
|
132
|
-
obj.streak_frequency.is_a?(TrophyApiClient::StreakFrequency) != false || raise("Passed value for field obj.streak_frequency is not the expected type, validation failed.")
|
133
108
|
obj.status.is_a?(TrophyApiClient::MetricStatus) != false || raise("Passed value for field obj.status is not the expected type, validation failed.")
|
134
109
|
obj.current.is_a?(Float) != false || raise("Passed value for field obj.current is not the expected type, validation failed.")
|
135
110
|
obj.achievements.is_a?(Array) != false || raise("Passed value for field obj.achievements is not the expected type, validation failed.")
|
136
|
-
obj.current_streak.nil? || TrophyApiClient::StreakResponse.validate_raw(obj: obj.current_streak)
|
137
111
|
end
|
138
112
|
end
|
139
113
|
end
|
data/lib/trophy_api_client/types/{achievement_response.rb → multi_stage_achievement_response.rb}
RENAMED
@@ -5,7 +5,7 @@ require "ostruct"
|
|
5
5
|
require "json"
|
6
6
|
|
7
7
|
module TrophyApiClient
|
8
|
-
class
|
8
|
+
class MultiStageAchievementResponse
|
9
9
|
# @return [String] The unique ID of the achievement.
|
10
10
|
attr_reader :id
|
11
11
|
# @return [String] The name of this achievement.
|
@@ -41,7 +41,7 @@ module TrophyApiClient
|
|
41
41
|
# @param key [String] The key used to reference this achievement in the API.
|
42
42
|
# @param achieved_at [DateTime] The date and time the achievement was completed, in ISO 8601 format.
|
43
43
|
# @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
|
44
|
-
# @return [TrophyApiClient::
|
44
|
+
# @return [TrophyApiClient::MultiStageAchievementResponse]
|
45
45
|
def initialize(id:, name: OMIT, badge_url: OMIT, metric_id: OMIT, metric_value: OMIT, metric_name: OMIT, key: OMIT,
|
46
46
|
achieved_at: OMIT, additional_properties: nil)
|
47
47
|
@id = id
|
@@ -67,10 +67,10 @@ module TrophyApiClient
|
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
|
-
# Deserialize a JSON object to an instance of
|
70
|
+
# Deserialize a JSON object to an instance of MultiStageAchievementResponse
|
71
71
|
#
|
72
72
|
# @param json_object [String]
|
73
|
-
# @return [TrophyApiClient::
|
73
|
+
# @return [TrophyApiClient::MultiStageAchievementResponse]
|
74
74
|
def self.from_json(json_object:)
|
75
75
|
struct = JSON.parse(json_object, object_class: OpenStruct)
|
76
76
|
parsed_json = JSON.parse(json_object)
|
@@ -95,7 +95,7 @@ module TrophyApiClient
|
|
95
95
|
)
|
96
96
|
end
|
97
97
|
|
98
|
-
# Serialize an instance of
|
98
|
+
# Serialize an instance of MultiStageAchievementResponse to a JSON object
|
99
99
|
#
|
100
100
|
# @return [String]
|
101
101
|
def to_json(*_args)
|
@@ -0,0 +1,95 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "date"
|
4
|
+
require "ostruct"
|
5
|
+
require "json"
|
6
|
+
|
7
|
+
module TrophyApiClient
|
8
|
+
class OneOffAchievementResponse
|
9
|
+
# @return [String] The unique ID of the achievement.
|
10
|
+
attr_reader :id
|
11
|
+
# @return [String] The name of this achievement.
|
12
|
+
attr_reader :name
|
13
|
+
# @return [String] The URL of the badge image for the achievement, if one has been uploaded.
|
14
|
+
attr_reader :badge_url
|
15
|
+
# @return [String] The key used to reference this achievement in the API.
|
16
|
+
attr_reader :key
|
17
|
+
# @return [DateTime] The date and time the achievement was completed, in ISO 8601 format.
|
18
|
+
attr_reader :achieved_at
|
19
|
+
# @return [OpenStruct] Additional properties unmapped to the current class definition
|
20
|
+
attr_reader :additional_properties
|
21
|
+
# @return [Object]
|
22
|
+
attr_reader :_field_set
|
23
|
+
protected :_field_set
|
24
|
+
|
25
|
+
OMIT = Object.new
|
26
|
+
|
27
|
+
# @param id [String] The unique ID of the achievement.
|
28
|
+
# @param name [String] The name of this achievement.
|
29
|
+
# @param badge_url [String] The URL of the badge image for the achievement, if one has been uploaded.
|
30
|
+
# @param key [String] The key used to reference this achievement in the API.
|
31
|
+
# @param achieved_at [DateTime] The date and time the achievement was completed, in ISO 8601 format.
|
32
|
+
# @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
|
33
|
+
# @return [TrophyApiClient::OneOffAchievementResponse]
|
34
|
+
def initialize(id:, name: OMIT, badge_url: OMIT, key: OMIT, achieved_at: OMIT, additional_properties: nil)
|
35
|
+
@id = id
|
36
|
+
@name = name if name != OMIT
|
37
|
+
@badge_url = badge_url if badge_url != OMIT
|
38
|
+
@key = key if key != OMIT
|
39
|
+
@achieved_at = achieved_at if achieved_at != OMIT
|
40
|
+
@additional_properties = additional_properties
|
41
|
+
@_field_set = {
|
42
|
+
"id": id,
|
43
|
+
"name": name,
|
44
|
+
"badgeUrl": badge_url,
|
45
|
+
"key": key,
|
46
|
+
"achievedAt": achieved_at
|
47
|
+
}.reject do |_k, v|
|
48
|
+
v == OMIT
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# Deserialize a JSON object to an instance of OneOffAchievementResponse
|
53
|
+
#
|
54
|
+
# @param json_object [String]
|
55
|
+
# @return [TrophyApiClient::OneOffAchievementResponse]
|
56
|
+
def self.from_json(json_object:)
|
57
|
+
struct = JSON.parse(json_object, object_class: OpenStruct)
|
58
|
+
parsed_json = JSON.parse(json_object)
|
59
|
+
id = parsed_json["id"]
|
60
|
+
name = parsed_json["name"]
|
61
|
+
badge_url = parsed_json["badgeUrl"]
|
62
|
+
key = parsed_json["key"]
|
63
|
+
achieved_at = (DateTime.parse(parsed_json["achievedAt"]) unless parsed_json["achievedAt"].nil?)
|
64
|
+
new(
|
65
|
+
id: id,
|
66
|
+
name: name,
|
67
|
+
badge_url: badge_url,
|
68
|
+
key: key,
|
69
|
+
achieved_at: achieved_at,
|
70
|
+
additional_properties: struct
|
71
|
+
)
|
72
|
+
end
|
73
|
+
|
74
|
+
# Serialize an instance of OneOffAchievementResponse to a JSON object
|
75
|
+
#
|
76
|
+
# @return [String]
|
77
|
+
def to_json(*_args)
|
78
|
+
@_field_set&.to_json
|
79
|
+
end
|
80
|
+
|
81
|
+
# Leveraged for Union-type generation, validate_raw attempts to parse the given
|
82
|
+
# hash and check each fields type against the current object's property
|
83
|
+
# definitions.
|
84
|
+
#
|
85
|
+
# @param obj [Object]
|
86
|
+
# @return [Void]
|
87
|
+
def self.validate_raw(obj:)
|
88
|
+
obj.id.is_a?(String) != false || raise("Passed value for field obj.id is not the expected type, validation failed.")
|
89
|
+
obj.name&.is_a?(String) != false || raise("Passed value for field obj.name is not the expected type, validation failed.")
|
90
|
+
obj.badge_url&.is_a?(String) != false || raise("Passed value for field obj.badge_url is not the expected type, validation failed.")
|
91
|
+
obj.key&.is_a?(String) != false || raise("Passed value for field obj.key is not the expected type, validation failed.")
|
92
|
+
obj.achieved_at&.is_a?(DateTime) != false || raise("Passed value for field obj.achieved_at is not the expected type, validation failed.")
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -1,15 +1,28 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative "streak_response_streak_history_item"
|
3
4
|
require_relative "streak_frequency"
|
4
5
|
require "ostruct"
|
5
6
|
require "json"
|
6
7
|
|
7
8
|
module TrophyApiClient
|
9
|
+
# An object representing the user's streak.
|
8
10
|
class StreakResponse
|
11
|
+
# @return [Array<TrophyApiClient::StreakResponseStreakHistoryItem>] A list of the user's past streak periods up through the current period. Each
|
12
|
+
# period includes the start and end dates and the length of the streak.
|
13
|
+
attr_reader :streak_history
|
9
14
|
# @return [Integer] The length of the user's current streak.
|
10
15
|
attr_reader :length
|
11
16
|
# @return [TrophyApiClient::StreakFrequency] The frequency of the streak.
|
12
17
|
attr_reader :frequency
|
18
|
+
# @return [String] The date the streak started.
|
19
|
+
attr_reader :started
|
20
|
+
# @return [String] The start date of the current streak period.
|
21
|
+
attr_reader :period_start
|
22
|
+
# @return [String] The end date of the current streak period.
|
23
|
+
attr_reader :period_end
|
24
|
+
# @return [String] The date the streak will expire if the user does not increment a metric.
|
25
|
+
attr_reader :expires
|
13
26
|
# @return [OpenStruct] Additional properties unmapped to the current class definition
|
14
27
|
attr_reader :additional_properties
|
15
28
|
# @return [Object]
|
@@ -18,15 +31,37 @@ module TrophyApiClient
|
|
18
31
|
|
19
32
|
OMIT = Object.new
|
20
33
|
|
34
|
+
# @param streak_history [Array<TrophyApiClient::StreakResponseStreakHistoryItem>] A list of the user's past streak periods up through the current period. Each
|
35
|
+
# period includes the start and end dates and the length of the streak.
|
21
36
|
# @param length [Integer] The length of the user's current streak.
|
22
37
|
# @param frequency [TrophyApiClient::StreakFrequency] The frequency of the streak.
|
38
|
+
# @param started [String] The date the streak started.
|
39
|
+
# @param period_start [String] The start date of the current streak period.
|
40
|
+
# @param period_end [String] The end date of the current streak period.
|
41
|
+
# @param expires [String] The date the streak will expire if the user does not increment a metric.
|
23
42
|
# @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
|
24
43
|
# @return [TrophyApiClient::StreakResponse]
|
25
|
-
def initialize(length:, frequency:,
|
44
|
+
def initialize(length:, frequency:, streak_history: OMIT, started: OMIT, period_start: OMIT, period_end: OMIT,
|
45
|
+
expires: OMIT, additional_properties: nil)
|
46
|
+
@streak_history = streak_history if streak_history != OMIT
|
26
47
|
@length = length
|
27
48
|
@frequency = frequency
|
49
|
+
@started = started if started != OMIT
|
50
|
+
@period_start = period_start if period_start != OMIT
|
51
|
+
@period_end = period_end if period_end != OMIT
|
52
|
+
@expires = expires if expires != OMIT
|
28
53
|
@additional_properties = additional_properties
|
29
|
-
@_field_set = {
|
54
|
+
@_field_set = {
|
55
|
+
"streakHistory": streak_history,
|
56
|
+
"length": length,
|
57
|
+
"frequency": frequency,
|
58
|
+
"started": started,
|
59
|
+
"periodStart": period_start,
|
60
|
+
"periodEnd": period_end,
|
61
|
+
"expires": expires
|
62
|
+
}.reject do |_k, v|
|
63
|
+
v == OMIT
|
64
|
+
end
|
30
65
|
end
|
31
66
|
|
32
67
|
# Deserialize a JSON object to an instance of StreakResponse
|
@@ -36,11 +71,24 @@ module TrophyApiClient
|
|
36
71
|
def self.from_json(json_object:)
|
37
72
|
struct = JSON.parse(json_object, object_class: OpenStruct)
|
38
73
|
parsed_json = JSON.parse(json_object)
|
74
|
+
streak_history = parsed_json["streakHistory"]&.map do |item|
|
75
|
+
item = item.to_json
|
76
|
+
TrophyApiClient::StreakResponseStreakHistoryItem.from_json(json_object: item)
|
77
|
+
end
|
39
78
|
length = parsed_json["length"]
|
40
79
|
frequency = parsed_json["frequency"]
|
80
|
+
started = parsed_json["started"]
|
81
|
+
period_start = parsed_json["periodStart"]
|
82
|
+
period_end = parsed_json["periodEnd"]
|
83
|
+
expires = parsed_json["expires"]
|
41
84
|
new(
|
85
|
+
streak_history: streak_history,
|
42
86
|
length: length,
|
43
87
|
frequency: frequency,
|
88
|
+
started: started,
|
89
|
+
period_start: period_start,
|
90
|
+
period_end: period_end,
|
91
|
+
expires: expires,
|
44
92
|
additional_properties: struct
|
45
93
|
)
|
46
94
|
end
|
@@ -59,8 +107,13 @@ module TrophyApiClient
|
|
59
107
|
# @param obj [Object]
|
60
108
|
# @return [Void]
|
61
109
|
def self.validate_raw(obj:)
|
110
|
+
obj.streak_history&.is_a?(Array) != false || raise("Passed value for field obj.streak_history is not the expected type, validation failed.")
|
62
111
|
obj.length.is_a?(Integer) != false || raise("Passed value for field obj.length is not the expected type, validation failed.")
|
63
112
|
obj.frequency.is_a?(TrophyApiClient::StreakFrequency) != false || raise("Passed value for field obj.frequency is not the expected type, validation failed.")
|
113
|
+
obj.started&.is_a?(String) != false || raise("Passed value for field obj.started is not the expected type, validation failed.")
|
114
|
+
obj.period_start&.is_a?(String) != false || raise("Passed value for field obj.period_start is not the expected type, validation failed.")
|
115
|
+
obj.period_end&.is_a?(String) != false || raise("Passed value for field obj.period_end is not the expected type, validation failed.")
|
116
|
+
obj.expires&.is_a?(String) != false || raise("Passed value for field obj.expires is not the expected type, validation failed.")
|
64
117
|
end
|
65
118
|
end
|
66
119
|
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "ostruct"
|
4
|
+
require "json"
|
5
|
+
|
6
|
+
module TrophyApiClient
|
7
|
+
# An object representing a past streak period.
|
8
|
+
class StreakResponseStreakHistoryItem
|
9
|
+
# @return [String] The date this streak period started.
|
10
|
+
attr_reader :period_start
|
11
|
+
# @return [String] The date this streak period ended.
|
12
|
+
attr_reader :period_end
|
13
|
+
# @return [Integer] The length of the user's streak during this period.
|
14
|
+
attr_reader :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 period_start [String] The date this streak period started.
|
24
|
+
# @param period_end [String] The date this streak period ended.
|
25
|
+
# @param length [Integer] The length of the user's streak during this period.
|
26
|
+
# @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
|
27
|
+
# @return [TrophyApiClient::StreakResponseStreakHistoryItem]
|
28
|
+
def initialize(period_start:, period_end:, length:, additional_properties: nil)
|
29
|
+
@period_start = period_start
|
30
|
+
@period_end = period_end
|
31
|
+
@length = length
|
32
|
+
@additional_properties = additional_properties
|
33
|
+
@_field_set = { "periodStart": period_start, "periodEnd": period_end, "length": length }
|
34
|
+
end
|
35
|
+
|
36
|
+
# Deserialize a JSON object to an instance of StreakResponseStreakHistoryItem
|
37
|
+
#
|
38
|
+
# @param json_object [String]
|
39
|
+
# @return [TrophyApiClient::StreakResponseStreakHistoryItem]
|
40
|
+
def self.from_json(json_object:)
|
41
|
+
struct = JSON.parse(json_object, object_class: OpenStruct)
|
42
|
+
parsed_json = JSON.parse(json_object)
|
43
|
+
period_start = parsed_json["periodStart"]
|
44
|
+
period_end = parsed_json["periodEnd"]
|
45
|
+
length = parsed_json["length"]
|
46
|
+
new(
|
47
|
+
period_start: period_start,
|
48
|
+
period_end: period_end,
|
49
|
+
length: length,
|
50
|
+
additional_properties: struct
|
51
|
+
)
|
52
|
+
end
|
53
|
+
|
54
|
+
# Serialize an instance of StreakResponseStreakHistoryItem to a JSON object
|
55
|
+
#
|
56
|
+
# @return [String]
|
57
|
+
def to_json(*_args)
|
58
|
+
@_field_set&.to_json
|
59
|
+
end
|
60
|
+
|
61
|
+
# Leveraged for Union-type generation, validate_raw attempts to parse the given
|
62
|
+
# hash and check each fields type against the current object's property
|
63
|
+
# definitions.
|
64
|
+
#
|
65
|
+
# @param obj [Object]
|
66
|
+
# @return [Void]
|
67
|
+
def self.validate_raw(obj:)
|
68
|
+
obj.period_start.is_a?(String) != false || raise("Passed value for field obj.period_start is not the expected type, validation failed.")
|
69
|
+
obj.period_end.is_a?(String) != false || raise("Passed value for field obj.period_end is not the expected type, validation failed.")
|
70
|
+
obj.length.is_a?(Integer) != false || raise("Passed value for field obj.length is not the expected type, validation failed.")
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -6,7 +6,8 @@ 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 "../types/
|
9
|
+
require_relative "../types/multi_stage_achievement_response"
|
10
|
+
require_relative "../types/streak_response"
|
10
11
|
require "async"
|
11
12
|
|
12
13
|
module TrophyApiClient
|
@@ -20,7 +21,7 @@ module TrophyApiClient
|
|
20
21
|
@request_client = request_client
|
21
22
|
end
|
22
23
|
|
23
|
-
#
|
24
|
+
# Identify a new user.
|
24
25
|
#
|
25
26
|
# @param request [Hash] The user object.Request of type TrophyApiClient::UpsertedUser, as a Hash
|
26
27
|
# * :id (String)
|
@@ -195,7 +196,7 @@ module TrophyApiClient
|
|
195
196
|
#
|
196
197
|
# @param id [String] ID of the user.
|
197
198
|
# @param request_options [TrophyApiClient::RequestOptions]
|
198
|
-
# @return [Array<TrophyApiClient::
|
199
|
+
# @return [Array<TrophyApiClient::MultiStageAchievementResponse>]
|
199
200
|
# @example
|
200
201
|
# api = TrophyApiClient::Client.new(
|
201
202
|
# base_url: "https://api.example.com",
|
@@ -223,9 +224,44 @@ module TrophyApiClient
|
|
223
224
|
parsed_json = JSON.parse(response.body)
|
224
225
|
parsed_json&.map do |item|
|
225
226
|
item = item.to_json
|
226
|
-
TrophyApiClient::
|
227
|
+
TrophyApiClient::MultiStageAchievementResponse.from_json(json_object: item)
|
227
228
|
end
|
228
229
|
end
|
230
|
+
|
231
|
+
# Get a user's streak data.
|
232
|
+
#
|
233
|
+
# @param id [String] ID of the user.
|
234
|
+
# @param history_periods [Integer] The number of past streak periods to include in the streakHistory field of the
|
235
|
+
# response.
|
236
|
+
# @param request_options [TrophyApiClient::RequestOptions]
|
237
|
+
# @return [TrophyApiClient::StreakResponse]
|
238
|
+
# @example
|
239
|
+
# api = TrophyApiClient::Client.new(
|
240
|
+
# base_url: "https://api.example.com",
|
241
|
+
# environment: TrophyApiClient::Environment::DEFAULT,
|
242
|
+
# api_key: "YOUR_API_KEY"
|
243
|
+
# )
|
244
|
+
# api.users.streak(id: "userId")
|
245
|
+
def streak(id:, history_periods: nil, request_options: nil)
|
246
|
+
response = @request_client.conn.get do |req|
|
247
|
+
req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
|
248
|
+
req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
|
249
|
+
req.headers = {
|
250
|
+
**(req.headers || {}),
|
251
|
+
**@request_client.get_headers,
|
252
|
+
**(request_options&.additional_headers || {})
|
253
|
+
}.compact
|
254
|
+
req.params = {
|
255
|
+
**(request_options&.additional_query_parameters || {}),
|
256
|
+
"historyPeriods": history_periods
|
257
|
+
}.compact
|
258
|
+
unless request_options.nil? || request_options&.additional_body_parameters.nil?
|
259
|
+
req.body = { **(request_options&.additional_body_parameters || {}) }.compact
|
260
|
+
end
|
261
|
+
req.url "#{@request_client.get_url(request_options: request_options)}/users/#{id}/streak"
|
262
|
+
end
|
263
|
+
TrophyApiClient::StreakResponse.from_json(json_object: response.body)
|
264
|
+
end
|
229
265
|
end
|
230
266
|
|
231
267
|
class AsyncUsersClient
|
@@ -238,7 +274,7 @@ module TrophyApiClient
|
|
238
274
|
@request_client = request_client
|
239
275
|
end
|
240
276
|
|
241
|
-
#
|
277
|
+
# Identify a new user.
|
242
278
|
#
|
243
279
|
# @param request [Hash] The user object.Request of type TrophyApiClient::UpsertedUser, as a Hash
|
244
280
|
# * :id (String)
|
@@ -423,7 +459,7 @@ module TrophyApiClient
|
|
423
459
|
#
|
424
460
|
# @param id [String] ID of the user.
|
425
461
|
# @param request_options [TrophyApiClient::RequestOptions]
|
426
|
-
# @return [Array<TrophyApiClient::
|
462
|
+
# @return [Array<TrophyApiClient::MultiStageAchievementResponse>]
|
427
463
|
# @example
|
428
464
|
# api = TrophyApiClient::Client.new(
|
429
465
|
# base_url: "https://api.example.com",
|
@@ -452,8 +488,45 @@ module TrophyApiClient
|
|
452
488
|
parsed_json = JSON.parse(response.body)
|
453
489
|
parsed_json&.map do |item|
|
454
490
|
item = item.to_json
|
455
|
-
TrophyApiClient::
|
491
|
+
TrophyApiClient::MultiStageAchievementResponse.from_json(json_object: item)
|
492
|
+
end
|
493
|
+
end
|
494
|
+
end
|
495
|
+
|
496
|
+
# Get a user's streak data.
|
497
|
+
#
|
498
|
+
# @param id [String] ID of the user.
|
499
|
+
# @param history_periods [Integer] The number of past streak periods to include in the streakHistory field of the
|
500
|
+
# response.
|
501
|
+
# @param request_options [TrophyApiClient::RequestOptions]
|
502
|
+
# @return [TrophyApiClient::StreakResponse]
|
503
|
+
# @example
|
504
|
+
# api = TrophyApiClient::Client.new(
|
505
|
+
# base_url: "https://api.example.com",
|
506
|
+
# environment: TrophyApiClient::Environment::DEFAULT,
|
507
|
+
# api_key: "YOUR_API_KEY"
|
508
|
+
# )
|
509
|
+
# api.users.streak(id: "userId")
|
510
|
+
def streak(id:, history_periods: nil, request_options: nil)
|
511
|
+
Async do
|
512
|
+
response = @request_client.conn.get do |req|
|
513
|
+
req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
|
514
|
+
req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
|
515
|
+
req.headers = {
|
516
|
+
**(req.headers || {}),
|
517
|
+
**@request_client.get_headers,
|
518
|
+
**(request_options&.additional_headers || {})
|
519
|
+
}.compact
|
520
|
+
req.params = {
|
521
|
+
**(request_options&.additional_query_parameters || {}),
|
522
|
+
"historyPeriods": history_periods
|
523
|
+
}.compact
|
524
|
+
unless request_options.nil? || request_options&.additional_body_parameters.nil?
|
525
|
+
req.body = { **(request_options&.additional_body_parameters || {}) }.compact
|
526
|
+
end
|
527
|
+
req.url "#{@request_client.get_url(request_options: request_options)}/users/#{id}/streak"
|
456
528
|
end
|
529
|
+
TrophyApiClient::StreakResponse.from_json(json_object: response.body)
|
457
530
|
end
|
458
531
|
end
|
459
532
|
end
|
data/lib/types_export.rb
CHANGED
@@ -2,8 +2,12 @@
|
|
2
2
|
|
3
3
|
require_relative "trophy_api_client/types/metric_status"
|
4
4
|
require_relative "trophy_api_client/types/streak_frequency"
|
5
|
+
require_relative "trophy_api_client/types/base_streak_response"
|
6
|
+
require_relative "trophy_api_client/types/increment_metric_streak_response"
|
7
|
+
require_relative "trophy_api_client/types/streak_response_streak_history_item"
|
5
8
|
require_relative "trophy_api_client/types/streak_response"
|
6
|
-
require_relative "trophy_api_client/types/
|
9
|
+
require_relative "trophy_api_client/types/multi_stage_achievement_response"
|
10
|
+
require_relative "trophy_api_client/types/one_off_achievement_response"
|
7
11
|
require_relative "trophy_api_client/types/metric_response"
|
8
12
|
require_relative "trophy_api_client/types/updated_user"
|
9
13
|
require_relative "trophy_api_client/types/upserted_user"
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
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.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Trophy Labs, Inc
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: async-http-faraday
|
@@ -102,14 +102,18 @@ 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/types/achievement_completion_response.rb
|
105
|
-
- lib/trophy_api_client/types/
|
105
|
+
- lib/trophy_api_client/types/base_streak_response.rb
|
106
106
|
- lib/trophy_api_client/types/error_body.rb
|
107
107
|
- lib/trophy_api_client/types/event_response.rb
|
108
108
|
- lib/trophy_api_client/types/event_response_metrics_item.rb
|
109
|
+
- lib/trophy_api_client/types/increment_metric_streak_response.rb
|
109
110
|
- lib/trophy_api_client/types/metric_response.rb
|
110
111
|
- lib/trophy_api_client/types/metric_status.rb
|
112
|
+
- lib/trophy_api_client/types/multi_stage_achievement_response.rb
|
113
|
+
- lib/trophy_api_client/types/one_off_achievement_response.rb
|
111
114
|
- lib/trophy_api_client/types/streak_frequency.rb
|
112
115
|
- lib/trophy_api_client/types/streak_response.rb
|
116
|
+
- lib/trophy_api_client/types/streak_response_streak_history_item.rb
|
113
117
|
- lib/trophy_api_client/types/updated_user.rb
|
114
118
|
- lib/trophy_api_client/types/upserted_user.rb
|
115
119
|
- lib/trophy_api_client/types/user.rb
|
@@ -136,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
140
|
- !ruby/object:Gem::Version
|
137
141
|
version: '0'
|
138
142
|
requirements: []
|
139
|
-
rubygems_version: 3.6.
|
143
|
+
rubygems_version: 3.6.7
|
140
144
|
specification_version: 4
|
141
145
|
summary: Ruby library for the Trophy API.
|
142
146
|
test_files: []
|