Module: BitrixWebhook::CRM::LEAD

Defined in:
lib/bitrix_webhook/CRM/lead.rb

Class Method Summary collapse

Class Method Details

.add(options = {}) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/bitrix_webhook/CRM/lead.rb', line 20

def self.add(options = {})
  options = config.merge(options )
  post_url =  base_url("add").to_s + "fields%5BTITLE%5D=#{options[:fname].to_s + '+' + options[:lname].to_s}&" +
      "fields%5BNAME%5D=#{options[:fname]}&" +
      "fields%5BLAST_NAME%5D=#{options[:lname]}&" +
      "fields%5BSTATUS_ID%5D=#{options[:status_id]}&" +
      "fields%5BOPENED%5D=#{options[:opened]}&" +
      "fields%5BASSIGNED_BY_ID%5D=#{options[:assigned_by_id]}&" +
      "fields%5BPHONE%5D%5B0%5D%5BVALUE%5D=#{options[:phone]}&" +
      "fields%5BEMAIL%5D%5B0%5D%5BVALUE%5D=#{options[:email]}&" +
      "params%5BREGISTER_SONET_EVENT%5D=#{options[:register_sonet_event]}"

  begin
    JSON.parse(HTTP.post(post_url).body)
  rescue => e
    {error:e}.to_json
  end
end

.base_url(method) ⇒ Object



16
17
18
# File 'lib/bitrix_webhook/CRM/lead.rb', line 16

def self.base_url(method)
  "https://#{BitrixWebhook.bitrix24_url}/rest/#{BitrixWebhook.webhook_user}/#{ BitrixWebhook.hook}/crm.lead.#{method}?"
end

.configObject



5
6
7
8
9
10
11
12
13
14
# File 'lib/bitrix_webhook/CRM/lead.rb', line 5

def self.config
  {
      fname: '',
      lname: '',
      status_id: 'NEW',
      opened:  'Y',
      assigned_by_id: BitrixWebhook.webhook_user,
      register_sonet_event: 'Y',
  }
end

.update_one_filed(id, filed, value) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/bitrix_webhook/CRM/lead.rb', line 40

def self.update_one_filed(id,filed,value)
  post_url =  base_url("update").to_s + "id=#{id}&fields%5B#{filed}%5D=#{value}"
  begin
    JSON.parse(HTTP.post(post_url).body)
  rescue => e
    {error:e}.to_json
  end
end