=begin #Klaviyo API #The Klaviyo REST API. Please visit https://developers.klaviyo.com for more details. The version of the OpenAPI document: 2024-10-15 Contact: developers@klaviyo.com Generated by: https://openapi-generator.tech OpenAPI Generator version: 6.2.1 =end require 'cgi' module KlaviyoAPI class ImagesApi attr_accessor :api_client def initialize(api_client = ApiClient.default) @api_client = api_client end # Get Image # Get the image with the given image ID.

*Rate limits*:
Burst: `10/s`
Steady: `150/m` **Scopes:** `images:read` # @param id [String] The ID of the image # @param [Hash] opts the optional parameters # @option opts [Array] :fields_image For more information please visit https://developers.klaviyo.com/en/v2024-10-15/reference/api-overview#sparse-fieldsets # @return [Hash] def get_image(id, opts = {}) data, _status_code, _headers = get_image_with_http_info(id, opts) data end # Get Image # Get the image with the given image ID.<br><br>*Rate limits*:<br>Burst: `10/s`<br>Steady: `150/m` **Scopes:** `images:read` # @param id [String] The ID of the image # @param [Hash] opts the optional parameters # @option opts [Array] :fields_image For more information please visit https://developers.klaviyo.com/en/v2024-10-15/reference/api-overview#sparse-fieldsets # @return [Array<(Hash, Integer, Hash)>] Hash data, response status code and response headers def get_image_with_http_info(id, opts = {}) if @api_client.config.debugging @api_client.config.logger.debug 'Calling API: ImagesApi.get_image ...' end # verify the required parameter 'id' is set if @api_client.config.client_side_validation && id.nil? fail ArgumentError, "Missing the required parameter 'id' when calling ImagesApi.get_image" end allowable_values = ["name", "image_url", "format", "size", "hidden", "updated_at"] if @api_client.config.client_side_validation && opts[:'fields_image'] && !opts[:'fields_image'].all? { |item| allowable_values.include?(item) } fail ArgumentError, "invalid value for \"fields_image\", must include one of #{allowable_values}" end # resource path local_var_path = '/api/images/{id}'.sub('{' + 'id' + '}', CGI.escape(id.to_s)) # query parameters query_params = opts[:query_params] || {} query_params[:'fields[image]'] = @api_client.build_collection_param(opts[:'fields_image'], :csv) if !opts[:'fields_image'].nil? # header parameters header_params = opts[:header_params] || {} # klaviyo api revision header_params['revision'] = ENV['KLAVIYO_API_REVISION'] || ENV['API_REVISION'] || "2024-10-15" # HTTP header 'Accept' (if needed) header_params['Accept'] = @api_client.select_header_accept(['application/vnd.api+json']) # form parameters form_params = opts[:form_params] || {} # http body (model) post_body = opts[:debug_body] # return_type return_type = opts[:debug_return_type] || 'Hash' # auth_names auth_names = opts[:debug_auth_names] || ['Klaviyo-API-Key'] new_options = opts.merge( :operation => :"ImagesApi.get_image", :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: ImagesApi#get_image\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end return data, status_code, headers end # Get Images # Get all images in an account.

