This is a basic application showing how to get started with the Xero's official xero-ruby SDK
It uses Sinatra which is a DSL for creating simple web applications in Ruby with minimal effort
1) This app is tested with Ruby 3.3.0
ruby -v
ruby 3.3.0
https://developer.xero.com/myapps/
https://developer.xero.com/documentation/oauth2/scopes
$ git clone [email protected]:XeroAPI/xero-ruby-oauth2-starter.git
$ cd xero-ruby-oauth2-starter/
$ mv sample.env .env
Replace CLIENT_ID
, CLIENT_SECRET
, REDIRECT_URI
& SCOPES
with your unique parameters
$ bundle install
$ bundle exec ruby xero_app.rb
Visit
http://localhost:4567/
and start exploring the code in your editor of choice 🥳
Setting up and connecting to the XeroAPI with the xero-ruby
SDK is simple
@xero_client = XeroRuby::ApiClient.new(credentials: {
client_id: ENV['CLIENT_ID'],
client_secret: ENV['CLIENT_SECRET'],
redirect_uri: 'http://localhost:4567/callback',
scopes: ENV['SCOPES']
})
get '/auth' do
redirect to(@xero_client.authorization_url)
end
get '/auth/callback' do
@xero_client.get_token_set_from_callback(params)
tenant_id = @xero_client.connections.last['tenantId']
@invoices = @xero_client.accounting_api.get_invoices(tenant_id).invoices
end
Checkout xero_app.rb
for all the sample code you need to get started for your own app