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 44 45 46 47 48 49 |
# 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 ) 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.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/square/catalog/images/client.rb', line 57 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 ) 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 |