7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/updox/models/extensions/sync.rb', line 7
def sync(items, account_id: , batch_size: RECOMMENDED_BATCH_SIZE, endpoint: self.const_get(:SYNC_ENDPOINT))
response = nil
list_type = self.const_get(:SYNC_LIST_TYPE)
if 0 >= batch_size
response = request(endpoint: endpoint, body: { list_type => items }, auth: {accountId: account_id}, required_auths: Updox::Models::Auth::AUTH_ACCT)
else
items.each_slice(batch_size) do |batch|
r = request(endpoint: endpoint, body: { list_type => batch }, auth: {accountId: account_id}, required_auths: Updox::Models::Auth::AUTH_ACCT)
return r unless r.successful?
if response
response.items += r.items
else
response = r
end
end
end
return response
end
|