1
1
# frozen_string_literal: true
2
2
3
3
module Svix
4
+ module_function
5
+
4
6
class MessageAPI
5
7
def initialize ( api_client )
6
8
@api = MessageApi . new ( api_client )
@@ -22,4 +24,31 @@ def expunge_content(app_id, msg_id)
22
24
return @api . v1_message_expunge_content ( app_id , msg_id )
23
25
end
24
26
end
27
+
28
+ # Creates a [`MessageIn`] with the payload already being serialized.
29
+ #
30
+ # The payload is not normalized on the server. Normally, payloads are required
31
+ # to be JSON, and Svix will minify the payload before sending the webhook
32
+ # (for example, by removing extraneous whitespace or unnecessarily escaped
33
+ # characters in strings). With this function, the payload will be sent
34
+ # "as is", without any minification or other processing.
35
+ #
36
+ # `attributes[:payload]` must be a string. An extra attribute `content_type`
37
+ # is accepted that sets the `content-type` header of the webhook, overwriting
38
+ # the default of `application/json` if specified. Other than that, the
39
+ # attributes are forwarded [`MessageIn.new`], so all the same ones are
40
+ # accepted.
41
+ def message_in_raw ( attributes = { } )
42
+ attributes [ :transformations_params ] ||= { }
43
+ attributes [ :transformations_params ] [ :rawPayload ] = attributes [ :payload ]
44
+ attributes [ :payload ] = { }
45
+
46
+ content_type = attributes . delete ( :content_type )
47
+ if content_type != nil
48
+ attributes [ :transformations_params ] [ :headers ] ||= { }
49
+ attributes [ :transformations_params ] [ :headers ] [ :'content-type' ] = content_type
50
+ end
51
+
52
+ return MessageIn . new ( attributes )
53
+ end
25
54
end
0 commit comments