Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Need some help? Contact us:

...

 

 

Like all our adapters, the Pipedrive adapter uses simple core concepts and common design patterns to ensure it is extensible and easy to understand.

...

Expand
titlemain checks the last time Deals were retrieved and calls PIPEDRIVEgetRecent for recent Deals to be queued

In main, the LastPollTime is checked and used to call PIPEDRIVEgetRecent for new Deals. If there are any new Deals they are serialized as a string and pushed to the component queue.

Code Block
languagelua
local LastPollTime = COUNTget('LastPollTime')
local NextPollTime = os.time()

-- Retrieve recent deals   
iguana.logInfo('Pulling recent items from '..os.date('%Y-%m-%d %H:%M:%S',LastPollTime))
local S, R = P:getRecent{LastPollTime = LastPollTime, items = 'deal', live=true}
if R.data ~= json.NULL then 
  for i=1,#R.data do 
    queue.push{data=json.serialize{data=R.data[i]}}
  end
end

Concepts used:

Expand
titlePIPEDRIVEgetRecent prepares the Pipedrive API for PIPEDRIVE custom to get the recent Deals

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. The COUNT Library returns 1 if the field is empty, therefore if the LastPollTime is 1, we set it 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. In the case that there are a large number of results, greater than the Pipedrive APIs limit (default ~500), then the Pipedrive API uses pagination to return results in pages with a flag to indicate where there are pages present and an index to the next item on the next page. This information is used to recursively call PIPEDRIVEgetRecent to compile all the results into a single table to be returned.

Code Block
languagelua
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:

...