Giter Site home page Giter Site logo

wobinb / xero-ruby-oauth2-starter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from xeroapi/xero-ruby-oauth2-starter

0.0 1.0 0.0 2.82 MB

This is a starter app to perform OAuth 2.0 authentication with xero-ruby

License: MIT License

Ruby 53.76% CSS 16.87% Shell 2.15% Haml 27.22%

xero-ruby-oauth2-starter's Introduction

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

Getting Started

1) Make sure you have at least Ruby 2.7 installed

ruby -v
ruby 2.7.0

2) Create an app in Xero's developer portal

https://developer.xero.com/myapps/

3) Decide what scopes your application needs

https://developer.xero.com/documentation/oauth2/scopes

4) Clone app and rename sample.env to .env and replace with the 4 required parameters

$ 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

5) Install dependencies & run the app

$ bundle install
$ bundle exec ruby xero_app.rb

Visit http://localhost:4567/ and start exploring the code in your editor of choice ๐Ÿฅณ


Sample getting started code

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

App functionality

walkthrough

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.