Skip to content

Commit

Permalink
Merge pull request #87 from XeroAPI/remaining_api_sets
Browse files Browse the repository at this point in the history
Add remaining Xero Product API Sets
  • Loading branch information
SerKnight authored Nov 3, 2020
2 parents 16ee559 + ac7d27b commit a35eeb8
Show file tree
Hide file tree
Showing 1,003 changed files with 122,431 additions and 2,360 deletions.
136 changes: 89 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,23 @@ Xero Ruby SDK for OAuth 2.0 generated from [Xero API OpenAPI Spec](https://githu
# Documentation
Xero Ruby SDK supports Xero's OAuth2.0 authentication and supports the following Xero API sets.

## APIS
## API Client Docs
* [Accounting Api Docs](/docs/accounting/AccountingApi.md)
* [Asset Api Docs](/docs/assets/AssetApi.md)
* [Project Api Docs](docs/projects/ProjectApi.md)
* [File Api Docs](docs/files/FileApi.md)
* [Payroll Docs (AU)](docs/payroll_au/PayrollAuApi.md)
* [Payroll Docs (NZ)](docs/payroll_nz/PayrollNzApi.md)
* [Payroll Docs (UK)](docs/payroll_uk/PayrollUkApi.md)

## Models
## API Model Docs
* [Accounting Models Docs](/docs/accounting/)
* [Asset Models Docs](/docs/assets/)
* [Project Models Docs](/docs/projects/)

### Coming soon
* payroll (AU)
* payroll (NZ/UK)
* files
* xero hq
* bank feeds
* [File Models Docs](/docs/files/)
* [Payroll Models (AU)](docs/payroll_au/)
* [Payroll Models (NZ)](docs/payroll_nz/)
* [Payroll Models (UK)](docs/payroll_uk/)

## Sample Apps
We have two apps showing SDK usage.
Expand Down Expand Up @@ -117,7 +118,8 @@ Refresh/connection helpers
```ruby
@token_set = xero_client.refresh_token_set(user.token_set)

# Xero's tokens can potentially facilitate (n) org connections in a single token. It is important to store the `tenantId` of the Organisation your user wants to read/write data.
# Xero's tokens can potentially facilitate (n) org connections in a single token.
# It is important to store the `tenantId` of the Organisation your user wants to read/write data.

# The `updatedDateUtc` will show you the most recently authorized Tenant (AKA Organisation)
connections = xero_client.connections
Expand All @@ -130,7 +132,8 @@ connections = xero_client.connections
"updatedDateUtc" => "2020-04-15T22:37:10.4943410"
}]

# disconnect an org from a user's connections. Pass the connection ['id'] not ['tenantId']. Useful if you want to enforce only a single org connection per token.
# disconnect an org from a user's connections. Pass the connection ['id'] not ['tenantId'].
# Useful if you want to enforce only a single org connection per token.
remaining_connections = xero_client.disconnect(connections[0]['id'])

# set a refreshed token_set
Expand All @@ -155,51 +158,90 @@ end
```

## API Usage

### Accounting API
```ruby
require 'xero-ruby'
require 'xero-ruby'

xero_client.refresh_token_set(user.token_set)

tenant_id = user.active_tenant_id
# example of how to store the `tenantId` of the specific tenant (aka organisation)

# https://github.com/XeroAPI/xero-ruby/blob/master/accounting/lib/xero-ruby/api/accounting_api.rb

# Get Accounts
accounts = xero_client.accounting_api.get_accounts(tenant_id).accounts

xero_client.refresh_token_set(user.token_set)
# Create Invoice
invoices = { invoices: [{ type: XeroRuby::Accounting::Invoice::ACCREC, contact: { contact_id: contacts[0].contact_id }, line_items: [{ description: "Big Agency", quantity: BigDecimal("2.0"), unit_amount: BigDecimal("50.99"), account_code: "600", tax_type: XeroRuby::Accounting::TaxType::NONE }], date: "2019-03-11", due_date: "2018-12-10", reference: "Website Design", status: XeroRuby::Accounting::Invoice::DRAFT }]}
invoice = xero_client.accounting_api.create_invoices(tenant_id, invoices).invoices.first

tenant_id = user.active_tenant_id
# example of how to store the `tenantId` of the specific tenant (aka organisation)
# Create History
payment = xero_client.accounting_api.get_payments(tenant_id).payments.first
history_records = { history_records: [{ details: "This payment now has some History!" }]}
payment_history = xero_client.accounting_api.create_payment_history(tenant_id, payment.payment_id, history_records)

# https://github.com/XeroAPI/xero-ruby/blob/master/accounting/lib/xero-ruby/api/accounting_api.rb
# Create Attachment
account = xero_client.accounting_api.get_accounts(tenant_id).accounts.first
file_name = "an-account-filename.png"
opts = {
include_online: true
}
file = File.read(Rails.root.join('app/assets/images/xero-api.png'))
attachment = xero_client.accounting_api.create_account_attachment_by_file_name(tenant_id, @account.account_id, file_name, file, opts)
```

### Assets API
```ruby
# https://github.com/XeroAPI/xero-ruby/blob/master/accounting/lib/xero-ruby/api/asset_api.rb

# Get Accounts
accounts = xero_client.accounting_api.get_accounts(tenant_id).accounts

# Create Invoice
invoices = { invoices: [{ type: XeroRuby::Accounting::Invoice::ACCREC, contact: { contact_id: contacts[0].contact_id }, line_items: [{ description: "Big Agency", quantity: BigDecimal("2.0"), unit_amount: BigDecimal("50.99"), account_code: "600", tax_type: XeroRuby::Accounting::TaxType::NONE }], date: "2019-03-11", due_date: "2018-12-10", reference: "Website Design", status: XeroRuby::Accounting::Invoice::DRAFT }]}
invoice = xero_client.accounting_api.create_invoices(tenant_id, invoices).invoices.first

# Create History
payment = xero_client.accounting_api.get_payments(tenant_id).payments.first
history_records = { history_records: [{ details: "This payment now has some History!" }]}
payment_history = xero_client.accounting_api.create_payment_history(tenant_id, payment.payment_id, history_records)

# Create Attachment
account = xero_client.accounting_api.get_accounts(tenant_id).accounts.first
file_name = "an-account-filename.png"
opts = {
include_online: true
}
file = File.read(Rails.root.join('app/assets/images/xero-api.png'))
attachment = xero_client.accounting_api.create_account_attachment_by_file_name(tenant_id, @account.account_id, file_name, file, opts)
# Create Asset
asset = {
"assetName": "AssetName: #{rand(10000)}",
"assetNumber": "Asset: #{rand(10000)}",
"assetStatus": "DRAFT"
}
asset = xero_client.asset_api.create_asset(tenant_id, asset)
```

### Project API
```ruby
# https://github.com/XeroAPI/xero-ruby/blob/master/docs/projects/ProjectApi.md

# Get Projects
projects = xero_client.project_api.get_projects(tenant_id).items
```

### Files API
```ruby
# https://github.com/XeroAPI/xero-ruby/blob/master/docs/files/FileApi.md

# https://github.com/XeroAPI/xero-ruby/blob/master/accounting/lib/xero-ruby/api/asset_api.rb
# Get Files
opts = {
pagesize: 50, # Integer | pass an optional page size value
page: 2, # Integer | number of records to skip for pagination
sort: 'CreatedDateUTC DESC' # String | values to sort by
}

# Create Asset
asset = {
"assetName": "AssetName: #{rand(10000)}",
"assetNumber": "Asset: #{rand(10000)}",
"assetStatus": "DRAFT"
}
asset = xero_client.asset_api.create_asset(tenant_id, asset)
files = xero_client.files_api.get_files(tenant_id, opts).files
```

### Payroll API(s)
```ruby
# https://github.com/XeroAPI/xero-ruby/blob/master/docs/payroll_au/PayrollAuApi.md
employee_id = 'employee_uuid'
employee = xero_client.payroll_au_api.get_employee(tenant_id, employee_id).employee


# https://github.com/XeroAPI/xero-ruby/blob/master/docs/payroll_nz/PayrollNzApi.md
timesheet_id = 'timesheeet_uuid'
timesheet = xero_client.payroll_nz_api.approve_timesheet(tenant_id, timesheet_id).timesheets

# https://github.com/XeroAPI/xero-ruby/blob/master/docs/projects/ProjectApi.md

# Get Projects
projects = xero_client.project_api.get_projects(tenant_id).items
# https://github.com/XeroAPI/xero-ruby/blob/master/docs/payroll_uk/PayrollUkApi.md
employee_id = 'employee_uuid'
wages = xero_client.payroll_uk_api.get_employee_salary_and_wages(tenant_id, employee_id, opts).salary_and_wages
```

## BigDecimal
Expand Down
Loading

0 comments on commit a35eeb8

Please sign in to comment.