*Rate limits*:
Burst: `10/s`
Steady: `150/m` **Scopes:** `images:read` # @param [Hash] opts the optional parameters # @option opts [Array] :fields_image For more information please visit https://developers.klaviyo.com/en/v2024-10-15/reference/api-overview#sparse-fieldsets # @option opts [String] :filter For more information please visit https://developers.klaviyo.com/en/v2024-10-15/reference/api-overview#filtering<br>Allowed field(s)/operator(s):<br>`id`: `any`, `equals`<br>`updated_at`: `greater-or-equal`, `greater-than`, `less-or-equal`, `less-than`<br>`format`: `any`, `equals`<br>`name`: `any`, `contains`, `ends-with`, `equals`, `starts-with`<br>`size`: `greater-or-equal`, `greater-than`, `less-or-equal`, `less-than`<br>`hidden`: `any`, `equals` # @option opts [String] :page_cursor For more information please visit https://developers.klaviyo.com/en/v2024-10-15/reference/api-overview#pagination # @option opts [Integer] :page_size Default: 20. Min: 1. Max: 100. (default to 20) # @option opts [String] :sort For more information please visit https://developers.klaviyo.com/en/v2024-10-15/reference/api-overview#sorting # @return [Hash] def get_images(opts = {}) data, _status_code, _headers = get_images_with_http_info(opts) data end # Get Images # Get all images in an account.<br><br>*Rate limits*:<br>Burst: `10/s`<br>Steady: `150/m` **Scopes:** `images:read` # @param [Hash] opts the optional parameters # @option opts [Array] :fields_image For more information please visit https://developers.klaviyo.com/en/v2024-10-15/reference/api-overview#sparse-fieldsets # @option opts [String] :filter For more information please visit https://developers.klaviyo.com/en/v2024-10-15/reference/api-overview#filtering<br>Allowed field(s)/operator(s):<br>`id`: `any`, `equals`<br>`updated_at`: `greater-or-equal`, `greater-than`, `less-or-equal`, `less-than`<br>`format`: `any`, `equals`<br>`name`: `any`, `contains`, `ends-with`, `equals`, `starts-with`<br>`size`: `greater-or-equal`, `greater-than`, `less-or-equal`, `less-than`<br>`hidden`: `any`, `equals` # @option opts [String] :page_cursor For more information please visit https://developers.klaviyo.com/en/v2024-10-15/reference/api-overview#pagination # @option opts [Integer] :page_size Default: 20. Min: 1. Max: 100. (default to 20) # @option opts [String] :sort For more information please visit https://developers.klaviyo.com/en/v2024-10-15/reference/api-overview#sorting # @return [Array<(Hash, Integer, Hash)>] Hash data, response status code and response headers def get_images_with_http_info(opts = {}) if @api_client.config.debugging @api_client.config.logger.debug 'Calling API: ImagesApi.get_images ...' end allowable_values = ["name", "image_url", "format", "size", "hidden", "updated_at"] if @api_client.config.client_side_validation && opts[:'fields_image'] && !opts[:'fields_image'].all? { |item| allowable_values.include?(item) } fail ArgumentError, "invalid value for \"fields_image\", must include one of #{allowable_values}" end if @api_client.config.client_side_validation && !opts[:'page_size'].nil? && opts[:'page_size'] > 100 fail ArgumentError, 'invalid value for "opts[:"page_size"]" when calling ImagesApi.get_images, must be smaller than or equal to 100.' end if @api_client.config.client_side_validation && !opts[:'page_size'].nil? && opts[:'page_size'] < 1 fail ArgumentError, 'invalid value for "opts[:"page_size"]" when calling ImagesApi.get_images, must be greater than or equal to 1.' end allowable_values = ["format", "-format", "id", "-id", "name", "-name", "size", "-size", "updated_at", "-updated_at"] 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 = '/api/images' # query parameters query_params = opts[:query_params] || {} query_params[:'fields[image]'] = @api_client.build_collection_param(opts[:'fields_image'], :csv) if !opts[:'fields_image'].nil? query_params[:'filter'] = opts[:'filter'] if !opts[:'filter'].nil? query_params[:'page[cursor]'] = opts[:'page_cursor'] if !opts[:'page_cursor'].nil? query_params[:'page[size]'] = opts[:'page_size'] if !opts[:'page_size'].nil? query_params[:'sort'] = opts[:'sort'] if !opts[:'sort'].nil? # header parameters header_params = opts[:header_params] || {} # klaviyo api revision header_params['revision'] = ENV['KLAVIYO_API_REVISION'] || ENV['API_REVISION'] || "2024-10-15" # HTTP header 'Accept' (if needed) header_params['Accept'] = @api_client.select_header_accept(['application/vnd.api+json']) # form parameters form_params = opts[:form_params] || {} # http body (model) post_body = opts[:debug_body] # return_type return_type = opts[:debug_return_type] || 'Hash' # auth_names auth_names = opts[:debug_auth_names] || ['Klaviyo-API-Key'] new_options = opts.merge( :operation => :"ImagesApi.get_images", :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: ImagesApi#get_images\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end return data, status_code, headers end # Update Image # Update the image with the given image ID.

