Class: Square::Catalog::Images::Client
- Inherits:
-
Object
- Object
- Square::Catalog::Images::Client
- Defined in:
- lib/square/catalog/images/client.rb
Instance Method Summary collapse
-
#create(request_options: {}, **params) ⇒ Square::Types::CreateCatalogImageResponse
Uploads an image file to be represented by a [CatalogImage](entity:CatalogImage) object that can be linked to an existing [CatalogObject](entity:CatalogObject) instance.
- #initialize(client:) ⇒ void constructor
-
#update(request_options: {}, **params) ⇒ Square::Types::UpdateCatalogImageResponse
Uploads a new image file to replace the existing one in the specified [CatalogImage](entity:CatalogImage) object.
Constructor Details
#initialize(client:) ⇒ void
10 11 12 |
# File 'lib/square/catalog/images/client.rb', line 10 def initialize(client:) @client = client end |
Instance Method Details
#create(request_options: {}, **params) ⇒ Square::Types::CreateCatalogImageResponse
Uploads an image file to be represented by a [CatalogImage](entity:CatalogImage) object that can be linked to an existing [CatalogObject](entity:CatalogObject) instance. The resulting ‘CatalogImage` is unattached to any `CatalogObject` if the `object_id` is not specified.
This ‘CreateCatalogImage` endpoint accepts HTTP multipart/form-data requests with a JSON part and an image file part in JPEG, PJPEG, PNG, or GIF format. The maximum file size is 15MB.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/square/catalog/images/client.rb', line 33 def create(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) body = Internal::Multipart::FormData.new if params[:request] body.add( name: "request", value: params[:request], content_type: "application/json; charset=utf-8" ) end body.add_part(params[:image_file].to_form_data_part(name: "image_file")) if params[:image_file] request = Square::Internal::Multipart::Request.new( base_url: [:base_url], method: "POST", path: "v2/catalog/images", body: body, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Square::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Square::Types::CreateCatalogImageResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#update(request_options: {}, **params) ⇒ Square::Types::UpdateCatalogImageResponse
Uploads a new image file to replace the existing one in the specified [CatalogImage](entity:CatalogImage) object.
This ‘UpdateCatalogImage` endpoint accepts HTTP multipart/form-data requests with a JSON part and an image file part in JPEG, PJPEG, PNG, or GIF format. The maximum file size is 15MB.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/square/catalog/images/client.rb', line 84 def update(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) body = Internal::Multipart::FormData.new if params[:request] body.add( name: "request", value: params[:request], content_type: "application/json; charset=utf-8" ) end body.add_part(params[:image_file].to_form_data_part(name: "image_file")) if params[:image_file] request = Square::Internal::Multipart::Request.new( base_url: [:base_url], method: "PUT", path: "v2/catalog/images/#{params[:image_id]}", body: body, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Square::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Square::Types::UpdateCatalogImageResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |