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
38
39
40
41
42
43
44
45
46
# File 'lib/bitrix_webhook/CRM/lead.rb', line 20

def self.add(options = {})
  options = config.merge(options )
  query_params = {
      fields:
          { TITLE: "#{options[:fname]} #{options[:lname]}",
            NAME: options[:fname],
            LAST_NAME: options[:lname],
            STATUS_ID: options[:status_id],
            ADDRESS_CITY: options[:address_city],
            ADDRESS_COUNTRY: options[:address_country],
            ADDRESS_REGION: options[:address_region],
            OPENED: options[:opened],
            ASSIGNED_BY_ID: options[:assigned_by_id],
            PHONE: { '0': { VALUE: options[:phone] } },
            EMAIL: { '0': { VALUE: options[:email] } } },
      params: {
          REGISTER_SONET_EVENT: options[:register_sonet_event]
      }
  }.to_query
  post_url = base_url('add').to_s + query_params

  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

.get(id) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/bitrix_webhook/CRM/lead.rb', line 48

def self.get(id)
  query_params = {
    id: id
  }.to_query
  get_url = base_url('get').to_s + query_params
  begin
    JSON.parse(HTTP.get(get_url).body)
  rescue => e
    {error:e}.to_json
  end
end

.update_one_filed(id, filed, value) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/bitrix_webhook/CRM/lead.rb', line 60

def self.update_one_filed(id,filed,value)
  query_params = {
      id: id,
      fields: {
          filed => value
      }
  }.to_query
  post_url = base_url('update').to_s + query_params


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