*Rate limits*:
Burst: `10/s`
Steady: `150/m` **Scopes:** `images:write` # @param id [String] The ID of the image # @param image_partial_update_query [ImagePartialUpdateQuery] # @param [Hash] opts the optional parameters # @return [Hash] def update_image(id, image_partial_update_query, opts = {}) data, _status_code, _headers = update_image_with_http_info(id, image_partial_update_query, opts) data end # Update Image # Update the image with the given image ID.<br><br>*Rate limits*:<br>Burst: `10/s`<br>Steady: `150/m` **Scopes:** `images:write` # @param id [String] The ID of the image # @param image_partial_update_query [ImagePartialUpdateQuery] # @param [Hash] opts the optional parameters # @return [Array<(Hash, Integer, Hash)>] Hash data, response status code and response headers def update_image_with_http_info(id, image_partial_update_query, opts = {}) if @api_client.config.debugging @api_client.config.logger.debug 'Calling API: ImagesApi.update_image ...' end # verify the required parameter 'id' is set if @api_client.config.client_side_validation && id.nil? fail ArgumentError, "Missing the required parameter 'id' when calling ImagesApi.update_image" end # verify the required parameter 'image_partial_update_query' is set if @api_client.config.client_side_validation && image_partial_update_query.nil? fail ArgumentError, "Missing the required parameter 'image_partial_update_query' when calling ImagesApi.update_image" end # resource path local_var_path = '/api/images/{id}'.sub('{' + 'id' + '}', CGI.escape(id.to_s)) # query parameters query_params = opts[:query_params] || {} # header parameters header_params = opts[:header_params] || {} # klaviyo api revision header_params['revision'] = ENV['KLAVIYO_API_REVISION'] || ENV['API_REVISION'] || "2024-10-15" # HTTP header 'Accept' (if needed) header_params['Accept'] = @api_client.select_header_accept(['application/vnd.api+json']) # HTTP header 'Content-Type' content_type = @api_client.select_header_content_type(['application/vnd.api+json']) if !content_type.nil? header_params['Content-Type'] = content_type end # form parameters form_params = opts[:form_params] || {} # http body (model) post_body = opts[:debug_body] || @api_client.object_to_http_body(image_partial_update_query) # return_type return_type = opts[:debug_return_type] || 'Hash' # auth_names auth_names = opts[:debug_auth_names] || ['Klaviyo-API-Key'] new_options = opts.merge( :operation => :"ImagesApi.update_image", :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(:PATCH, local_var_path, new_options) if @api_client.config.debugging @api_client.config.logger.debug "API called: ImagesApi#update_image\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end return data, status_code, headers end # Upload Image From File # Upload an image from a file. If you want to import an image from an existing url or a data uri, use the Upload Image From URL endpoint instead.

