Skip to content

Commit

Permalink
Merge pull request #74 from XeroAPI/better_serialization_complex_params
Browse files Browse the repository at this point in the history
Better serialization of complex params
  • Loading branch information
SerKnight authored Sep 23, 2020
2 parents 91d39db + 57620d9 commit 07f2ad0
Show file tree
Hide file tree
Showing 10 changed files with 537 additions and 259 deletions.
31 changes: 22 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,31 +219,43 @@ All monetary and fields and a couple quantity fields utilize BigDecimal
```

## Querying & Filtering
Examples for the `opts` (_options_) parameters most endpoints support.
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).
```ruby
# Invoices
opts = {
statuses: [XeroRuby::Accounting::Invoice::PAID],
where: { amount_due: '=0' },
if_modified_since: (DateTime.now - 1.hour).to_s
opts = {
page: 1,
where: {
type: ['=', XeroRuby::Accounting::Invoice::ACCREC],
fully_paid_on_date: (DateTime.now - 6.month)..DateTime.now,
amount_due: ['>=', 0],
reference: ['=', "Website Design"],
invoice_number: ['=', "INV-0001"],
contact_id: ['=', 'contact-uuid-xxxx-xxx-xxxxxxx'],
contact_number: ['=', "the-contact-number"],
# date: (DateTime.now - 2.year)..DateTime.now
# ▲ you can pass a range ▼ or a date & operator
date: ['>=', DateTime.now - 2.year],
status: ['=', XeroRuby::Accounting::Invoice::PAID]
}
}
xero_client.accounting_api.get_invoices(tenant_id, opts).invoices

# Contacts
opts = {
if_modified_since: (DateTime.now - 1.weeks).to_s,
# ▼ ordering by strings needs PascalCase convention
order: 'UpdatedDateUtc DESC',
where: {
is_customer: '==true',
is_supplier: '==true',
is_customer: ['==', true],
is_supplier: ['==', true]
}
}
xero_client.accounting_api.get_contacts(tenant_id, opts).contacts

# Bank Transactions
opts = {
if_modified_since: (DateTime.now - 1.year).to_s,
where: { type: %{=="#{XeroRuby::Accounting::BankTransaction::SPEND}"}},
where: { type: ['==', XeroRuby::Accounting::BankTransaction::SPEND] },
order: 'UpdatedDateUtc DESC',
page: 2,
unitdp: 4 # (Unit Decimal Places)
Expand All @@ -252,8 +264,9 @@ xero_client.accounting_api.get_bank_transactions(tenant_id, opts).bank_transacti

# Bank Transfers
opts = {
if_modified_since: (DateTime.now - 1.month).to_s,
where: {
amount: "> 999.99"
amount: [">=" , 999.99]
},
order: 'Amount ASC'
}
Expand Down
12 changes: 6 additions & 6 deletions docs/assets/AssetApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ api_instance = xero_client.asset_api
api_instance = xero_client.projects_api


xero_tenant_id = 'xero_tenant_id_example' # String | Xero identifier for Tenant
xero_tenant_id = 'YOUR_XERO_TENANT_ID' # String | Xero identifier for Tenant
asset = { "assetName":"Computer74863", "assetNumber":"123477544", "purchaseDate":"2020-01-01", "purchasePrice":100.0, "disposalPrice":23.23, "assetStatus":"Draft", "bookDepreciationSetting":{ "depreciationMethod":"StraightLine", "averagingMethod":"ActualDays", "depreciationRate":0.5, "depreciationCalculationMethod":"None" }, "bookDepreciationDetail":{ "currentCapitalGain":5.32, "currentGainLoss":3.88, "depreciationStartDate":"2020-01-02", "costLimit":100.0, "currentAccumDepreciationAmount":2.25 }, "AccountingBookValue":99.5 } # Asset | Fixed asset you are creating
begin
#adds a fixed asset
Expand Down Expand Up @@ -116,7 +116,7 @@ api_instance = xero_client.asset_api
api_instance = xero_client.projects_api


xero_tenant_id = 'xero_tenant_id_example' # String | Xero identifier for Tenant
xero_tenant_id = 'YOUR_XERO_TENANT_ID' # String | Xero identifier for Tenant
opts = {
asset_type: { "assetTypeName":"Machinery11004", "fixedAssetAccountId":"3d8d063a-c148-4bb8-8b3c-a5e2ad3b1e82", "depreciationExpenseAccountId":"d1602f69-f900-4616-8d34-90af393fa368", "accumulatedDepreciationAccountId":"9195cadd-8645-41e6-9f67-7bcd421defe8", "bookDepreciationSetting":{ "depreciationMethod":"DiminishingValue100", "averagingMethod":"ActualDays", "depreciationRate":0.05, "depreciationCalculationMethod":"None" } } # AssetType | Asset type to add
}
Expand Down Expand Up @@ -187,7 +187,7 @@ api_instance = xero_client.asset_api
api_instance = xero_client.projects_api


xero_tenant_id = 'xero_tenant_id_example' # String | Xero identifier for Tenant
xero_tenant_id = 'YOUR_XERO_TENANT_ID' # String | Xero identifier for Tenant
id = '4f7bcdcb-5ec1-4258-9558-19f662fccdfe' # String | fixed asset id for single object
begin
#retrieves fixed asset by id
Expand Down Expand Up @@ -255,7 +255,7 @@ api_instance = xero_client.asset_api
api_instance = xero_client.projects_api


xero_tenant_id = 'xero_tenant_id_example' # String | Xero identifier for Tenant
xero_tenant_id = 'YOUR_XERO_TENANT_ID' # String | Xero identifier for Tenant
begin
#searches fixed asset settings
result = api_instance.get_asset_settings(xero_tenant_id)
Expand Down Expand Up @@ -321,7 +321,7 @@ api_instance = xero_client.asset_api
api_instance = xero_client.projects_api


xero_tenant_id = 'xero_tenant_id_example' # String | Xero identifier for Tenant
xero_tenant_id = 'YOUR_XERO_TENANT_ID' # String | Xero identifier for Tenant
begin
#searches fixed asset types
result = api_instance.get_asset_types(xero_tenant_id)
Expand Down Expand Up @@ -387,7 +387,7 @@ api_instance = xero_client.asset_api
api_instance = xero_client.projects_api


xero_tenant_id = 'xero_tenant_id_example' # String | Xero identifier for Tenant
xero_tenant_id = 'YOUR_XERO_TENANT_ID' # String | Xero identifier for Tenant
status = XeroRuby::Assets::AssetStatusQueryParam.new # AssetStatusQueryParam | Required when retrieving a collection of assets. See Asset Status Codes
opts = {
page: 1, # Integer | Results are paged. This specifies which page of the results to return. The default page is 1.
Expand Down
Loading

0 comments on commit 07f2ad0

Please sign in to comment.