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.
Files changed (204) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +181 -72
  3. data/build_notes.md +52 -0
  4. data/docs/accounting/Account.md +1 -1
  5. data/docs/accounting/AccountingApi.md +23 -11
  6. data/docs/accounting/AccountsPayable.md +2 -2
  7. data/docs/accounting/AccountsReceivable.md +2 -2
  8. data/docs/accounting/Allocation.md +1 -1
  9. data/docs/accounting/Attachment.md +1 -1
  10. data/docs/accounting/BankTransaction.md +6 -6
  11. data/docs/accounting/BankTransfer.md +3 -3
  12. data/docs/accounting/BatchPayment.md +2 -2
  13. data/docs/accounting/BrandingTheme.md +1 -1
  14. data/docs/accounting/Contact.md +2 -2
  15. data/docs/accounting/CreditNote.md +6 -6
  16. data/docs/accounting/Employee.md +1 -1
  17. data/docs/accounting/ExpenseClaim.md +4 -4
  18. data/docs/accounting/HistoryRecord.md +1 -1
  19. data/docs/accounting/Invoice.md +10 -10
  20. data/docs/accounting/Item.md +3 -3
  21. data/docs/accounting/Journal.md +1 -1
  22. data/docs/accounting/JournalLine.md +3 -3
  23. data/docs/accounting/LineItem.md +6 -6
  24. data/docs/accounting/LinkedTransaction.md +1 -1
  25. data/docs/accounting/ManualJournal.md +1 -1
  26. data/docs/accounting/ManualJournalLine.md +4 -2
  27. data/docs/accounting/Organisation.md +2 -2
  28. data/docs/accounting/Overpayment.md +6 -6
  29. data/docs/accounting/Payment.md +3 -3
  30. data/docs/accounting/Prepayment.md +6 -6
  31. data/docs/accounting/Purchase.md +1 -1
  32. data/docs/accounting/PurchaseOrder.md +6 -6
  33. data/docs/accounting/Quote.md +5 -5
  34. data/docs/accounting/Receipt.md +4 -4
  35. data/docs/accounting/RepeatingInvoice.md +3 -3
  36. data/docs/accounting/Report.md +2 -2
  37. data/docs/accounting/ReportWithRow.md +1 -1
  38. data/docs/accounting/TaxComponent.md +1 -1
  39. data/docs/accounting/TaxRate.md +2 -2
  40. data/docs/accounting/{TenNinteyNineContact.md → TenNinetyNineContact.md} +15 -15
  41. data/docs/accounting/User.md +1 -1
  42. data/docs/assets/Asset.md +3 -3
  43. data/docs/assets/BookDepreciationDetail.md +6 -6
  44. data/docs/assets/BookDepreciationSetting.md +1 -1
  45. data/docs/projects/Amount.md +1 -1
  46. data/docs/projects/ProjectCreateOrUpdate.md +1 -1
  47. data/lib/xero-ruby.rb +2 -2
  48. data/lib/xero-ruby/api/accounting_api.rb +1311 -7
  49. data/lib/xero-ruby/api/asset_api.rb +37 -1
  50. data/lib/xero-ruby/api/project_api.rb +79 -1
  51. data/lib/xero-ruby/api_client.rb +72 -32
  52. data/lib/xero-ruby/api_error.rb +1 -1
  53. data/lib/xero-ruby/configuration.rb +2 -5
  54. data/lib/xero-ruby/models/accounting/account.rb +7 -2
  55. data/lib/xero-ruby/models/accounting/account_type.rb +1 -1
  56. data/lib/xero-ruby/models/accounting/accounts.rb +5 -1
  57. data/lib/xero-ruby/models/accounting/accounts_payable.rb +7 -3
  58. data/lib/xero-ruby/models/accounting/accounts_receivable.rb +7 -3
  59. data/lib/xero-ruby/models/accounting/address.rb +5 -1
  60. data/lib/xero-ruby/models/accounting/allocation.rb +6 -2
  61. data/lib/xero-ruby/models/accounting/allocations.rb +5 -1
  62. data/lib/xero-ruby/models/accounting/attachment.rb +6 -2
  63. data/lib/xero-ruby/models/accounting/attachments.rb +5 -1
  64. data/lib/xero-ruby/models/accounting/balances.rb +5 -1
  65. data/lib/xero-ruby/models/accounting/bank_transaction.rb +9 -10
  66. data/lib/xero-ruby/models/accounting/bank_transactions.rb +5 -1
  67. data/lib/xero-ruby/models/accounting/bank_transfer.rb +7 -3
  68. data/lib/xero-ruby/models/accounting/bank_transfers.rb +5 -1
  69. data/lib/xero-ruby/models/accounting/batch_payment.rb +6 -2
  70. data/lib/xero-ruby/models/accounting/batch_payment_details.rb +5 -1
  71. data/lib/xero-ruby/models/accounting/batch_payments.rb +5 -1
  72. data/lib/xero-ruby/models/accounting/bill.rb +5 -1
  73. data/lib/xero-ruby/models/accounting/branding_theme.rb +5 -1
  74. data/lib/xero-ruby/models/accounting/branding_themes.rb +5 -1
  75. data/lib/xero-ruby/models/accounting/cis_org_setting.rb +5 -1
  76. data/lib/xero-ruby/models/accounting/cis_setting.rb +5 -1
  77. data/lib/xero-ruby/models/accounting/cis_settings.rb +5 -1
  78. data/lib/xero-ruby/models/accounting/contact.rb +6 -2
  79. data/lib/xero-ruby/models/accounting/contact_group.rb +5 -1
  80. data/lib/xero-ruby/models/accounting/contact_groups.rb +5 -1
  81. data/lib/xero-ruby/models/accounting/contact_person.rb +5 -1
  82. data/lib/xero-ruby/models/accounting/contacts.rb +5 -1
  83. data/lib/xero-ruby/models/accounting/country_code.rb +1 -1
  84. data/lib/xero-ruby/models/accounting/credit_note.rb +10 -6
  85. data/lib/xero-ruby/models/accounting/credit_notes.rb +5 -1
  86. data/lib/xero-ruby/models/accounting/currencies.rb +5 -1
  87. data/lib/xero-ruby/models/accounting/currency.rb +5 -1
  88. data/lib/xero-ruby/models/accounting/currency_code.rb +1 -1
  89. data/lib/xero-ruby/models/accounting/element.rb +5 -1
  90. data/lib/xero-ruby/models/accounting/employee.rb +8 -3
  91. data/lib/xero-ruby/models/accounting/employees.rb +5 -1
  92. data/lib/xero-ruby/models/accounting/error.rb +5 -1
  93. data/lib/xero-ruby/models/accounting/expense_claim.rb +8 -4
  94. data/lib/xero-ruby/models/accounting/expense_claims.rb +5 -1
  95. data/lib/xero-ruby/models/accounting/external_link.rb +5 -1
  96. data/lib/xero-ruby/models/accounting/history_record.rb +5 -1
  97. data/lib/xero-ruby/models/accounting/history_records.rb +5 -1
  98. data/lib/xero-ruby/models/accounting/invoice.rb +14 -10
  99. data/lib/xero-ruby/models/accounting/invoice_reminder.rb +5 -1
  100. data/lib/xero-ruby/models/accounting/invoice_reminders.rb +5 -1
  101. data/lib/xero-ruby/models/accounting/invoices.rb +5 -1
  102. data/lib/xero-ruby/models/accounting/item.rb +7 -3
  103. data/lib/xero-ruby/models/accounting/items.rb +5 -1
  104. data/lib/xero-ruby/models/accounting/journal.rb +5 -1
  105. data/lib/xero-ruby/models/accounting/journal_line.rb +8 -4
  106. data/lib/xero-ruby/models/accounting/journals.rb +5 -1
  107. data/lib/xero-ruby/models/accounting/line_amount_types.rb +1 -1
  108. data/lib/xero-ruby/models/accounting/line_item.rb +11 -7
  109. data/lib/xero-ruby/models/accounting/line_item_tracking.rb +5 -1
  110. data/lib/xero-ruby/models/accounting/linked_transaction.rb +5 -1
  111. data/lib/xero-ruby/models/accounting/linked_transactions.rb +5 -1
  112. data/lib/xero-ruby/models/accounting/manual_journal.rb +5 -1
  113. data/lib/xero-ruby/models/accounting/manual_journal_line.rb +18 -4
  114. data/lib/xero-ruby/models/accounting/manual_journals.rb +5 -1
  115. data/lib/xero-ruby/models/accounting/online_invoice.rb +5 -1
  116. data/lib/xero-ruby/models/accounting/online_invoices.rb +5 -1
  117. data/lib/xero-ruby/models/accounting/organisation.rb +33 -3
  118. data/lib/xero-ruby/models/accounting/organisations.rb +5 -1
  119. data/lib/xero-ruby/models/accounting/overpayment.rb +10 -6
  120. data/lib/xero-ruby/models/accounting/overpayments.rb +5 -1
  121. data/lib/xero-ruby/models/accounting/payment.rb +7 -3
  122. data/lib/xero-ruby/models/accounting/payment_delete.rb +5 -1
  123. data/lib/xero-ruby/models/accounting/payment_service.rb +5 -1
  124. data/lib/xero-ruby/models/accounting/payment_services.rb +5 -1
  125. data/lib/xero-ruby/models/accounting/payment_term.rb +5 -1
  126. data/lib/xero-ruby/models/accounting/payment_term_type.rb +1 -1
  127. data/lib/xero-ruby/models/accounting/payments.rb +5 -1
  128. data/lib/xero-ruby/models/accounting/phone.rb +5 -1
  129. data/lib/xero-ruby/models/accounting/prepayment.rb +10 -6
  130. data/lib/xero-ruby/models/accounting/prepayments.rb +5 -1
  131. data/lib/xero-ruby/models/accounting/purchase.rb +6 -2
  132. data/lib/xero-ruby/models/accounting/purchase_order.rb +10 -6
  133. data/lib/xero-ruby/models/accounting/purchase_orders.rb +5 -1
  134. data/lib/xero-ruby/models/accounting/quote.rb +9 -5
  135. data/lib/xero-ruby/models/accounting/quote_line_amount_types.rb +1 -1
  136. data/lib/xero-ruby/models/accounting/quote_status_codes.rb +2 -1
  137. data/lib/xero-ruby/models/accounting/quotes.rb +5 -1
  138. data/lib/xero-ruby/models/accounting/receipt.rb +8 -4
  139. data/lib/xero-ruby/models/accounting/receipts.rb +5 -1
  140. data/lib/xero-ruby/models/accounting/repeating_invoice.rb +8 -4
  141. data/lib/xero-ruby/models/accounting/repeating_invoices.rb +5 -1
  142. data/lib/xero-ruby/models/accounting/report.rb +6 -2
  143. data/lib/xero-ruby/models/accounting/report_attribute.rb +5 -1
  144. data/lib/xero-ruby/models/accounting/report_cell.rb +5 -1
  145. data/lib/xero-ruby/models/accounting/report_fields.rb +5 -1
  146. data/lib/xero-ruby/models/accounting/report_row.rb +5 -1
  147. data/lib/xero-ruby/models/accounting/report_rows.rb +5 -1
  148. data/lib/xero-ruby/models/accounting/report_with_row.rb +5 -1
  149. data/lib/xero-ruby/models/accounting/report_with_rows.rb +5 -1
  150. data/lib/xero-ruby/models/accounting/reports.rb +5 -1
  151. data/lib/xero-ruby/models/accounting/request_empty.rb +5 -1
  152. data/lib/xero-ruby/models/accounting/row_type.rb +1 -1
  153. data/lib/xero-ruby/models/accounting/sales_tracking_category.rb +5 -1
  154. data/lib/xero-ruby/models/accounting/schedule.rb +5 -1
  155. data/lib/xero-ruby/models/accounting/tax_component.rb +6 -2
  156. data/lib/xero-ruby/models/accounting/tax_rate.rb +7 -3
  157. data/lib/xero-ruby/models/accounting/tax_rates.rb +5 -1
  158. data/lib/xero-ruby/models/accounting/tax_type.rb +1 -1
  159. data/lib/xero-ruby/models/accounting/{ten_nintey_nine_contact.rb → ten_ninety_nine_contact.rb} +21 -17
  160. data/lib/xero-ruby/models/accounting/time_zone.rb +1 -1
  161. data/lib/xero-ruby/models/accounting/tracking_categories.rb +5 -1
  162. data/lib/xero-ruby/models/accounting/tracking_category.rb +5 -1
  163. data/lib/xero-ruby/models/accounting/tracking_option.rb +5 -1
  164. data/lib/xero-ruby/models/accounting/tracking_options.rb +5 -1
  165. data/lib/xero-ruby/models/accounting/user.rb +5 -1
  166. data/lib/xero-ruby/models/accounting/users.rb +5 -1
  167. data/lib/xero-ruby/models/accounting/validation_error.rb +5 -1
  168. data/lib/xero-ruby/models/assets/asset.rb +8 -4
  169. data/lib/xero-ruby/models/assets/asset_status.rb +1 -1
  170. data/lib/xero-ruby/models/assets/asset_status_query_param.rb +1 -1
  171. data/lib/xero-ruby/models/assets/asset_type.rb +5 -1
  172. data/lib/xero-ruby/models/assets/assets.rb +5 -1
  173. data/lib/xero-ruby/models/assets/book_depreciation_detail.rb +11 -7
  174. data/lib/xero-ruby/models/assets/book_depreciation_setting.rb +6 -2
  175. data/lib/xero-ruby/models/assets/error.rb +5 -1
  176. data/lib/xero-ruby/models/assets/field_validation_errors_element.rb +5 -1
  177. data/lib/xero-ruby/models/assets/pagination.rb +5 -1
  178. data/lib/xero-ruby/models/assets/resource_validation_errors_element.rb +5 -1
  179. data/lib/xero-ruby/models/assets/setting.rb +5 -1
  180. data/lib/xero-ruby/models/projects/amount.rb +6 -2
  181. data/lib/xero-ruby/models/projects/charge_type.rb +1 -1
  182. data/lib/xero-ruby/models/projects/currency_code.rb +1 -1
  183. data/lib/xero-ruby/models/projects/error.rb +5 -1
  184. data/lib/xero-ruby/models/projects/pagination.rb +5 -1
  185. data/lib/xero-ruby/models/projects/project.rb +5 -1
  186. data/lib/xero-ruby/models/projects/project_create_or_update.rb +6 -2
  187. data/lib/xero-ruby/models/projects/project_patch.rb +5 -1
  188. data/lib/xero-ruby/models/projects/project_status.rb +1 -1
  189. data/lib/xero-ruby/models/projects/project_user.rb +5 -1
  190. data/lib/xero-ruby/models/projects/project_users.rb +5 -1
  191. data/lib/xero-ruby/models/projects/projects.rb +5 -1
  192. data/lib/xero-ruby/models/projects/task.rb +5 -1
  193. data/lib/xero-ruby/models/projects/task_create_or_update.rb +5 -1
  194. data/lib/xero-ruby/models/projects/tasks.rb +5 -1
  195. data/lib/xero-ruby/models/projects/time_entries.rb +5 -1
  196. data/lib/xero-ruby/models/projects/time_entry.rb +5 -1
  197. data/lib/xero-ruby/models/projects/time_entry_create_or_update.rb +5 -1
  198. data/lib/xero-ruby/version.rb +2 -2
  199. data/spec/accounting/models/ten_nintey_nine_contact_spec.rb +6 -6
  200. data/spec/api_client_spec.rb +103 -16
  201. data/xero-ruby.gemspec +1 -2
  202. metadata +5 -6
  203. data/Gemfile.lock +0 -68
  204. data/xero-ruby.gem +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b7e332228c5727298e0b8c261d41c8045836097801b3394df3e4162113ddcac1
