trophy_api_client 1.0.3 → 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/base_streak_response.rb +104 -0
- data/lib/trophy_api_client/types/event_response.rb +5 -5
- data/lib/trophy_api_client/types/increment_metric_streak_response.rb +113 -0
- data/lib/trophy_api_client/types/metric_response.rb +3 -29
- 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 +73 -0
- data/lib/trophy_api_client/version.rb +1 -1
- data/lib/types_export.rb +3 -0
- metadata +6 -3
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
@@ -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
|
@@ -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
4
|
require_relative "multi_stage_achievement_response"
|
6
|
-
require_relative "streak_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
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
38
|
# @param achievements [Array<TrophyApiClient::MultiStageAchievementResponse>] A list of the metric's achievements and the user's progress towards each.
|
46
|
-
# @param current_streak [TrophyApiClient::StreakResponse] The user's current streak for the metric, if the metric has streaks enabled.
|
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
76
|
TrophyApiClient::MultiStageAchievementResponse.from_json(json_object: item)
|
93
77
|
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)
|
99
|
-
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
|
@@ -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
|
@@ -7,6 +7,7 @@ require_relative "../types/updated_user"
|
|
7
7
|
require_relative "../types/metric_response"
|
8
8
|
require "json"
|
9
9
|
require_relative "../types/multi_stage_achievement_response"
|
10
|
+
require_relative "../types/streak_response"
|
10
11
|
require "async"
|
11
12
|
|
12
13
|
module TrophyApiClient
|
@@ -226,6 +227,41 @@ module TrophyApiClient
|
|
226
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
|
@@ -456,5 +492,42 @@ module TrophyApiClient
|
|
456
492
|
end
|
457
493
|
end
|
458
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"
|
528
|
+
end
|
529
|
+
TrophyApiClient::StreakResponse.from_json(json_object: response.body)
|
530
|
+
end
|
531
|
+
end
|
459
532
|
end
|
460
533
|
end
|
data/lib/types_export.rb
CHANGED
@@ -2,6 +2,9 @@
|
|
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
9
|
require_relative "trophy_api_client/types/multi_stage_achievement_response"
|
7
10
|
require_relative "trophy_api_client/types/one_off_achievement_response"
|
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,15 +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/base_streak_response.rb
|
105
106
|
- lib/trophy_api_client/types/error_body.rb
|
106
107
|
- lib/trophy_api_client/types/event_response.rb
|
107
108
|
- lib/trophy_api_client/types/event_response_metrics_item.rb
|
109
|
+
- lib/trophy_api_client/types/increment_metric_streak_response.rb
|
108
110
|
- lib/trophy_api_client/types/metric_response.rb
|
109
111
|
- lib/trophy_api_client/types/metric_status.rb
|
110
112
|
- lib/trophy_api_client/types/multi_stage_achievement_response.rb
|
111
113
|
- lib/trophy_api_client/types/one_off_achievement_response.rb
|
112
114
|
- lib/trophy_api_client/types/streak_frequency.rb
|
113
115
|
- lib/trophy_api_client/types/streak_response.rb
|
116
|
+
- lib/trophy_api_client/types/streak_response_streak_history_item.rb
|
114
117
|
- lib/trophy_api_client/types/updated_user.rb
|
115
118
|
- lib/trophy_api_client/types/upserted_user.rb
|
116
119
|
- lib/trophy_api_client/types/user.rb
|
@@ -137,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
137
140
|
- !ruby/object:Gem::Version
|
138
141
|
version: '0'
|
139
142
|
requirements: []
|
140
|
-
rubygems_version: 3.6.
|
143
|
+
rubygems_version: 3.6.7
|
141
144
|
specification_version: 4
|
142
145
|
summary: Ruby library for the Trophy API.
|
143
146
|
test_files: []
|