=begin #MailSlurp API #MailSlurp is an API for sending and receiving emails from dynamically allocated email addresses. It's designed for developers and QA teams to test applications, process inbound emails, send templated notifications, attachments, and more. ## Resources - [Homepage](https://www.mailslurp.com) - Get an [API KEY](https://app.mailslurp.com/sign-up/) - Generated [SDK Clients](https://www.mailslurp.com/docs/) - [Examples](https://github.com/mailslurp/examples) repository The version of the OpenAPI document: 6.5.2 Contact: contact@mailslurp.dev Generated by: https://openapi-generator.tech OpenAPI Generator version: 4.3.1 =end require 'cgi' module MailSlurpClient class AttachmentControllerApi attr_accessor :api_client def initialize(api_client = ApiClient.default) @api_client = api_client end # Delete all attachments # @param [Hash] opts the optional parameters # @return [nil] def delete_all_attachments(opts = {}) delete_all_attachments_with_http_info(opts) nil end # Delete all attachments # @param [Hash] opts the optional parameters # @return [Array<(nil, Integer, Hash)>] nil, response status code and response headers def delete_all_attachments_with_http_info(opts = {}) if @api_client.config.debugging @api_client.config.logger.debug 'Calling API: AttachmentControllerApi.delete_all_attachments ...' end # resource path local_var_path = '/attachments' # query parameters query_params = opts[:query_params] || {} # header parameters header_params = opts[:header_params] || {} # form parameters form_params = opts[:form_params] || {} # http body (model) post_body = opts[:body] # return_type return_type = opts[:return_type] # auth_names auth_names = opts[:auth_names] || ['API_KEY'] new_options = opts.merge( :header_params => header_params, :query_params => query_params, :form_params => form_params, :body => post_body, :auth_names => auth_names, :return_type => return_type ) data, status_code, headers = @api_client.call_api(:DELETE, local_var_path, new_options) if @api_client.config.debugging @api_client.config.logger.debug "API called: AttachmentControllerApi#delete_all_attachments\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end return data, status_code, headers end # Delete an attachment # @param attachment_id [String] ID of attachment # @param [Hash] opts the optional parameters # @return [nil] def delete_attachment(attachment_id, opts = {}) delete_attachment_with_http_info(attachment_id, opts) nil end # Delete an attachment # @param attachment_id [String] ID of attachment # @param [Hash] opts the optional parameters # @return [Array<(nil, Integer, Hash)>] nil, response status code and response headers def delete_attachment_with_http_info(attachment_id, opts = {}) if @api_client.config.debugging @api_client.config.logger.debug 'Calling API: AttachmentControllerApi.delete_attachment ...' end # verify the required parameter 'attachment_id' is set if @api_client.config.client_side_validation && attachment_id.nil? fail ArgumentError, "Missing the required parameter 'attachment_id' when calling AttachmentControllerApi.delete_attachment" end # resource path local_var_path = '/attachments/{attachmentId}'.sub('{' + 'attachmentId' + '}', CGI.escape(attachment_id.to_s)) # query parameters query_params = opts[:query_params] || {} # header parameters header_params = opts[:header_params] || {} # form parameters form_params = opts[:form_params] || {} # http body (model) post_body = opts[:body] # return_type return_type = opts[:return_type] # auth_names auth_names = opts[:auth_names] || ['API_KEY'] new_options = opts.merge( :header_params => header_params, :query_params => query_params, :form_params => form_params, :body => post_body, :auth_names => auth_names, :return_type => return_type ) data, status_code, headers = @api_client.call_api(:DELETE, local_var_path, new_options) if @api_client.config.debugging @api_client.config.logger.debug "API called: AttachmentControllerApi#delete_attachment\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end return data, status_code, headers end # Get email attachment as base64 encoded string as alternative to binary responses. To read the content decode the Base64 encoded contents. # Returns the specified attachment for a given email as a base 64 encoded string. The response type is application/json. This method is similar to the `downloadAttachment` method but allows some clients to get around issues with binary responses. # @param attachment_id [String] ID of attachment # @param [Hash] opts the optional parameters # @return [DownloadAttachmentDto] def download_attachment_as_base64_encoded(attachment_id, opts = {}) data, _status_code, _headers = download_attachment_as_base64_encoded_with_http_info(attachment_id, opts) data end # Get email attachment as base64 encoded string as alternative to binary responses. To read the content decode the Base64 encoded contents. # Returns the specified attachment for a given email as a base 64 encoded string. The response type is application/json. This method is similar to the `downloadAttachment` method but allows some clients to get around issues with binary responses. # @param attachment_id [String] ID of attachment # @param [Hash] opts the optional parameters # @return [Array<(DownloadAttachmentDto, Integer, Hash)>] DownloadAttachmentDto data, response status code and response headers def download_attachment_as_base64_encoded_with_http_info(attachment_id, opts = {}) if @api_client.config.debugging @api_client.config.logger.debug 'Calling API: AttachmentControllerApi.download_attachment_as_base64_encoded ...' end # verify the required parameter 'attachment_id' is set if @api_client.config.client_side_validation && attachment_id.nil? fail ArgumentError, "Missing the required parameter 'attachment_id' when calling AttachmentControllerApi.download_attachment_as_base64_encoded" end # resource path local_var_path = '/attachments/{attachmentId}/base64'.sub('{' + 'attachmentId' + '}', CGI.escape(attachment_id.to_s)) # query parameters query_params = opts[:query_params] || {} # header parameters header_params = opts[:header_params] || {} # HTTP header 'Accept' (if needed) header_params['Accept'] = @api_client.select_header_accept(['*/*']) # form parameters form_params = opts[:form_params] || {} # http body (model) post_body = opts[:body] # return_type return_type = opts[:return_type] || 'DownloadAttachmentDto' # auth_names auth_names = opts[:auth_names] || ['API_KEY'] new_options = opts.merge( :header_params => header_params, :query_params => query_params, :form_params => form_params, :body => post_body, :auth_names => auth_names, :return_type => return_type ) data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options) if @api_client.config.debugging @api_client.config.logger.debug "API called: AttachmentControllerApi#download_attachment_as_base64_encoded\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end return data, status_code, headers end # Download attachments. Get email attachment bytes. If you have trouble with byte responses try the `downloadAttachmentBase64` response endpoints. # Returns the specified attachment for a given email as a stream / array of bytes. You can find attachment ids in email responses endpoint responses. The response type is application/octet-stream. # @param attachment_id [String] ID of attachment # @param [Hash] opts the optional parameters # @return [String] def download_attachment_as_bytes(attachment_id, opts = {}) data, _status_code, _headers = download_attachment_as_bytes_with_http_info(attachment_id, opts) data end # Download attachments. Get email attachment bytes. If you have trouble with byte responses try the `downloadAttachmentBase64` response endpoints. # Returns the specified attachment for a given email as a stream / array of bytes. You can find attachment ids in email responses endpoint responses. The response type is application/octet-stream. # @param attachment_id [String] ID of attachment # @param [Hash] opts the optional parameters # @return [Array<(String, Integer, Hash)>] String data, response status code and response headers def download_attachment_as_bytes_with_http_info(attachment_id, opts = {}) if @api_client.config.debugging @api_client.config.logger.debug 'Calling API: AttachmentControllerApi.download_attachment_as_bytes ...' end # verify the required parameter 'attachment_id' is set if @api_client.config.client_side_validation && attachment_id.nil? fail ArgumentError, "Missing the required parameter 'attachment_id' when calling AttachmentControllerApi.download_attachment_as_bytes" end # resource path local_var_path = '/attachments/{attachmentId}/bytes'.sub('{' + 'attachmentId' + '}', CGI.escape(attachment_id.to_s)) # query parameters query_params = opts[:query_params] || {} # header parameters header_params = opts[:header_params] || {} # HTTP header 'Accept' (if needed) header_params['Accept'] = @api_client.select_header_accept(['application/octet-stream']) # form parameters form_params = opts[:form_params] || {} # http body (model) post_body = opts[:body] # return_type return_type = opts[:return_type] || 'String' # auth_names auth_names = opts[:auth_names] || ['API_KEY'] new_options = opts.merge( :header_params => header_params, :query_params => query_params, :form_params => form_params, :body => post_body, :auth_names => auth_names, :return_type => return_type ) data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options) if @api_client.config.debugging @api_client.config.logger.debug "API called: AttachmentControllerApi#download_attachment_as_bytes\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end return data, status_code, headers end # Get an attachment entity # @param attachment_id [String] ID of attachment # @param [Hash] opts the optional parameters # @return [AttachmentEntity] def get_attachment(attachment_id, opts = {}) data, _status_code, _headers = get_attachment_with_http_info(attachment_id, opts) data end # Get an attachment entity # @param attachment_id [String] ID of attachment # @param [Hash] opts the optional parameters # @return [Array<(AttachmentEntity, Integer, Hash)>] AttachmentEntity data, response status code and response headers def get_attachment_with_http_info(attachment_id, opts = {}) if @api_client.config.debugging @api_client.config.logger.debug 'Calling API: AttachmentControllerApi.get_attachment ...' end # verify the required parameter 'attachment_id' is set if @api_client.config.client_side_validation && attachment_id.nil? fail ArgumentError, "Missing the required parameter 'attachment_id' when calling AttachmentControllerApi.get_attachment" end # resource path local_var_path = '/attachments/{attachmentId}'.sub('{' + 'attachmentId' + '}', CGI.escape(attachment_id.to_s)) # query parameters query_params = opts[:query_params] || {} # header parameters header_params = opts[:header_params] || {} # HTTP header 'Accept' (if needed) header_params['Accept'] = @api_client.select_header_accept(['*/*']) # form parameters form_params = opts[:form_params] || {} # http body (model) post_body = opts[:body] # return_type return_type = opts[:return_type] || 'AttachmentEntity' # auth_names auth_names = opts[:auth_names] || ['API_KEY'] new_options = opts.merge( :header_params => header_params, :query_params => query_params, :form_params => form_params, :body => post_body, :auth_names => auth_names, :return_type => return_type ) data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options) if @api_client.config.debugging @api_client.config.logger.debug "API called: AttachmentControllerApi#get_attachment\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end return data, status_code, headers end # Get email attachment metadata information # Returns the metadata for an attachment. It is saved separately to the content of the attachment. Contains properties `name` and `content-type` and `content-length` in bytes for a given attachment. # @param attachment_id [String] ID of attachment # @param [Hash] opts the optional parameters # @return [AttachmentMetaData] def get_attachment_info(attachment_id, opts = {}) data, _status_code, _headers = get_attachment_info_with_http_info(attachment_id, opts) data end # Get email attachment metadata information # Returns the metadata for an attachment. It is saved separately to the content of the attachment. Contains properties `name` and `content-type` and `content-length` in bytes for a given attachment. # @param attachment_id [String] ID of attachment # @param [Hash] opts the optional parameters # @return [Array<(AttachmentMetaData, Integer, Hash)>] AttachmentMetaData data, response status code and response headers def get_attachment_info_with_http_info(attachment_id, opts = {}) if @api_client.config.debugging @api_client.config.logger.debug 'Calling API: AttachmentControllerApi.get_attachment_info ...' end # verify the required parameter 'attachment_id' is set if @api_client.config.client_side_validation && attachment_id.nil? fail ArgumentError, "Missing the required parameter 'attachment_id' when calling AttachmentControllerApi.get_attachment_info" end # resource path local_var_path = '/attachments/{attachmentId}/metadata'.sub('{' + 'attachmentId' + '}', CGI.escape(attachment_id.to_s)) # query parameters query_params = opts[:query_params] || {} # header parameters header_params = opts[:header_params] || {} # HTTP header 'Accept' (if needed) header_params['Accept'] = @api_client.select_header_accept(['*/*']) # form parameters form_params = opts[:form_params] || {} # http body (model) post_body = opts[:body] # return_type return_type = opts[:return_type] || 'AttachmentMetaData' # auth_names auth_names = opts[:auth_names] || ['API_KEY'] new_options = opts.merge( :header_params => header_params, :query_params => query_params, :form_params => form_params, :body => post_body, :auth_names => auth_names, :return_type => return_type ) data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options) if @api_client.config.debugging @api_client.config.logger.debug "API called: AttachmentControllerApi#get_attachment_info\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end return data, status_code, headers end # Get email attachments # Get all attachments in paginated response. Each entity contains meta data for the attachment such as `name` and `content-type`. Use the `attachmentId` and the download endpoints to get the file contents. # @param [Hash] opts the optional parameters # @option opts [Integer] :page Optional page index event list pagination (default to 0) # @option opts [Integer] :size Optional page size event list pagination (default to 20) # @option opts [String] :sort Optional createdAt sort direction ASC or DESC (default to 'ASC') # @option opts [String] :file_name_filter Optional file name and content type search filter # @option opts [DateTime] :since Filter by created at after the given timestamp # @option opts [DateTime] :before Filter by created at before the given timestamp # @return [PageAttachmentEntity] def get_attachments1(opts = {}) data, _status_code, _headers = get_attachments1_with_http_info(opts) data end # Get email attachments # Get all attachments in paginated response. Each entity contains meta data for the attachment such as `name` and `content-type`. Use the `attachmentId` and the download endpoints to get the file contents. # @param [Hash] opts the optional parameters # @option opts [Integer] :page Optional page index event list pagination # @option opts [Integer] :size Optional page size event list pagination # @option opts [String] :sort Optional createdAt sort direction ASC or DESC # @option opts [String] :file_name_filter Optional file name and content type search filter # @option opts [DateTime] :since Filter by created at after the given timestamp # @option opts [DateTime] :before Filter by created at before the given timestamp # @return [Array<(PageAttachmentEntity, Integer, Hash)>] PageAttachmentEntity data, response status code and response headers def get_attachments1_with_http_info(opts = {}) if @api_client.config.debugging @api_client.config.logger.debug 'Calling API: AttachmentControllerApi.get_attachments1 ...' end allowable_values = ["ASC", "DESC"] if @api_client.config.client_side_validation && opts[:'sort'] && !allowable_values.include?(opts[:'sort']) fail ArgumentError, "invalid value for \"sort\", must be one of #{allowable_values}" end # resource path local_var_path = '/attachments' # query parameters query_params = opts[:query_params] || {} query_params[:'page'] = opts[:'page'] if !opts[:'page'].nil? query_params[:'size'] = opts[:'size'] if !opts[:'size'].nil? query_params[:'sort'] = opts[:'sort'] if !opts[:'sort'].nil? query_params[:'fileNameFilter'] = opts[:'file_name_filter'] if !opts[:'file_name_filter'].nil? query_params[:'since'] = opts[:'since'] if !opts[:'since'].nil? query_params[:'before'] = opts[:'before'] if !opts[:'before'].nil? # header parameters header_params = opts[:header_params] || {} # HTTP header 'Accept' (if needed) header_params['Accept'] = @api_client.select_header_accept(['*/*']) # form parameters form_params = opts[:form_params] || {} # http body (model) post_body = opts[:body] # return_type return_type = opts[:return_type] || 'PageAttachmentEntity' # auth_names auth_names = opts[:auth_names] || ['API_KEY'] new_options = opts.merge( :header_params => header_params, :query_params => query_params, :form_params => form_params, :body => post_body, :auth_names => auth_names, :return_type => return_type ) data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options) if @api_client.config.debugging @api_client.config.logger.debug "API called: AttachmentControllerApi#get_attachments1\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end return data, status_code, headers end # Upload an attachment for sending using base64 file encoding. Returns an array whose first element is the ID of the uploaded attachment. # @param upload_attachment_options [UploadAttachmentOptions] # @param [Hash] opts the optional parameters # @return [Array] def upload_attachment(upload_attachment_options, opts = {}) data, _status_code, _headers = upload_attachment_with_http_info(upload_attachment_options, opts) data end # Upload an attachment for sending using base64 file encoding. Returns an array whose first element is the ID of the uploaded attachment. # @param upload_attachment_options [UploadAttachmentOptions] # @param [Hash] opts the optional parameters # @return [Array<(Array, Integer, Hash)>] Array data, response status code and response headers def upload_attachment_with_http_info(upload_attachment_options, opts = {}) if @api_client.config.debugging @api_client.config.logger.debug 'Calling API: AttachmentControllerApi.upload_attachment ...' end # verify the required parameter 'upload_attachment_options' is set if @api_client.config.client_side_validation && upload_attachment_options.nil? fail ArgumentError, "Missing the required parameter 'upload_attachment_options' when calling AttachmentControllerApi.upload_attachment" end # resource path local_var_path = '/attachments' # query parameters query_params = opts[:query_params] || {} # header parameters header_params = opts[:header_params] || {} # HTTP header 'Accept' (if needed) header_params['Accept'] = @api_client.select_header_accept(['*/*']) # HTTP header 'Content-Type' header_params['Content-Type'] = @api_client.select_header_content_type(['application/json']) # form parameters form_params = opts[:form_params] || {} # http body (model) post_body = opts[:body] || @api_client.object_to_http_body(upload_attachment_options) # return_type return_type = opts[:return_type] || 'Array' # auth_names auth_names = opts[:auth_names] || ['API_KEY'] new_options = opts.merge( :header_params => header_params, :query_params => query_params, :form_params => form_params, :body => post_body, :auth_names => auth_names, :return_type => return_type ) data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options) if @api_client.config.debugging @api_client.config.logger.debug "API called: AttachmentControllerApi#upload_attachment\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end return data, status_code, headers end # Upload an attachment for sending using file byte stream input octet stream. Returns an array whose first element is the ID of the uploaded attachment. # @param request_body [Array] # @param [Hash] opts the optional parameters # @option opts [String] :content_type Optional contentType for file. For instance `application/pdf` # @option opts [String] :filename Optional filename to save upload with # @return [Array] def upload_attachment_bytes(request_body, opts = {}) data, _status_code, _headers = upload_attachment_bytes_with_http_info(request_body, opts) data end # Upload an attachment for sending using file byte stream input octet stream. Returns an array whose first element is the ID of the uploaded attachment. # @param request_body [Array] # @param [Hash] opts the optional parameters # @option opts [String] :content_type Optional contentType for file. For instance `application/pdf` # @option opts [String] :filename Optional filename to save upload with # @return [Array<(Array, Integer, Hash)>] Array data, response status code and response headers def upload_attachment_bytes_with_http_info(request_body, opts = {}) if @api_client.config.debugging @api_client.config.logger.debug 'Calling API: AttachmentControllerApi.upload_attachment_bytes ...' end # verify the required parameter 'request_body' is set if @api_client.config.client_side_validation && request_body.nil? fail ArgumentError, "Missing the required parameter 'request_body' when calling AttachmentControllerApi.upload_attachment_bytes" end # resource path local_var_path = '/attachments/bytes' # query parameters query_params = opts[:query_params] || {} query_params[:'contentType'] = opts[:'content_type'] if !opts[:'content_type'].nil? query_params[:'filename'] = opts[:'filename'] if !opts[:'filename'].nil? # header parameters header_params = opts[:header_params] || {} # HTTP header 'Accept' (if needed) header_params['Accept'] = @api_client.select_header_accept(['application/json']) # HTTP header 'Content-Type' header_params['Content-Type'] = @api_client.select_header_content_type(['application/octet-stream']) # form parameters form_params = opts[:form_params] || {} # http body (model) post_body = opts[:body] || @api_client.object_to_http_body(request_body) # return_type return_type = opts[:return_type] || 'Array' # auth_names auth_names = opts[:auth_names] || ['API_KEY'] new_options = opts.merge( :header_params => header_params, :query_params => query_params, :form_params => form_params, :body => post_body, :auth_names => auth_names, :return_type => return_type ) data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options) if @api_client.config.debugging @api_client.config.logger.debug "API called: AttachmentControllerApi#upload_attachment_bytes\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end return data, status_code, headers end # Upload an attachment for sending using a Multipart Form request. Returns an array whose first element is the ID of the uploaded attachment. # @param [Hash] opts the optional parameters # @option opts [String] :content_type Optional content type of attachment # @option opts [String] :filename Optional name of file # @option opts [String] :x_filename Optional content type header of attachment # @option opts [InlineObject] :inline_object # @return [Array] def upload_multipart_form(opts = {}) data, _status_code, _headers = upload_multipart_form_with_http_info(opts) data end # Upload an attachment for sending using a Multipart Form request. Returns an array whose first element is the ID of the uploaded attachment. # @param [Hash] opts the optional parameters # @option opts [String] :content_type Optional content type of attachment # @option opts [String] :filename Optional name of file # @option opts [String] :x_filename Optional content type header of attachment # @option opts [InlineObject] :inline_object # @return [Array<(Array, Integer, Hash)>] Array data, response status code and response headers def upload_multipart_form_with_http_info(opts = {}) if @api_client.config.debugging @api_client.config.logger.debug 'Calling API: AttachmentControllerApi.upload_multipart_form ...' end # resource path local_var_path = '/attachments/multipart' # query parameters query_params = opts[:query_params] || {} query_params[:'contentType'] = opts[:'content_type'] if !opts[:'content_type'].nil? query_params[:'filename'] = opts[:'filename'] if !opts[:'filename'].nil? query_params[:'x-filename'] = opts[:'x_filename'] if !opts[:'x_filename'].nil? # header parameters header_params = opts[:header_params] || {} # HTTP header 'Accept' (if needed) header_params['Accept'] = @api_client.select_header_accept(['*/*']) # HTTP header 'Content-Type' header_params['Content-Type'] = @api_client.select_header_content_type(['application/json']) # form parameters form_params = opts[:form_params] || {} # http body (model) post_body = opts[:body] || @api_client.object_to_http_body(opts[:'inline_object']) # return_type return_type = opts[:return_type] || 'Array' # auth_names auth_names = opts[:auth_names] || ['API_KEY'] new_options = opts.merge( :header_params => header_params, :query_params => query_params, :form_params => form_params, :body => post_body, :auth_names => auth_names, :return_type => return_type ) data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options) if @api_client.config.debugging @api_client.config.logger.debug "API called: AttachmentControllerApi#upload_multipart_form\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end return data, status_code, headers end end end