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.
Files changed (203) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +183 -101
  3. data/build_notes.md +35 -5
  4. data/docs/accounting/Account.md +1 -1
  5. data/docs/accounting/AccountsPayable.md +2 -2
  6. data/docs/accounting/AccountsReceivable.md +2 -2
  7. data/docs/accounting/Allocation.md +1 -1
  8. data/docs/accounting/Attachment.md +1 -1
  9. data/docs/accounting/BankTransaction.md +6 -6
  10. data/docs/accounting/BankTransfer.md +3 -3
  11. data/docs/accounting/BatchPayment.md +2 -2
  12. data/docs/accounting/BrandingTheme.md +1 -1
  13. data/docs/accounting/Contact.md +2 -2
  14. data/docs/accounting/CreditNote.md +6 -6
  15. data/docs/accounting/Employee.md +1 -1
  16. data/docs/accounting/ExpenseClaim.md +4 -4
  17. data/docs/accounting/HistoryRecord.md +1 -1
  18. data/docs/accounting/Invoice.md +10 -10
  19. data/docs/accounting/Item.md +3 -3
  20. data/docs/accounting/Journal.md +1 -1
  21. data/docs/accounting/JournalLine.md +3 -3
  22. data/docs/accounting/LineItem.md +6 -6
  23. data/docs/accounting/LinkedTransaction.md +1 -1
  24. data/docs/accounting/ManualJournal.md +1 -1
  25. data/docs/accounting/ManualJournalLine.md +2 -2
  26. data/docs/accounting/Organisation.md +1 -1
  27. data/docs/accounting/Overpayment.md +6 -6
  28. data/docs/accounting/Payment.md +3 -3
  29. data/docs/accounting/Prepayment.md +6 -6
  30. data/docs/accounting/Purchase.md +1 -1
  31. data/docs/accounting/PurchaseOrder.md +6 -6
  32. data/docs/accounting/Quote.md +5 -5
  33. data/docs/accounting/Receipt.md +4 -4
  34. data/docs/accounting/RepeatingInvoice.md +3 -3
  35. data/docs/accounting/Report.md +1 -1
  36. data/docs/accounting/ReportWithRow.md +1 -1
  37. data/docs/accounting/TaxComponent.md +1 -1
  38. data/docs/accounting/TaxRate.md +2 -2
  39. data/docs/accounting/TenNinetyNineContact.md +13 -13
  40. data/docs/accounting/User.md +1 -1
  41. data/docs/assets/Asset.md +3 -3
  42. data/docs/assets/AssetApi.md +6 -6
  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 +1 -1
  48. data/lib/xero-ruby/api/accounting_api.rb +1506 -1
  49. data/lib/xero-ruby/api/asset_api.rb +49 -7
  50. data/lib/xero-ruby/api/project_api.rb +92 -1
  51. data/lib/xero-ruby/api_client.rb +36 -3
  52. data/lib/xero-ruby/api_error.rb +1 -1
  53. data/lib/xero-ruby/configuration.rb +2 -2
  54. data/lib/xero-ruby/models/accounting/account.rb +1 -17
  55. data/lib/xero-ruby/models/accounting/account_type.rb +1 -1
  56. data/lib/xero-ruby/models/accounting/accounts.rb +1 -1
  57. data/lib/xero-ruby/models/accounting/accounts_payable.rb +1 -1
  58. data/lib/xero-ruby/models/accounting/accounts_receivable.rb +1 -1
  59. data/lib/xero-ruby/models/accounting/address.rb +1 -1
  60. data/lib/xero-ruby/models/accounting/allocation.rb +1 -1
  61. data/lib/xero-ruby/models/accounting/allocations.rb +1 -1
  62. data/lib/xero-ruby/models/accounting/attachment.rb +2 -2
  63. data/lib/xero-ruby/models/accounting/attachments.rb +1 -1
  64. data/lib/xero-ruby/models/accounting/balances.rb +1 -1
  65. data/lib/xero-ruby/models/accounting/bank_transaction.rb +1 -6
  66. data/lib/xero-ruby/models/accounting/bank_transactions.rb +1 -1
  67. data/lib/xero-ruby/models/accounting/bank_transfer.rb +1 -1
  68. data/lib/xero-ruby/models/accounting/bank_transfers.rb +1 -1
  69. data/lib/xero-ruby/models/accounting/batch_payment.rb +1 -16
  70. data/lib/xero-ruby/models/accounting/batch_payment_details.rb +1 -1
  71. data/lib/xero-ruby/models/accounting/batch_payments.rb +1 -1
  72. data/lib/xero-ruby/models/accounting/bill.rb +1 -1
  73. data/lib/xero-ruby/models/accounting/branding_theme.rb +1 -1
  74. data/lib/xero-ruby/models/accounting/branding_themes.rb +1 -1
  75. data/lib/xero-ruby/models/accounting/cis_org_setting.rb +1 -1
  76. data/lib/xero-ruby/models/accounting/cis_setting.rb +1 -1
  77. data/lib/xero-ruby/models/accounting/cis_settings.rb +1 -1
  78. data/lib/xero-ruby/models/accounting/contact.rb +1 -1
  79. data/lib/xero-ruby/models/accounting/contact_group.rb +1 -1
  80. data/lib/xero-ruby/models/accounting/contact_groups.rb +1 -1
  81. data/lib/xero-ruby/models/accounting/contact_person.rb +1 -1
  82. data/lib/xero-ruby/models/accounting/contacts.rb +1 -1
  83. data/lib/xero-ruby/models/accounting/country_code.rb +1 -1
  84. data/lib/xero-ruby/models/accounting/credit_note.rb +1 -1
  85. data/lib/xero-ruby/models/accounting/credit_notes.rb +1 -1
  86. data/lib/xero-ruby/models/accounting/currencies.rb +1 -1
  87. data/lib/xero-ruby/models/accounting/currency.rb +1 -1
  88. data/lib/xero-ruby/models/accounting/currency_code.rb +1 -1
  89. data/lib/xero-ruby/models/accounting/element.rb +1 -1
  90. data/lib/xero-ruby/models/accounting/employee.rb +4 -3
  91. data/lib/xero-ruby/models/accounting/employees.rb +1 -1
  92. data/lib/xero-ruby/models/accounting/error.rb +1 -1
  93. data/lib/xero-ruby/models/accounting/expense_claim.rb +1 -1
  94. data/lib/xero-ruby/models/accounting/expense_claims.rb +1 -1
  95. data/lib/xero-ruby/models/accounting/external_link.rb +1 -1
  96. data/lib/xero-ruby/models/accounting/history_record.rb +1 -1
  97. data/lib/xero-ruby/models/accounting/history_records.rb +1 -1
  98. data/lib/xero-ruby/models/accounting/invoice.rb +1 -1
  99. data/lib/xero-ruby/models/accounting/invoice_reminder.rb +1 -1
  100. data/lib/xero-ruby/models/accounting/invoice_reminders.rb +1 -1
  101. data/lib/xero-ruby/models/accounting/invoices.rb +1 -1
  102. data/lib/xero-ruby/models/accounting/item.rb +1 -1
  103. data/lib/xero-ruby/models/accounting/items.rb +1 -1
  104. data/lib/xero-ruby/models/accounting/journal.rb +1 -1
  105. data/lib/xero-ruby/models/accounting/journal_line.rb +1 -1
  106. data/lib/xero-ruby/models/accounting/journals.rb +1 -1
  107. data/lib/xero-ruby/models/accounting/line_amount_types.rb +1 -1
  108. data/lib/xero-ruby/models/accounting/line_item.rb +1 -1
  109. data/lib/xero-ruby/models/accounting/line_item_tracking.rb +1 -1
  110. data/lib/xero-ruby/models/accounting/linked_transaction.rb +1 -1
  111. data/lib/xero-ruby/models/accounting/linked_transactions.rb +1 -1
  112. data/lib/xero-ruby/models/accounting/manual_journal.rb +1 -1
  113. data/lib/xero-ruby/models/accounting/manual_journal_line.rb +1 -1
  114. data/lib/xero-ruby/models/accounting/manual_journals.rb +1 -1
  115. data/lib/xero-ruby/models/accounting/online_invoice.rb +1 -1
  116. data/lib/xero-ruby/models/accounting/online_invoices.rb +1 -1
  117. data/lib/xero-ruby/models/accounting/organisation.rb +1 -3
  118. data/lib/xero-ruby/models/accounting/organisations.rb +1 -1
  119. data/lib/xero-ruby/models/accounting/overpayment.rb +1 -1
  120. data/lib/xero-ruby/models/accounting/overpayments.rb +1 -1
  121. data/lib/xero-ruby/models/accounting/payment.rb +1 -1
  122. data/lib/xero-ruby/models/accounting/payment_delete.rb +1 -1
  123. data/lib/xero-ruby/models/accounting/payment_service.rb +1 -1
  124. data/lib/xero-ruby/models/accounting/payment_services.rb +1 -1
  125. data/lib/xero-ruby/models/accounting/payment_term.rb +1 -1
  126. data/lib/xero-ruby/models/accounting/payment_term_type.rb +1 -1
  127. data/lib/xero-ruby/models/accounting/payments.rb +1 -1
  128. data/lib/xero-ruby/models/accounting/phone.rb +1 -1
  129. data/lib/xero-ruby/models/accounting/prepayment.rb +1 -1
  130. data/lib/xero-ruby/models/accounting/prepayments.rb +1 -1
  131. data/lib/xero-ruby/models/accounting/purchase.rb +1 -1
  132. data/lib/xero-ruby/models/accounting/purchase_order.rb +1 -1
  133. data/lib/xero-ruby/models/accounting/purchase_orders.rb +1 -1
  134. data/lib/xero-ruby/models/accounting/quote.rb +1 -1
  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 +1 -1
  137. data/lib/xero-ruby/models/accounting/quotes.rb +1 -1
  138. data/lib/xero-ruby/models/accounting/receipt.rb +1 -1
  139. data/lib/xero-ruby/models/accounting/receipts.rb +1 -1
  140. data/lib/xero-ruby/models/accounting/repeating_invoice.rb +1 -1
  141. data/lib/xero-ruby/models/accounting/repeating_invoices.rb +1 -1
  142. data/lib/xero-ruby/models/accounting/report.rb +1 -1
  143. data/lib/xero-ruby/models/accounting/report_attribute.rb +1 -1
  144. data/lib/xero-ruby/models/accounting/report_cell.rb +1 -1
  145. data/lib/xero-ruby/models/accounting/report_fields.rb +1 -1
  146. data/lib/xero-ruby/models/accounting/report_row.rb +1 -1
  147. data/lib/xero-ruby/models/accounting/report_rows.rb +1 -1
  148. data/lib/xero-ruby/models/accounting/report_with_row.rb +1 -1
  149. data/lib/xero-ruby/models/accounting/report_with_rows.rb +1 -1
  150. data/lib/xero-ruby/models/accounting/reports.rb +1 -1
  151. data/lib/xero-ruby/models/accounting/request_empty.rb +1 -1
  152. data/lib/xero-ruby/models/accounting/row_type.rb +1 -1
  153. data/lib/xero-ruby/models/accounting/sales_tracking_category.rb +1 -1
  154. data/lib/xero-ruby/models/accounting/schedule.rb +1 -1
  155. data/lib/xero-ruby/models/accounting/tax_component.rb +1 -1
  156. data/lib/xero-ruby/models/accounting/tax_rate.rb +1 -1
  157. data/lib/xero-ruby/models/accounting/tax_rates.rb +1 -1
  158. data/lib/xero-ruby/models/accounting/tax_type.rb +1 -1
  159. data/lib/xero-ruby/models/accounting/ten_ninety_nine_contact.rb +1 -1
  160. data/lib/xero-ruby/models/accounting/time_zone.rb +2 -1
  161. data/lib/xero-ruby/models/accounting/tracking_categories.rb +1 -1
  162. data/lib/xero-ruby/models/accounting/tracking_category.rb +1 -1
  163. data/lib/xero-ruby/models/accounting/tracking_option.rb +1 -1
  164. data/lib/xero-ruby/models/accounting/tracking_options.rb +1 -1
  165. data/lib/xero-ruby/models/accounting/user.rb +1 -1
  166. data/lib/xero-ruby/models/accounting/users.rb +1 -1
  167. data/lib/xero-ruby/models/accounting/validation_error.rb +1 -1
  168. data/lib/xero-ruby/models/assets/asset.rb +1 -1
  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 +1 -1
  172. data/lib/xero-ruby/models/assets/assets.rb +1 -1
  173. data/lib/xero-ruby/models/assets/book_depreciation_detail.rb +1 -1
  174. data/lib/xero-ruby/models/assets/book_depreciation_setting.rb +1 -1
  175. data/lib/xero-ruby/models/assets/error.rb +1 -1
  176. data/lib/xero-ruby/models/assets/field_validation_errors_element.rb +1 -1
  177. data/lib/xero-ruby/models/assets/pagination.rb +1 -1
  178. data/lib/xero-ruby/models/assets/resource_validation_errors_element.rb +1 -1
  179. data/lib/xero-ruby/models/assets/setting.rb +1 -1
  180. data/lib/xero-ruby/models/projects/amount.rb +1 -1
  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 +1 -1
  184. data/lib/xero-ruby/models/projects/pagination.rb +1 -1
  185. data/lib/xero-ruby/models/projects/project.rb +1 -1
  186. data/lib/xero-ruby/models/projects/project_create_or_update.rb +1 -1
  187. data/lib/xero-ruby/models/projects/project_patch.rb +1 -1
  188. data/lib/xero-ruby/models/projects/project_status.rb +1 -1
  189. data/lib/xero-ruby/models/projects/project_user.rb +1 -1
  190. data/lib/xero-ruby/models/projects/project_users.rb +1 -1
  191. data/lib/xero-ruby/models/projects/projects.rb +1 -1
  192. data/lib/xero-ruby/models/projects/task.rb +1 -1
  193. data/lib/xero-ruby/models/projects/task_create_or_update.rb +1 -1
  194. data/lib/xero-ruby/models/projects/tasks.rb +1 -1
  195. data/lib/xero-ruby/models/projects/time_entries.rb +1 -1
  196. data/lib/xero-ruby/models/projects/time_entry.rb +1 -1
  197. data/lib/xero-ruby/models/projects/time_entry_create_or_update.rb +1 -1
  198. data/lib/xero-ruby/version.rb +2 -2
  199. data/spec/api_client_spec.rb +6 -6
  200. data/xero-ruby.gem +0 -0
  201. data/xero-ruby.gemspec +2 -2
  202. metadata +4 -4
  203. data/Gemfile.lock +0 -68
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 333abb6f3c4cb576451f3fa4f47be4843502e06acb09be2a918ec2f2f313b4c2
4
- data.tar.gz: adba7b3e9fac9cd66ea70935598c08fcc3506221fb27219200686d9630a2b3ce
3
+ metadata.gz: c8250dd8ab9c60af3fa465ae94075ab3f9a6ca740ba550ca1c89ce06e7d2d293
4
+ data.tar.gz: 34d4b08070f17257e204ba7072c0f294fa9424b0a8cb230326d6b678264320a4
5
5
  SHA512:
