The Square Connect Ruby SDK is retired (EOL) as of 2019-08-15 and will no longer receive bug fixes or product updates. To continue receiving API and SDK improvements, please follow the instructions below to migrate to the new Square Ruby SDK gem.
The old Connect SDK documentation is available under the
/docs folder.
Follow the instructions below to migrate your apps from the deprecated
square_connect gem to the new square.rb gem.
- Find the line in your
Gemfilestarting withgem: 'square_connect'and change the entire line togem: 'square.rb'. - Run
bundleto update yourGemfile.lock.
- Change all instances of
require 'square_connect'torequire 'square'. - Replace models with plain Ruby Hash equivalents.
- Update client instantiation to follow the method outlined below.
- Update code for accessing response data to follow the method outlined below.
- Check
response.success?orresponse.error?rather than rescuing exceptions for flow control.
To simplify your code, we also recommend that you use method chaining to access APIs instead of explicitly instantiating multiple clients.
require'square'square=Square::Client.new(access_token: 'YOUR ACCESS TOKEN')response=square.API.ENDPOINT(body: BODY)ifresponse.success?presponse.dataelsewarnresponse.errorsendAs a specific example, consider the following code for creating a new customer from the following Hash:
new_customer={given_name: 'Ava',address: {address_line_1: '555 Electric Ave',locality: 'Los Angeles',country: 'US'}}With the deprecated square_connect gem, this is how you instantiate a client
for the Customers API, format the request, and call the endpoint:
require'square_connect'# Instantiate the clientSquareConnect.configuredo |config|
config.access_token='YOUR ACCESS TOKEN'endapi_instance=SquareConnect::CustomersApi.new# Create the modelsaddress=SquareConnect::Address.new(new_customer[:address])body=SquareConnect::CreateCustomerRequest.new(given_name: new_customer[:given_name],address: address)begin# Call the endpointresponse=api_instance.create_customer(body)# Handle the response and warn on errorspresponse.customer.to_hashrescueSquareConnect::ApiErrorwarnresponse.errorsendNow consider equivalent code using the new square.rb gem:
require'square'# Instantiate the clientsquare=Square::Client.new(access_token: 'YOUR ACCESS TOKEN')# Call the endpointresponse=square.customers.create_customer(body: new_customer)# Handle the response and warn on errorsifresponse.success?presponse.dataelsewarnresponse.errorsendThat's it!
What was once a multi-block process can be handled in 2 lines of code and an
if/else block. Migrating to the square.rb gem reduces boilerplate and lets
you focus on the parts of your code that really matter.
Please join us in our Square developer community if you have any questions!