Class: Crm_2

Inherits:
Object
  • Object
show all
Defined in:
lib/imperituroard/projects/mhub/subs/dabrab/dabrab_platform.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(crm_callback_url, crm_login, crm_password, telegram_api_url, telegram_chat_id, log_level) ⇒ Crm_2

Returns a new instance of Crm_2.



8
9
10
11
12
13
14
15
# File 'lib/imperituroard/projects/mhub/subs/dabrab/dabrab_platform.rb', line 8

def initialize(crm_callback_url, , crm_password, telegram_api_url, telegram_chat_id, log_level)
  @crm_callback_url = crm_callback_url
  @crm_login = 
  @log_level = log_level
  @crm_password = crm_password
  @internal_func = InternalFunc.new
  @telegram_connector = Telegram_2.new(telegram_api_url, telegram_chat_id)
end

Instance Attribute Details

#crm_callback_urlObject

Returns the value of attribute crm_callback_url.



6
7
8
# File 'lib/imperituroard/projects/mhub/subs/dabrab/dabrab_platform.rb', line 6

def crm_callback_url
  @crm_callback_url
end

#crm_loginObject

Returns the value of attribute crm_login.



6
7
8
# File 'lib/imperituroard/projects/mhub/subs/dabrab/dabrab_platform.rb', line 6

def 
  @crm_login
end

#crm_passwordObject

Returns the value of attribute crm_password.



6
7
8
# File 'lib/imperituroard/projects/mhub/subs/dabrab/dabrab_platform.rb', line 6

def crm_password
  @crm_password
end

#internal_funcObject

Returns the value of attribute internal_func.



6
7
8
# File 'lib/imperituroard/projects/mhub/subs/dabrab/dabrab_platform.rb', line 6

def internal_func
  @internal_func
end

#log_levelObject

Returns the value of attribute log_level.



6
7
8
# File 'lib/imperituroard/projects/mhub/subs/dabrab/dabrab_platform.rb', line 6

def log_level
  @log_level
end

#telegram_connectorObject

Returns the value of attribute telegram_connector.



6
7
8
# File 'lib/imperituroard/projects/mhub/subs/dabrab/dabrab_platform.rb', line 6

def telegram_connector
  @telegram_connector
end

Instance Method Details

#crm_status_2(crm_payload, slice_num) ⇒ Object



17
18
19
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/imperituroard/projects/mhub/subs/dabrab/dabrab_platform.rb', line 17

def crm_status_2(crm_payload, slice_num)

  input_params = {:crm_payload => crm_payload}
  output_params = {}
  request_message = {}

  begin

    internal_func.printer_texter({:input => 'Start process', :procedure => "Crm_2.crm_status_2"}, log_level)


    thr_crm_status_2 = Thread.new do

      internal_func.printer_texter({:input => 'Thread start', :procedure => 'Crm_2.crm_status_2'}, log_level)

      partnnn = crm_payload[:results].each_slice(slice_num).to_a

      partnnn.each { |one_part_reports|

        crm_payload2 = {:results => one_part_reports }


        uri = URI(crm_callback_url)
        #8 - client id

        internal_func.printer_texter({:input => 'before net', :procedure => 'Crm_2.crm_status_2'}, log_level)

        https = Net::HTTP.new(uri.host, uri.port)
        https.use_ssl = true
        https.verify_mode = OpenSSL::SSL::VERIFY_NONE
        req = Net::HTTP::Post.new(uri.path, initheader = {:"Content-Type" => 'application/json'})

        req.basic_auth , crm_password

        req["Content-Type"] = "application/json"
        req["Accept"] = "application/json"

        internal_func.printer_texter({:input => {:crm_payload2 => crm_payload2}, :procedure => "Crm_2.crm_status_2"}, log_level)


        req.body = crm_payload2.to_json

        internal_func.printer_texter({:input => "Before send request to crm", :procedure => "Crm_2.crm_status_2"}, log_level)

        begin

          res = https.request(req)
          internal_func.printer_texter({:input => "After send request to crm Ok", :procedure => "Crm_2.crm_status_2"}, log_level)
          internal_func.printer_texter({:input => {:res_code => res.code, :res_body => res.body.to_s}, :procedure => "Crm_2.crm_status_2"}, log_level)

        rescue

          res = 'dabrabyt error'
          internal_func.printer_texter({:input => "After send request to crm error", :procedure => "Crm_2.crm_status_2"}, log_level)
          internal_func.printer_texter({:input => {:res_code => "500", :res_body => res}, :procedure => "Crm_2.crm_status_2"}, log_level)

        end

      }

      output_params = {:code => 200,
                       :result => "Crm_2.crm_status_2: Request processed",
                       :body => {:request_message => crm_payload,
                                 :res_code => "200",
                                 :res_body => ""}}
      #p res.body
    end
    thr_crm_status_2.join

  rescue
    output_params = {:code => 500, :result => "Crm_2.crm_status_2: Something wrong", :body => {:request_message => request_message}}
    telegram_connector.telegram_message(output_params)
  end
  internal_func.printer_texter({:input => input_params, :output => output_params, :procedure => "Crm_2.crm_status_2"}, log_level)
  output_params

end