xero-ruby 2.0.2 → 2.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +183 -101
- data/build_notes.md +35 -5
- data/docs/accounting/Account.md +1 -1
- 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 +2 -2
- data/docs/accounting/Organisation.md +1 -1
- 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 +1 -1
- data/docs/accounting/ReportWithRow.md +1 -1
- data/docs/accounting/TaxComponent.md +1 -1
- data/docs/accounting/TaxRate.md +2 -2
- data/docs/accounting/TenNinetyNineContact.md +13 -13
- data/docs/accounting/User.md +1 -1
- data/docs/assets/Asset.md +3 -3
- data/docs/assets/AssetApi.md +6 -6
- 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 +1 -1
- data/lib/xero-ruby/api/accounting_api.rb +1506 -1
- data/lib/xero-ruby/api/asset_api.rb +49 -7
- data/lib/xero-ruby/api/project_api.rb +92 -1
- data/lib/xero-ruby/api_client.rb +36 -3
- data/lib/xero-ruby/api_error.rb +1 -1
- data/lib/xero-ruby/configuration.rb +2 -2
- data/lib/xero-ruby/models/accounting/account.rb +1 -17
- data/lib/xero-ruby/models/accounting/account_type.rb +1 -1
- data/lib/xero-ruby/models/accounting/accounts.rb +1 -1
- data/lib/xero-ruby/models/accounting/accounts_payable.rb +1 -1
- data/lib/xero-ruby/models/accounting/accounts_receivable.rb +1 -1
- data/lib/xero-ruby/models/accounting/address.rb +1 -1
- data/lib/xero-ruby/models/accounting/allocation.rb +1 -1
- data/lib/xero-ruby/models/accounting/allocations.rb +1 -1
- data/lib/xero-ruby/models/accounting/attachment.rb +2 -2
- data/lib/xero-ruby/models/accounting/attachments.rb +1 -1
- data/lib/xero-ruby/models/accounting/balances.rb +1 -1
- data/lib/xero-ruby/models/accounting/bank_transaction.rb +1 -6
- data/lib/xero-ruby/models/accounting/bank_transactions.rb +1 -1
- data/lib/xero-ruby/models/accounting/bank_transfer.rb +1 -1
- data/lib/xero-ruby/models/accounting/bank_transfers.rb +1 -1
- data/lib/xero-ruby/models/accounting/batch_payment.rb +1 -16
- data/lib/xero-ruby/models/accounting/batch_payment_details.rb +1 -1
- data/lib/xero-ruby/models/accounting/batch_payments.rb +1 -1
- data/lib/xero-ruby/models/accounting/bill.rb +1 -1
- data/lib/xero-ruby/models/accounting/branding_theme.rb +1 -1
- data/lib/xero-ruby/models/accounting/branding_themes.rb +1 -1
- data/lib/xero-ruby/models/accounting/cis_org_setting.rb +1 -1
- data/lib/xero-ruby/models/accounting/cis_setting.rb +1 -1
- data/lib/xero-ruby/models/accounting/cis_settings.rb +1 -1
- data/lib/xero-ruby/models/accounting/contact.rb +1 -1
- data/lib/xero-ruby/models/accounting/contact_group.rb +1 -1
- data/lib/xero-ruby/models/accounting/contact_groups.rb +1 -1
- data/lib/xero-ruby/models/accounting/contact_person.rb +1 -1
- data/lib/xero-ruby/models/accounting/contacts.rb +1 -1
- data/lib/xero-ruby/models/accounting/country_code.rb +1 -1
- data/lib/xero-ruby/models/accounting/credit_note.rb +1 -1
- data/lib/xero-ruby/models/accounting/credit_notes.rb +1 -1
- data/lib/xero-ruby/models/accounting/currencies.rb +1 -1
- data/lib/xero-ruby/models/accounting/currency.rb +1 -1
- data/lib/xero-ruby/models/accounting/currency_code.rb +1 -1
- data/lib/xero-ruby/models/accounting/element.rb +1 -1
- data/lib/xero-ruby/models/accounting/employee.rb +4 -3
- data/lib/xero-ruby/models/accounting/employees.rb +1 -1
- data/lib/xero-ruby/models/accounting/error.rb +1 -1
- data/lib/xero-ruby/models/accounting/expense_claim.rb +1 -1
- data/lib/xero-ruby/models/accounting/expense_claims.rb +1 -1
- data/lib/xero-ruby/models/accounting/external_link.rb +1 -1
- data/lib/xero-ruby/models/accounting/history_record.rb +1 -1
- data/lib/xero-ruby/models/accounting/history_records.rb +1 -1
- data/lib/xero-ruby/models/accounting/invoice.rb +1 -1
- data/lib/xero-ruby/models/accounting/invoice_reminder.rb +1 -1
- data/lib/xero-ruby/models/accounting/invoice_reminders.rb +1 -1
- data/lib/xero-ruby/models/accounting/invoices.rb +1 -1
- data/lib/xero-ruby/models/accounting/item.rb +1 -1
- data/lib/xero-ruby/models/accounting/items.rb +1 -1
- data/lib/xero-ruby/models/accounting/journal.rb +1 -1
- data/lib/xero-ruby/models/accounting/journal_line.rb +1 -1
- data/lib/xero-ruby/models/accounting/journals.rb +1 -1
- data/lib/xero-ruby/models/accounting/line_amount_types.rb +1 -1
- data/lib/xero-ruby/models/accounting/line_item.rb +1 -1
- data/lib/xero-ruby/models/accounting/line_item_tracking.rb +1 -1
- data/lib/xero-ruby/models/accounting/linked_transaction.rb +1 -1
- data/lib/xero-ruby/models/accounting/linked_transactions.rb +1 -1
- data/lib/xero-ruby/models/accounting/manual_journal.rb +1 -1
- data/lib/xero-ruby/models/accounting/manual_journal_line.rb +1 -1
- data/lib/xero-ruby/models/accounting/manual_journals.rb +1 -1
- data/lib/xero-ruby/models/accounting/online_invoice.rb +1 -1
- data/lib/xero-ruby/models/accounting/online_invoices.rb +1 -1
- data/lib/xero-ruby/models/accounting/organisation.rb +1 -3
- data/lib/xero-ruby/models/accounting/organisations.rb +1 -1
- data/lib/xero-ruby/models/accounting/overpayment.rb +1 -1
- data/lib/xero-ruby/models/accounting/overpayments.rb +1 -1
- data/lib/xero-ruby/models/accounting/payment.rb +1 -1
- data/lib/xero-ruby/models/accounting/payment_delete.rb +1 -1
- data/lib/xero-ruby/models/accounting/payment_service.rb +1 -1
- data/lib/xero-ruby/models/accounting/payment_services.rb +1 -1
- data/lib/xero-ruby/models/accounting/payment_term.rb +1 -1
- data/lib/xero-ruby/models/accounting/payment_term_type.rb +1 -1
- data/lib/xero-ruby/models/accounting/payments.rb +1 -1
- data/lib/xero-ruby/models/accounting/phone.rb +1 -1
- data/lib/xero-ruby/models/accounting/prepayment.rb +1 -1
- data/lib/xero-ruby/models/accounting/prepayments.rb +1 -1
- data/lib/xero-ruby/models/accounting/purchase.rb +1 -1
- data/lib/xero-ruby/models/accounting/purchase_order.rb +1 -1
- data/lib/xero-ruby/models/accounting/purchase_orders.rb +1 -1
- data/lib/xero-ruby/models/accounting/quote.rb +1 -1
- data/lib/xero-ruby/models/accounting/quote_line_amount_types.rb +1 -1
- data/lib/xero-ruby/models/accounting/quote_status_codes.rb +1 -1
- data/lib/xero-ruby/models/accounting/quotes.rb +1 -1
- data/lib/xero-ruby/models/accounting/receipt.rb +1 -1
- data/lib/xero-ruby/models/accounting/receipts.rb +1 -1
- data/lib/xero-ruby/models/accounting/repeating_invoice.rb +1 -1
- data/lib/xero-ruby/models/accounting/repeating_invoices.rb +1 -1
- data/lib/xero-ruby/models/accounting/report.rb +1 -1
- data/lib/xero-ruby/models/accounting/report_attribute.rb +1 -1
- data/lib/xero-ruby/models/accounting/report_cell.rb +1 -1
- data/lib/xero-ruby/models/accounting/report_fields.rb +1 -1
- data/lib/xero-ruby/models/accounting/report_row.rb +1 -1
- data/lib/xero-ruby/models/accounting/report_rows.rb +1 -1
- data/lib/xero-ruby/models/accounting/report_with_row.rb +1 -1
- data/lib/xero-ruby/models/accounting/report_with_rows.rb +1 -1
- data/lib/xero-ruby/models/accounting/reports.rb +1 -1
- data/lib/xero-ruby/models/accounting/request_empty.rb +1 -1
- data/lib/xero-ruby/models/accounting/row_type.rb +1 -1
- data/lib/xero-ruby/models/accounting/sales_tracking_category.rb +1 -1
- data/lib/xero-ruby/models/accounting/schedule.rb +1 -1
- data/lib/xero-ruby/models/accounting/tax_component.rb +1 -1
- data/lib/xero-ruby/models/accounting/tax_rate.rb +1 -1
- data/lib/xero-ruby/models/accounting/tax_rates.rb +1 -1
- data/lib/xero-ruby/models/accounting/tax_type.rb +1 -1
- data/lib/xero-ruby/models/accounting/ten_ninety_nine_contact.rb +1 -1
- data/lib/xero-ruby/models/accounting/time_zone.rb +2 -1
- data/lib/xero-ruby/models/accounting/tracking_categories.rb +1 -1
- data/lib/xero-ruby/models/accounting/tracking_category.rb +1 -1
- data/lib/xero-ruby/models/accounting/tracking_option.rb +1 -1
- data/lib/xero-ruby/models/accounting/tracking_options.rb +1 -1
- data/lib/xero-ruby/models/accounting/user.rb +1 -1
- data/lib/xero-ruby/models/accounting/users.rb +1 -1
- data/lib/xero-ruby/models/accounting/validation_error.rb +1 -1
- data/lib/xero-ruby/models/assets/asset.rb +1 -1
- 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 +1 -1
- data/lib/xero-ruby/models/assets/assets.rb +1 -1
- data/lib/xero-ruby/models/assets/book_depreciation_detail.rb +1 -1
- data/lib/xero-ruby/models/assets/book_depreciation_setting.rb +1 -1
- data/lib/xero-ruby/models/assets/error.rb +1 -1
- data/lib/xero-ruby/models/assets/field_validation_errors_element.rb +1 -1
- data/lib/xero-ruby/models/assets/pagination.rb +1 -1
- data/lib/xero-ruby/models/assets/resource_validation_errors_element.rb +1 -1
- data/lib/xero-ruby/models/assets/setting.rb +1 -1
- data/lib/xero-ruby/models/projects/amount.rb +1 -1
- 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 +1 -1
- data/lib/xero-ruby/models/projects/pagination.rb +1 -1
- data/lib/xero-ruby/models/projects/project.rb +1 -1
- data/lib/xero-ruby/models/projects/project_create_or_update.rb +1 -1
- data/lib/xero-ruby/models/projects/project_patch.rb +1 -1
- data/lib/xero-ruby/models/projects/project_status.rb +1 -1
- data/lib/xero-ruby/models/projects/project_user.rb +1 -1
- data/lib/xero-ruby/models/projects/project_users.rb +1 -1
- data/lib/xero-ruby/models/projects/projects.rb +1 -1
- data/lib/xero-ruby/models/projects/task.rb +1 -1
- data/lib/xero-ruby/models/projects/task_create_or_update.rb +1 -1
- data/lib/xero-ruby/models/projects/tasks.rb +1 -1
- data/lib/xero-ruby/models/projects/time_entries.rb +1 -1
- data/lib/xero-ruby/models/projects/time_entry.rb +1 -1
- data/lib/xero-ruby/models/projects/time_entry_create_or_update.rb +1 -1
- data/lib/xero-ruby/version.rb +2 -2
- data/spec/api_client_spec.rb +6 -6
- data/xero-ruby.gem +0 -0
- data/xero-ruby.gemspec +2 -2
- metadata +4 -4
- data/Gemfile.lock +0 -68
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8250dd8ab9c60af3fa465ae94075ab3f9a6ca740ba550ca1c89ce06e7d2d293
|
4
|
+
data.tar.gz: 34d4b08070f17257e204ba7072c0f294fa9424b0a8cb230326d6b678264320a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b28ca284de2cdcaca6cbfda133b47d7582ebc7b0781ab49ea8cd589a2c1ebb93638341ac5d633f853118fdd385722f1baf5328893a24ddef033c764229d9f663
|
7
|
+
data.tar.gz: a89d029c7572c597f8da49d1a2bde41bdb50ad6413559113fdb5ddaf1ea488a2fdac03b979154b923d4262144491c9a826e8f4791c4bc9bcfc3afebed6f41cb1
|
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)
|
10
|
-
* [projects](https://developer.xero.com/documentation/projects/overview-projects)
|
6
|
+
# Documentation
|
7
|
+
Xero Ruby SDK supports Xero's OAuth2.0 authentication and supports the following Xero API sets.
|
11
8
|
|
12
|
-
|
13
|
-
*
|
14
|
-
*
|
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)
|
15
21
|
* payroll (NZ/UK)
|
16
22
|
* files
|
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,97 +130,157 @@ 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
|
|
121
|
-
|
122
|
-
|
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
|
123
151
|
|
124
|
-
|
152
|
+
def decoded_access_token
|
153
|
+
JWT.decode(token_set['access_token'], nil, false)[0]
|
154
|
+
end
|
155
|
+
```
|
125
156
|
|
157
|
+
## API Usage
|
126
158
|
```ruby
|
127
159
|
require 'xero-ruby'
|
128
160
|
|
129
|
-
# reference `Authorization & Callback` to first store a valid token_set on the `xero_client`
|
130
161
|
xero_client.refresh_token_set(user.token_set)
|
131
162
|
|
132
|
-
|
133
|
-
|
134
|
-
# Examples
|
135
|
-
invoices = xero_client.accounting_api.get_invoices(user.active_tenant_id).invoices
|
136
|
-
accounts = xero_client.accounting_api.get_accounts(user.active_tenant_id).accounts
|
137
|
-
contacts = xero_client.accounting_api.get_contacts(user.active_tenant_id).contacts
|
138
|
-
|
139
|
-
contacts = xero_client.accounting_api.get_contacts(current_user.active_tenant_id).contacts
|
140
|
-
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 }]}
|
141
|
-
invoice = xero_client.accounting_api.create_invoices(current_user.active_tenant_id, invoices).invoices.first
|
163
|
+
tenant_id = user.active_tenant_id
|
164
|
+
# example of how to store the `tenantId` of the specific tenant (aka organisation)
|
142
165
|
|
143
|
-
#
|
144
|
-
puts invoice.unit_amount
|
145
|
-
=> 0.2099e2
|
166
|
+
# https://github.com/XeroAPI/xero-ruby/blob/master/accounting/lib/xero-ruby/api/accounting_api.rb
|
146
167
|
|
147
|
-
|
148
|
-
|
168
|
+
# Get Accounts
|
169
|
+
accounts = xero_client.accounting_api.get_accounts(tenant_id).accounts
|
149
170
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
# or if using Rails https://api.rubyonrails.org/classes/ActionView/Helpers/NumberHelper.html#method-i-number_to_currency
|
154
|
-
number_to_currency(invoice.unit_amount, :unit => "$")
|
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
|
155
174
|
|
156
|
-
#
|
157
|
-
payment = xero_client.accounting_api.get_payments(
|
158
|
-
history_records = { history_records:[
|
159
|
-
payment_history = xero_client.accounting_api.create_payment_history(
|
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)
|
160
179
|
|
161
|
-
#
|
162
|
-
account = xero_client.accounting_api.get_accounts(
|
180
|
+
# Create Attachment
|
181
|
+
account = xero_client.accounting_api.get_accounts(tenant_id).accounts.first
|
163
182
|
file_name = "an-account-filename.png"
|
164
183
|
opts = {
|
165
|
-
include_online: true
|
184
|
+
include_online: true
|
166
185
|
}
|
167
186
|
file = File.read(Rails.root.join('app/assets/images/xero-api.png'))
|
168
|
-
attachment = xero_client.accounting_api.create_account_attachment_by_file_name(
|
187
|
+
attachment = xero_client.accounting_api.create_account_attachment_by_file_name(tenant_id, @account.account_id, file_name, file, opts)
|
169
188
|
|
170
|
-
#
|
189
|
+
# https://github.com/XeroAPI/xero-ruby/blob/master/accounting/lib/xero-ruby/api/asset_api.rb
|
190
|
+
|
191
|
+
# Create Asset
|
171
192
|
asset = {
|
172
193
|
"assetName": "AssetName: #{rand(10000)}",
|
173
194
|
"assetNumber": "Asset: #{rand(10000)}",
|
174
195
|
"assetStatus": "DRAFT"
|
175
196
|
}
|
176
|
-
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
|
177
200
|
|
178
|
-
#
|
179
|
-
projects = xero_client.project_api.get_projects(
|
201
|
+
# Get Projects
|
202
|
+
projects = xero_client.project_api.get_projects(tenant_id).items
|
180
203
|
```
|
181
204
|
|
182
|
-
|
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
|
213
|
+
|
214
|
+
puts invoice.unit_amount.to_s("F")
|
215
|
+
=> "20.99"
|
183
216
|
|
184
|
-
|
185
|
-
|
186
|
-
|
217
|
+
# Rails method-number_to_currency
|
218
|
+
number_to_currency(invoice.unit_amount, :unit => "$")
|
219
|
+
```
|
187
220
|
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
221
|
+
## Querying & Filtering
|
222
|
+
Examples for the `opts` (_options_) parameters most endpoints support. This is an area of focus and improvement. If you have a complex filering/sorting/where usage that is not supported please [open an issue](https://github.com/XeroAPI/xero-ruby/issues).
|
223
|
+
```ruby
|
224
|
+
# Invoices
|
225
|
+
opts = {
|
226
|
+
page: 1,
|
227
|
+
where: {
|
228
|
+
type: ['=', XeroRuby::Accounting::Invoice::ACCREC],
|
229
|
+
fully_paid_on_date: (DateTime.now - 6.month)..DateTime.now,
|
230
|
+
amount_due: ['>=', 0],
|
231
|
+
reference: ['=', "Website Design"],
|
232
|
+
invoice_number: ['=', "INV-0001"],
|
233
|
+
contact_id: ['=', 'contact-uuid-xxxx-xxx-xxxxxxx'],
|
234
|
+
contact_number: ['=', "the-contact-number"],
|
235
|
+
# date: (DateTime.now - 2.year)..DateTime.now
|
236
|
+
# ▲ you can pass a range ▼ or a date & operator
|
237
|
+
date: ['>=', DateTime.now - 2.year],
|
238
|
+
status: ['=', XeroRuby::Accounting::Invoice::PAID]
|
239
|
+
}
|
240
|
+
}
|
241
|
+
xero_client.accounting_api.get_invoices(tenant_id, opts).invoices
|
242
|
+
|
243
|
+
# Contacts
|
244
|
+
opts = {
|
245
|
+
if_modified_since: (DateTime.now - 1.weeks).to_s,
|
246
|
+
# ▼ ordering by strings needs PascalCase convention
|
247
|
+
order: 'UpdatedDateUtc DESC',
|
248
|
+
where: {
|
249
|
+
is_customer: ['==', true],
|
250
|
+
is_supplier: ['==', true]
|
251
|
+
}
|
252
|
+
}
|
253
|
+
xero_client.accounting_api.get_contacts(tenant_id, opts).contacts
|
254
|
+
|
255
|
+
# Bank Transactions
|
256
|
+
opts = {
|
257
|
+
if_modified_since: (DateTime.now - 1.year).to_s,
|
258
|
+
where: { type: ['==', XeroRuby::Accounting::BankTransaction::SPEND] },
|
259
|
+
order: 'UpdatedDateUtc DESC',
|
260
|
+
page: 2,
|
261
|
+
unitdp: 4 # (Unit Decimal Places)
|
262
|
+
}
|
263
|
+
xero_client.accounting_api.get_bank_transactions(tenant_id, opts).bank_transactions
|
264
|
+
|
265
|
+
# Bank Transfers
|
266
|
+
opts = {
|
267
|
+
if_modified_since: (DateTime.now - 1.month).to_s,
|
268
|
+
where: {
|
269
|
+
amount: [">=" , 999.99]
|
270
|
+
},
|
271
|
+
order: 'Amount ASC'
|
272
|
+
}
|
273
|
+
xero_client.accounting_api.get_bank_transfers(tenant_id, opts).bank_transfers
|
274
|
+
```
|
275
|
+
### NOTE
|
276
|
+
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.
|
195
277
|
|
196
|
-
|
278
|
+
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).
|
279
|
+
* `opts = { order: 'UpdatedDateUtc DESC'}`
|
197
280
|
|
198
|
-
|
199
|
-
* [Accounting Api Docs](/docs/accounting/AccountingApi.md)
|
200
|
-
* [Asset Api Docs](/docs/assets/AssetApi.md)
|
281
|
+
3) If you have use cases outside of these examples let us know.
|
201
282
|
|
202
|
-
##
|
203
|
-
|
204
|
-
|
283
|
+
## Sample App
|
284
|
+
The best resource to understanding how to best leverage this SDK is the sample applications showing all the features of the gem.
|
285
|
+
> https://github.com/XeroAPI/xero-ruby-oauth2-starter (Sinatra - simple getting started)
|
286
|
+
> https://github.com/XeroAPI/xero-ruby-oauth2-app (Rails - full featured examples)
|
data/build_notes.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Developing gem locally
|
1
|
+
# Developing gem locally
|
2
2
|
|
3
3
|
> xero-ruby
|
4
4
|
```bash
|
@@ -7,16 +7,46 @@ mv xero-ruby-<vsn>.gem xero-ruby.gem
|
|
7
7
|
```
|
8
8
|
|
9
9
|
> xero-ruby-oauth2-app
|
10
|
-
|
11
10
|
Replace gem file with local path:
|
12
11
|
```bash
|
13
12
|
gem 'xero-ruby', path: '/Users/chris.knight/code/sdks/xero-ruby/'
|
14
13
|
bundle install
|
15
14
|
```
|
16
15
|
|
17
|
-
Deploying to Rubygems
|
16
|
+
# Deploying to Rubygems
|
18
17
|
|
19
18
|
```bash
|
20
19
|
gem build
|
21
|
-
gem push xero-ruby-<vsn>.gem
|
22
|
-
```
|
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
|
```
|