trophy_api_client 1.0.21 → 1.0.23
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39897ab7658149ab5f3bf2a97e23eb07e0f2a2e2e5efc65e44b3aa70ca4ca36b
|
4
|
+
data.tar.gz: c202d22246b40b860ea0e201b8f90df0379fbb2c0330913c89b44d969ddafc3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1716545b54c6ba34b2e33306d3ee3a6a2f638597898527c3df0ddeb200bd2a5686801661d41542bd36ebbf4cc005807bdcc81ab8c39f3cfc8de6dfccb423ae5
|
7
|
+
data.tar.gz: 5f6a490904fb8842edc52c718c3e1559d5c3d048a920cfa5e0d4255f8dce0d9c83b4d4ae3d199513f25cee5c52e38c101fc62b5887b8a6ce58f713a950b7e4aa
|
data/lib/gemconfig.rb
CHANGED
@@ -18,6 +18,7 @@ module TrophyApiClient
|
|
18
18
|
|
19
19
|
# Increment or decrement the value of a metric for a user.
|
20
20
|
#
|
21
|
+
# @param idempotency_key [String]
|
21
22
|
# @param key [String] Unique reference of the metric as set when created.
|
22
23
|
# @param user [Hash] The user that triggered the event.Request of type TrophyApiClient::UpsertedUser, as a Hash
|
23
24
|
# * :id (String)
|
@@ -39,19 +40,21 @@ module TrophyApiClient
|
|
39
40
|
# api_key: "YOUR_API_KEY"
|
40
41
|
# )
|
41
42
|
# api.metrics.event(
|
43
|
+
# idempotency_key: "e4296e4b-8493-4bd1-9c30-5a1a9ac4d78f",
|
42
44
|
# key: "words-written",
|
43
45
|
# user: { email: "user@example.com", tz: "Europe/London", attributes: { "department": "engineering", "role": "developer" }, id: "18" },
|
44
46
|
# value: 750,
|
45
47
|
# attributes: { "category": "writing", "source": "mobile-app" }
|
46
48
|
# )
|
47
|
-
def event(key:, user:, value:, attributes: nil, request_options: nil)
|
49
|
+
def event(key:, user:, value:, idempotency_key: nil, attributes: nil, request_options: nil)
|
48
50
|
response = @request_client.conn.post do |req|
|
49
51
|
req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
|
50
52
|
req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
|
51
53
|
req.headers = {
|
52
|
-
|
53
|
-
|
54
|
-
|
54
|
+
**(req.headers || {}),
|
55
|
+
**@request_client.get_headers,
|
56
|
+
**(request_options&.additional_headers || {}),
|
57
|
+
"Idempotency-Key": idempotency_key
|
55
58
|
}.compact
|
56
59
|
unless request_options.nil? || request_options&.additional_query_parameters.nil?
|
57
60
|
req.params = { **(request_options&.additional_query_parameters || {}) }.compact
|
@@ -80,6 +83,7 @@ module TrophyApiClient
|
|
80
83
|
|
81
84
|
# Increment or decrement the value of a metric for a user.
|
82
85
|
#
|
86
|
+
# @param idempotency_key [String]
|
83
87
|
# @param key [String] Unique reference of the metric as set when created.
|
84
88
|
# @param user [Hash] The user that triggered the event.Request of type TrophyApiClient::UpsertedUser, as a Hash
|
85
89
|
# * :id (String)
|
@@ -101,20 +105,22 @@ module TrophyApiClient
|
|
101
105
|
# api_key: "YOUR_API_KEY"
|
102
106
|
# )
|
103
107
|
# api.metrics.event(
|
108
|
+
# idempotency_key: "e4296e4b-8493-4bd1-9c30-5a1a9ac4d78f",
|
104
109
|
# key: "words-written",
|
105
110
|
# user: { email: "user@example.com", tz: "Europe/London", attributes: { "department": "engineering", "role": "developer" }, id: "18" },
|
106
111
|
# value: 750,
|
107
112
|
# attributes: { "category": "writing", "source": "mobile-app" }
|
108
113
|
# )
|
109
|
-
def event(key:, user:, value:, attributes: nil, request_options: nil)
|
114
|
+
def event(key:, user:, value:, idempotency_key: nil, attributes: nil, request_options: nil)
|
110
115
|
Async do
|
111
116
|
response = @request_client.conn.post do |req|
|
112
117
|
req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
|
113
118
|
req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
|
114
119
|
req.headers = {
|
115
|
-
|
116
|
-
|
117
|
-
|
120
|
+
**(req.headers || {}),
|
121
|
+
**@request_client.get_headers,
|
122
|
+
**(request_options&.additional_headers || {}),
|
123
|
+
"Idempotency-Key": idempotency_key
|
118
124
|
}.compact
|
119
125
|
unless request_options.nil? || request_options&.additional_query_parameters.nil?
|
120
126
|
req.params = { **(request_options&.additional_query_parameters || {}) }.compact
|
@@ -19,6 +19,10 @@ module TrophyApiClient
|
|
19
19
|
attr_reader :current_streak
|
20
20
|
# @return [Hash{String => TrophyApiClient::MetricEventPointsResponse}] A map of points systems by key that were affected by this event.
|
21
21
|
attr_reader :points
|
22
|
+
# @return [String] The idempotency key used for the event, if one was provided.
|
23
|
+
attr_reader :idempotency_key
|
24
|
+
# @return [Boolean] Whether the event was replayed due to idempotency.
|
25
|
+
attr_reader :idempotent_replayed
|
22
26
|
# @return [OpenStruct] Additional properties unmapped to the current class definition
|
23
27
|
attr_reader :additional_properties
|
24
28
|
# @return [Object]
|
@@ -33,16 +37,20 @@ module TrophyApiClient
|
|
33
37
|
# @param achievements [Array<TrophyApiClient::CompletedAchievementResponse>] Achievements completed as a result of this event.
|
34
38
|
# @param current_streak [TrophyApiClient::MetricEventStreakResponse] The user's current streak for the metric, if the metric has streaks enabled.
|
35
39
|
# @param points [Hash{String => TrophyApiClient::MetricEventPointsResponse}] A map of points systems by key that were affected by this event.
|
40
|
+
# @param idempotency_key [String] The idempotency key used for the event, if one was provided.
|
41
|
+
# @param idempotent_replayed [Boolean] Whether the event was replayed due to idempotency.
|
36
42
|
# @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
|
37
43
|
# @return [TrophyApiClient::EventResponse]
|
38
44
|
def initialize(event_id:, metric_id:, total:, achievements: OMIT, current_streak: OMIT, points: OMIT,
|
39
|
-
additional_properties: nil)
|
45
|
+
idempotency_key: OMIT, idempotent_replayed: OMIT, additional_properties: nil)
|
40
46
|
@event_id = event_id
|
41
47
|
@metric_id = metric_id
|
42
48
|
@total = total
|
43
49
|
@achievements = achievements if achievements != OMIT
|
44
50
|
@current_streak = current_streak if current_streak != OMIT
|
45
51
|
@points = points if points != OMIT
|
52
|
+
@idempotency_key = idempotency_key if idempotency_key != OMIT
|
53
|
+
@idempotent_replayed = idempotent_replayed if idempotent_replayed != OMIT
|
46
54
|
@additional_properties = additional_properties
|
47
55
|
@_field_set = {
|
48
56
|
"eventId": event_id,
|
@@ -50,7 +58,9 @@ module TrophyApiClient
|
|
50
58
|
"total": total,
|
51
59
|
"achievements": achievements,
|
52
60
|
"currentStreak": current_streak,
|
53
|
-
"points": points
|
61
|
+
"points": points,
|
62
|
+
"idempotencyKey": idempotency_key,
|
63
|
+
"idempotentReplayed": idempotent_replayed
|
54
64
|
}.reject do |_k, v|
|
55
65
|
v == OMIT
|
56
66
|
end
|
@@ -80,6 +90,8 @@ module TrophyApiClient
|
|
80
90
|
value = value.to_json
|
81
91
|
TrophyApiClient::MetricEventPointsResponse.from_json(json_object: value)
|
82
92
|
end
|
93
|
+
idempotency_key = parsed_json["idempotencyKey"]
|
94
|
+
idempotent_replayed = parsed_json["idempotentReplayed"]
|
83
95
|
new(
|
84
96
|
event_id: event_id,
|
85
97
|
metric_id: metric_id,
|
@@ -87,6 +99,8 @@ module TrophyApiClient
|
|
87
99
|
achievements: achievements,
|
88
100
|
current_streak: current_streak,
|
89
101
|
points: points,
|
102
|
+
idempotency_key: idempotency_key,
|
103
|
+
idempotent_replayed: idempotent_replayed,
|
90
104
|
additional_properties: struct
|
91
105
|
)
|
92
106
|
end
|
@@ -111,6 +125,8 @@ module TrophyApiClient
|
|
111
125
|
obj.achievements&.is_a?(Array) != false || raise("Passed value for field obj.achievements is not the expected type, validation failed.")
|
112
126
|
obj.current_streak.nil? || TrophyApiClient::MetricEventStreakResponse.validate_raw(obj: obj.current_streak)
|
113
127
|
obj.points&.is_a?(Hash) != false || raise("Passed value for field obj.points is not the expected type, validation failed.")
|
128
|
+
obj.idempotency_key&.is_a?(String) != false || raise("Passed value for field obj.idempotency_key is not the expected type, validation failed.")
|
129
|
+
obj.idempotent_replayed&.is_a?(Boolean) != false || raise("Passed value for field obj.idempotent_replayed is not the expected type, validation failed.")
|
114
130
|
end
|
115
131
|
end
|
116
132
|
end
|