Module: BitrixWebhook::TASK::ITEM

Defined in:
lib/bitrix_webhook/task/item.rb

Class Method Summary collapse

Class Method Details

.add(options = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/bitrix_webhook/task/item.rb', line 15

def self.add(options = {})
  options = config.merge(options)
  query_params = {
      fields: {
          TITLE: options[:title],
          RESPONSIBLE_ID: options[:responsible_id],
          DEADLINE: (DateTime.now + 1.day).strftime("%FT%T%:z"),
          UF_CRM_TASK: ["L_#{options[:crm_user_id]}"]
      },
  }.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



11
12
13
# File 'lib/bitrix_webhook/task/item.rb', line 11

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

.configObject



5
6
7
8
9
# File 'lib/bitrix_webhook/task/item.rb', line 5

def self.config
  {
      responsible_id: BitrixWebhook.webhook_user
  }
end

.getdata(task_id) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/bitrix_webhook/task/item.rb', line 53

def self.getdata(task_id)
  query_params = {
      TASKID: task_id
  }.to_query
  post_url = base_url('getdata').to_s + query_params

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

.raw_add(options = {}) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/bitrix_webhook/task/item.rb', line 34

def self.raw_add(options = {})
  options = config.merge(options)
  fields = {}
  options.each_pair do |k,v|
    fields.merge!({k.upcase => v})
  end
  query_params = {
      fields: fields,
  }.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