trophy_api_client 1.0.9 → 1.0.11

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.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/lib/gemconfig.rb +1 -1
  3. data/lib/trophy_api_client/achievements/client.rb +79 -7
  4. data/lib/trophy_api_client/points/client.rb +175 -0
  5. data/lib/trophy_api_client/types/achievement_completion_response.rb +5 -5
  6. data/lib/trophy_api_client/types/achievement_response.rb +29 -15
  7. data/lib/trophy_api_client/types/achievement_response_trigger.rb +10 -0
  8. data/lib/trophy_api_client/types/achievement_with_stats_response.rb +176 -0
  9. data/lib/trophy_api_client/types/completed_achievement_response.rb +169 -0
  10. data/lib/trophy_api_client/types/event_response.rb +28 -11
  11. data/lib/trophy_api_client/types/get_user_points_response.rb +71 -0
  12. data/lib/trophy_api_client/types/metric_event_points_response.rb +78 -0
  13. data/lib/trophy_api_client/types/{increment_metric_streak_response.rb → metric_event_streak_response.rb} +6 -6
  14. data/lib/trophy_api_client/types/metric_response.rb +4 -4
  15. data/lib/trophy_api_client/types/points_award.rb +80 -0
  16. data/lib/trophy_api_client/types/points_range.rb +74 -0
  17. data/lib/trophy_api_client/types/points_summary_response.rb +7 -0
  18. data/lib/trophy_api_client/types/points_trigger.rb +116 -0
  19. data/lib/trophy_api_client/types/points_trigger_response.rb +164 -0
  20. data/lib/trophy_api_client/types/points_trigger_response_status.rb +9 -0
  21. data/lib/trophy_api_client/types/points_trigger_response_type.rb +10 -0
  22. data/lib/trophy_api_client/types/points_trigger_type.rb +10 -0
  23. data/lib/trophy_api_client/users/client.rb +278 -5
  24. data/lib/trophy_api_client/users/types/users_metric_event_summary_request_aggregation.rb +11 -0
  25. data/lib/trophy_api_client/users/types/users_metric_event_summary_response_item.rb +76 -0
  26. data/lib/trophy_api_client/users/types/users_points_event_summary_request_aggregation.rb +11 -0
  27. data/lib/trophy_api_client/users/types/users_points_event_summary_response_item.rb +76 -0
  28. data/lib/trophy_api_client/version.rb +1 -1
  29. data/lib/trophy_api_client.rb +7 -0
  30. data/lib/types_export.rb +18 -1
  31. metadata +20 -2
@@ -0,0 +1,80 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "points_trigger"
4
+ require "ostruct"
5
+ require "json"
6
+
7
+ module TrophyApiClient
8
+ class PointsAward
9
+ # @return [String] The ID of the trigger award
10
+ attr_reader :id
11
+ # @return [Float] The points awarded by this trigger
12
+ attr_reader :awarded
13
+ # @return [TrophyApiClient::PointsTrigger]
14
+ attr_reader :trigger
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 id [String] The ID of the trigger award
24
+ # @param awarded [Float] The points awarded by this trigger
25
+ # @param trigger [TrophyApiClient::PointsTrigger]
26
+ # @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
27
+ # @return [TrophyApiClient::PointsAward]
28
+ def initialize(id: OMIT, awarded: OMIT, trigger: OMIT, additional_properties: nil)
29
+ @id = id if id != OMIT
30
+ @awarded = awarded if awarded != OMIT
31
+ @trigger = trigger if trigger != OMIT
32
+ @additional_properties = additional_properties
33
+ @_field_set = { "id": id, "awarded": awarded, "trigger": trigger }.reject do |_k, v|
34
+ v == OMIT
35
+ end
36
+ end
37
+
38
+ # Deserialize a JSON object to an instance of PointsAward
39
+ #
40
+ # @param json_object [String]
41
+ # @return [TrophyApiClient::PointsAward]
42
+ def self.from_json(json_object:)
43
+ struct = JSON.parse(json_object, object_class: OpenStruct)
44
+ parsed_json = JSON.parse(json_object)
45
+ id = parsed_json["id"]
46
+ awarded = parsed_json["awarded"]
47
+ if parsed_json["trigger"].nil?
48
+ trigger = nil
49
+ else
50
+ trigger = parsed_json["trigger"].to_json
51
+ trigger = TrophyApiClient::PointsTrigger.from_json(json_object: trigger)
52
+ end
53
+ new(
54
+ id: id,
55
+ awarded: awarded,
56
+ trigger: trigger,
57
+ additional_properties: struct
58
+ )
59
+ end
60
+
61
+ # Serialize an instance of PointsAward to a JSON object
62
+ #
63
+ # @return [String]
64
+ def to_json(*_args)
65
+ @_field_set&.to_json
66
+ end
67
+
68
+ # Leveraged for Union-type generation, validate_raw attempts to parse the given
69
+ # hash and check each fields type against the current object's property
70
+ # definitions.
71
+ #
72
+ # @param obj [Object]
73
+ # @return [Void]
74
+ def self.validate_raw(obj:)
75
+ obj.id&.is_a?(String) != false || raise("Passed value for field obj.id is not the expected type, validation failed.")
76
+ obj.awarded&.is_a?(Float) != false || raise("Passed value for field obj.awarded is not the expected type, validation failed.")
77
+ obj.trigger.nil? || TrophyApiClient::PointsTrigger.validate_raw(obj: obj.trigger)
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "ostruct"
4
+ require "json"
5
+
6
+ module TrophyApiClient
7
+ class PointsRange
8
+ # @return [Float] The start of the points range. Inclusive.
9
+ attr_reader :from
10
+ # @return [Float] The end of the points range. Inclusive.
11
+ attr_reader :to
12
+ # @return [Float] The number of users in this points range.
13
+ attr_reader :users
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 from [Float] The start of the points range. Inclusive.
23
+ # @param to [Float] The end of the points range. Inclusive.
24
+ # @param users [Float] The number of users in this points range.
25
+ # @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
26
+ # @return [TrophyApiClient::PointsRange]
27
+ def initialize(from: OMIT, to: OMIT, users: OMIT, additional_properties: nil)
28
+ @from = from if from != OMIT
29
+ @to = to if to != OMIT
30
+ @users = users if users != OMIT
31
+ @additional_properties = additional_properties
32
+ @_field_set = { "from": from, "to": to, "users": users }.reject do |_k, v|
33
+ v == OMIT
34
+ end
35
+ end
36
+
37
+ # Deserialize a JSON object to an instance of PointsRange
38
+ #
39
+ # @param json_object [String]
40
+ # @return [TrophyApiClient::PointsRange]
41
+ def self.from_json(json_object:)
42
+ struct = JSON.parse(json_object, object_class: OpenStruct)
43
+ parsed_json = JSON.parse(json_object)
44
+ from = parsed_json["from"]
45
+ to = parsed_json["to"]
46
+ users = parsed_json["users"]
47
+ new(
48
+ from: from,
49
+ to: to,
50
+ users: users,
51
+ additional_properties: struct
52
+ )
53
+ end
54
+
55
+ # Serialize an instance of PointsRange 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.from&.is_a?(Float) != false || raise("Passed value for field obj.from is not the expected type, validation failed.")
70
+ obj.to&.is_a?(Float) != false || raise("Passed value for field obj.to is not the expected type, validation failed.")
71
+ obj.users&.is_a?(Float) != false || raise("Passed value for field obj.users is not the expected type, validation failed.")
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "points_range"
4
+
5
+ module TrophyApiClient
6
+ POINTS_SUMMARY_RESPONSE = Array
7
+ end
@@ -0,0 +1,116 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "points_trigger_type"
4
+ require "ostruct"
5
+ require "json"
6
+
7
+ module TrophyApiClient
8
+ class PointsTrigger
9
+ # @return [String] The ID of the trigger
10
+ attr_reader :id
11
+ # @return [TrophyApiClient::PointsTriggerType] The type of trigger
12
+ attr_reader :type
13
+ # @return [Float] The points awarded by this trigger.
14
+ attr_reader :points
15
+ # @return [String] If the trigger has type 'metric', the name of the metric
16
+ attr_reader :metric_name
17
+ # @return [Float] If the trigger has type 'metric', the threshold of the metric that triggers the
18
+ # points
19
+ attr_reader :metric_threshold
20
+ # @return [Float] If the trigger has type 'streak', the threshold of the streak that triggers the
21
+ # points
22
+ attr_reader :streak_length_threshold
23
+ # @return [String] If the trigger has type 'achievement', the name of the achievement
24
+ attr_reader :achievement_name
25
+ # @return [OpenStruct] Additional properties unmapped to the current class definition
26
+ attr_reader :additional_properties
27
+ # @return [Object]
28
+ attr_reader :_field_set
29
+ protected :_field_set
30
+
31
+ OMIT = Object.new
32
+
33
+ # @param id [String] The ID of the trigger
34
+ # @param type [TrophyApiClient::PointsTriggerType] The type of trigger
35
+ # @param points [Float] The points awarded by this trigger.
36
+ # @param metric_name [String] If the trigger has type 'metric', the name of the metric
37
+ # @param metric_threshold [Float] If the trigger has type 'metric', the threshold of the metric that triggers the
38
+ # points
39
+ # @param streak_length_threshold [Float] If the trigger has type 'streak', the threshold of the streak that triggers the
40
+ # points
41
+ # @param achievement_name [String] If the trigger has type 'achievement', the name of the achievement
42
+ # @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
43
+ # @return [TrophyApiClient::PointsTrigger]
44
+ def initialize(id: OMIT, type: OMIT, points: OMIT, metric_name: OMIT, metric_threshold: OMIT,
45
+ streak_length_threshold: OMIT, achievement_name: OMIT, additional_properties: nil)
46
+ @id = id if id != OMIT
47
+ @type = type if type != OMIT
48
+ @points = points if points != OMIT
49
+ @metric_name = metric_name if metric_name != OMIT
50
+ @metric_threshold = metric_threshold if metric_threshold != OMIT
51
+ @streak_length_threshold = streak_length_threshold if streak_length_threshold != OMIT
52
+ @achievement_name = achievement_name if achievement_name != OMIT
53
+ @additional_properties = additional_properties
54
+ @_field_set = {
55
+ "id": id,
56
+ "type": type,
57
+ "points": points,
58
+ "metricName": metric_name,
59
+ "metricThreshold": metric_threshold,
60
+ "streakLengthThreshold": streak_length_threshold,
61
+ "achievementName": achievement_name
62
+ }.reject do |_k, v|
63
+ v == OMIT
64
+ end
65
+ end
66
+
67
+ # Deserialize a JSON object to an instance of PointsTrigger
68
+ #
69
+ # @param json_object [String]
70
+ # @return [TrophyApiClient::PointsTrigger]
71
+ def self.from_json(json_object:)
72
+ struct = JSON.parse(json_object, object_class: OpenStruct)
73
+ parsed_json = JSON.parse(json_object)
74
+ id = parsed_json["id"]
75
+ type = parsed_json["type"]
76
+ points = parsed_json["points"]
77
+ metric_name = parsed_json["metricName"]
78
+ metric_threshold = parsed_json["metricThreshold"]
79
+ streak_length_threshold = parsed_json["streakLengthThreshold"]
80
+ achievement_name = parsed_json["achievementName"]
81
+ new(
82
+ id: id,
83
+ type: type,
84
+ points: points,
85
+ metric_name: metric_name,
86
+ metric_threshold: metric_threshold,
87
+ streak_length_threshold: streak_length_threshold,
88
+ achievement_name: achievement_name,
89
+ additional_properties: struct
90
+ )
91
+ end
92
+
93
+ # Serialize an instance of PointsTrigger to a JSON object
94
+ #
95
+ # @return [String]
96
+ def to_json(*_args)
97
+ @_field_set&.to_json
98
+ end
99
+
100
+ # Leveraged for Union-type generation, validate_raw attempts to parse the given
101
+ # hash and check each fields type against the current object's property
102
+ # definitions.
103
+ #
104
+ # @param obj [Object]
105
+ # @return [Void]
106
+ def self.validate_raw(obj:)
107
+ obj.id&.is_a?(String) != false || raise("Passed value for field obj.id is not the expected type, validation failed.")
108
+ obj.type&.is_a?(TrophyApiClient::PointsTriggerType) != false || raise("Passed value for field obj.type is not the expected type, validation failed.")
109
+ obj.points&.is_a?(Float) != false || raise("Passed value for field obj.points is not the expected type, validation failed.")
110
+ obj.metric_name&.is_a?(String) != false || raise("Passed value for field obj.metric_name is not the expected type, validation failed.")
111
+ obj.metric_threshold&.is_a?(Float) != false || raise("Passed value for field obj.metric_threshold is not the expected type, validation failed.")
112
+ obj.streak_length_threshold&.is_a?(Float) != false || raise("Passed value for field obj.streak_length_threshold is not the expected type, validation failed.")
113
+ obj.achievement_name&.is_a?(String) != false || raise("Passed value for field obj.achievement_name is not the expected type, validation failed.")
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,164 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "points_trigger_response_type"
4
+ require_relative "points_trigger_response_status"
5
+ require "date"
6
+ require "ostruct"
7
+ require "json"
8
+
9
+ module TrophyApiClient
10
+ class PointsTriggerResponse
11
+ # @return [String] The unique ID of the trigger.
12
+ attr_reader :id
13
+ # @return [TrophyApiClient::PointsTriggerResponseType] The type of trigger.
14
+ attr_reader :type
15
+ # @return [Float] The points awarded by this trigger.
16
+ attr_reader :points
17
+ # @return [TrophyApiClient::PointsTriggerResponseStatus] The status of the trigger.
18
+ attr_reader :status
19
+ # @return [String] The unique ID of the achievement associated with this trigger, if the trigger is
20
+ # an achievement.
21
+ attr_reader :achievement_id
22
+ # @return [String] The unique ID of the metric associated with this trigger, if the trigger is a
23
+ # metric.
24
+ attr_reader :metric_id
25
+ # @return [Float] The amount that a user must increase the metric to earn the points, if the
26
+ # trigger is a metric.
27
+ attr_reader :metric_threshold
28
+ # @return [Float] The number of consecutive streak periods that a user must complete to earn the
29
+ # points, if the trigger is a streak.
30
+ attr_reader :streak_length_threshold
31
+ # @return [String] The name of the metric associated with this trigger, if the trigger is a metric.
32
+ attr_reader :metric_name
33
+ # @return [String] The name of the achievement associated with this trigger, if the trigger is an
34
+ # achievement.
35
+ attr_reader :achievement_name
36
+ # @return [DateTime] The date and time the trigger was created, in ISO 8601 format.
37
+ attr_reader :created
38
+ # @return [DateTime] The date and time the trigger was last updated, in ISO 8601 format.
39
+ attr_reader :updated
40
+ # @return [OpenStruct] Additional properties unmapped to the current class definition
41
+ attr_reader :additional_properties
42
+ # @return [Object]
43
+ attr_reader :_field_set
44
+ protected :_field_set
45
+
46
+ OMIT = Object.new
47
+
48
+ # @param id [String] The unique ID of the trigger.
49
+ # @param type [TrophyApiClient::PointsTriggerResponseType] The type of trigger.
50
+ # @param points [Float] The points awarded by this trigger.
51
+ # @param status [TrophyApiClient::PointsTriggerResponseStatus] The status of the trigger.
52
+ # @param achievement_id [String] The unique ID of the achievement associated with this trigger, if the trigger is
53
+ # an achievement.
54
+ # @param metric_id [String] The unique ID of the metric associated with this trigger, if the trigger is a
55
+ # metric.
56
+ # @param metric_threshold [Float] The amount that a user must increase the metric to earn the points, if the
57
+ # trigger is a metric.
58
+ # @param streak_length_threshold [Float] The number of consecutive streak periods that a user must complete to earn the
59
+ # points, if the trigger is a streak.
60
+ # @param metric_name [String] The name of the metric associated with this trigger, if the trigger is a metric.
61
+ # @param achievement_name [String] The name of the achievement associated with this trigger, if the trigger is an
62
+ # achievement.
63
+ # @param created [DateTime] The date and time the trigger was created, in ISO 8601 format.
64
+ # @param updated [DateTime] The date and time the trigger was last updated, in ISO 8601 format.
65
+ # @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
66
+ # @return [TrophyApiClient::PointsTriggerResponse]
67
+ def initialize(id: OMIT, type: OMIT, points: OMIT, status: OMIT, achievement_id: OMIT, metric_id: OMIT,
68
+ metric_threshold: OMIT, streak_length_threshold: OMIT, metric_name: OMIT, achievement_name: OMIT, created: OMIT, updated: OMIT, additional_properties: nil)
69
+ @id = id if id != OMIT
70
+ @type = type if type != OMIT
71
+ @points = points if points != OMIT
72
+ @status = status if status != OMIT
73
+ @achievement_id = achievement_id if achievement_id != OMIT
74
+ @metric_id = metric_id if metric_id != OMIT
75
+ @metric_threshold = metric_threshold if metric_threshold != OMIT
76
+ @streak_length_threshold = streak_length_threshold if streak_length_threshold != OMIT
77
+ @metric_name = metric_name if metric_name != OMIT
78
+ @achievement_name = achievement_name if achievement_name != OMIT
79
+ @created = created if created != OMIT
80
+ @updated = updated if updated != OMIT
81
+ @additional_properties = additional_properties
82
+ @_field_set = {
83
+ "id": id,
84
+ "type": type,
85
+ "points": points,
86
+ "status": status,
87
+ "achievementId": achievement_id,
88
+ "metricId": metric_id,
89
+ "metricThreshold": metric_threshold,
90
+ "streakLengthThreshold": streak_length_threshold,
91
+ "metricName": metric_name,
92
+ "achievementName": achievement_name,
93
+ "created": created,
94
+ "updated": updated
95
+ }.reject do |_k, v|
96
+ v == OMIT
97
+ end
98
+ end
99
+
100
+ # Deserialize a JSON object to an instance of PointsTriggerResponse
101
+ #
102
+ # @param json_object [String]
103
+ # @return [TrophyApiClient::PointsTriggerResponse]
104
+ def self.from_json(json_object:)
105
+ struct = JSON.parse(json_object, object_class: OpenStruct)
106
+ parsed_json = JSON.parse(json_object)
107
+ id = parsed_json["id"]
108
+ type = parsed_json["type"]
109
+ points = parsed_json["points"]
110
+ status = parsed_json["status"]
111
+ achievement_id = parsed_json["achievementId"]
112
+ metric_id = parsed_json["metricId"]
113
+ metric_threshold = parsed_json["metricThreshold"]
114
+ streak_length_threshold = parsed_json["streakLengthThreshold"]
115
+ metric_name = parsed_json["metricName"]
116
+ achievement_name = parsed_json["achievementName"]
117
+ created = (DateTime.parse(parsed_json["created"]) unless parsed_json["created"].nil?)
118
+ updated = (DateTime.parse(parsed_json["updated"]) unless parsed_json["updated"].nil?)
119
+ new(
120
+ id: id,
121
+ type: type,
122
+ points: points,
123
+ status: status,
124
+ achievement_id: achievement_id,
125
+ metric_id: metric_id,
126
+ metric_threshold: metric_threshold,
127
+ streak_length_threshold: streak_length_threshold,
128
+ metric_name: metric_name,
129
+ achievement_name: achievement_name,
130
+ created: created,
131
+ updated: updated,
132
+ additional_properties: struct
133
+ )
134
+ end
135
+
136
+ # Serialize an instance of PointsTriggerResponse to a JSON object
137
+ #
138
+ # @return [String]
139
+ def to_json(*_args)
140
+ @_field_set&.to_json
141
+ end
142
+
143
+ # Leveraged for Union-type generation, validate_raw attempts to parse the given
144
+ # hash and check each fields type against the current object's property
145
+ # definitions.
146
+ #
147
+ # @param obj [Object]
148
+ # @return [Void]
149
+ def self.validate_raw(obj:)
150
+ obj.id&.is_a?(String) != false || raise("Passed value for field obj.id is not the expected type, validation failed.")
151
+ obj.type&.is_a?(TrophyApiClient::PointsTriggerResponseType) != false || raise("Passed value for field obj.type is not the expected type, validation failed.")
152
+ obj.points&.is_a?(Float) != false || raise("Passed value for field obj.points is not the expected type, validation failed.")
153
+ obj.status&.is_a?(TrophyApiClient::PointsTriggerResponseStatus) != false || raise("Passed value for field obj.status is not the expected type, validation failed.")
154
+ obj.achievement_id&.is_a?(String) != false || raise("Passed value for field obj.achievement_id is not the expected type, validation failed.")
155
+ obj.metric_id&.is_a?(String) != false || raise("Passed value for field obj.metric_id is not the expected type, validation failed.")
156
+ obj.metric_threshold&.is_a?(Float) != false || raise("Passed value for field obj.metric_threshold is not the expected type, validation failed.")
157
+ obj.streak_length_threshold&.is_a?(Float) != false || raise("Passed value for field obj.streak_length_threshold is not the expected type, validation failed.")
158
+ obj.metric_name&.is_a?(String) != false || raise("Passed value for field obj.metric_name is not the expected type, validation failed.")
159
+ obj.achievement_name&.is_a?(String) != false || raise("Passed value for field obj.achievement_name is not the expected type, validation failed.")
160
+ obj.created&.is_a?(DateTime) != false || raise("Passed value for field obj.created is not the expected type, validation failed.")
161
+ obj.updated&.is_a?(DateTime) != false || raise("Passed value for field obj.updated is not the expected type, validation failed.")
162
+ end
163
+ end
164
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TrophyApiClient
4
+ # The status of the trigger.
5
+ class PointsTriggerResponseStatus
6
+ ACTIVE = "active"
7
+ ARCHIVED = "archived"
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TrophyApiClient
4
+ # The type of trigger.
5
+ class PointsTriggerResponseType
6
+ METRIC = "metric"
7
+ ACHIEVEMENT = "achievement"
8
+ STREAK = "streak"
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TrophyApiClient
4
+ # The type of trigger
5
+ class PointsTriggerType
6
+ METRIC = "metric"
7
+ ACHIEVEMENT = "achievement"
8
+ STREAK = "streak"
9
+ end
10
+ end