Skip to content

Commit

Permalink
Merge pull request #54 from XeroAPI/xero-ruby-2-0-0
Browse files Browse the repository at this point in the history
Xero ruby 2.0.0
  • Loading branch information
SerKnight authored Aug 5, 2020
2 parents 781825f + da3c71d commit 6323001
Show file tree
Hide file tree
Showing 162 changed files with 987 additions and 335 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@ build-iPhoneSimulator/
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
.rvmrc
.DS_Store
build_notes.md
44 changes: 42 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,24 +119,64 @@ token_set = xero_client.token_set
```

## API Usage
> Comprehensive xero-ruby API usage is showcased here: https://github.com/XeroAPI/xero-ruby-oauth2-app
Here is the basic workflow of using SDK once you have a valid `access_token` (and `token_set`) stored on an instance of the `xero_client`

```ruby
require 'xero-ruby'

# reference `Authorization & Callback` to first store a valid token_set on the `xero_client`
xero_client.refresh_token_set(user.token_set)

# Accounting API set (https://github.com/XeroAPI/xero-ruby/blob/master/accounting/lib/xero-ruby/api/accounting_api.rb)
# Using the Accounting API set (https://github.com/XeroAPI/xero-ruby/blob/master/accounting/lib/xero-ruby/api/accounting_api.rb)

# Examples
invoices = xero_client.accounting_api.get_invoices(user.active_tenant_id).invoices
accounts = xero_client.accounting_api.get_accounts(user.active_tenant_id).accounts
contacts = xero_client.accounting_api.get_contacts(user.active_tenant_id).contacts