6
- metadata.gz: 4a07d78ad0a2f8c3be6f2ee677342a85dfc862b075095820cc193a572329218ad0bc055d0a1d2fe9484e7cf208056dfd55040b2f1b6dd6b6600589caee3253d5
7
- data.tar.gz: a7578f993ff86feaa3ef0d221188a64210f5b8ceec35e0fbdb7749424532c8f83a49cfdb9f76cb5b0e832f5d526b9b063a1413743752632906a7f89e332e154a
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
- ## 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)
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
- Coming soon
13
- * bank feeds
14
- * 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)
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
- 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,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
- ## API Usage
122
- > Comprehensive xero-ruby API usage is showcased here: https://github.com/XeroAPI/xero-ruby-oauth2-app
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
- Here is the basic workflow of using SDK once you have a valid `access_token` (and `token_set`) stored on an instance of the `xero_client`
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
- # Using the Accounting API set (https://github.com/XeroAPI/xero-ruby/blob/master/accounting/lib/xero-ruby/api/accounting_api.rb)
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
- # all money and fields requiring advanced precision utilize BigDecimal
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
- puts invoice.unit_amount.class
148
- => BigDecimal
168
+ # Get Accounts
169
+ accounts = xero_client.accounting_api.get_accounts(tenant_id).accounts
149
170
 
