Module: Mrkt::CrudLeads

Included in:
Client
Defined in:
lib/mrkt/concerns/crud_leads.rb

Instance Method Summary collapse

Instance Method Details

#associate_lead(id, cookie) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/mrkt/concerns/crud_leads.rb', line 39

def associate_lead(id, cookie)
  params = Faraday::Utils::ParamsHash.new
  params[:cookie] = cookie

  post("/rest/v1/leads/#{id}/associate.json?#{params.to_query}") do |req|
    json_payload(req, {})
  end
end

#createupdate_leads(leads, action: 'createOrUpdate', lookup_field: nil, partition_name: nil) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/mrkt/concerns/crud_leads.rb', line 15

def createupdate_leads(leads, action: 'createOrUpdate', lookup_field: nil, partition_name: nil)
  post('/rest/v1/leads.json') do |req|
    params = {
      action: action,
      input: leads
    }
    params[:lookupField] = lookup_field if lookup_field
    params[:partitionName] = partition_name if partition_name

    json_payload(req, params)
  end
end

#delete_leads(leads) ⇒ Object



28
29
30
31
32
# File 'lib/mrkt/concerns/crud_leads.rb', line 28

def delete_leads(leads)
  delete('/rest/v1/leads.json') do |req|
    json_payload(req, input: leads.map { |lead_id| { id: lead_id } })
  end
end

#get_leads(filter_type, filter_values, fields: nil, batch_size: nil, next_page_token: nil) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/mrkt/concerns/crud_leads.rb', line 3

def get_leads(filter_type, filter_values, fields: nil, batch_size: nil, next_page_token: nil)
  params = {
    filterType: filter_type,
    filterValues: filter_values.join(',')
  }
  params[:fields] = fields if fields
  params[:batchSize] = batch_size if batch_size
  params[:nextPageToken] = next_page_token if next_page_token

  get('/rest/v1/leads.json', params)
end

#json_payload(req, payload) ⇒ Object



34
35
36
37
# File 'lib/mrkt/concerns/crud_leads.rb', line 34

def json_payload(req, payload)
  req.headers[:content_type] = 'application/json'
  req.body = JSON.generate(payload)
end