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:) ⇒ Square::Catalog::Images::Client 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:) ⇒ Square::Catalog::Images::Client
8 9 10 |
# File 'lib/square/catalog/images/client.rb', line 8 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.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/square/catalog/images/client.rb', line 20 def create(request_options: {}, **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( method: POST, path: "v2/catalog/images", body: body ) _response = @client.send(_request) if _response.code >= "200" && _response.code < "300" return Square::Types::CreateCatalogImageResponse.load(_response.body) end raise _response.body 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.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/square/catalog/images/client.rb', line 51 def update(request_options: {}, **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( method: PUT, path: "v2/catalog/images/#{params[:image_id]}", body: body ) _response = @client.send(_request) if _response.code >= "200" && _response.code < "300" return Square::Types::UpdateCatalogImageResponse.load(_response.body) end raise _response.body end |