150
- puts invoice.unit_amount.to_s("F")
151
- => "20.99"
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
- # creating an object History record
157
- payment = xero_client.accounting_api.get_payments(current_user.active_tenant_id).payments.first
158
- history_records = { history_records:[ { details: "This payment now has some History #{rand(10000)}" } ]}
159
- payment_history = xero_client.accounting_api.create_payment_history(user.active_tenant_id, payment.payment_id, history_records)
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
- # creating an object Attachment record
162
- account = xero_client.accounting_api.get_accounts(current_user.active_tenant_id).accounts.first
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 # Boolean | Allows an attachment to be seen by the end customer within their online invoice
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(current_user.active_tenant_id, @account.account_id, file_name, file, opts)
187
+ attachment = xero_client.accounting_api.create_account_attachment_by_file_name(tenant_id, @account.account_id, file_name, file, opts)
169
188
 
170
- # Using the Asset API set (https://github.com/XeroAPI/xero-ruby/blob/master/accounting/lib/xero-ruby/api/asset_api.rb)
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(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
177
200
 
178
- # Using the Project API set (https://github.com/XeroAPI/xero-ruby/blob/master/docs/projects/ProjectApi.md)
179
- projects = xero_client.project_api.get_projects(current_user.active_tenant_id).items
201
+ # Get Projects
202
+ projects = xero_client.project_api.get_projects(tenant_id).items
180
203
  ```
181
204
 
182
- 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
213
+
214
+ puts invoice.unit_amount.to_s("F")
215
+ => "20.99"
183
216
 
184
- ## Sample App
185
- 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:
186
- > https://github.com/XeroAPI/xero-ruby-oauth2-app
217
+ # Rails method-number_to_currency
218
+ number_to_currency(invoice.unit_amount, :unit => "$")
219
+ ```
187
220
 
188
- * Complete the OAuth2.0 Authorization flow
189
- * Store token_sets against a user object in a DB
190
- * Storing info about active connections
191
- * Change the active tenant & make api calls to multiple orgs
192
- * Refreshing your token sets
193
- * Decoding your token_set items and strategy around how/when to refresh
194
- * Disconnecting a connection for a user
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
- ## Additional Documentation for API Endpoints
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
- ### APIS
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
- ## Models
203
- * [Accounting Models Docs](/docs/accounting/)
204
- * [Asset Models Docs](/docs/assets/)
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)
@@ -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
+ {{{.}}}
@@ -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
  ```