lib/notifications/client/speaker.rb in notifications-ruby-client-2.8.0 vs lib/notifications/client/speaker.rb in notifications-ruby-client-2.9.0
- old
+ new
@@ -1,5 +1,6 @@
+require "base64"
require "net/https"
require "uri"
require "jwt"
require_relative "request_error"
@@ -93,18 +94,34 @@
)
request.body = form_data.is_a?(Hash) ? form_data.to_json : form_data
perform_request!(request)
end
+ ##
+ # @param reference [String] reference of the notification
+ # @param pdf_file [File] PDF file opened for reading
+ # @see #perform_request!
+ def post_precompiled_letter(reference, pdf_file)
+ content = Base64.strict_encode64(pdf_file.read)
+ form_data = { reference: reference, content: content }
+
+ request = Net::HTTP::Post.new(
+ "#{BASE_PATH}/letter",
+ headers
+ )
+ request.body = form_data.to_json
+ perform_request!(request)
+ end
+
private
##
# @return [Hash] JSON parsed response
# @raise [RequestError] if request is
# not successful
def perform_request!(request)
response = open(request)
- if response.is_a?(Net::HTTPClientError)
+ if response.is_a?(Net::HTTPClientError) || response.is_a?(Net::HTTPServerError)
raise RequestError.new(response)
else
JSON.parse(response.body)
end
end