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


49
50
51
52
53
# File 'lib/mrkt/concerns/crud_leads.rb', line 49

def associate_lead(id, cookie)
  params = Mrkt::Faraday::ParamsEncoder.encode(cookie: cookie)

  post_json("/rest/v1/leads/#{id}/associate.json?#{params}")
end

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


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/mrkt/concerns/crud_leads.rb', line 26

def createupdate_leads(leads, action: 'createOrUpdate', lookup_field: nil, partition_name: nil, async_processing: nil)
  post_json('/rest/v1/leads.json') do
    params = {
      action: action,
      input: leads
    }

    optional = {
      lookupField: lookup_field,
      partitionName: partition_name,
      asyncProcessing: async_processing
    }

    merge_params(params, optional)
  end
end

#delete_leads(leads) ⇒ Object


43
44
45
46
47
# File 'lib/mrkt/concerns/crud_leads.rb', line 43

def delete_leads(leads)
  delete('/rest/v1/leads.json') do |req|
    json_payload(req, input: map_lead_ids(leads))
  end
end

#describe_leadObject


66
67
68
# File 'lib/mrkt/concerns/crud_leads.rb', line 66

def describe_lead
  get('/rest/v1/leads/describe.json')
end

#get_lead_by_id(id, fields: nil) ⇒ Object


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

def get_lead_by_id(id, fields: nil)
  optional = {
    fields: fields
  }

  get("/rest/v1/lead/#{id}.json", {}, optional)
end

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


11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/mrkt/concerns/crud_leads.rb', line 11

def get_leads(filter_type, filter_values, fields: nil, batch_size: nil, next_page_token: nil)
  params = {
    filterType: filter_type,
    filterValues: filter_values
  }

  optional = {
    fields: fields,
    batchSize: batch_size,
    nextPageToken: next_page_token
  }

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

#merge_leads(winning_lead_id, losing_lead_ids, merge_in_crm: false) ⇒ Object


55
56
57
58
59
60
61
62
63
64
# File 'lib/mrkt/concerns/crud_leads.rb', line 55

def merge_leads(winning_lead_id, losing_lead_ids, merge_in_crm: false)
  params = {}

  params[:mergeInCRM] = merge_in_crm
  params[:leadIds] = losing_lead_ids if losing_lead_ids

  query_params = Mrkt::Faraday::ParamsEncoder.encode(params)

  post_json("/rest/v1/leads/#{winning_lead_id}/merge.json?#{query_params}")
end