4
- data.tar.gz: f140c421f16483696de6b103c9a56abdb38719174a11ac8d64aa14bf3c29a41b
3
+ metadata.gz: 50e381e3e8975dd61f56fa2607644c0cdcdb5f726e6f87a72d0a7226a68ac366
4
+ data.tar.gz: c93ed7a03a843e4afd2edf231c06b65acfe8d0fe9d0fafeaafd7f4bfbff5c4f9
5
5
  SHA512:
6
- metadata.gz: 23448878790a25e553a847cab323c44b8588d18bd365a5dd0c9f32fefad1c38cdad24647fbd84935c4d75e15d725829ba8a12072561615c1ff90635b69ce098c
7
- data.tar.gz: a63e52f263263545f63e1b402ffb29d1ada1d5dff9bdb7ccc9ba0a728458d8e18643f144590f41948f356b9b00b32135a00e06aefe4bc57cbddb41efc5876c7d
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
- ## Current release of SDK with OAuth 2.0 support
7
- Xero Ruby SDK supports Xero's OAuth2.0 authentication (token generation & refresh) and supports the following Xero API sets.
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
- Coming soon
12
- * bank feeds
13
- * payroll (AU))
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
- This SDK is published as a gem on RubyGems as [xero-ruby](https://rubygems.org/gems/xero-ruby) To install this gem to your current gemset, run:
25
-
36
+ To install this gem to your current gemset.
26
37
  ```
27
38
  gem install 'xero-ruby'
28
39
  ```
29
- Or, add this to your gemfile:
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
- Require the gem:
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. If this is the first time you are calling the Xero API on a users behalf you will need to generate an authorized token set, which will look something like this:
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 with this SDK from Xero, have your user follow the authorization url:
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
- # https://login.xero.com/identity/connect/authorize?response_type=code&client_id=<xxx>&redirect_uri=<redirect_uri>&scope=<scopes>
72
+
73
+ redirect_to @authorization_url
76
74
  ```
77
75
 
78
- > The `get_token_set_from_callback` method will set the `token_set` on the client, however you can also initialize a client and set the `token_set` explicitely using `set_token_set` or `refresh_token_set`.
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
- # /my-redirect-uri
81
+ # => http://localhost:3000/oauth/callback
82
+
82
83
  token_set = xero_client.get_token_set_from_callback(params)
83
84
 
84
- # this is where you will want to save the token set for future API usage..
85
- # ex: user.update!(xero_token_set: token_set)
85
+ # save token_set JSON in a datastore in relation to the user authentication
86
+ ```
86
87
 
87
- # if you already saved a token_set you don't need the user to authenticate via UI
88
- # and can just set the token on the client by refreshing it.
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
- ## Token & SDK Helpers
100
+ **An `access_token` is valid 30 minutes and a `refresh_token` is valid for 60 days**
93
101
 
94
- Token Sets contain information about your API connection, but most important are the access_token, refresh_token, and the expiry:
95
- * An `access_token` is valid 30 minutes and a `refresh_token` is valid for 60 days
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
- # TIP: the `updatedDateUtc` will show you the most recently authorized Tenant (AKA Organisation)
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
- # Accounting API set (https://github.com/XeroAPI/xero-ruby/blob/master/accounting/lib/xero-ruby/api/accounting_api.rb)
129
- invoices = xero_client.accounting_api.get_invoices(user.active_tenant_id).invoices
130
- accounts = xero_client.accounting_api.get_accounts(user.active_tenant_id).accounts
131
- contacts = xero_client.accounting_api.get_contacts(user.active_tenant_id).contacts
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
- # Asset API set (https://github.com/XeroAPI/xero-ruby/blob/master/accounting/lib/xero-ruby/api/asset_api.rb)
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(current_user.active_tenant_id, 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
- If you have use cases outside of these examples or this readmy, please let us know!
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
- ## Sample App
145
- The best resource to understanding how to best leverage this SDK is to clone down our Sample Rails application which showcases all the features of this project. The sample app can help you quickly understand how to:
146
- > https://github.com/XeroAPI/xero-ruby-oauth2-app
214
+ puts invoice.unit_amount.to_s("F")
215
+ => "20.99"
147
216
 
148
- * Complete the OAuth2.0 Authorization flow
149
- * Store token_sets against a user object in a DB
150
- * Storing info about active connections
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
- ## Additional Documentation for API Endpoints
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
- ### APIS
159
- * [Accounting Api Docs](/docs/accounting/AccountingApi.md)
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
- ## Models
163
- * [Accounting Models Docs](/docs/accounting/)
164
- * [Asset Models Docs](/docs/assets/)
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)
@@ -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
+ {{{.}}}
@@ -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: null,
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 createa an Attachment on BankTransaction by Filename
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 createa an Attachment on BankTransaction by Filename
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 createa an Attachment on BankTransaction by Filename
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: [{ contactID: "a3675fc4-f8dd-4f03-ba5b-f1870566bcd7" }, { contactID: "4e1753b9-018a-4775-b6aa-1bc7871cfee3" }]}
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" }}]} 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:
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
- result = api_instance.update_bank_transaction(xero_tenant_id, bank_transactions)
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&#x3D;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