trophy_api_client 0

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.
@@ -0,0 +1,82 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "ostruct"
4
+ require "json"
5
+
6
+ module TrophyApiClient
7
+ # The user that triggered the event.
8
+ class EventRequestUser
9
+ # @return [String] The ID of the user in your database. Must be a string.
10
+ attr_reader :id
11
+ # @return [String] The user's email address.
12
+ attr_reader :email
13
+ # @return [String] The name to refer to the user by in emails.
14
+ attr_reader :name
15
+ # @return [String] The user's timezone (used for email scheduling).
16
+ attr_reader :tz
17
+ # @return [OpenStruct] Additional properties unmapped to the current class definition
18
+ attr_reader :additional_properties
19
+ # @return [Object]
20
+ attr_reader :_field_set
21
+ protected :_field_set
22
+
23
+ OMIT = Object.new
24
+
25
+ # @param id [String] The ID of the user in your database. Must be a string.
26
+ # @param email [String] The user's email address.
27
+ # @param name [String] The name to refer to the user by in emails.
28
+ # @param tz [String] The user's timezone (used for email scheduling).
29
+ # @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
30
+ # @return [TrophyApiClient::EventRequestUser]
31
+ def initialize(id:, email: OMIT, name: OMIT, tz: OMIT, additional_properties: nil)
32
+ @id = id
33
+ @email = email if email != OMIT
34
+ @name = name if name != OMIT
35
+ @tz = tz if tz != OMIT
36
+ @additional_properties = additional_properties
37
+ @_field_set = { "id": id, "email": email, "name": name, "tz": tz }.reject do |_k, v|
38
+ v == OMIT
39
+ end
40
+ end
41
+
42
+ # Deserialize a JSON object to an instance of EventRequestUser
43
+ #
44
+ # @param json_object [String]
45
+ # @return [TrophyApiClient::EventRequestUser]
46
+ def self.from_json(json_object:)
47
+ struct = JSON.parse(json_object, object_class: OpenStruct)
48
+ parsed_json = JSON.parse(json_object)
49
+ id = parsed_json["id"]
50
+ email = parsed_json["email"]
51
+ name = parsed_json["name"]
52
+ tz = parsed_json["tz"]
53
+ new(
54
+ id: id,
55
+ email: email,
56
+ name: name,
57
+ tz: tz,
58
+ additional_properties: struct
59
+ )
60
+ end
61
+
62
+ # Serialize an instance of EventRequestUser to a JSON object
63
+ #
64
+ # @return [String]
65
+ def to_json(*_args)
66
+ @_field_set&.to_json
67
+ end
68
+
69
+ # Leveraged for Union-type generation, validate_raw attempts to parse the given
70
+ # hash and check each fields type against the current object's property
71
+ # definitions.
72
+ #
73
+ # @param obj [Object]
74
+ # @return [Void]
75
+ def self.validate_raw(obj:)
76
+ obj.id.is_a?(String) != false || raise("Passed value for field obj.id is not the expected type, validation failed.")
77
+ obj.email&.is_a?(String) != false || raise("Passed value for field obj.email is not the expected type, validation failed.")
78
+ obj.name&.is_a?(String) != false || raise("Passed value for field obj.name is not the expected type, validation failed.")
79
+ obj.tz&.is_a?(String) != false || raise("Passed value for field obj.tz is not the expected type, validation failed.")
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "event_response_metrics_item"
4
+ require "ostruct"
5
+ require "json"
6
+
7
+ module TrophyApiClient
8
+ class EventResponse
9
+ # @return [String] The unique ID of the event.
10
+ attr_reader :event_id
11
+ # @return [String] The unique ID of the metric that was updated.
12
+ attr_reader :metric_id
13
+ # @return [Float] The user's new total progress against the metric.
14
+ attr_reader :total
15
+ # @return [Array<TrophyApiClient::EventResponseMetricsItem>] Changes to achievements as a result of this event.
16
+ attr_reader :achievements
17
+ # @return [OpenStruct] Additional properties unmapped to the current class definition
18
+ attr_reader :additional_properties
19
+ # @return [Object]
20
+ attr_reader :_field_set
21
+ protected :_field_set
22
+
23
+ OMIT = Object.new
24
+
25
+ # @param event_id [String] The unique ID of the event.
26
+ # @param metric_id [String] The unique ID of the metric that was updated.
27
+ # @param total [Float] The user's new total progress against the metric.
28
+ # @param achievements [Array<TrophyApiClient::EventResponseMetricsItem>] Changes to achievements as a result of this event.
29
+ # @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
30
+ # @return [TrophyApiClient::EventResponse]
31
+ def initialize(event_id:, metric_id:, total:, achievements: OMIT, additional_properties: nil)
32
+ @event_id = event_id
33
+ @metric_id = metric_id
34
+ @total = total
35
+ @achievements = achievements if achievements != OMIT
36
+ @additional_properties = additional_properties
37
+ @_field_set = {
38
+ "eventId": event_id,
39
+ "metricId": metric_id,
40
+ "total": total,
41
+ "achievements": achievements
42
+ }.reject do |_k, v|
43
+ v == OMIT
44
+ end
45
+ end
46
+
47
+ # Deserialize a JSON object to an instance of EventResponse
48
+ #
49
+ # @param json_object [String]
50
+ # @return [TrophyApiClient::EventResponse]
51
+ def self.from_json(json_object:)
52
+ struct = JSON.parse(json_object, object_class: OpenStruct)
53
+ parsed_json = JSON.parse(json_object)
54
+ event_id = parsed_json["eventId"]
55
+ metric_id = parsed_json["metricId"]
56
+ total = parsed_json["total"]
57
+ achievements = parsed_json["achievements"]&.map do |item|
58
+ item = item.to_json
59
+ TrophyApiClient::EventResponseMetricsItem.from_json(json_object: item)
60
+ end
61
+ new(
62
+ event_id: event_id,
63
+ metric_id: metric_id,
64
+ total: total,
65
+ achievements: achievements,
66
+ additional_properties: struct
67
+ )
68
+ end
69
+
70
+ # Serialize an instance of EventResponse to a JSON object
71
+ #
72
+ # @return [String]
73
+ def to_json(*_args)
74
+ @_field_set&.to_json
75
+ end
76
+
77
+ # Leveraged for Union-type generation, validate_raw attempts to parse the given
78
+ # hash and check each fields type against the current object's property
79
+ # definitions.
80
+ #
81
+ # @param obj [Object]
82
+ # @return [Void]
83
+ def self.validate_raw(obj:)
84
+ obj.event_id.is_a?(String) != false || raise("Passed value for field obj.event_id is not the expected type, validation failed.")
85
+ obj.metric_id.is_a?(String) != false || raise("Passed value for field obj.metric_id is not the expected type, validation failed.")
86
+ obj.total.is_a?(Float) != false || raise("Passed value for field obj.total is not the expected type, validation failed.")
87
+ obj.achievements&.is_a?(Array) != false || raise("Passed value for field obj.achievements is not the expected type, validation failed.")
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "achievement_response"
4
+ require "ostruct"
5
+ require "json"
6
+
7
+ module TrophyApiClient
8
+ class EventResponseMetricsItem
9
+ # @return [String] The ID of the metric.
10
+ attr_reader :metric_id
11
+ # @return [Array<TrophyApiClient::AchievementResponse>] A list of any new achievements that the user has now completed as a result of
12
+ # this event being submitted.
13
+ attr_reader :completed
14
+ # @return [OpenStruct] Additional properties unmapped to the current class definition
15
+ attr_reader :additional_properties
16
+ # @return [Object]
17
+ attr_reader :_field_set
18
+ protected :_field_set
19
+
20
+ OMIT = Object.new
21
+
22
+ # @param metric_id [String] The ID of the metric.
23
+ # @param completed [Array<TrophyApiClient::AchievementResponse>] A list of any new achievements that the user has now completed as a result of
24
+ # this event being submitted.
25
+ # @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
26
+ # @return [TrophyApiClient::EventResponseMetricsItem]
27
+ def initialize(metric_id: OMIT, completed: OMIT, additional_properties: nil)
28
+ @metric_id = metric_id if metric_id != OMIT
29
+ @completed = completed if completed != OMIT
30
+ @additional_properties = additional_properties
31
+ @_field_set = { "metricId": metric_id, "completed": completed }.reject do |_k, v|
32
+ v == OMIT
33
+ end
34
+ end
35
+
36
+ # Deserialize a JSON object to an instance of EventResponseMetricsItem
37
+ #
38
+ # @param json_object [String]
39
+ # @return [TrophyApiClient::EventResponseMetricsItem]
40
+ def self.from_json(json_object:)
41
+ struct = JSON.parse(json_object, object_class: OpenStruct)
42
+ parsed_json = JSON.parse(json_object)
43
+ metric_id = parsed_json["metricId"]
44
+ completed = parsed_json["completed"]&.map do |item|
45
+ item = item.to_json
46
+ TrophyApiClient::AchievementResponse.from_json(json_object: item)
47
+ end
48
+ new(
49
+ metric_id: metric_id,
50
+ completed: completed,
51
+ additional_properties: struct
52
+ )
53
+ end
54
+
55
+ # Serialize an instance of EventResponseMetricsItem to a JSON object
56
+ #
57
+ # @return [String]
58
+ def to_json(*_args)
59
+ @_field_set&.to_json
60
+ end
61
+
62
+ # Leveraged for Union-type generation, validate_raw attempts to parse the given
63
+ # hash and check each fields type against the current object's property
64
+ # definitions.
65
+ #
66
+ # @param obj [Object]
67
+ # @return [Void]
68
+ def self.validate_raw(obj:)
69
+ obj.metric_id&.is_a?(String) != false || raise("Passed value for field obj.metric_id is not the expected type, validation failed.")
70
+ obj.completed&.is_a?(Array) != false || raise("Passed value for field obj.completed is not the expected type, validation failed.")
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,139 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "streak_frequency"
4
+ require_relative "metric_status"
5
+ require_relative "achievement_response"
6
+ require_relative "streak_response"
7
+ require "ostruct"
8
+ require "json"
9
+
10
+ module TrophyApiClient
11
+ class MetricResponse
12
+ # @return [String] The unique ID of the metric.
13
+ attr_reader :id
14
+ # @return [String] The unique key of the metric.
15
+ attr_reader :key
16
+ # @return [String] The name of the metric.
17
+ attr_reader :name
18
+ # @return [String] The emoji to represent the metric.
19
+ attr_reader :emoji
20
+ # @return [TrophyApiClient::StreakFrequency] The frequency of the streak.
21
+ attr_reader :streak_frequency
22
+ # @return [TrophyApiClient::MetricStatus] The status of the metric.
23
+ attr_reader :status
24
+ # @return [Float] The user's current total for the metric.
25
+ attr_reader :current
26
+ # @return [Array<TrophyApiClient::AchievementResponse>] A list of the metric's achievements and the user's progress towards each.
27
+ attr_reader :achievements
28
+ # @return [TrophyApiClient::StreakResponse] The user's current streak for the metric, if the metric has streaks enabled.
29
+ attr_reader :streak
30
+ # @return [OpenStruct] Additional properties unmapped to the current class definition
31
+ attr_reader :additional_properties
32
+ # @return [Object]
33
+ attr_reader :_field_set
34
+ protected :_field_set
35
+
36
+ OMIT = Object.new
37
+
38
+ # @param id [String] The unique ID of the metric.
39
+ # @param key [String] The unique key of the metric.
40
+ # @param name [String] The name of the metric.
41
+ # @param emoji [String] The emoji to represent the metric.
42
+ # @param streak_frequency [TrophyApiClient::StreakFrequency] The frequency of the streak.
43
+ # @param status [TrophyApiClient::MetricStatus] The status of the metric.
44
+ # @param current [Float] The user's current total for the metric.
45
+ # @param achievements [Array<TrophyApiClient::AchievementResponse>] A list of the metric's achievements and the user's progress towards each.
46
+ # @param streak [TrophyApiClient::StreakResponse] The user's current streak for the metric, if the metric has streaks enabled.
47
+ # @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
48
+ # @return [TrophyApiClient::MetricResponse]
49
+ def initialize(id:, key:, name:, emoji:, streak_frequency:, status:, current:, achievements:, streak: OMIT,
50
+ additional_properties: nil)
51
+ @id = id
52
+ @key = key
53
+ @name = name
54
+ @emoji = emoji
55
+ @streak_frequency = streak_frequency
56
+ @status = status
57
+ @current = current
58
+ @achievements = achievements
59
+ @streak = streak if streak != OMIT
60
+ @additional_properties = additional_properties
61
+ @_field_set = {
62
+ "id": id,
63
+ "key": key,
64
+ "name": name,
65
+ "emoji": emoji,
66
+ "streakFrequency": streak_frequency,
67
+ "status": status,
68
+ "current": current,
69
+ "achievements": achievements,
70
+ "streak": streak
71
+ }.reject do |_k, v|
72
+ v == OMIT
73
+ end
74
+ end
75
+
76
+ # Deserialize a JSON object to an instance of MetricResponse
77
+ #
78
+ # @param json_object [String]
79
+ # @return [TrophyApiClient::MetricResponse]
80
+ def self.from_json(json_object:)
81
+ struct = JSON.parse(json_object, object_class: OpenStruct)
82
+ parsed_json = JSON.parse(json_object)
83
+ id = parsed_json["id"]
84
+ key = parsed_json["key"]
85
+ name = parsed_json["name"]
86
+ emoji = parsed_json["emoji"]
87
+ streak_frequency = parsed_json["streakFrequency"]
88
+ status = parsed_json["status"]
89
+ current = parsed_json["current"]
90
+ achievements = parsed_json["achievements"]&.map do |item|
91
+ item = item.to_json
92
+ TrophyApiClient::AchievementResponse.from_json(json_object: item)
93
+ end
94
+ if parsed_json["streak"].nil?
95
+ streak = nil
96
+ else
97
+ streak = parsed_json["streak"].to_json
98
+ streak = TrophyApiClient::StreakResponse.from_json(json_object: streak)
99
+ end
100
+ new(
101
+ id: id,
102
+ key: key,
103
+ name: name,
104
+ emoji: emoji,
105
+ streak_frequency: streak_frequency,
106
+ status: status,
107
+ current: current,
108
+ achievements: achievements,
109
+ streak: streak,
110
+ additional_properties: struct
111
+ )
112
+ end
113
+
114
+ # Serialize an instance of MetricResponse to a JSON object
115
+ #
116
+ # @return [String]
117
+ def to_json(*_args)
118
+ @_field_set&.to_json
119
+ end
120
+
121
+ # Leveraged for Union-type generation, validate_raw attempts to parse the given
122
+ # hash and check each fields type against the current object's property
123
+ # definitions.
124
+ #
125
+ # @param obj [Object]
126
+ # @return [Void]
127
+ def self.validate_raw(obj:)
128
+ obj.id.is_a?(String) != false || raise("Passed value for field obj.id is not the expected type, validation failed.")
129
+ obj.key.is_a?(String) != false || raise("Passed value for field obj.key is not the expected type, validation failed.")
130
+ obj.name.is_a?(String) != false || raise("Passed value for field obj.name is not the expected type, validation failed.")
131
+ 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
+ obj.status.is_a?(TrophyApiClient::MetricStatus) != false || raise("Passed value for field obj.status is not the expected type, validation failed.")
134
+ obj.current.is_a?(Float) != false || raise("Passed value for field obj.current is not the expected type, validation failed.")
135
+ obj.achievements.is_a?(Array) != false || raise("Passed value for field obj.achievements is not the expected type, validation failed.")
136
+ obj.streak.nil? || TrophyApiClient::StreakResponse.validate_raw(obj: obj.streak)
137
+ end
138
+ end
139
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TrophyApiClient
4
+ # The status of the achievement.
5
+ class MetricStatus
6
+ ARCHIVED = "archived"
7
+ ACTIVE = "active"
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TrophyApiClient
4
+ class StreakFrequency
5
+ DAILY = "daily"
6
+ WEEKLY = "weekly"
7
+ MONTHLY = "monthly"
8
+ YEARLY = "yearly"
9
+ end
10
+ end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "streak_frequency"
4
+ require "ostruct"
5
+ require "json"
6
+
7
+ module TrophyApiClient
8
+ class StreakResponse
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 [OpenStruct] Additional properties unmapped to the current class definition
14
+ attr_reader :additional_properties
15
+ # @return [Object]
16
+ attr_reader :_field_set
17
+ protected :_field_set
18
+
19
+ OMIT = Object.new
20
+
21
+ # @param length [Integer] The length of the user's current streak.
22
+ # @param frequency [TrophyApiClient::StreakFrequency] The frequency of the streak.
23
+ # @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
24
+ # @return [TrophyApiClient::StreakResponse]
25
+ def initialize(length:, frequency:, additional_properties: nil)
26
+ @length = length
27
+ @frequency = frequency
28
+ @additional_properties = additional_properties
29
+ @_field_set = { "length": length, "frequency": frequency }
30
+ end
31
+
32
+ # Deserialize a JSON object to an instance of StreakResponse
33
+ #
34
+ # @param json_object [String]
35
+ # @return [TrophyApiClient::StreakResponse]
36
+ def self.from_json(json_object:)
37
+ struct = JSON.parse(json_object, object_class: OpenStruct)
38
+ parsed_json = JSON.parse(json_object)
39
+ length = parsed_json["length"]
40
+ frequency = parsed_json["frequency"]
41
+ new(
42
+ length: length,
43
+ frequency: frequency,
44
+ additional_properties: struct
45
+ )
46
+ end
47
+
48
+ # Serialize an instance of StreakResponse to a JSON object
49
+ #
50
+ # @return [String]
51
+ def to_json(*_args)
52
+ @_field_set&.to_json
53
+ end
54
+
55
+ # Leveraged for Union-type generation, validate_raw attempts to parse the given
56
+ # hash and check each fields type against the current object's property
57
+ # definitions.
58
+ #
59
+ # @param obj [Object]
60
+ # @return [Void]
61
+ def self.validate_raw(obj:)
62
+ obj.length.is_a?(Integer) != false || raise("Passed value for field obj.length is not the expected type, validation failed.")
63
+ obj.frequency.is_a?(TrophyApiClient::StreakFrequency) != false || raise("Passed value for field obj.frequency is not the expected type, validation failed.")
64
+ end
65
+ end
66
+ end