Class: Square::Merchants::CustomAttributes::Client
- Inherits:
-
Object
- Object
- Square::Merchants::CustomAttributes::Client
- Defined in:
- lib/square/merchants/custom_attributes/client.rb
Instance Method Summary collapse
-
#batch_delete(request_options: {}, **params) ⇒ Square::Types::BulkDeleteMerchantCustomAttributesResponse
Deletes [custom attributes](entity:CustomAttribute) for a merchant as a bulk operation.
-
#batch_upsert(request_options: {}, **params) ⇒ Square::Types::BulkUpsertMerchantCustomAttributesResponse
Creates or updates [custom attributes](entity:CustomAttribute) for a merchant as a bulk operation.
-
#delete(request_options: {}, **params) ⇒ Square::Types::DeleteMerchantCustomAttributeResponse
Deletes a [custom attribute](entity:CustomAttribute) associated with a merchant.
-
#get(request_options: {}, **params) ⇒ Square::Types::RetrieveMerchantCustomAttributeResponse
Retrieves a [custom attribute](entity:CustomAttribute) associated with a merchant.
- #initialize(client:) ⇒ void constructor
-
#list(request_options: {}, **params) ⇒ Square::Types::ListMerchantCustomAttributesResponse
Lists the [custom attributes](entity:CustomAttribute) associated with a merchant.
-
#upsert(request_options: {}, **params) ⇒ Square::Types::UpsertMerchantCustomAttributeResponse
Creates or updates a [custom attribute](entity:CustomAttribute) for a merchant.
Constructor Details
#initialize(client:) ⇒ void
10 11 12 |
# File 'lib/square/merchants/custom_attributes/client.rb', line 10 def initialize(client:) @client = client end |
Instance Method Details
#batch_delete(request_options: {}, **params) ⇒ Square::Types::BulkDeleteMerchantCustomAttributesResponse
Deletes [custom attributes](entity:CustomAttribute) for a merchant as a bulk operation. To delete a custom attribute owned by another application, the ‘visibility` setting must be `VISIBILITY_READ_WRITE_VALUES`.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/square/merchants/custom_attributes/client.rb', line 27 def batch_delete(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "v2/merchants/custom-attributes/bulk-delete", body: Square::Merchants::CustomAttributes::Types::BulkDeleteMerchantCustomAttributesRequest.new(params).to_h, 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::BulkDeleteMerchantCustomAttributesResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#batch_upsert(request_options: {}, **params) ⇒ Square::Types::BulkUpsertMerchantCustomAttributesResponse
Creates or updates [custom attributes](entity:CustomAttribute) for a merchant as a bulk operation. Use this endpoint to set the value of one or more custom attributes for a merchant. A custom attribute is based on a custom attribute definition in a Square seller account, which is created using the [CreateMerchantCustomAttributeDefinition](api-endpoint:MerchantCustomAttributes-CreateMerchantCustomAttributeDefinition) endpoint. This ‘BulkUpsertMerchantCustomAttributes` endpoint accepts a map of 1 to 25 individual upsert requests and returns a map of individual upsert responses. Each upsert request has a unique ID and provides a merchant ID and custom attribute. Each upsert response is returned with the ID of the corresponding request. To create or update a custom attribute owned by another application, the `visibility` setting must be `VISIBILITY_READ_WRITE_VALUES`.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/square/merchants/custom_attributes/client.rb', line 72 def batch_upsert(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "v2/merchants/custom-attributes/bulk-upsert", body: Square::Merchants::CustomAttributes::Types::BulkUpsertMerchantCustomAttributesRequest.new(params).to_h, 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::BulkUpsertMerchantCustomAttributesResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#delete(request_options: {}, **params) ⇒ Square::Types::DeleteMerchantCustomAttributeResponse
Deletes a [custom attribute](entity:CustomAttribute) associated with a merchant. To delete a custom attribute owned by another application, the ‘visibility` setting must be `VISIBILITY_READ_WRITE_VALUES`.
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
# File 'lib/square/merchants/custom_attributes/client.rb', line 264 def delete(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "DELETE", path: "v2/merchants/#{params[:merchant_id]}/custom-attributes/#{params[:key]}", 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::DeleteMerchantCustomAttributeResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#get(request_options: {}, **params) ⇒ Square::Types::RetrieveMerchantCustomAttributeResponse
Retrieves a [custom attribute](entity:CustomAttribute) associated with a merchant. You can use the ‘with_definition` query parameter to also retrieve the custom attribute definition in the same call. To retrieve a custom attribute owned by another application, the `visibility` setting must be `VISIBILITY_READ_ONLY` or `VISIBILITY_READ_WRITE_VALUES`.
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/square/merchants/custom_attributes/client.rb', line 173 def get(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) query_param_names = %i[with_definition version] query_params = {} query_params["with_definition"] = params[:with_definition] if params.key?(:with_definition) query_params["version"] = params[:version] if params.key?(:version) params = params.except(*query_param_names) request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "v2/merchants/#{params[:merchant_id]}/custom-attributes/#{params[:key]}", query: query_params, 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::RetrieveMerchantCustomAttributeResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#list(request_options: {}, **params) ⇒ Square::Types::ListMerchantCustomAttributesResponse
Lists the [custom attributes](entity:CustomAttribute) associated with a merchant. You can use the ‘with_definitions` query parameter to also retrieve custom attribute definitions in the same call. When all response pages are retrieved, the results include all custom attributes that are visible to the requesting application, including those that are owned by other applications and set to `VISIBILITY_READ_ONLY` or `VISIBILITY_READ_WRITE_VALUES`.
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/square/merchants/custom_attributes/client.rb', line 116 def list(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) query_param_names = %i[visibility_filter limit cursor with_definitions] query_params = {} query_params["visibility_filter"] = params[:visibility_filter] if params.key?(:visibility_filter) query_params["limit"] = params[:limit] if params.key?(:limit) query_params["cursor"] = params[:cursor] if params.key?(:cursor) query_params["with_definitions"] = params[:with_definitions] if params.key?(:with_definitions) params = params.except(*query_param_names) Square::Internal::CursorItemIterator.new( cursor_field: :cursor, item_field: :custom_attributes, initial_cursor: query_params[:cursor] ) do |next_cursor| query_params[:cursor] = next_cursor request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "v2/merchants/#{params[:merchant_id]}/custom-attributes", query: query_params, 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::ListMerchantCustomAttributesResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end end |
#upsert(request_options: {}, **params) ⇒ Square::Types::UpsertMerchantCustomAttributeResponse
Creates or updates a [custom attribute](entity:CustomAttribute) for a merchant. Use this endpoint to set the value of a custom attribute for a specified merchant. A custom attribute is based on a custom attribute definition in a Square seller account, which is created using the [CreateMerchantCustomAttributeDefinition](api-endpoint:MerchantCustomAttributes-CreateMerchantCustomAttributeDefinition) endpoint. To create or update a custom attribute owned by another application, the ‘visibility` setting must be `VISIBILITY_READ_WRITE_VALUES`.
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
# File 'lib/square/merchants/custom_attributes/client.rb', line 222 def upsert(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) request_data = Square::Merchants::CustomAttributes::Types::UpsertMerchantCustomAttributeRequest.new(params).to_h non_body_param_names = %w[merchant_id key] body = request_data.except(*non_body_param_names) request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "v2/merchants/#{params[:merchant_id]}/custom-attributes/#{params[:key]}", 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::UpsertMerchantCustomAttributeResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |