xero-ruby 2.0.0 → 2.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (201) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +171 -87
  3. data/build_notes.md +39 -4
  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/BookDepreciationDetail.md +6 -6
  43. data/docs/assets/BookDepreciationSetting.md +1 -1
  44. data/docs/projects/Amount.md +1 -1
  45. data/docs/projects/ProjectCreateOrUpdate.md +1 -1
  46. data/lib/xero-ruby.rb +1 -1
  47. data/lib/xero-ruby/api/accounting_api.rb +1291 -1
  48. data/lib/xero-ruby/api/asset_api.rb +37 -1
  49. data/lib/xero-ruby/api/project_api.rb +79 -1
  50. data/lib/xero-ruby/api_client.rb +13 -8
  51. data/lib/xero-ruby/api_error.rb +1 -1
  52. data/lib/xero-ruby/configuration.rb +2 -2
  53. data/lib/xero-ruby/models/accounting/account.rb +1 -16
  54. data/lib/xero-ruby/models/accounting/account_type.rb +1 -1
  55. data/lib/xero-ruby/models/accounting/accounts.rb +1 -1
  56. data/lib/xero-ruby/models/accounting/accounts_payable.rb +1 -1
  57. data/lib/xero-ruby/models/accounting/accounts_receivable.rb +1 -1
  58. data/lib/xero-ruby/models/accounting/address.rb +1 -1
  59. data/lib/xero-ruby/models/accounting/allocation.rb +1 -1
  60. data/lib/xero-ruby/models/accounting/allocations.rb +1 -1
  61. data/lib/xero-ruby/models/accounting/attachment.rb +2 -2
  62. data/lib/xero-ruby/models/accounting/attachments.rb +1 -1
  63. data/lib/xero-ruby/models/accounting/balances.rb +1 -1
  64. data/lib/xero-ruby/models/accounting/bank_transaction.rb +1 -6
  65. data/lib/xero-ruby/models/accounting/bank_transactions.rb +1 -1
  66. data/lib/xero-ruby/models/accounting/bank_transfer.rb +1 -1
  67. data/lib/xero-ruby/models/accounting/bank_transfers.rb +1 -1
  68. data/lib/xero-ruby/models/accounting/batch_payment.rb +1 -16
  69. data/lib/xero-ruby/models/accounting/batch_payment_details.rb +1 -1
  70. data/lib/xero-ruby/models/accounting/batch_payments.rb +1 -1
  71. data/lib/xero-ruby/models/accounting/bill.rb +1 -1
  72. data/lib/xero-ruby/models/accounting/branding_theme.rb +1 -1
  73. data/lib/xero-ruby/models/accounting/branding_themes.rb +1 -1
  74. data/lib/xero-ruby/models/accounting/cis_org_setting.rb +1 -1
  75. data/lib/xero-ruby/models/accounting/cis_setting.rb +1 -1
  76. data/lib/xero-ruby/models/accounting/cis_settings.rb +1 -1
  77. data/lib/xero-ruby/models/accounting/contact.rb +1 -1
  78. data/lib/xero-ruby/models/accounting/contact_group.rb +1 -1
  79. data/lib/xero-ruby/models/accounting/contact_groups.rb +1 -1
  80. data/lib/xero-ruby/models/accounting/contact_person.rb +1 -1
  81. data/lib/xero-ruby/models/accounting/contacts.rb +1 -1
  82. data/lib/xero-ruby/models/accounting/country_code.rb +1 -1
  83. data/lib/xero-ruby/models/accounting/credit_note.rb +1 -1
  84. data/lib/xero-ruby/models/accounting/credit_notes.rb +1 -1
  85. data/lib/xero-ruby/models/accounting/currencies.rb +1 -1
  86. data/lib/xero-ruby/models/accounting/currency.rb +1 -1
  87. data/lib/xero-ruby/models/accounting/currency_code.rb +1 -1
  88. data/lib/xero-ruby/models/accounting/element.rb +1 -1
  89. data/lib/xero-ruby/models/accounting/employee.rb +4 -3
  90. data/lib/xero-ruby/models/accounting/employees.rb +1 -1
  91. data/lib/xero-ruby/models/accounting/error.rb +1 -1
  92. data/lib/xero-ruby/models/accounting/expense_claim.rb +1 -1
  93. data/lib/xero-ruby/models/accounting/expense_claims.rb +1 -1
  94. data/lib/xero-ruby/models/accounting/external_link.rb +1 -1
  95. data/lib/xero-ruby/models/accounting/history_record.rb +1 -1
  96. data/lib/xero-ruby/models/accounting/history_records.rb +1 -1
  97. data/lib/xero-ruby/models/accounting/invoice.rb +1 -1
  98. data/lib/xero-ruby/models/accounting/invoice_reminder.rb +1 -1
  99. data/lib/xero-ruby/models/accounting/invoice_reminders.rb +1 -1
  100. data/lib/xero-ruby/models/accounting/invoices.rb +1 -1
  101. data/lib/xero-ruby/models/accounting/item.rb +1 -1
  102. data/lib/xero-ruby/models/accounting/items.rb +1 -1
  103. data/lib/xero-ruby/models/accounting/journal.rb +1 -1
  104. data/lib/xero-ruby/models/accounting/journal_line.rb +1 -1
  105. data/lib/xero-ruby/models/accounting/journals.rb +1 -1
  106. data/lib/xero-ruby/models/accounting/line_amount_types.rb +1 -1
  107. data/lib/xero-ruby/models/accounting/line_item.rb +1 -1
  108. data/lib/xero-ruby/models/accounting/line_item_tracking.rb +1 -1
  109. data/lib/xero-ruby/models/accounting/linked_transaction.rb +1 -1
  110. data/lib/xero-ruby/models/accounting/linked_transactions.rb +1 -1
  111. data/lib/xero-ruby/models/accounting/manual_journal.rb +1 -1
  112. data/lib/xero-ruby/models/accounting/manual_journal_line.rb +1 -1
  113. data/lib/xero-ruby/models/accounting/manual_journals.rb +1 -1
  114. data/lib/xero-ruby/models/accounting/online_invoice.rb +1 -1
  115. data/lib/xero-ruby/models/accounting/online_invoices.rb +1 -1
  116. data/lib/xero-ruby/models/accounting/organisation.rb +1 -1
  117. data/lib/xero-ruby/models/accounting/organisations.rb +1 -1
  118. data/lib/xero-ruby/models/accounting/overpayment.rb +1 -1
  119. data/lib/xero-ruby/models/accounting/overpayments.rb +1 -1
  120. data/lib/xero-ruby/models/accounting/payment.rb +1 -1
  121. data/lib/xero-ruby/models/accounting/payment_delete.rb +1 -1
  122. data/lib/xero-ruby/models/accounting/payment_service.rb +1 -1
  123. data/lib/xero-ruby/models/accounting/payment_services.rb +1 -1
  124. data/lib/xero-ruby/models/accounting/payment_term.rb +1 -1
  125. data/lib/xero-ruby/models/accounting/payment_term_type.rb +1 -1
  126. data/lib/xero-ruby/models/accounting/payments.rb +1 -1
  127. data/lib/xero-ruby/models/accounting/phone.rb +1 -1
  128. data/lib/xero-ruby/models/accounting/prepayment.rb +1 -1
  129. data/lib/xero-ruby/models/accounting/prepayments.rb +1 -1
  130. data/lib/xero-ruby/models/accounting/purchase.rb +1 -1
  131. data/lib/xero-ruby/models/accounting/purchase_order.rb +1 -1
  132. data/lib/xero-ruby/models/accounting/purchase_orders.rb +1 -1
  133. data/lib/xero-ruby/models/accounting/quote.rb +1 -1
  134. data/lib/xero-ruby/models/accounting/quote_line_amount_types.rb +1 -1
  135. data/lib/xero-ruby/models/accounting/quote_status_codes.rb +1 -1
  136. data/lib/xero-ruby/models/accounting/quotes.rb +1 -1
  137. data/lib/xero-ruby/models/accounting/receipt.rb +1 -1
  138. data/lib/xero-ruby/models/accounting/receipts.rb +1 -1
  139. data/lib/xero-ruby/models/accounting/repeating_invoice.rb +1 -1
  140. data/lib/xero-ruby/models/accounting/repeating_invoices.rb +1 -1
  141. data/lib/xero-ruby/models/accounting/report.rb +1 -1
  142. data/lib/xero-ruby/models/accounting/report_attribute.rb +1 -1
  143. data/lib/xero-ruby/models/accounting/report_cell.rb +1 -1
  144. data/lib/xero-ruby/models/accounting/report_fields.rb +1 -1
  145. data/lib/xero-ruby/models/accounting/report_row.rb +1 -1
  146. data/lib/xero-ruby/models/accounting/report_rows.rb +1 -1
  147. data/lib/xero-ruby/models/accounting/report_with_row.rb +1 -1
  148. data/lib/xero-ruby/models/accounting/report_with_rows.rb +1 -1
  149. data/lib/xero-ruby/models/accounting/reports.rb +1 -1
  150. data/lib/xero-ruby/models/accounting/request_empty.rb +1 -1
  151. data/lib/xero-ruby/models/accounting/row_type.rb +1 -1
  152. data/lib/xero-ruby/models/accounting/sales_tracking_category.rb +1 -1
  153. data/lib/xero-ruby/models/accounting/schedule.rb +1 -1
  154. data/lib/xero-ruby/models/accounting/tax_component.rb +1 -1
  155. data/lib/xero-ruby/models/accounting/tax_rate.rb +1 -1
  156. data/lib/xero-ruby/models/accounting/tax_rates.rb +1 -1
  157. data/lib/xero-ruby/models/accounting/tax_type.rb +1 -1
  158. data/lib/xero-ruby/models/accounting/ten_ninety_nine_contact.rb +1 -1
  159. data/lib/xero-ruby/models/accounting/time_zone.rb +1 -1
  160. data/lib/xero-ruby/models/accounting/tracking_categories.rb +1 -1
  161. data/lib/xero-ruby/models/accounting/tracking_category.rb +1 -1
  162. data/lib/xero-ruby/models/accounting/tracking_option.rb +1 -1
  163. data/lib/xero-ruby/models/accounting/tracking_options.rb +1 -1
  164. data/lib/xero-ruby/models/accounting/user.rb +1 -1
  165. data/lib/xero-ruby/models/accounting/users.rb +1 -1
  166. data/lib/xero-ruby/models/accounting/validation_error.rb +1 -1
  167. data/lib/xero-ruby/models/assets/asset.rb +1 -1
  168. data/lib/xero-ruby/models/assets/asset_status.rb +1 -1
  169. data/lib/xero-ruby/models/assets/asset_status_query_param.rb +1 -1
  170. data/lib/xero-ruby/models/assets/asset_type.rb +1 -1
  171. data/lib/xero-ruby/models/assets/assets.rb +1 -1
  172. data/lib/xero-ruby/models/assets/book_depreciation_detail.rb +1 -1
  173. data/lib/xero-ruby/models/assets/book_depreciation_setting.rb +1 -1
  174. data/lib/xero-ruby/models/assets/error.rb +1 -1
  175. data/lib/xero-ruby/models/assets/field_validation_errors_element.rb +1 -1
  176. data/lib/xero-ruby/models/assets/pagination.rb +1 -1
  177. data/lib/xero-ruby/models/assets/resource_validation_errors_element.rb +1 -1
  178. data/lib/xero-ruby/models/assets/setting.rb +1 -1
  179. data/lib/xero-ruby/models/projects/amount.rb +1 -1
  180. data/lib/xero-ruby/models/projects/charge_type.rb +1 -1
  181. data/lib/xero-ruby/models/projects/currency_code.rb +1 -1
  182. data/lib/xero-ruby/models/projects/error.rb +1 -1
  183. data/lib/xero-ruby/models/projects/pagination.rb +1 -1
  184. data/lib/xero-ruby/models/projects/project.rb +1 -1
  185. data/lib/xero-ruby/models/projects/project_create_or_update.rb +1 -1
  186. data/lib/xero-ruby/models/projects/project_patch.rb +1 -1
  187. data/lib/xero-ruby/models/projects/project_status.rb +1 -1
  188. data/lib/xero-ruby/models/projects/project_user.rb +1 -1
  189. data/lib/xero-ruby/models/projects/project_users.rb +1 -1
  190. data/lib/xero-ruby/models/projects/projects.rb +1 -1
  191. data/lib/xero-ruby/models/projects/task.rb +1 -1
  192. data/lib/xero-ruby/models/projects/task_create_or_update.rb +1 -1
  193. data/lib/xero-ruby/models/projects/tasks.rb +1 -1
  194. data/lib/xero-ruby/models/projects/time_entries.rb +1 -1
  195. data/lib/xero-ruby/models/projects/time_entry.rb +1 -1
  196. data/lib/xero-ruby/models/projects/time_entry_create_or_update.rb +1 -1
  197. data/lib/xero-ruby/version.rb +2 -2
  198. data/spec/api_client_spec.rb +98 -9
  199. data/xero-ruby.gemspec +2 -2
  200. metadata +3 -4
  201. data/Gemfile.lock +0 -68
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c469455936635d16067b4269ad96bda3ae65b7d8f9a34399532b380a7f34d72b
4
- data.tar.gz: '039093400b943441b6f987a279cc981c23052e6575047f301ba9527192b26d34'
3
+ metadata.gz: 2b109231681fa5a25b5e26d02d4146c5979a5129aff1c95ee0e19c4fd458ea22
4
+ data.tar.gz: 270e82a505686f53eb9992b90a2bade56c69252fcedabe565342b528ed0fef8b
5
5
  SHA512:
6
- metadata.gz: bcc87f93d7203239d688b12e4d0f7496953fb1563cd4d3865384f3d9a51342d18b44029c8c2af4670d55e71c27e0561df1c4e24d05bea7afd64da1ac679d0610
7
- data.tar.gz: 9362cfe1d6822dc0caedad0213ec31c35172503bf8da0af3c145e80c5794dbed5122fc739d02ed7ce4234db8d9e159d7458cea082efe42152a31be4106a7b377
6
+ metadata.gz: da10f455c433426046bd3365beb1a1916a0336e1371a3ff81bfc44ccdeca88b9a85c2b4f5e04667e37bb50f5deda48b70e8244159409e18e0912555aa5a94096
7
+ data.tar.gz: 63a5909520a9bf086e4ea23b657dc0ed1af541522f0f2571cf76932d6d12b4693b727ac91442db09168f6977021d8139b2bee8004aefb5734db5faf4d84131ad
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,82 +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
 
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
- # Accounting API set (https://github.com/XeroAPI/xero-ruby/blob/master/accounting/lib/xero-ruby/api/accounting_api.rb)
163
+ tenant_id = user.active_tenant_id
164
+ # example of how to store the `tenantId` of the specific tenant (aka organisation)
133
165
 
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
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
138
170
 
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
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
142
174
 
143
- payment = xero_client.accounting_api.get_payments(current_user.active_tenant_id).payments.first
144
- history_records = { history_records:[ { details: "This payment now has some History #{rand(10000)}" } ]}
145
- 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)
146
179
 
147
- 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
148
182
  file_name = "an-account-filename.png"
149
183
  opts = {
150
- include_online: true # Boolean | Allows an attachment to be seen by the end customer within their online invoice
184
+ include_online: true
151
185
  }
152
186
  file = File.read(Rails.root.join('app/assets/images/xero-api.png'))
153
- 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)
154
188
 
155
- # 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
156
192
  asset = {
157
193
  "assetName": "AssetName: #{rand(10000)}",
158
194
  "assetNumber": "Asset: #{rand(10000)}",
159
195
  "assetStatus": "DRAFT"
160
196
  }
161
- asset = xero_client.asset_api.create_asset(current_user.active_tenant_id, asset)
197
+ asset = xero_client.asset_api.create_asset(tenant_id, asset)
162
198
 
163
- # Project API set (https://github.com/XeroAPI/xero-ruby/blob/master/docs/projects/ProjectApi.md)
164
- projects = xero_client.project_api.get_projects(current_user.active_tenant_id).items
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
165
203
  ```
166
204
 
167
- 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"
168
216
 
169
- ## Sample App
170
- 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:
171
- > https://github.com/XeroAPI/xero-ruby-oauth2-app
217
+ # Rails method-number_to_currency
218
+ number_to_currency(invoice.unit_amount, :unit => "$")
219
+ ```
172
220
 
173
- * Complete the OAuth2.0 Authorization flow
174
- * Store token_sets against a user object in a DB
175
- * Storing info about active connections
176
- * Change the active tenant & make api calls to multiple orgs
177
- * Refreshing your token sets
178
- * Decoding your token_set items and strategy around how/when to refresh
179
- * Disconnecting a connection for a user
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.
180
264
 
181
- ## Additional Documentation for API Endpoints
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'}`
182
267
 
183
- ### APIS
184
- * [Accounting Api Docs](/docs/accounting/AccountingApi.md)
185
- * [Asset Api Docs](/docs/assets/AssetApi.md)
268
+ 3) If you have use cases outside of these examples let us know.
186
269
 
187
- ## Models
188
- * [Accounting Models Docs](/docs/accounting/)
189
- * [Asset Models Docs](/docs/assets/)
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)
@@ -1,4 +1,4 @@
1
- Developing gem locally
1
+ # Developing gem locally
2
2
 
3
3
  > xero-ruby
4
4
  ```bash
@@ -7,11 +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
- `gem 'xero-ruby', path: '/Users/chris.knight/code/sdks/xero-ruby/'`
13
11
  ```bash
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
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
  ```
@@ -4,8 +4,8 @@
4
4
 
5
5
  Name | Type | Description | Notes
6
6
  ------------ | ------------- | ------------- | -------------
7
- **outstanding** | **Float** | | [optional]
8
- **overdue** | **Float** | | [optional]
7
+ **outstanding** | **BigDecimal** | | [optional]
8
+ **overdue** | **BigDecimal** | | [optional]
9
9
 
10
10
  ## Code Sample
11
11
 
@@ -4,8 +4,8 @@
4
4
 
5
5
  Name | Type | Description | Notes
6
6
  ------------ | ------------- | ------------- | -------------
7
- **outstanding** | **Float** | | [optional]
8
- **overdue** | **Float** | | [optional]
7
+ **outstanding** | **BigDecimal** | | [optional]
8
+ **overdue** | **BigDecimal** | | [optional]
9
9
 
10
10
  ## Code Sample
11
11