lib/xeroizer/http.rb in xeroizer-2.15.8 vs lib/xeroizer/http.rb in xeroizer-2.15.9

- old
+ new

@@ -55,10 +55,13 @@ def http_request(client, method, url, body, params = {}) # headers = {'Accept-Encoding' => 'gzip, deflate'} headers = self.default_headers.merge({ 'charset' => 'utf-8' }) + # include the unitdp query string parameter + params.merge!(unitdp_param(url)) + if method != :get headers['Content-Type'] ||= "application/x-www-form-urlencoded" end content_type = params.delete(:content_type) @@ -191,9 +194,17 @@ raise BadResponse.new("Unknown response code: #{response.code.to_i}") end def sleep_for(seconds = 1) sleep seconds + end + + # unitdp query string parameter to be added to request params + # when the application option has been set and the model has line items + # http://developer.xero.com/documentation/advanced-docs/rounding-in-xero/#unitamount + def unitdp_param(request_url) + models = [/Invoices/, /CreditNotes/, /BankTransactions/, /Receipts/] + self.unitdp == 4 && models.any?{ |m| request_url =~ m } ? {:unitdp => 4} : {} end end end