Repository is archived
No commit activity in last 3 years
No release in over 3 years
The Square Connect Ruby SDK is retired. Please migrate to the new Square gem: https://github.com/square/square-ruby-sdk
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 4.4, >= 4.4.6
~> 0.2, >= 0.2.11
~> 0.2, >= 0.2.16
~> 4.1, >= 4.1.2
~> 3.4, >= 3.4.0
~> 3.0, >= 3.0.1
~> 1.24, >= 1.24.3

Runtime

~> 2.1, >= 2.1.0
~> 1.0, >= 1.0.1
 Project Readme

Square logo

Square Connect Ruby SDK - RETIRED


Build Status Gem Version Apache-2 license

NOTICE: Square Connect Ruby SDK retired

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.



  • Migrate to the Square Ruby SDK
    • Update your bundle
    • Update your code
  • Example code migration
  • Ask the Community


Migrate to the Square Ruby SDK

Follow the instructions below to migrate your apps from the deprecated square_connect gem to the new square.rb gem.

Update your bundle

  1. Find the line in your Gemfile starting with gem: 'square_connect' and change the entire line to gem: 'square.rb'.
  2. Run bundle to update your Gemfile.lock.

Update your code

  1. Change all instances of require 'square_connect' to require 'square'.
  2. Replace models with plain Ruby Hash equivalents.
  3. Update client instantiation to follow the method outlined below.
  4. Update code for accessing response data to follow the method outlined below.
  5. Check response.success? or response.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.

Client instantiation

require 'square'

square = Square::Client.new(access_token: 'YOUR ACCESS TOKEN')

response = square.API.ENDPOINT(body: BODY)

Accessing response data

if response.success?
  p response.data
else
  warn response.errors
end



Example code migration

As 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 client
SquareConnect.configure do |config|
  config.access_token = 'YOUR ACCESS TOKEN'
end

api_instance = SquareConnect::CustomersApi.new

# Create the models
address = SquareConnect::Address.new(new_customer[:address])

body = SquareConnect::CreateCustomerRequest.new(
  given_name: new_customer[:given_name],
  address: address
)

begin
  # Call the endpoint
  response = api_instance.create_customer(body)

  # Handle the response and warn on errors
  p response.customer.to_hash
rescue SquareConnect::ApiError
  warn response.errors
end

Now consider equivalent code using the new square.rb gem:

require 'square'

# Instantiate the client
square = Square::Client.new(access_token: 'YOUR ACCESS TOKEN')

# Call the endpoint
response = square.customers.create_customer(body: new_customer)

# Handle the response and warn on errors
if response.success?
  p response.data
else
  warn response.errors
end

That'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.




Ask the community

Please join us in our Square developer community if you have any questions!