*Rate limits*:
Burst: `3/s`
Steady: `100/m`
Daily: `100/d` **Scopes:** `images:write` # @param file [File] The image file to upload. Supported image formats: jpeg,png,gif. Maximum image size: 5MB. # @param [Hash] opts the optional parameters # @option opts [String] :name A name for the image. Defaults to the filename if not provided. If the name matches an existing image, a suffix will be added. # @option opts [Boolean] :hidden If true, this image is not shown in the asset library. (default to false) # @return [Hash] def upload_image_from_file(file, opts = {}) data, _status_code, _headers = upload_image_from_file_with_http_info(file, opts) data end # alias of `upload_image_from_file` alias create_image_upload upload_image_from_file # Upload Image From File # Upload an image from a file. If you want to import an image from an existing url or a data uri, use the Upload Image From URL endpoint instead.<br><br>*Rate limits*:<br>Burst: `3/s`<br>Steady: `100/m`<br>Daily: `100/d` **Scopes:** `images:write` # @param file [File] The image file to upload. Supported image formats: jpeg,png,gif. Maximum image size: 5MB. # @param [Hash] opts the optional parameters # @option opts [String] :name A name for the image. Defaults to the filename if not provided. If the name matches an existing image, a suffix will be added. # @option opts [Boolean] :hidden If true, this image is not shown in the asset library. (default to false) # @return [Array<(Hash, Integer, Hash)>] Hash data, response status code and response headers def upload_image_from_file_with_http_info(file, opts = {}) if @api_client.config.debugging @api_client.config.logger.debug 'Calling API: ImagesApi.upload_image_from_file ...' end # verify the required parameter 'file' is set if @api_client.config.client_side_validation && file.nil? fail ArgumentError, "Missing the required parameter 'file' when calling ImagesApi.upload_image_from_file" end # resource path local_var_path = '/api/image-upload' # query parameters query_params = opts[:query_params] || {} # header parameters header_params = opts[:header_params] || {} # klaviyo api revision header_params['revision'] = ENV['KLAVIYO_API_REVISION'] || ENV['API_REVISION'] || "2024-10-15" # HTTP header 'Accept' (if needed) header_params['Accept'] = @api_client.select_header_accept(['application/vnd.api+json']) # HTTP header 'Content-Type' content_type = @api_client.select_header_content_type(['multipart/form-data']) if !content_type.nil? header_params['Content-Type'] = content_type end # form parameters form_params = opts[:form_params] || {} form_params['file'] = file form_params['name'] = opts[:'name'] if !opts[:'name'].nil? form_params['hidden'] = opts[:'hidden'] if !opts[:'hidden'].nil? # http body (model) post_body = opts[:debug_body] # return_type return_type = opts[:debug_return_type] || 'Hash' # auth_names auth_names = opts[:debug_auth_names] || ['Klaviyo-API-Key'] new_options = opts.merge( :operation => :"ImagesApi.upload_image_from_file", :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: ImagesApi#upload_image_from_file\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end return data, status_code, headers end # alias of `upload_image_from_file_with_http_info` alias create_image_upload_with_http_info upload_image_from_file_with_http_info # Upload Image From URL # Import an image from a url or data uri. If you want to upload an image from a file, use the Upload Image From File endpoint instead.

*Rate limits*:
Burst: `3/s`
Steady: `100/m`
Daily: `100/d` **Scopes:** `images:write` # @param image_create_query [ImageCreateQuery] # @param [Hash] opts the optional parameters # @return [Hash] def upload_image_from_url(image_create_query, opts = {}) data, _status_code, _headers = upload_image_from_url_with_http_info(image_create_query, opts) data end # alias of `upload_image_from_url` alias create_image upload_image_from_url # Upload Image From URL # Import an image from a url or data uri. If you want to upload an image from a file, use the Upload Image From File endpoint instead.<br><br>*Rate limits*:<br>Burst: `3/s`<br>Steady: `100/m`<br>Daily: `100/d` **Scopes:** `images:write` # @param image_create_query [ImageCreateQuery] # @param [Hash] opts the optional parameters # @return [Array<(Hash, Integer, Hash)>] Hash data, response status code and response headers def upload_image_from_url_with_http_info(image_create_query, opts = {}) if @api_client.config.debugging @api_client.config.logger.debug 'Calling API: ImagesApi.upload_image_from_url ...' end # verify the required parameter 'image_create_query' is set if @api_client.config.client_side_validation && image_create_query.nil? fail ArgumentError, "Missing the required parameter 'image_create_query' when calling ImagesApi.upload_image_from_url" end # resource path local_var_path = '/api/images' # query parameters query_params = opts[:query_params] || {} # header parameters header_params = opts[:header_params] || {} # klaviyo api revision header_params['revision'] = ENV['KLAVIYO_API_REVISION'] || ENV['API_REVISION'] || "2024-10-15" # HTTP header 'Accept' (if needed) header_params['Accept'] = @api_client.select_header_accept(['application/vnd.api+json']) # HTTP header 'Content-Type' content_type = @api_client.select_header_content_type(['application/vnd.api+json']) if !content_type.nil? header_params['Content-Type'] = content_type end # form parameters form_params = opts[:form_params] || {} # http body (model) post_body = opts[:debug_body] || @api_client.object_to_http_body(image_create_query) # return_type return_type = opts[:debug_return_type] || 'Hash' # auth_names auth_names = opts[:debug_auth_names] || ['Klaviyo-API-Key'] new_options = opts.merge( :operation => :"ImagesApi.upload_image_from_url", :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: ImagesApi#upload_image_from_url\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end return data, status_code, headers end # alias of `upload_image_from_url_with_http_info` alias create_image_with_http_info upload_image_from_url_with_http_info end end