我正在使用 Xero API 检索本月的所有 Invoices,然后检索所有 CreditNotes,然后我计划适当分配 Credits。
在此之前,我需要授权我的所有发票和 CreditNotes。当我要保存更新时,我遇到了Xeroizer::OAuth::RateLimitExceeded
异常,被验证步骤抛出,这似乎是通过#download_complete_record 单独检索每条记录!在lib/xeroizer/record/record_association_helper.rb:131。
在保存之前,我尝试在所有对象上手动设置 complete_record_downloaded 标志,但随后出现验证错误,提示发票没有行项目,这是预期的。
这就是我正在尝试做的事情,我应该以不同的方式来解决这个问题,这样它就不会在发送更新之前尝试重新验证所有记录?
require 'xeroizer'
key = Rails.application.secrets.xero[:key]
secret = Rails.application.secrets.xero[:secret]
cert = Rails.application.secrets.xero[:cert]
xeroizer = Xeroizer::PrivateApplication.new(key, secret, cert)
issue_date = Date.new(2019,11,22)
# Retrieving this broad selection of invoices here as it's used later in this worker for other purposes
xero_all_invoices = xeroizer.Invoice.all(where: "AmountDue>0")
xero_invoices = xero_all_invoices.select{|i| i.date == issue_date && i.status == 'DRAFT'}
xeroizer.Invoice.batch_save do
xero_invoices.each{|i| i.status = 'AUTHORISED' }
end
# At this point, the Xeroizer::OAuth::RateLimitExceeded exception is thrown.
异常回溯的相关部分如下:
.../xeroizer/http.rb:175:in `handle_oauth_error!'
.../xeroizer/http.rb:124:in `http_request'
.../xeroizer/http.rb:31:in `http_get'
.../xeroizer/record/base_model.rb:152:in `find'
.../xeroizer/record/base.rb:100:in `download_complete_record!'
.../xeroizer/record/record_association_helper.rb:131:in `block in define_association_attribute'
.../xeroizer/record/base.rb:54:in `[]'
.../xeroizer/record/validators/associated_validator.rb:12:in `valid?'
.../xeroizer/record/validators/validator.rb:15:in `validate'
.../xeroizer/record/validation_helper.rb:59:in `block in valid?'
.../xeroizer/record/validation_helper.rb:58:in `each'
.../xeroizer/record/validation_helper.rb:58:in `valid?'
.../xeroizer/record/base_model.rb:161:in `each'
.../xeroizer/record/base_model.rb:161:in `all?'
.../xeroizer/record/base_model.rb:161:in `save_records'
作为参考,我在 Xeroizer gem 问题页面上提出了同样的问题,但没有任何回应,所以现在在这里提问。