# Asset API set (https://github.com/XeroAPI/xero-ruby/blob/master/accounting/lib/xero-ruby/api/asset_api.rb)
contacts = xero_client.accounting_api.get_contacts(current_user.active_tenant_id).contacts
invoices = { invoices: [{ type: XeroRuby::Accounting::Invoice::ACCREC, contact: { contact_id: contacts[0].contact_id }, line_items: [{ description: "Acme Tires", quantity: BigDecimal("2.0"), unit_amount: BigDecimal("20.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(current_user.active_tenant_id, invoices).invoices.first

# all money and fields requiring advanced precision utilize BigDecimal
puts invoice.unit_amount
=> 0.2099e2

puts invoice.unit_amount.class
=> BigDecimal

puts invoice.unit_amount.to_s("F")
=> "20.99"

# or if using Rails https://api.rubyonrails.org/classes/ActionView/Helpers/NumberHelper.html#method-i-number_to_currency
number_to_currency(invoice.unit_amount, :unit => "$")

# creating an object History record
payment = xero_client.accounting_api.get_payments(current_user.active_tenant_id).payments.first
history_records = { history_records:[ { details: "This payment now has some History #{rand(10000)}" } ]}
payment_history = xero_client.accounting_api.create_payment_history(user.active_tenant_id, payment.payment_id, history_records)

# creating an object Attachment record
account = xero_client.accounting_api.get_accounts(current_user.active_tenant_id).accounts.first
file_name = "an-account-filename.png"
opts = {
include_online: true # Boolean | Allows an attachment to be seen by the end customer within their online invoice
}
file = File.read(Rails.root.join('app/assets/images/xero-api.png'))
attachment = xero_client.accounting_api.create_account_attachment_by_file_name(current_user.active_tenant_id, @account.account_id, file_name, file, opts)

# Using the Asset API set (https://github.com/XeroAPI/xero-ruby/blob/master/accounting/lib/xero-ruby/api/asset_api.rb)
asset = {
"assetName": "AssetName: #{rand(10000)}",
"assetNumber": "Asset: #{rand(10000)}",
"assetStatus": "DRAFT"
}
asset = xero_client.asset_api.create_asset(current_user.active_tenant_id, asset)

# Using the Project API set (https://github.com/XeroAPI/xero-ruby/blob/master/docs/projects/ProjectApi.md)
projects = xero_client.project_api.get_projects(current_user.active_tenant_id).items
```

If you have use cases outside of these examples or this readmy, please let us know!
Expand Down
34 changes: 23 additions & 11 deletions docs/accounting/AccountingApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Method | HTTP request | Description
------------- | ------------- | -------------
[**create_account**](AccountingApi.md#create_account) | **PUT** /Accounts | Allows you to create a new chart of accounts
[**create_account_attachment_by_file_name**](AccountingApi.md#create_account_attachment_by_file_name) | **PUT** /Accounts/{AccountID}/Attachments/{FileName} | Allows you to create Attachment on Account
[**create_bank_transaction_attachment_by_file_name**](AccountingApi.md#create_bank_transaction_attachment_by_file_name) | **PUT** /BankTransactions/{BankTransactionID}/Attachments/{FileName} | Allows you to createa an Attachment on BankTransaction by Filename
[**create_bank_transaction_attachment_by_file_name**](AccountingApi.md#create_bank_transaction_attachment_by_file_name) | **PUT** /BankTransactions/{BankTransactionID}/Attachments/{FileName} | Allows you to create an Attachment on BankTransaction by Filename
[**create_bank_transaction_history_record**](AccountingApi.md#create_bank_transaction_history_record) | **PUT** /BankTransactions/{BankTransactionID}/History | Allows you to create history record for a bank transactions
[**create_bank_transactions**](AccountingApi.md#create_bank_transactions) | **PUT** /BankTransactions | Allows you to create one or more spend or receive money transaction
[**create_bank_transfer**](AccountingApi.md#create_bank_transfer) | **PUT** /BankTransfers | Allows you to create a bank transfers
Expand Down Expand Up @@ -186,7 +186,7 @@ Method | HTTP request | Description
[**get_users**](AccountingApi.md#get_users) | **GET** /Users | Allows you to retrieve users
[**update_account**](AccountingApi.md#update_account) | **POST** /Accounts/{AccountID} | Allows you to update a chart of accounts
[**update_account_attachment_by_file_name**](AccountingApi.md#update_account_attachment_by_file_name) | **POST** /Accounts/{AccountID}/Attachments/{FileName} | Allows you to update Attachment on Account by Filename
[**update_bank_transaction**](AccountingApi.md#update_bank_transaction) | **POST** /BankTransactions/{BankTransactionID} |
[**update_bank_transaction**](AccountingApi.md#update_bank_transaction) | **POST** /BankTransactions/{BankTransactionID} | Allows you to update a single spend or receive money transaction
[**update_bank_transaction_attachment_by_file_name**](AccountingApi.md#update_bank_transaction_attachment_by_file_name) | **POST** /BankTransactions/{BankTransactionID}/Attachments/{FileName} | Allows you to update an Attachment on BankTransaction by Filename
[**update_bank_transfer_attachment_by_file_name**](AccountingApi.md#update_bank_transfer_attachment_by_file_name) | **POST** /BankTransfers/{BankTransferID}/Attachments/{FileName} |
[**update_contact**](AccountingApi.md#update_contact) | **POST** /Contacts/{ContactID} |
Expand Down Expand Up @@ -360,7 +360,7 @@ Name | Type | Description | Notes

> Attachments create_bank_transaction_attachment_by_file_name(xero_tenant_id, bank_transaction_id, file_name, body)
Allows you to createa an Attachment on BankTransaction by Filename
Allows you to create an Attachment on BankTransaction by Filename

### Example

Expand Down Expand Up @@ -394,7 +394,7 @@ bank_transaction_id = '00000000-0000-0000-000-000000000000' # String | Xero gene
file_name = 'xero-dev.jpg' # String | The name of the file being attached
body = 'body_example' # String | Byte array of file in body of request
begin
#Allows you to createa an Attachment on BankTransaction by Filename
#Allows you to create an Attachment on BankTransaction by Filename
result = api_instance.create_bank_transaction_attachment_by_file_name(xero_tenant_id, bank_transaction_id, file_name, body)
p result
rescue XeroRuby::Accounting::ApiError => e
Expand Down Expand Up @@ -1132,7 +1132,7 @@ api_instance = xero_client.accounting_api
api_instance = xero_client.asset_api
# :projects_api
api_instance = xero_client.projects_api
contacts = { contacts: [{ contactID: "a3675fc4-f8dd-4f03-ba5b-f1870566bcd7" }, { contactID: "4e1753b9-018a-4775-b6aa-1bc7871cfee3" }]}
contacts = { contacts: [{ contact_id: "a3675fc4-f8dd-4f03-ba5b-f1870566bcd7" }, { contact_id: "4e1753b9-018a-4775-b6aa-1bc7871cfee3" }]}

begin
#Allows you to add Contacts to a Contact Group
Expand Down Expand Up @@ -1305,7 +1305,7 @@ Name | Type | Description | Notes

## create_credit_note_allocation

> Allocations create_credit_note_allocation(xero_tenant_id, credit_note_id, allocations)
> Allocations create_credit_note_allocation(xero_tenant_id, credit_note_id, allocations, opts)
Allows you to create Allocation on CreditNote

Expand Down Expand Up @@ -1336,9 +1336,13 @@ api_instance = xero_client.asset_api
api_instance = xero_client.projects_api
allocations = { allocations: [{ amount: 1.0, date: "2019-03-05", invoice: { invoice_id: "c45720a1-ade3-4a38-a064-d15489be6841", line_items: [], type: XeroRuby::Accounting::Invoice::ACCPAY, contact: {} }}]}

opts = {
summarize_errors: false # Boolean | If false return 200 OK and mix of successfully created obejcts and any with validation errors
}

begin
#Allows you to create Allocation on CreditNote
result = api_instance.create_credit_note_allocation(xero_tenant_id, credit_note_id, allocations)
result = api_instance.create_credit_note_allocation(xero_tenant_id, credit_note_id, allocations, opts)
p result
rescue XeroRuby::Accounting::ApiError => e
puts "Exception when calling AccountingApi->create_credit_note_allocation: #{e}"
Expand All @@ -1353,6 +1357,7 @@ Name | Type | Description | Notes
**xero_tenant_id** | **String**| Xero identifier for Tenant |
**credit_note_id** | [**String**](.md)| Unique identifier for a Credit Note |
**allocations** | [**Allocations**](Allocations.md)| Allocations with array of Allocation object in body of request. |
**summarize_errors** | **Boolean**| If false return 200 OK and mix of successfully created obejcts and any with validation errors | [optional] [default to false]

### Return type

Expand Down Expand Up @@ -12874,9 +12879,9 @@ Name | Type | Description | Notes

## update_bank_transaction

> BankTransactions update_bank_transaction(xero_tenant_id, bank_transactions)
> BankTransactions update_bank_transaction(xero_tenant_id, bank_transaction_id, bank_transactions, opts)
Allows you to update a single spend or receive money transaction

### Example

Expand All @@ -12903,10 +12908,15 @@ api_instance = xero_client.accounting_api
api_instance = xero_client.asset_api
# :projects_api
api_instance = xero_client.projects_api
{ bank_transactions: [{ type: XeroRuby::Accounting::BankTransaction::SPEND, date: "2019-02-25", reference: "You just updated", status: XeroRuby::Accounting::BankTransaction::AUTHORISED, bank_transaction_id: "00000000-0000-0000-000-000000000000", line_items: [], contact: {}, bank_account: { account_id: "00000000-0000-0000-000-000000000000" }}]} summary: Allows you to update a single spend or receive money transaction parameters: - required: true in: path name: BankTransactionID description: Xero generated unique identifier for a bank transaction example: "00000000-0000-0000-000-000000000000" schema: type: string format: uuid - $ref:
{ bank_transactions: [{ type: XeroRuby::Accounting::BankTransaction::SPEND, date: "2019-02-25", reference: "You just updated", status: XeroRuby::Accounting::BankTransaction::AUTHORISED, bank_transaction_id: "00000000-0000-0000-000-000000000000", line_items: [], contact: {}, bank_account: { account_id: "00000000-0000-0000-000-000000000000" }}]}

opts = {
unitdp: 4 # Integer | e.g. unitdp=4 – (Unit Decimal Places) You can opt in to use four decimal places for unit amounts
}

begin
result = api_instance.update_bank_transaction(xero_tenant_id, bank_transactions)
#Allows you to update a single spend or receive money transaction
result = api_instance.update_bank_transaction(xero_tenant_id, bank_transaction_id, bank_transactions, opts)
p result
rescue XeroRuby::Accounting::ApiError => e
puts "Exception when calling AccountingApi->update_bank_transaction: #{e}"
Expand All @@ -12919,7 +12929,9 @@ end
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**xero_tenant_id** | **String**| Xero identifier for Tenant |
**bank_transaction_id** | [**String**](.md)| Xero generated unique identifier for a bank transaction |
**bank_transactions** | [**BankTransactions**](BankTransactions.md)| |
**unitdp** | **Integer**| e.g. unitdp&#x3D;4 – (Unit Decimal Places) You can opt in to use four decimal places for unit amounts | [optional]

### Return type

Expand Down
2 changes: 2 additions & 0 deletions docs/accounting/ManualJournalLine.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**line_amount** | **Float** | total for line. Debits are positive, credits are negative value | [optional]
**account_code** | **String** | See Accounts | [optional]
**account_id** | **String** | See Accounts | [optional]
**description** | **String** | Description for journal line | [optional]
**tax_type** | **String** | The tax type from TaxRates | [optional]
**tracking** | [**Array&lt;TrackingCategory&gt;**](TrackingCategory.md) | Optional Tracking Category – see Tracking. Any JournalLine can have a maximum of 2 &lt;TrackingCategory&gt; elements. | [optional]
Expand All @@ -19,6 +20,7 @@ require 'XeroRuby::Accounting'

instance = XeroRuby::Accounting::ManualJournalLine.new(line_amount: -2569.0,
account_code: 720,
account_id: null,
description: Coded incorrectly Office Equipment should be Computer Equipment,
tax_type: null,
tracking: null,
Expand Down
2 changes: 1 addition & 1 deletion docs/accounting/Organisation.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Name | Type | Description | Notes
**end_of_year_lock_date** | **Date** | Shown if set. See lock dates | [optional]
**created_date_utc** | **DateTime** | Timestamp when the organisation was created in Xero | [optional]
**timezone** | [**TimeZone**](TimeZone.md) | | [optional]
**organisation_entity_type** | **String** | Organisation Type | [optional]
**organisation_entity_type** | **String** | Organisation Entity Type | [optional]
**short_code** | **String** | A unique identifier for the organisation. Potential uses. | [optional]
**_class** | **String** | Organisation Classes describe which plan the Xero organisation is on (e.g. DEMO, TRIAL, PREMIUM) | [optional]
**edition** | **String** | BUSINESS or PARTNER. Partner edition organisations are sold exclusively through accounting partners and have restricted functionality (e.g. no access to invoicing) | [optional]
Expand Down
2 changes: 1 addition & 1 deletion docs/accounting/Report.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Name | Type | Description | Notes
**report_title** | **String** | See Prepayment Types | [optional]
**report_date** | **String** | Date of report | [optional]
**updated_date_utc** | **DateTime** | Updated Date | [optional]
**contacts** | [**Array&lt;TenNinteyNineContact&gt;**](TenNinteyNineContact.md) | | [optional]
**contacts** | [**Array&lt;TenNinetyNineContact&gt;**](TenNinetyNineContact.md) | | [optional]

## Code Sample

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# XeroRuby::Accounting::TenNinteyNineContact
# XeroRuby::Accounting::TenNinetyNineContact

## Properties

Expand Down Expand Up @@ -32,7 +32,7 @@ Name | Type | Description | Notes
```ruby
require 'XeroRuby::Accounting'

instance = XeroRuby::Accounting::TenNinteyNineContact.new(box1: null,
instance = XeroRuby::Accounting::TenNinetyNineContact.new(box1: null,
box2: null,
box3: null,
box4: null,
Expand Down
4 changes: 2 additions & 2 deletions lib/xero-ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
The version of the OpenAPI document: 2.2.2
The version of the OpenAPI document: 2.2.11
Contact: [email protected]
Generated by: https://openapi-generator.tech
OpenAPI Generator version: 4.3.1
Expand Down Expand Up @@ -152,7 +152,7 @@
require 'xero-ruby/models/accounting/tax_rate'
require 'xero-ruby/models/accounting/tax_rates'
require 'xero-ruby/models/accounting/tax_type'
require 'xero-ruby/models/accounting/ten_nintey_nine_contact'
require 'xero-ruby/models/accounting/ten_ninety_nine_contact'
require 'xero-ruby/models/accounting/time_zone'
require 'xero-ruby/models/accounting/tracking_categories'
require 'xero-ruby/models/accounting/tracking_category'
Expand Down
Loading

0 comments on commit 6323001

Please sign in to comment.