xero-ruby 1.2.0 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +181 -72
- data/build_notes.md +52 -0
- data/docs/accounting/Account.md +1 -1
- data/docs/accounting/AccountingApi.md +23 -11
- data/docs/accounting/AccountsPayable.md +2 -2
- data/docs/accounting/AccountsReceivable.md +2 -2
- data/docs/accounting/Allocation.md +1 -1
- data/docs/accounting/Attachment.md +1 -1
- data/docs/accounting/BankTransaction.md +6 -6
- data/docs/accounting/BankTransfer.md +3 -3
- data/docs/accounting/BatchPayment.md +2 -2
- data/docs/accounting/BrandingTheme.md +1 -1
- data/docs/accounting/Contact.md +2 -2
- data/docs/accounting/CreditNote.md +6 -6
- data/docs/accounting/Employee.md +1 -1
- data/docs/accounting/ExpenseClaim.md +4 -4
- data/docs/accounting/HistoryRecord.md +1 -1
- data/docs/accounting/Invoice.md +10 -10
- data/docs/accounting/Item.md +3 -3
- data/docs/accounting/Journal.md +1 -1
- data/docs/accounting/JournalLine.md +3 -3
- data/docs/accounting/LineItem.md +6 -6
- data/docs/accounting/LinkedTransaction.md +1 -1
- data/docs/accounting/ManualJournal.md +1 -1
- data/docs/accounting/ManualJournalLine.md +4 -2
- data/docs/accounting/Organisation.md +2 -2
- data/docs/accounting/Overpayment.md +6 -6
- data/docs/accounting/Payment.md +3 -3
- data/docs/accounting/Prepayment.md +6 -6
- data/docs/accounting/Purchase.md +1 -1
- data/docs/accounting/PurchaseOrder.md +6 -6
- data/docs/accounting/Quote.md +5 -5
- data/docs/accounting/Receipt.md +4 -4
- data/docs/accounting/RepeatingInvoice.md +3 -3
- data/docs/accounting/Report.md +2 -2
- data/docs/accounting/ReportWithRow.md +1 -1
- data/docs/accounting/TaxComponent.md +1 -1
- data/docs/accounting/TaxRate.md +2 -2
- data/docs/accounting/{TenNinteyNineContact.md → TenNinetyNineContact.md} +15 -15
- data/docs/accounting/User.md +1 -1
- data/docs/assets/Asset.md +3 -3
- data/docs/assets/BookDepreciationDetail.md +6 -6
- data/docs/assets/BookDepreciationSetting.md +1 -1
- data/docs/projects/Amount.md +1 -1
- data/docs/projects/ProjectCreateOrUpdate.md +1 -1
- data/lib/xero-ruby.rb +2 -2
- data/lib/xero-ruby/api/accounting_api.rb +1311 -7
- data/lib/xero-ruby/api/asset_api.rb +37 -1
- data/lib/xero-ruby/api/project_api.rb +79 -1
- data/lib/xero-ruby/api_client.rb +72 -32
- data/lib/xero-ruby/api_error.rb +1 -1
- data/lib/xero-ruby/configuration.rb +2 -5
- data/lib/xero-ruby/models/accounting/account.rb +7 -2
- data/lib/xero-ruby/models/accounting/account_type.rb +1 -1
- data/lib/xero-ruby/models/accounting/accounts.rb +5 -1
- data/lib/xero-ruby/models/accounting/accounts_payable.rb +7 -3
- data/lib/xero-ruby/models/accounting/accounts_receivable.rb +7 -3
- data/lib/xero-ruby/models/accounting/address.rb +5 -1
- data/lib/xero-ruby/models/accounting/allocation.rb +6 -2
- data/lib/xero-ruby/models/accounting/allocations.rb +5 -1
- data/lib/xero-ruby/models/accounting/attachment.rb +6 -2
- data/lib/xero-ruby/models/accounting/attachments.rb +5 -1
- data/lib/xero-ruby/models/accounting/balances.rb +5 -1
- data/lib/xero-ruby/models/accounting/bank_transaction.rb +9 -10
- data/lib/xero-ruby/models/accounting/bank_transactions.rb +5 -1
- data/lib/xero-ruby/models/accounting/bank_transfer.rb +7 -3
- data/lib/xero-ruby/models/accounting/bank_transfers.rb +5 -1
- data/lib/xero-ruby/models/accounting/batch_payment.rb +6 -2
- data/lib/xero-ruby/models/accounting/batch_payment_details.rb +5 -1
- data/lib/xero-ruby/models/accounting/batch_payments.rb +5 -1
- data/lib/xero-ruby/models/accounting/bill.rb +5 -1
- data/lib/xero-ruby/models/accounting/branding_theme.rb +5 -1
- data/lib/xero-ruby/models/accounting/branding_themes.rb +5 -1
- data/lib/xero-ruby/models/accounting/cis_org_setting.rb +5 -1
- data/lib/xero-ruby/models/accounting/cis_setting.rb +5 -1
- data/lib/xero-ruby/models/accounting/cis_settings.rb +5 -1
- data/lib/xero-ruby/models/accounting/contact.rb +6 -2
- data/lib/xero-ruby/models/accounting/contact_group.rb +5 -1
- data/lib/xero-ruby/models/accounting/contact_groups.rb +5 -1
- data/lib/xero-ruby/models/accounting/contact_person.rb +5 -1
- data/lib/xero-ruby/models/accounting/contacts.rb +5 -1
- data/lib/xero-ruby/models/accounting/country_code.rb +1 -1
- data/lib/xero-ruby/models/accounting/credit_note.rb +10 -6
- data/lib/xero-ruby/models/accounting/credit_notes.rb +5 -1
- data/lib/xero-ruby/models/accounting/currencies.rb +5 -1
- data/lib/xero-ruby/models/accounting/currency.rb +5 -1
- data/lib/xero-ruby/models/accounting/currency_code.rb +1 -1
- data/lib/xero-ruby/models/accounting/element.rb +5 -1
- data/lib/xero-ruby/models/accounting/employee.rb +8 -3
- data/lib/xero-ruby/models/accounting/employees.rb +5 -1
- data/lib/xero-ruby/models/accounting/error.rb +5 -1
- data/lib/xero-ruby/models/accounting/expense_claim.rb +8 -4
- data/lib/xero-ruby/models/accounting/expense_claims.rb +5 -1
- data/lib/xero-ruby/models/accounting/external_link.rb +5 -1
- data/lib/xero-ruby/models/accounting/history_record.rb +5 -1
- data/lib/xero-ruby/models/accounting/history_records.rb +5 -1
- data/lib/xero-ruby/models/accounting/invoice.rb +14 -10
- data/lib/xero-ruby/models/accounting/invoice_reminder.rb +5 -1
- data/lib/xero-ruby/models/accounting/invoice_reminders.rb +5 -1
- data/lib/xero-ruby/models/accounting/invoices.rb +5 -1
- data/lib/xero-ruby/models/accounting/item.rb +7 -3
- data/lib/xero-ruby/models/accounting/items.rb +5 -1
- data/lib/xero-ruby/models/accounting/journal.rb +5 -1
- data/lib/xero-ruby/models/accounting/journal_line.rb +8 -4
- data/lib/xero-ruby/models/accounting/journals.rb +5 -1
- data/lib/xero-ruby/models/accounting/line_amount_types.rb +1 -1
- data/lib/xero-ruby/models/accounting/line_item.rb +11 -7
- data/lib/xero-ruby/models/accounting/line_item_tracking.rb +5 -1
- data/lib/xero-ruby/models/accounting/linked_transaction.rb +5 -1
- data/lib/xero-ruby/models/accounting/linked_transactions.rb +5 -1
- data/lib/xero-ruby/models/accounting/manual_journal.rb +5 -1
- data/lib/xero-ruby/models/accounting/manual_journal_line.rb +18 -4
- data/lib/xero-ruby/models/accounting/manual_journals.rb +5 -1
- data/lib/xero-ruby/models/accounting/online_invoice.rb +5 -1
- data/lib/xero-ruby/models/accounting/online_invoices.rb +5 -1
- data/lib/xero-ruby/models/accounting/organisation.rb +33 -3
- data/lib/xero-ruby/models/accounting/organisations.rb +5 -1
- data/lib/xero-ruby/models/accounting/overpayment.rb +10 -6
- data/lib/xero-ruby/models/accounting/overpayments.rb +5 -1
- data/lib/xero-ruby/models/accounting/payment.rb +7 -3
- data/lib/xero-ruby/models/accounting/payment_delete.rb +5 -1
- data/lib/xero-ruby/models/accounting/payment_service.rb +5 -1
- data/lib/xero-ruby/models/accounting/payment_services.rb +5 -1
- data/lib/xero-ruby/models/accounting/payment_term.rb +5 -1
- data/lib/xero-ruby/models/accounting/payment_term_type.rb +1 -1
- data/lib/xero-ruby/models/accounting/payments.rb +5 -1
- data/lib/xero-ruby/models/accounting/phone.rb +5 -1
- data/lib/xero-ruby/models/accounting/prepayment.rb +10 -6
- data/lib/xero-ruby/models/accounting/prepayments.rb +5 -1
- data/lib/xero-ruby/models/accounting/purchase.rb +6 -2
- data/lib/xero-ruby/models/accounting/purchase_order.rb +10 -6
- data/lib/xero-ruby/models/accounting/purchase_orders.rb +5 -1
- data/lib/xero-ruby/models/accounting/quote.rb +9 -5
- data/lib/xero-ruby/models/accounting/quote_line_amount_types.rb +1 -1
- data/lib/xero-ruby/models/accounting/quote_status_codes.rb +2 -1
- data/lib/xero-ruby/models/accounting/quotes.rb +5 -1
- data/lib/xero-ruby/models/accounting/receipt.rb +8 -4
- data/lib/xero-ruby/models/accounting/receipts.rb +5 -1
- data/lib/xero-ruby/models/accounting/repeating_invoice.rb +8 -4
- data/lib/xero-ruby/models/accounting/repeating_invoices.rb +5 -1
- data/lib/xero-ruby/models/accounting/report.rb +6 -2
- data/lib/xero-ruby/models/accounting/report_attribute.rb +5 -1
- data/lib/xero-ruby/models/accounting/report_cell.rb +5 -1
- data/lib/xero-ruby/models/accounting/report_fields.rb +5 -1
- data/lib/xero-ruby/models/accounting/report_row.rb +5 -1
- data/lib/xero-ruby/models/accounting/report_rows.rb +5 -1
- data/lib/xero-ruby/models/accounting/report_with_row.rb +5 -1
- data/lib/xero-ruby/models/accounting/report_with_rows.rb +5 -1
- data/lib/xero-ruby/models/accounting/reports.rb +5 -1
- data/lib/xero-ruby/models/accounting/request_empty.rb +5 -1
- data/lib/xero-ruby/models/accounting/row_type.rb +1 -1
- data/lib/xero-ruby/models/accounting/sales_tracking_category.rb +5 -1
- data/lib/xero-ruby/models/accounting/schedule.rb +5 -1
- data/lib/xero-ruby/models/accounting/tax_component.rb +6 -2
- data/lib/xero-ruby/models/accounting/tax_rate.rb +7 -3
- data/lib/xero-ruby/models/accounting/tax_rates.rb +5 -1
- data/lib/xero-ruby/models/accounting/tax_type.rb +1 -1
- data/lib/xero-ruby/models/accounting/{ten_nintey_nine_contact.rb → ten_ninety_nine_contact.rb} +21 -17
- data/lib/xero-ruby/models/accounting/time_zone.rb +1 -1
- data/lib/xero-ruby/models/accounting/tracking_categories.rb +5 -1
- data/lib/xero-ruby/models/accounting/tracking_category.rb +5 -1
- data/lib/xero-ruby/models/accounting/tracking_option.rb +5 -1
- data/lib/xero-ruby/models/accounting/tracking_options.rb +5 -1
- data/lib/xero-ruby/models/accounting/user.rb +5 -1
- data/lib/xero-ruby/models/accounting/users.rb +5 -1
- data/lib/xero-ruby/models/accounting/validation_error.rb +5 -1
- data/lib/xero-ruby/models/assets/asset.rb +8 -4
- data/lib/xero-ruby/models/assets/asset_status.rb +1 -1
- data/lib/xero-ruby/models/assets/asset_status_query_param.rb +1 -1
- data/lib/xero-ruby/models/assets/asset_type.rb +5 -1
- data/lib/xero-ruby/models/assets/assets.rb +5 -1
- data/lib/xero-ruby/models/assets/book_depreciation_detail.rb +11 -7
- data/lib/xero-ruby/models/assets/book_depreciation_setting.rb +6 -2
- data/lib/xero-ruby/models/assets/error.rb +5 -1
- data/lib/xero-ruby/models/assets/field_validation_errors_element.rb +5 -1
- data/lib/xero-ruby/models/assets/pagination.rb +5 -1
- data/lib/xero-ruby/models/assets/resource_validation_errors_element.rb +5 -1
- data/lib/xero-ruby/models/assets/setting.rb +5 -1
- data/lib/xero-ruby/models/projects/amount.rb +6 -2
- data/lib/xero-ruby/models/projects/charge_type.rb +1 -1
- data/lib/xero-ruby/models/projects/currency_code.rb +1 -1
- data/lib/xero-ruby/models/projects/error.rb +5 -1
- data/lib/xero-ruby/models/projects/pagination.rb +5 -1
- data/lib/xero-ruby/models/projects/project.rb +5 -1
- data/lib/xero-ruby/models/projects/project_create_or_update.rb +6 -2
- data/lib/xero-ruby/models/projects/project_patch.rb +5 -1
- data/lib/xero-ruby/models/projects/project_status.rb +1 -1
- data/lib/xero-ruby/models/projects/project_user.rb +5 -1
- data/lib/xero-ruby/models/projects/project_users.rb +5 -1
- data/lib/xero-ruby/models/projects/projects.rb +5 -1
- data/lib/xero-ruby/models/projects/task.rb +5 -1
- data/lib/xero-ruby/models/projects/task_create_or_update.rb +5 -1
- data/lib/xero-ruby/models/projects/tasks.rb +5 -1
- data/lib/xero-ruby/models/projects/time_entries.rb +5 -1
- data/lib/xero-ruby/models/projects/time_entry.rb +5 -1
- data/lib/xero-ruby/models/projects/time_entry_create_or_update.rb +5 -1
- data/lib/xero-ruby/version.rb +2 -2
- data/spec/accounting/models/ten_nintey_nine_contact_spec.rb +6 -6
- data/spec/api_client_spec.rb +103 -16
- data/xero-ruby.gemspec +1 -2
- metadata +5 -6
- data/Gemfile.lock +0 -68
- data/xero-ruby.gem +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50e381e3e8975dd61f56fa2607644c0cdcdb5f726e6f87a72d0a7226a68ac366
|
4
|
+
data.tar.gz: c93ed7a03a843e4afd2edf231c06b65acfe8d0fe9d0fafeaafd7f4bfbff5c4f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8293bbec6977ebf1f596e6c79b951b3d8751755fee5fb694e292580640f76d590e5a51b632a151657dc0534ee05bba85b4c37576be1ed91fb1195cf95b568ef
|
7
|
+
data.tar.gz: 1066cb551c1431139e3d2efd3a63235c527198e6fe3f07819cad9f77234f7644e1a3387c2af187f0182baa4f1da7205fbb69e8181643275d3087e2b771b903bc
|
data/README.md
CHANGED
@@ -1,32 +1,43 @@
|
|
1
1
|
# xero-ruby
|
2
|
-
Xero Ruby SDK for OAuth 2.0 generated from [Xero API OpenAPI Spec](https://github.com/XeroAPI/Xero-OpenAPI)
|
2
|
+
Xero Ruby SDK for OAuth 2.0 generated from [Xero API OpenAPI Spec](https://github.com/XeroAPI/Xero-OpenAPI).
|
3
3
|
|
4
4
|
[![RubyGem](https://img.shields.io/badge/xero--ruby%20gem-v0.2.4-brightgreen)](https://rubygems.org/gems/xero-ruby)
|
5
5
|
|
6
|
-
|
7
|
-
Xero Ruby SDK supports Xero's OAuth2.0 authentication
|
8
|
-
* [accounting](https://developer.xero.com/documentation/api/api-overview)
|
9
|
-
* [assets](https://developer.xero.com/documentation/assets-api/overview)
|
6
|
+
# Documentation
|
7
|
+
Xero Ruby SDK supports Xero's OAuth2.0 authentication and supports the following Xero API sets.
|
10
8
|
|
11
|
-
|
12
|
-
*
|
13
|
-
*
|
9
|
+
## APIS
|
10
|
+
* [Accounting Api Docs](/docs/accounting/AccountingApi.md)
|
11
|
+
* [Asset Api Docs](/docs/assets/AssetApi.md)
|
12
|
+
* [Project Api Docs](docs/projects/ProjectApi.md)
|
13
|
+
|
14
|
+
## Models
|
15
|
+
* [Accounting Models Docs](/docs/accounting/)
|
16
|
+
* [Asset Models Docs](/docs/assets/)
|
17
|
+
* [Project Models Docs](/docs/projects/)
|
18
|
+
|
19
|
+
### Coming soon
|
20
|
+
* payroll (AU)
|
14
21
|
* payroll (NZ/UK)
|
15
22
|
* files
|
16
|
-
* projects
|
17
23
|
* xero hq
|
24
|
+
* bank feeds
|
25
|
+
|
26
|
+
## Sample Apps
|
27
|
+
We have two apps showing SDK usage.
|
28
|
+
* https://github.com/XeroAPI/xero-ruby-oauth2-starter (**Sinatra** - session based / getting started)
|
29
|
+
* https://github.com/XeroAPI/xero-ruby-oauth2-app (**Rails** - token management / full examples)
|
18
30
|
|
19
31
|
## Looking for OAuth 1.0a support?
|
20
|
-
Check out the [Xeroizer](https://github.com/waynerobinson/xeroizer) gem (maintained by community)
|
32
|
+
Check out the [Xeroizer](https://github.com/waynerobinson/xeroizer) gem (maintained by community).
|
21
33
|
|
22
34
|
---
|
23
35
|
## Installation
|
24
|
-
|
25
|
-
|
36
|
+
To install this gem to your current gemset.
|
26
37
|
```
|
27
38
|
gem install 'xero-ruby'
|
28
39
|
```
|
29
|
-
Or
|
40
|
+
Or add to your gemfile and run `bundle install`.
|
30
41
|
```
|
31
42
|
gem 'xero-ruby'
|
32
43
|
```
|
@@ -36,16 +47,12 @@ gem 'xero-ruby'
|
|
36
47
|
* Login to your Xero developer [/myapps](https://developer.xero.com/myapps) dashboard & create an API application and note your API app's credentials.
|
37
48
|
|
38
49
|
### Creating a Client
|
39
|
-
|
50
|
+
* Get the credential values from an API application at https://developer.xero.com/myapps/.
|
51
|
+
* Include [neccesary scopes](https://developer.xero.com/documentation/oauth2/scopes) as comma seperated list
|
52
|
+
* example => "`openid profile email accounting.transactions accounting.settings`"
|
40
53
|
```
|
41
54
|
require 'xero-ruby'
|
42
55
|
```
|
43
|
-
Then create a client by passing in a named hash object `credentials:`.
|
44
|
-
|
45
|
-
> *client_id*, *client_secret*, *redirect_uri*: Get this from your API application in /myapps dashboard.
|
46
|
-
*scopes*: Include scopes as comma seperated list, https://developer.xero.com/documentation/oauth2/scopes
|
47
|
-
**ex:** 'openid profile email accounting.transactions'
|
48
|
-
|
49
56
|
```ruby
|
50
57
|
creds = {
|
51
58
|
client_id: ENV['CLIENT_ID'],
|
@@ -56,48 +63,63 @@ creds = {
|
|
56
63
|
xero_client ||= XeroRuby::ApiClient.new(credentials: creds)
|
57
64
|
```
|
58
65
|
|
59
|
-
## Authorization & Callback
|
60
|
-
All API requests require a valid access token to be set on the client.
|
61
|
-
```json
|
62
|
-
{
|
63
|
-
"id_token": "xxx.yyy.zz",
|
64
|
-
"access_token": "xxx.yyy.zzz",
|
65
|
-
"expires_in": 1800,
|
66
|
-
"token_type": "Bearer",
|
67
|
-
"refresh_token": "xxxxxx",
|
68
|
-
"scope": "email profile openid accounting.transactions offline_access"
|
69
|
-
}
|
70
|
-
```
|
66
|
+
## User Authorization & Callback
|
67
|
+
All API requests require a valid access token to be set on the client.
|
71
68
|
|
72
|
-
To generate a valid token_set
|
69
|
+
To generate a valid `token_set` send a user to the `authorization_url`:
|
73
70
|
```ruby
|
74
71
|
@authorization_url = xero_client.authorization_url
|
75
|
-
|
72
|
+
|
73
|
+
redirect_to @authorization_url
|
76
74
|
```
|
77
75
|
|
78
|
-
|
76
|
+
Xero will then redirect back to the URI defined in your ENV['REDIRECT_URI'] variable.
|
77
|
+
*This must match **exactly** with the variable in your /myapps dashboard.*
|
79
78
|
|
79
|
+
In your callback route catch, calling `get_token_set_from_callback` will exchange the temp code in your params, with a valid `token_set` that you can use to make API calls.
|
80
80
|
```ruby
|
81
|
-
# /
|
81
|
+
# => http://localhost:3000/oauth/callback
|
82
|
+
|
82
83
|
token_set = xero_client.get_token_set_from_callback(params)
|
83
84
|
|
84
|
-
#
|
85
|
-
|
85
|
+
# save token_set JSON in a datastore in relation to the user authentication
|
86
|
+
```
|
86
87
|
|
87
|
-
|
88
|
-
|
88
|
+
## Making API calls once you have a token_set
|
89
|
+
For use outside of the initial auth flow, setup the client by passing the whole token_set to `refresh_token_set` or `set_token_set`.
|
90
|
+
```ruby
|
89
91
|
xero_client.refresh_token_set(user.token_set)
|
92
|
+
|
93
|
+
xero_client.set_token_set(user.token_set)
|
90
94
|
```
|
95
|
+
A `token_set` contains data about your API connection most importantly :
|
96
|
+
* `access_token`
|
97
|
+
* `refresh_token`
|
98
|
+
* `expiry`
|
91
99
|
|
92
|
-
|
100
|
+
**An `access_token` is valid 30 minutes and a `refresh_token` is valid for 60 days**
|
93
101
|
|
94
|
-
Token
|
95
|
-
|
102
|
+
Example Token set:
|
103
|
+
> You can decode the `id_token` & `access_token` for additional metadata by using a [decoding library](https://github.com/jwt/ruby-jwt):
|
104
|
+
```json
|
105
|
+
{
|
106
|
+
"id_token": "xxx.yyy.zz",
|
107
|
+
"access_token": "xxx.yyy.zzz",
|
108
|
+
"expires_in": 1800,
|
109
|
+
"token_type": "Bearer",
|
110
|
+
"refresh_token": "xxxxxx",
|
111
|
+
"scope": "email profile openid accounting.transactions offline_access"
|
112
|
+
}
|
113
|
+
```
|
96
114
|
|
115
|
+
## Token & SDK Helpers
|
116
|
+
Refresh/connection helpers
|
97
117
|
```ruby
|
98
118
|
@token_set = xero_client.refresh_token_set(user.token_set)
|
99
119
|
|
100
|
-
#
|
120
|
+
# 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.
|
121
|
+
|
122
|
+
# The `updatedDateUtc` will show you the most recently authorized Tenant (AKA Organisation)
|
101
123
|
connections = xero_client.connections
|
102
124
|
[{
|
103
125
|
"id" => "xxx-yyy-zzz",
|
@@ -108,57 +130,144 @@ connections = xero_client.connections
|
|
108
130
|
"updatedDateUtc" => "2020-04-15T22:37:10.4943410"
|
109
131
|
}]
|
110
132
|
|
111
|
-
# disconnect an org from a user's connections. Pass the connection ['id'] not ['tenantId'].
|
133
|
+
# 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.
|
112
134
|
remaining_connections = xero_client.disconnect(connections[0]['id'])
|
113
135
|
|
114
|
-
# set token_set
|
136
|
+
# set a refreshed token_set
|
115
137
|
token_set = xero_client.set_token_set(user.token_set)
|
116
138
|
|
117
|
-
# access token_set
|
139
|
+
# access token_set once it is set on the client
|
118
140
|
token_set = xero_client.token_set
|
119
141
|
```
|
120
142
|
|
143
|
+
Example token expiry helper
|
144
|
+
```ruby
|
145
|
+
require 'jwt'
|
146
|
+
|
147
|
+
def token_expired?
|
148
|
+
token_expiry = Time.at(decoded_access_token['exp'])
|
149
|
+
token_expiry > Time.now
|
150
|
+
end
|
151
|
+
|
152
|
+
def decoded_access_token
|
153
|
+
JWT.decode(token_set['access_token'], nil, false)[0]
|
154
|
+
end
|
155
|
+
```
|
156
|
+
|
121
157
|
## API Usage
|
122
158
|
```ruby
|
123
159
|
require 'xero-ruby'
|
124
160
|
|
125
|
-
# reference `Authorization & Callback` to first store a valid token_set on the `xero_client`
|
126
161
|
xero_client.refresh_token_set(user.token_set)
|
127
162
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
163
|
+
tenant_id = user.active_tenant_id
|
164
|
+
# example of how to store the `tenantId` of the specific tenant (aka organisation)
|
165
|
+
|
166
|
+
# https://github.com/XeroAPI/xero-ruby/blob/master/accounting/lib/xero-ruby/api/accounting_api.rb
|
167
|
+
|
168
|
+
# Get Accounts
|
169
|
+
accounts = xero_client.accounting_api.get_accounts(tenant_id).accounts
|
170
|
+
|
171
|
+
# Create Invoice
|
172
|
+
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 }]}
|
173
|
+
invoice = xero_client.accounting_api.create_invoices(tenant_id, invoices).invoices.first
|
174
|
+
|
175
|
+
# Create History
|
176
|
+
payment = xero_client.accounting_api.get_payments(tenant_id).payments.first
|
177
|
+
history_records = { history_records: [{ details: "This payment now has some History!" }]}
|
178
|
+
payment_history = xero_client.accounting_api.create_payment_history(tenant_id, payment.payment_id, history_records)
|
132
179
|
|
133
|
-
#
|
180
|
+
# Create Attachment
|
181
|
+
account = xero_client.accounting_api.get_accounts(tenant_id).accounts.first
|
182
|
+
file_name = "an-account-filename.png"
|
183
|
+
opts = {
|
184
|
+
include_online: true
|
185
|
+
}
|
186
|
+
file = File.read(Rails.root.join('app/assets/images/xero-api.png'))
|
187
|
+
attachment = xero_client.accounting_api.create_account_attachment_by_file_name(tenant_id, @account.account_id, file_name, file, opts)
|
188
|
+
|
189
|
+
# https://github.com/XeroAPI/xero-ruby/blob/master/accounting/lib/xero-ruby/api/asset_api.rb
|
190
|
+
|
191
|
+
# Create Asset
|
134
192
|
asset = {
|
135
193
|
"assetName": "AssetName: #{rand(10000)}",
|
136
194
|
"assetNumber": "Asset: #{rand(10000)}",
|
137
195
|
"assetStatus": "DRAFT"
|
138
196
|
}
|
139
|
-
asset = xero_client.asset_api.create_asset(
|
197
|
+
asset = xero_client.asset_api.create_asset(tenant_id, asset)
|
198
|
+
|
199
|
+
# https://github.com/XeroAPI/xero-ruby/blob/master/docs/projects/ProjectApi.md
|
200
|
+
|
201
|
+
# Get Projects
|
202
|
+
projects = xero_client.project_api.get_projects(tenant_id).items
|
140
203
|
```
|
141
204
|
|
142
|
-
|
205
|
+
## BigDecimal
|
206
|
+
All monetary and fields and a couple quantity fields utilize BigDecimal
|
207
|
+
```ruby
|
208
|
+
puts invoice.unit_amount
|
209
|
+
=> 0.2099e2
|
210
|
+
|
211
|
+
puts invoice.unit_amount.class
|
212
|
+
=> BigDecimal
|
143
213
|
|
144
|
-
|
145
|
-
|
146
|
-
> https://github.com/XeroAPI/xero-ruby-oauth2-app
|
214
|
+
puts invoice.unit_amount.to_s("F")
|
215
|
+
=> "20.99"
|
147
216
|
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
* Change the active tenant & make api calls to multiple orgs
|
152
|
-
* Refreshing your token sets
|
153
|
-
* Decoding your token_set items and strategy around how/when to refresh
|
154
|
-
* Disconnecting a connection for a user
|
217
|
+
# Rails method-number_to_currency
|
218
|
+
number_to_currency(invoice.unit_amount, :unit => "$")
|
219
|
+
```
|
155
220
|
|
156
|
-
##
|
221
|
+
## Querying & Filtering
|
222
|
+
Examples for the `opts` (_options_) parameters most endpoints support.
|
223
|
+
```ruby
|
224
|
+
# Invoices
|
225
|
+
opts = {
|
226
|
+
statuses: [XeroRuby::Accounting::Invoice::PAID],
|
227
|
+
where: { amount_due: '=0' },
|
228
|
+
if_modified_since: (DateTime.now - 1.hour).to_s
|
229
|
+
}
|
230
|
+
xero_client.accounting_api.get_invoices(tenant_id, opts).invoices
|
231
|
+
|
232
|
+
# Contacts
|
233
|
+
opts = {
|
234
|
+
if_modified_since: (DateTime.now - 1.weeks).to_s,
|
235
|
+
order: 'UpdatedDateUtc DESC',
|
236
|
+
where: {
|
237
|
+
is_customer: '==true',
|
238
|
+
is_supplier: '==true',
|
239
|
+
}
|
240
|
+
}
|
241
|
+
xero_client.accounting_api.get_contacts(tenant_id, opts).contacts
|
242
|
+
|
243
|
+
# Bank Transactions
|
244
|
+
opts = {
|
245
|
+
if_modified_since: (DateTime.now - 1.year).to_s,
|
246
|
+
where: { type: %{=="#{XeroRuby::Accounting::BankTransaction::SPEND}"}},
|
247
|
+
order: 'UpdatedDateUtc DESC',
|
248
|
+
page: 2,
|
249
|
+
unitdp: 4 # (Unit Decimal Places)
|
250
|
+
}
|
251
|
+
xero_client.accounting_api.get_bank_transactions(tenant_id, opts).bank_transactions
|
252
|
+
|
253
|
+
# Bank Transfers
|
254
|
+
opts = {
|
255
|
+
where: {
|
256
|
+
amount: "> 999.99"
|
257
|
+
},
|
258
|
+
order: 'Amount ASC'
|
259
|
+
}
|
260
|
+
xero_client.accounting_api.get_bank_transfers(tenant_id, opts).bank_transfers
|
261
|
+
```
|
262
|
+
### NOTE
|
263
|
+
1) Not all `opts` parameter combinations are available for all endpoints, and there are likely some undiscovered edge cases. If you encounter a filter / sort / where clause that seems buggy open an issue and we will dig.
|
157
264
|
|
158
|
-
|
159
|
-
*
|
160
|
-
* [Asset Api Docs](/docs/assets/AssetApi.md)
|
265
|
+
2) Some opts string values may need PascalCasing to match casing defined in our [core API docs](https://developer.xero.com/documentation/api/api-overview).
|
266
|
+
* `opts = { order: 'UpdatedDateUtc DESC'}`
|
161
267
|
|
162
|
-
|
163
|
-
|
164
|
-
|
268
|
+
3) If you have use cases outside of these examples let us know.
|
269
|
+
|
270
|
+
## Sample App
|
271
|
+
The best resource to understanding how to best leverage this SDK is the sample applications showing all the features of the gem.
|
272
|
+
> https://github.com/XeroAPI/xero-ruby-oauth2-starter (Sinatra - simple getting started)
|
273
|
+
> https://github.com/XeroAPI/xero-ruby-oauth2-app (Rails - full featured examples)
|
data/build_notes.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# Developing gem locally
|
2
|
+
|
3
|
+
> xero-ruby
|
4
|
+
```bash
|
5
|
+
gem build
|
6
|
+
mv xero-ruby-<vsn>.gem xero-ruby.gem
|
7
|
+
```
|
8
|
+
|
9
|
+
> xero-ruby-oauth2-app
|
10
|
+
Replace gem file with local path:
|
11
|
+
```bash
|
12
|
+
gem 'xero-ruby', path: '/Users/chris.knight/code/sdks/xero-ruby/'
|
13
|
+
bundle install
|
14
|
+
```
|
15
|
+
|
16
|
+
# Deploying to Rubygems
|
17
|
+
|
18
|
+
```bash
|
19
|
+
gem build
|
20
|
+
gem push xero-ruby-<vsn>.gem
|
21
|
+
```
|
22
|
+
|
23
|
+
# manual updates
|
24
|
+
account.rb
|
25
|
+
```ruby
|
26
|
+
# duplicate definitions generated: https://github.com/XeroAPI/xero-ruby/issues/53#issuecomment-668893305
|
27
|
+
# EMPTY = "".freeze
|
28
|
+
```
|
29
|
+
|
30
|
+
organisation.rb
|
31
|
+
```ruby
|
32
|
+
# duplicate definitions generated: https://github.com/XeroAPI/xero-ruby/issues/53#issuecomment-668893305
|
33
|
+
# NONE = "NONE".freeze
|
34
|
+
|
35
|
+
# duplicate definitions generated: https://github.com/XeroAPI/xero-ruby/issues/53#issuecomment-668893305
|
36
|
+
# ACCOUNTING_PRACTICE = "ACCOUNTING_PRACTICE".freeze
|
37
|
+
# COMPANY = "COMPANY".freeze
|
38
|
+
# CHARITY = "CHARITY".freeze
|
39
|
+
# CLUB_OR_SOCIETY = "CLUB_OR_SOCIETY".freeze
|
40
|
+
# LOOK_THROUGH_COMPANY = "LOOK_THROUGH_COMPANY".freeze
|
41
|
+
# NOT_FOR_PROFIT = "NOT_FOR_PROFIT".freeze
|
42
|
+
# PARTNERSHIP = "PARTNERSHIP".freeze
|
43
|
+
# S_CORPORATION = "S_CORPORATION".freeze
|
44
|
+
# SELF_MANAGED_SUPERANNUATION_FUND = "SELF_MANAGED_SUPERANNUATION_FUND".freeze
|
45
|
+
# SOLE_TRADER = "SOLE_TRADER".freeze
|
46
|
+
# SUPERANNUATION_FUND = "SUPERANNUATION_FUND".freeze
|
47
|
+
# TRUST = "TRUST".freeze
|
48
|
+
```
|
49
|
+
|
50
|
+
# Debugging in mustache templates + open api generator
|
51
|
+
{{{this}}}
|
52
|
+
{{{.}}}
|
data/docs/accounting/Account.md
CHANGED
@@ -47,7 +47,7 @@ instance = XeroRuby::Accounting::Account.new(code: 4400,
|
|
47
47
|
reporting_code: null,
|
48
48
|
reporting_code_name: null,
|
49
49
|
has_attachments: false,
|
50
|
-
updated_date_utc:
|
50
|
+
updated_date_utc: /Date(1573755038314)/,
|
51
51
|
add_to_watchlist: null,
|
52
52
|
validation_errors: null)
|
53
53
|
```
|
@@ -6,7 +6,7 @@ Method | HTTP request | Description
|
|
6
6
|
------------- | ------------- | -------------
|
7
7
|
[**create_account**](AccountingApi.md#create_account) | **PUT** /Accounts | Allows you to create a new chart of accounts
|
8
8
|
[**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
|
9
|
-
[**create_bank_transaction_attachment_by_file_name**](AccountingApi.md#create_bank_transaction_attachment_by_file_name) | **PUT** /BankTransactions/{BankTransactionID}/Attachments/{FileName} | Allows you to
|
9
|
+
[**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
|
10
10
|
[**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
|
11
11
|
[**create_bank_transactions**](AccountingApi.md#create_bank_transactions) | **PUT** /BankTransactions | Allows you to create one or more spend or receive money transaction
|
12
12
|
[**create_bank_transfer**](AccountingApi.md#create_bank_transfer) | **PUT** /BankTransfers | Allows you to create a bank transfers
|
@@ -186,7 +186,7 @@ Method | HTTP request | Description
|
|
186
186
|
[**get_users**](AccountingApi.md#get_users) | **GET** /Users | Allows you to retrieve users
|
187
187
|
[**update_account**](AccountingApi.md#update_account) | **POST** /Accounts/{AccountID} | Allows you to update a chart of accounts
|
188
188
|
[**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
|
189
|
-
[**update_bank_transaction**](AccountingApi.md#update_bank_transaction) | **POST** /BankTransactions/{BankTransactionID} |
|
189
|
+
[**update_bank_transaction**](AccountingApi.md#update_bank_transaction) | **POST** /BankTransactions/{BankTransactionID} | Allows you to update a single spend or receive money transaction
|
190
190
|
[**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
|
191
191
|
[**update_bank_transfer_attachment_by_file_name**](AccountingApi.md#update_bank_transfer_attachment_by_file_name) | **POST** /BankTransfers/{BankTransferID}/Attachments/{FileName} |
|
192
192
|
[**update_contact**](AccountingApi.md#update_contact) | **POST** /Contacts/{ContactID} |
|
@@ -360,7 +360,7 @@ Name | Type | Description | Notes
|
|
360
360
|
|
361
361
|
> Attachments create_bank_transaction_attachment_by_file_name(xero_tenant_id, bank_transaction_id, file_name, body)
|
362
362
|
|
363
|
-
Allows you to
|
363
|
+
Allows you to create an Attachment on BankTransaction by Filename
|
364
364
|
|
365
365
|
### Example
|
366
366
|
|
@@ -394,7 +394,7 @@ bank_transaction_id = '00000000-0000-0000-000-000000000000' # String | Xero gene
|
|
394
394
|
file_name = 'xero-dev.jpg' # String | The name of the file being attached
|
395
395
|
body = 'body_example' # String | Byte array of file in body of request
|
396
396
|
begin
|
397
|
-
#Allows you to
|
397
|
+
#Allows you to create an Attachment on BankTransaction by Filename
|
398
398
|
result = api_instance.create_bank_transaction_attachment_by_file_name(xero_tenant_id, bank_transaction_id, file_name, body)
|
399
399
|
p result
|
400
400
|
rescue XeroRuby::Accounting::ApiError => e
|
@@ -1132,7 +1132,7 @@ api_instance = xero_client.accounting_api
|
|
1132
1132
|
api_instance = xero_client.asset_api
|
1133
1133
|
# :projects_api
|
1134
1134
|
api_instance = xero_client.projects_api
|
1135
|
-
contacts = { contacts: [{
|
1135
|
+
contacts = { contacts: [{ contact_id: "a3675fc4-f8dd-4f03-ba5b-f1870566bcd7" }, { contact_id: "4e1753b9-018a-4775-b6aa-1bc7871cfee3" }]}
|
1136
1136
|
|
1137
1137
|
begin
|
1138
1138
|
#Allows you to add Contacts to a Contact Group
|
@@ -1305,7 +1305,7 @@ Name | Type | Description | Notes
|
|
1305
1305
|
|
1306
1306
|
## create_credit_note_allocation
|
1307
1307
|
|
1308
|
-
> Allocations create_credit_note_allocation(xero_tenant_id, credit_note_id, allocations)
|
1308
|
+
> Allocations create_credit_note_allocation(xero_tenant_id, credit_note_id, allocations, opts)
|
1309
1309
|
|
1310
1310
|
Allows you to create Allocation on CreditNote
|
1311
1311
|
|
@@ -1336,9 +1336,13 @@ api_instance = xero_client.asset_api
|
|
1336
1336
|
api_instance = xero_client.projects_api
|
1337
1337
|
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: {} }}]}
|
1338
1338
|
|
1339
|
+
opts = {
|
1340
|
+
summarize_errors: false # Boolean | If false return 200 OK and mix of successfully created obejcts and any with validation errors
|
1341
|
+
}
|
1342
|
+
|
1339
1343
|
begin
|
1340
1344
|
#Allows you to create Allocation on CreditNote
|
1341
|
-
result = api_instance.create_credit_note_allocation(xero_tenant_id, credit_note_id, allocations)
|
1345
|
+
result = api_instance.create_credit_note_allocation(xero_tenant_id, credit_note_id, allocations, opts)
|
1342
1346
|
p result
|
1343
1347
|
rescue XeroRuby::Accounting::ApiError => e
|
1344
1348
|
puts "Exception when calling AccountingApi->create_credit_note_allocation: #{e}"
|
@@ -1353,6 +1357,7 @@ Name | Type | Description | Notes
|
|
1353
1357
|
**xero_tenant_id** | **String**| Xero identifier for Tenant |
|
1354
1358
|
**credit_note_id** | [**String**](.md)| Unique identifier for a Credit Note |
|
1355
1359
|
**allocations** | [**Allocations**](Allocations.md)| Allocations with array of Allocation object in body of request. |
|
1360
|
+
**summarize_errors** | **Boolean**| If false return 200 OK and mix of successfully created obejcts and any with validation errors | [optional] [default to false]
|
1356
1361
|
|
1357
1362
|
### Return type
|
1358
1363
|
|
@@ -12874,9 +12879,9 @@ Name | Type | Description | Notes
|
|
12874
12879
|
|
12875
12880
|
## update_bank_transaction
|
12876
12881
|
|
12877
|
-
> BankTransactions update_bank_transaction(xero_tenant_id, bank_transactions)
|
12878
|
-
|
12882
|
+
> BankTransactions update_bank_transaction(xero_tenant_id, bank_transaction_id, bank_transactions, opts)
|
12879
12883
|
|
12884
|
+
Allows you to update a single spend or receive money transaction
|
12880
12885
|
|
12881
12886
|
### Example
|
12882
12887
|
|
@@ -12903,10 +12908,15 @@ api_instance = xero_client.accounting_api
|
|
12903
12908
|
api_instance = xero_client.asset_api
|
12904
12909
|
# :projects_api
|
12905
12910
|
api_instance = xero_client.projects_api
|
12906
|
-
{ 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" }}]}
|
12911
|
+
{ 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" }}]}
|
12912
|
+
|
12913
|
+
opts = {
|
12914
|
+
unitdp: 4 # Integer | e.g. unitdp=4 – (Unit Decimal Places) You can opt in to use four decimal places for unit amounts
|
12915
|
+
}
|
12907
12916
|
|
12908
12917
|
begin
|
12909
|
-
|
12918
|
+
#Allows you to update a single spend or receive money transaction
|
12919
|
+
result = api_instance.update_bank_transaction(xero_tenant_id, bank_transaction_id, bank_transactions, opts)
|
12910
12920
|
p result
|
12911
12921
|
rescue XeroRuby::Accounting::ApiError => e
|
12912
12922
|
puts "Exception when calling AccountingApi->update_bank_transaction: #{e}"
|
@@ -12919,7 +12929,9 @@ end
|
|
12919
12929
|
Name | Type | Description | Notes
|
12920
12930
|
------------- | ------------- | ------------- | -------------
|
12921
12931
|
**xero_tenant_id** | **String**| Xero identifier for Tenant |
|
12932
|
+
**bank_transaction_id** | [**String**](.md)| Xero generated unique identifier for a bank transaction |
|
12922
12933
|
**bank_transactions** | [**BankTransactions**](BankTransactions.md)| |
|
12934
|
+
**unitdp** | **Integer**| e.g. unitdp=4 – (Unit Decimal Places) You can opt in to use four decimal places for unit amounts | [optional]
|
12923
12935
|
|
12924
12936
|
### Return type
|
12925
12937
|
|