如何解决在不更改其他请求的情况下在一个块中使用API测试密钥?
我正在尝试了解块。您肯定会发现我在方法中做的很烂,我做得很差。我可以为用户做一件好事,给他们看一个测试标签,以便他们可以看到从输入中得到的结果。我不想更改API密钥来更改其他需要活动密钥的请求。自然地或直觉上,我不知道阻止声音正确。我如何有效地做到这一点,以及将方法声明放在何处?是否有方法声明或lambda,proc或block作为方法参数?
我认为我已经通过在其中放置模型记录进行测试来简化了此过程。谢谢。
# normal api key,:live
# Shippo::API.token = Rails.application.credentials.api[:shippo][:live]
def test_label(quickrate,shippo_shipment)
logs(Shippo::API.token,:light_green) # for debugging,needs to show :live key
test_label = lambda do
quickrate = Quickrate.find(58)
shippo_shipment = Shippo::Shipment.get(quickrate.shipment.shippo_id)
Shippo::API.token = Rails.application.credentials.api[:shippo][:test]
transaction_response =
Shippo::Transaction
.create(rate: shippo_shipment['rates'][3]['object_id'],label_file_type: 'PNG',test: true,async: false)
return transaction_response
end
logs(Shippo::API.token,:light_green) # shows :test !
@test_label_response = test_label.call
session[:test_label_response] = @test_label_response
end
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。