PIPEDRIVEgetRecent is passed the client object and the table of defined parameters.
PIPEDRIVEgetRecent formats the required endpoint and parameters to call PIPEDRIVEcustom to make the 'recents' API call. If the passed LastPollTime is 1, it defaults to poll for deals from the last 24 hours.
If successful, then we check the response for an indication that there are more items to be collected. If true, then PIPEDRIVEgetRecent is recursively called with a new start position to get the additional Deals and insert them into the returned table of Deals.
local function PIPEDRIVEgetRecent(T, C)
local P = {}
if C.LastPollTime == 1 then
C.LastPollTime = os.time()-24*60*60 -- Default to 24 hours ago
end
P.since_timestamp = os.date('!%Y-%m-%d %H:%M:%S',C.LastPollTime)
P.items = C.items
P.start = C.index
local S, R = T:custom({api='recents',parameters=P,live=C.live})
if S then
if R.additional_data.pagination.more_items_in_collection then
C.index = R.additional_data.pagination.next_start
local NextS, NextPage = PIPEDRIVEgetRecent(T,C)
for i=1,#NextPage.data do
table.insert(R.data,NextPage.data[i])
end
end
end
return S, R
end
return PIPEDRIVEgetRecent
Concepts used: