ProductPromotion
Logo

Ruby

made by https://0x3d.site

GitHub - square/connect-ruby-sdk: Ruby client library for the Square Connect APIs
Ruby client library for the Square Connect APIs. Contribute to square/connect-ruby-sdk development by creating an account on GitHub.
Visit Site

GitHub - square/connect-ruby-sdk: Ruby client library for the Square Connect APIs

GitHub - square/connect-ruby-sdk: Ruby client library for the Square Connect APIs

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

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!

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory