imperituroard 1.0.8 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5e7e99efd1a73f476d513d802842f3f0433cd5be
4
- data.tar.gz: 760abd30d5d6ea6419c0f4195c08b9dca3d73537
3
+ metadata.gz: 44204f257643647687e7d62d06c363274cad09f3
4
+ data.tar.gz: 710581ba122cda979fd1989107dd981f028c456e
5
5
  SHA512:
6
- metadata.gz: 6f8d0903a392cf44f300612e621ea34647cf5158c67dbd2f0fa75c7470e867e48a3d94b0676f666ed50ea6e9b40d6702467ac9a05ea9737831fe9cf024e8903f
7
- data.tar.gz: 24741e66dc260aaef273175b302f840a89b4ffb7b25395e73bc1d087661f89cd54130e7c49076d4572c782a4a574adfff19c495f099ce1ac044c004d435c78dd
6
+ metadata.gz: fd5089b028b66fb283f57a0f5a870113ba4ad0c183c056937c2440b09c38c27d5166cb4d8670b95aa8da4f083cb6abcbe981b61a0474eb6cc1a8caeeda44a133
7
+ data.tar.gz: c5a0e5737f947b4dfcd360170309cf8bf2c955532b35e3f93e84280d1ee39c8a0751cf7009dbcff36c9da2afcc73fd351e8531135aed8612572966d6184ec63a
@@ -168,6 +168,10 @@ class Iot
168
168
  iot_connector.add_device_to_prof_2(login, imei_list, real_ip, remote_ip)
169
169
  end
170
170
 
171
+ def add_device_to_profile2(request_f, real_ip, remote_ip)
172
+ iot_connector.add_device_to_prof2_2(request_f, real_ip, remote_ip)
173
+ end
174
+
171
175
 
172
176
  #!!2 Find device (only mongo datebase. IOT platform not need)
173
177
  # procedure for data selection from mongo database.
@@ -270,10 +274,19 @@ class Iot
270
274
  mongo_client.audit_logger(proc_name, src_ip, input_json, output_json, real_ip)
271
275
  end
272
276
 
277
+
278
+ ####################################################################
279
+ #######technological procedures
280
+ ####################################################################
281
+ def delete_all_iot_device_in_db
282
+ iot_connector.delete_all_devices_in_database
283
+ end
284
+
273
285
  def test111
274
286
  iot_connector.test1278493
275
287
  end
276
288
 
289
+
277
290
  end
278
291
 
279
292
 
@@ -131,9 +131,174 @@ class IotFunctions_2
131
131
 
132
132
  #########
133
133
 
134
+ if aaa.key?("type") && !aaa.key?("device_type")
135
+ aaa["device_type"] = aaa["type"]
136
+ aaa = internal_func.delete_key_hash(aaa, "type")
137
+ end
138
+
139
+ aaa = internal_func.hash_val_to_string(aaa)
134
140
 
135
141
  if credentials[:code] == 200
136
142
 
143
+ begin
144
+ dev_name = aaa["imei"].to_s
145
+
146
+ #get {"model"=>"BGT_PPMC", "ManufacturerID"=>"unknown", "ManufacturerNAME"=>"unknown", "device_type"=>"unknown"}
147
+ #from database
148
+ model_data = mongo_client.get_device_type_info_universal(aaa["device_type"])
149
+ profile_data = mongo_client.get_profile_universal(aaa["profile"])
150
+ p profile_data
151
+ p model_data
152
+ p "model_data"
153
+ resss = hua_aceanconnect_connector.add_new_device_on_huawei(credentials[:body][:app_id],
154
+ credentials[:body][:secret],
155
+ aaa["imei"],
156
+ dev_name,
157
+ aaa["description"],
158
+ model_data[:body]["device_type"],
159
+ aaa["profile"],
160
+ model_data[:body]["ManufacturerID"],
161
+ model_data[:body]["ManufacturerNAME"],
162
+ model_data[:body]["model"]
163
+ )
164
+ if resss[:code]=="200"
165
+ if resss[:body].key?("error_code") && resss[:body]["error_code"] != 200
166
+ not_processed_list.append({:imei => aaa["imei"], :error => resss})
167
+ else
168
+ s1 = aaa
169
+ s1[:huadata] = resss
170
+ s1[:created] = DateTime.now
171
+ s1["device_type"] = model_data[:body]["model"]
172
+ s1["profile"] = profile_data["profile_id"]
173
+ added_on_iot_platf.append(s1)
174
+ end
175
+ else
176
+ not_processed_list.append({:imei => aaa["imei"], :error => resss})
177
+ end
178
+ rescue
179
+ not_processed_list.append({:imei => aaa["imei"], :error => "Unknown error with insertion imei on IOT platform"})
180
+ end
181
+ #########end iot platform logic#######
182
+
183
+ else
184
+ resss_err = {:code => 400, :result => "IOT platform credentials not found"}
185
+ not_processed_list.append({:imei => aaa["imei"], :error => resss_err})
186
+ end
187
+
188
+ end
189
+
190
+ if added_on_iot_platf.length != 0
191
+ mongo_client.imei_insert_list(added_on_iot_platf)
192
+ resp_out = {:code => 200, :result => "Data processed", :body => {:imei_processed => added_on_iot_platf, :error_list => not_processed_list}}
193
+ else
194
+ resp_out = {:code => 202, :result => "Empty list. Nothing for insertion", :body => {:imei_processed => added_on_iot_platf, :error_list => not_processed_list}}
195
+ end
196
+ else
197
+ resp_out = {:code => 202, :result => "Nothing for insertion", :body => {:imei_processed => added_on_iot_platf, :error_list => not_processed_list}}
198
+ end
199
+ rescue
200
+ resp_out = {:code => 505, :result => "Error with database communication"}
201
+ end
202
+ else
203
+ resp_out = {:code => 509, :result => "Input data invalid"}
204
+ end
205
+ end
206
+ rescue
207
+ resp_out = {:code => 507, :result => "Unknown SDK error"}
208
+ end
209
+ thr1.join
210
+
211
+ resp_out[:body][:tosoapgw] = internal_func.iot_create_dev_soapgw_answer(input_json, resp_out)
212
+ mongo_client.audit_logger("add_device_to_profile", remote_ip, input_json, resp_out, real_ip, {})
213
+ resp_out
214
+ end
215
+
216
+
217
+
218
+ def add_device_to_prof2_2(request_full, real_ip, remote_ip)
219
+
220
+ #{"autorization"=>{"login"=>"test", "token"=>"tE3aFvs27"}, "devlist"=>[{"devices"=>{"imei"=>123419520034999, "type"=>"1000002", "profile"=>0}}]}
221
+
222
+ login = request_full["autorization"]["login"]
223
+
224
+ im_li =[]
225
+
226
+ for sd in request_full["devlist"]
227
+ im_li.append(sd["devices"])
228
+ end
229
+ imei_list = im_li
230
+
231
+ input_json = {:request_full => request_full}
232
+ resp_out = {}
233
+ begin
234
+
235
+ thr1 = Thread.new do
236
+ if add_functions_connector.check_input_1(login, imei_list)[:code]==200
237
+
238
+ imei = []
239
+ list1 = {}
240
+ for_insert = []
241
+ not_processed_list = []
242
+ processed_list = []
243
+
244
+ for ii in imei_list
245
+ valid_resp = internal_func.imei_validate(ii["imei"])
246
+ if valid_resp[:checked]
247
+ list1[ii["imei"]] = ii
248
+ imei.append(ii["imei"])
249
+ else
250
+ not_processed_list.append({:imei => ii["imei"], :error => valid_resp[:result]})
251
+ end
252
+ end
253
+
254
+ if imei != []
255
+ list_checked = mongo_client.check_imei_exists(imei)
256
+
257
+ for ss in list_checked[:body][:exists]
258
+ not_processed_list.append({:imei => ss, :error => "Device exists in database"})
259
+ p ss
260
+ p "ss"
261
+ p list_checked
262
+ end
263
+
264
+ for jj in list_checked[:body][:not_exists]
265
+ begin
266
+ get_login_info = mongo_client.check_login_prof_perm_id_one(login, list1[jj]["profile"])[:code]
267
+ if get_login_info==200
268
+ for_insert.append(list1[jj])
269
+ else
270
+ not_processed_list.append({:imei => list1[jj], :error => "Permission denied for this profile"})
271
+ end
272
+ rescue
273
+ not_processed_list.append({:imei => list1[jj], :error => "Unknown error"})
274
+ end
275
+ end
276
+ end
277
+
278
+ begin
279
+ added_on_iot_platf = []
280
+ if for_insert != []
281
+ ##Logic for IOT Platform connection###
282
+
283
+
284
+ for aaa in for_insert
285
+
286
+ #########change 2020.05.11. imperituroard
287
+ #########replace process for get iot app_id and password from users to profile
288
+
289
+ #credentials = mongo_client.get_iot_oceanconnect_credent(login)
290
+ credentials = mongo_client.get_iot_oceanconn_credent_2(aaa["profile"])
291
+
292
+ #########
293
+
294
+ if aaa.key?("type") && !aaa.key?("device_type")
295
+ aaa["device_type"] = aaa["type"]
296
+ aaa = internal_func.delete_key_hash(aaa, "type")
297
+ end
298
+
299
+ aaa = internal_func.hash_val_to_string(aaa)
300
+
301
+ if credentials[:code] == 200
137
302
 
138
303
  begin
139
304
  dev_name = aaa["imei"].to_s
@@ -141,6 +306,8 @@ class IotFunctions_2
141
306
  #get {"model"=>"BGT_PPMC", "ManufacturerID"=>"unknown", "ManufacturerNAME"=>"unknown", "device_type"=>"unknown"}
142
307
  #from database
143
308
  model_data = mongo_client.get_device_type_info_universal(aaa["device_type"])
309
+ profile_data = mongo_client.get_profile_universal(aaa["profile"])
310
+ p profile_data
144
311
  p model_data
145
312
  p "model_data"
146
313
  resss = hua_aceanconnect_connector.add_new_device_on_huawei(credentials[:body][:app_id],
@@ -161,6 +328,8 @@ class IotFunctions_2
161
328
  s1 = aaa
162
329
  s1[:huadata] = resss
163
330
  s1[:created] = DateTime.now
331
+ s1["device_type"] = model_data[:body]["model"]
332
+ s1["profile"] = profile_data["profile_id"]
164
333
  added_on_iot_platf.append(s1)
165
334
  end
166
335
  else
@@ -200,7 +369,7 @@ class IotFunctions_2
200
369
  thr1.join
201
370
 
202
371
  resp_out[:body][:tosoapgw] = internal_func.iot_create_dev_soapgw_answer(input_json, resp_out)
203
- mongo_client.audit_logger("add_device_to_profile", remote_ip, input_json, resp_out, real_ip)
372
+ mongo_client.audit_logger("add_device_to_profile", remote_ip, input_json, resp_out, real_ip, {})
204
373
  resp_out
205
374
  end
206
375
 
@@ -263,7 +432,7 @@ class IotFunctions_2
263
432
 
264
433
  resp_out[:data][:tosoapgw] = add_functions_connector.iot_query_dev_soapgw_answer(input_json, resp_out)
265
434
 
266
- mongo_client.audit_logger("device_find", remote_ip, input_json, resp_out, real_ip)
435
+ mongo_client.audit_logger("device_find", remote_ip, input_json, resp_out, real_ip, {})
267
436
  resp_out
268
437
 
269
438
  end
@@ -435,7 +604,7 @@ class IotFunctions_2
435
604
  end
436
605
 
437
606
  thr3.join
438
- mongo_client.audit_logger("imei_replace", remote_ip, input_json, resp_out, real_ip)
607
+ mongo_client.audit_logger("imei_replace", remote_ip, input_json, resp_out, real_ip, {})
439
608
 
440
609
  resp_out
441
610
 
@@ -522,7 +691,7 @@ class IotFunctions_2
522
691
  resp_out = {:code => 507, :result => "Unknown SDK error"}
523
692
  end
524
693
  thr4.join
525
- mongo_client.audit_logger("device_remove", remote_ip, input_json, resp_out, real_ip)
694
+ mongo_client.audit_logger("device_remove", remote_ip, input_json, resp_out, real_ip, {})
526
695
  resp_out
527
696
  end
528
697
 
@@ -602,7 +771,7 @@ class IotFunctions_2
602
771
  resp_out = {:code => 507, :result => "Unknown SDK error"}
603
772
  end
604
773
  thr5.join
605
- mongo_client.audit_logger("device_add_address", remote_ip, input_json, resp_out, real_ip)
774
+ mongo_client.audit_logger("device_add_address", remote_ip, input_json, resp_out, real_ip, {})
606
775
  resp_out
607
776
  end
608
777
 
@@ -680,7 +849,7 @@ class IotFunctions_2
680
849
  resp_out = {:code => 507, :result => "Unknown SDK error"}
681
850
  end
682
851
  thr6.join
683
- mongo_client.audit_logger("device_remove", remote_ip, input_json, resp_out, real_ip)
852
+ mongo_client.audit_logger("device_remove", remote_ip, input_json, resp_out, real_ip, {})
684
853
  resp_out
685
854
  end
686
855
 
@@ -708,7 +877,7 @@ class IotFunctions_2
708
877
  end
709
878
  end
710
879
  thr7.join
711
- mongo_client.audit_logger("autorize_subscriber", remote_ip, input_json, resp_out, real_ip)
880
+ mongo_client.audit_logger("autorize_subscriber", remote_ip, input_json, resp_out, real_ip, {})
712
881
  resp_out
713
882
  end
714
883
 
@@ -766,7 +935,7 @@ class IotFunctions_2
766
935
  }
767
936
  resp_out = {:code => 507, :result => "Unknown SDK error", :body => {:tosoapgw => tosoapgw}}
768
937
  end
769
- mongo_client.audit_logger("get_available_prof_2", remote_ip, input_params, resp_out, real_ip)
938
+ mongo_client.audit_logger("get_available_prof_2", remote_ip, input_params, resp_out, real_ip, {})
770
939
  resp_out
771
940
  end
772
941
 
@@ -822,7 +991,7 @@ class IotFunctions_2
822
991
  }
823
992
  resp_out = {:code => 507, :result => "Unknown SDK error", :body => {:tosoapgw => tosoapgw}}
824
993
  end
825
- mongo_client.audit_logger("get_available_types_2", remote_ip, input_params, resp_out, real_ip)
994
+ mongo_client.audit_logger("get_available_types_2", remote_ip, input_params, resp_out, real_ip, {})
826
995
  resp_out
827
996
  end
828
997
 
@@ -893,7 +1062,7 @@ class IotFunctions_2
893
1062
  }
894
1063
  resp_out = {:code => 507, :result => "Unknown SDK error", :body => {:tosoapgw => tosoapgw}}
895
1064
  end
896
- mongo_client.audit_logger("get_available_types_2", remote_ip, input_params, resp_out, real_ip)
1065
+ mongo_client.audit_logger("get_available_types_2", remote_ip, input_params, resp_out, real_ip, {})
897
1066
  resp_out
898
1067
  end
899
1068
 
@@ -923,7 +1092,7 @@ class IotFunctions_2
923
1092
  rescue
924
1093
  output_answ = {:code => 507, :result => "Unknown SDK error"}
925
1094
  end
926
- mongo_client.audit_logger("get_info_data_type_2", remote_ip, input_params, output_answ, real_ip)
1095
+ mongo_client.audit_logger("get_info_data_type_2", remote_ip, input_params, output_answ, real_ip, {})
927
1096
  output_answ
928
1097
  end
929
1098
 
@@ -954,7 +1123,7 @@ class IotFunctions_2
954
1123
  rescue
955
1124
  output_answ = {:code => 507, :result => "Unknown SDK error"}
956
1125
  end
957
- mongo_client.audit_logger("get_info_data_profile_2", remote_ip, input_params, output_answ, real_ip)
1126
+ mongo_client.audit_logger("get_info_data_profile_2", remote_ip, input_params, output_answ, real_ip, {})
958
1127
  output_answ
959
1128
  end
960
1129
 
@@ -1130,7 +1299,7 @@ class IotFunctions_2
1130
1299
  thr13set.join
1131
1300
 
1132
1301
  output_answ = {:code => 200, :result => "Success", :body => {:to_soap_gw => answ_to_soapgw, :not_processed_list => not_processed_list, :processed_list => processed_list}}
1133
- mongo_client.audit_logger("set_data_replace_2", remote_ip, input_params, output_answ, real_ip)
1302
+ mongo_client.audit_logger("set_data_replace_2", remote_ip, input_params, output_answ, real_ip, {})
1134
1303
  output_answ
1135
1304
  end
1136
1305
 
@@ -1212,6 +1381,31 @@ class IotFunctions_2
1212
1381
  end
1213
1382
 
1214
1383
 
1384
+
1385
+
1386
+
1387
+
1388
+ ################################################
1389
+ ############technology procedures###############
1390
+ ################################################
1391
+
1392
+ def delete_all_devices_in_database
1393
+
1394
+ imei_list = []
1395
+ all_imei = mongo_client.get_all_imei_from_db
1396
+ all_imei[:body].each do |immm|
1397
+ imei_list.append(immm["imei"])
1398
+ end
1399
+
1400
+ imei_list.each do |del_imei|
1401
+ p del_imei
1402
+ self.device_remove_2("test", del_imei, "localhost", "localhost")
1403
+ end
1404
+ end
1405
+
1406
+
1407
+
1408
+
1215
1409
  #for internal use. Add new device model
1216
1410
  def add_model_to_mongo(model, manufacture_id, manufacture_name, device_type, description, note)
1217
1411
  model = {
@@ -25,6 +25,12 @@ class HuaIot
25
25
  @client_iot_mongo = MongoIot.new(mongo_ip, mongo_port, mongo_database)
26
26
  end
27
27
 
28
+ def valid_json?(json)
29
+ JSON.parse(json)
30
+ rescue JSON::ParserError => e
31
+ json
32
+ end
33
+
28
34
  def parse_token(str)
29
35
  begin
30
36
  dd = str.split(",")
@@ -79,7 +85,9 @@ class HuaIot
79
85
  p res.code
80
86
  p res.message
81
87
  p res.body.to_s
82
- out_resp = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
88
+
89
+ out_resp = {:code => res.code, :message => res.message, :body => valid_json?(res.body.to_s)}
90
+
83
91
  fff = {:func => "get_token",
84
92
  :iot_fun => "",
85
93
  :req_header => {:content_type => 'application/x-www-form-urlencoded',
@@ -120,7 +128,9 @@ class HuaIot
120
128
  request.content_type = 'application/json'
121
129
  request.body = URI.encode_www_form(data)
122
130
  res = https.request(request)
123
- out_resp = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
131
+ #JSON.parse(res.body.to_s)
132
+ out_resp = {:code => res.code, :message => res.message, :body => valid_json?(res.body.to_s) }
133
+
124
134
  fff = {:func => "token_logout",
125
135
  :iot_fun => "logout",
126
136
  :platform => "Huawei oceanconnect"
@@ -157,7 +167,7 @@ class HuaIot
157
167
  data = {nodeId: node_id}
158
168
  request.body = data.to_json
159
169
  res = https.request(request)
160
- out_resp = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
170
+ out_resp = {:code => res.code, :message => res.message, :body => valid_json?(res.body.to_s)}
161
171
  fff = {:func => "dev_register_verif_code_mode",
162
172
  :iot_fun => "Registering a Directly Connected Device (Verification Code Mode) (V2)",
163
173
  :req_header => {:content_type => 'application/json',
@@ -195,7 +205,7 @@ class HuaIot
195
205
  internal_func.printer_texter({:procedure => "dev_register_passw_code_mode2", :data => {:body => data_out, :url => url_string}}, "debug")
196
206
  request.body = data_out.to_json
197
207
  res = https.request(request)
198
- out_resp = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
208
+ out_resp = {:code => res.code, :message => res.message, :body => valid_json?(res.body.to_s)}
199
209
  fff = {:func => "dev_register_passw_code_mode2",
200
210
  :iot_fun => "2.2.4",
201
211
  :req_header => {:authorization => 'Bearer ' + token,
@@ -230,7 +240,7 @@ class HuaIot
230
240
  request.body = data_out
231
241
  res = https.request(request)
232
242
  p res.body.to_s
233
- out_resp = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
243
+ out_resp = {:code => res.code, :message => res.message, :body => valid_json?(res.body.to_s)}
234
244
  fff = {:func => "dev_reg_passw_code_mode2_2",
235
245
  :iot_fun => "2.2.4",
236
246
  :req_header => {:content_type => 'application/json',
@@ -262,7 +272,7 @@ class HuaIot
262
272
  request['app_key'] = app_id
263
273
  res = https.request(request)
264
274
  if res.body != nil
265
- out_resp = {:code => res.code, :message => res.message, :body => {:answ => JSON.parse(res.body.to_s)}}
275
+ out_resp = {:code => res.code, :message => res.message, :body => {:answ => valid_json?(res.body.to_s)}}
266
276
  else
267
277
  out_resp = {:code => res.code, :message => res.message, :body => {:answ => "no data"}}
268
278
  end
@@ -303,7 +313,7 @@ class HuaIot
303
313
  res = https.request(request)
304
314
  p res.body.to_s
305
315
  p res.code
306
- {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
316
+ {:code => res.code, :message => res.message, :body => valid_json?(res.body.to_s)}
307
317
  end
308
318
 
309
319
  #2.2.14 Querying Device Activation Status
@@ -323,7 +333,7 @@ class HuaIot
323
333
  request['Authorization'] = 'Bearer ' + token
324
334
  request['app_key'] = app_id
325
335
  res = https.request(request)
326
- output_ans = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
336
+ output_ans = {:code => res.code, :message => res.message, :body => valid_json?(res.body.to_s)}
327
337
  fff = {:func => "querying_device_activ_status",
328
338
  :iot_fun => "2.2.14",
329
339
  :req_header => {:content_type => 'application/json',
@@ -353,7 +363,7 @@ class HuaIot
353
363
  request['Authorization'] = 'Bearer ' + token
354
364
  request['app_key'] = app_id
355
365
  res = https.request(request)
356
- out_resp = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
366
+ out_resp = {:code => res.code, :message => res.message, :body => valid_json?(res.body.to_s)}
357
367
  fff = {:func => "querying_device_info",
358
368
  :iot_fun => "2.9.1",
359
369
  :req_header => {:authorization => 'Bearer ' + token,
@@ -384,7 +394,7 @@ class HuaIot
384
394
  req_body = {deviceIds: dev_list}
385
395
  request.body = req_body.to_json
386
396
  res = https.request(request)
387
- output_str = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
397
+ output_str = {:code => res.code, :message => res.message, :body => valid_json?(res.body.to_s)}
388
398
  fff = {:func => "querying_device_direct_conn",
389
399
  :iot_fun => "2.9.6",
390
400
  :req_header => {:authorization => 'Bearer ' + token,
@@ -414,7 +424,7 @@ class HuaIot
414
424
  request['Authorization'] = 'Bearer ' + token
415
425
  request['app_key'] = app_id
416
426
  res = https.request(request)
417
- output_ans = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
427
+ output_ans = {:code => res.code, :message => res.message, :body => valid_json?(res.body.to_s)}
418
428
 
419
429
  fff = {:func => "querying_device_type_list",
420
430
  :iot_fun => "2.9.19",
@@ -448,7 +458,7 @@ class HuaIot
448
458
  data = {deviceIds: dev_list}
449
459
  request.body = data.to_json
450
460
  res = https.request(request)
451
- output_ans = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
461
+ output_ans = {:code => res.code, :message => res.message, :body => valid_json?(res.body.to_s)}
452
462
  fff = {:func => "quer_dev_direct_conn_batches",
453
463
  :iot_fun => "2.9.6",
454
464
  :req_header => {:content_type => 'application/json',
@@ -485,7 +495,7 @@ class HuaIot
485
495
  p res.code
486
496
  p res.body
487
497
  if res.body != nil
488
- out_resp = {:code => res.code, :message => res.message, :body => {:answ => JSON.parse(res.body.to_s)}}
498
+ out_resp = {:code => res.code, :message => res.message, :body => {:answ => valid_json?(res.body.to_s)}}
489
499
  else
490
500
  out_resp = {:code => res.code, :message => res.message, :body => {:answ => "no data"}}
491
501
  end
@@ -65,6 +65,7 @@ class InternalFunc
65
65
  else
66
66
  output_params = {:code => 200, :result => "if_digit_or_string: Request processed. Its string", :body => {:string => true}}
67
67
  end
68
+ printer_texter({:input_params => input_params, :output_params => output_params}, "debug")
68
69
  output_params
69
70
 
70
71
  end
@@ -76,7 +77,6 @@ class InternalFunc
76
77
 
77
78
  output_info = {}
78
79
  begin
79
-
80
80
  if output_answer[:code] != 200
81
81
  deviceserr = []
82
82
  failednum = input_params[:imei_list].length
@@ -151,7 +151,7 @@ class InternalFunc
151
151
  else
152
152
  answer = {:code => 400, :result => "Invalid IMEI. Data is not integer", :checked => false}
153
153
  end
154
- printer_texter({:answer => answer, :input => input}, "debug")
154
+ printer_texter({:answer => answer, :input => input, :fun => "imei_validate"}, "debug")
155
155
  answer
156
156
  end
157
157
 
@@ -163,6 +163,35 @@ class InternalFunc
163
163
  v3.uniq - v2.uniq - v1.uniq
164
164
  end
165
165
 
166
+
167
+ #delete one key from hash
168
+ def delete_key_hash(hash_f, delete_key)
169
+ inp_fun = {:hash_f => hash_f, :delete_key => delete_key}
170
+ hash_f = hash_f.to_h
171
+ out_data = {}
172
+ res = {}
173
+ hash_f.each do |ggg|
174
+ if ggg[0].to_s != delete_key.to_s
175
+ res[ggg[0]] = ggg[1]
176
+ end
177
+ end
178
+ out_data = res
179
+ printer_texter({:out_data => out_data, :inp_fun => inp_fun, :fun => "delete_key_hash" }, "debug")
180
+ out_data
181
+ end
182
+
183
+
184
+ #process hash array. Transform keys to string keys
185
+ def hash_val_to_string(hash_full)
186
+ resp = {}
187
+ hash_full.each do |hsh|
188
+ resp[hsh[0].to_s] = hsh[1]
189
+ end
190
+ resp
191
+ end
192
+
193
+
194
+
166
195
  def test()
167
196
  p "eeeeeeeeeeeeeeeeeeeeeeee"
168
197
  end
@@ -20,7 +20,7 @@ class MongoIot
20
20
  @internal_func = InternalFunc.new
21
21
  end
22
22
 
23
- def audit_logger(proc_name, src_ip, input_json, output_json, real_ip)
23
+ def audit_logger(proc_name, src_ip, input_json, output_json, real_ip, add_params)
24
24
  out_resp = {}
25
25
  begin
26
26
  current = internal_func.datetimenow
@@ -30,7 +30,8 @@ class MongoIot
30
30
  :date => current,
31
31
  :sender => {:src_ip => src_ip, :real_ip => real_ip},
32
32
  :input_params => input_json,
33
- :output_params => output_json
33
+ :output_params => output_json,
34
+ :add_params => add_params
34
35
  }
35
36
  result = collection.insert_one(doc)
36
37
  out_resp = {:code => 200, :result => "audit_logger: Request completed successfully", :body => result}
@@ -554,6 +555,7 @@ class MongoIot
554
555
 
555
556
  #universal procedure. Use id or name
556
557
  def get_device_type_info_universal(device_model)
558
+ input_fun = {:device_model => device_model}
557
559
  out_resp = {}
558
560
  begin
559
561
  as = internal_func.if_digit_or_string(device_model)
@@ -587,7 +589,7 @@ class MongoIot
587
589
  rescue
588
590
  out_resp = {:code => 500, :result => "get_device_type_info_universal: procedure error", :body => {"model" => device_model, "ManufacturerID" => "unknown", "ManufacturerNAME" => "unknown", "device_type" => "unknown"}}
589
591
  end
590
- internal_func.printer_texter(out_resp, "debug")
592
+ internal_func.printer_texter({:input_fun => input_fun, :out_resp => out_resp, :fun => "get_device_type_info_universal"}, "debug")
591
593
  out_resp
592
594
  end
593
595
 
@@ -686,6 +688,8 @@ class MongoIot
686
688
 
687
689
  #universal procedure. put there profile name or id in string or int
688
690
  def get_profile_universal(profile)
691
+ input_inf = {:profile => profile}
692
+ out = {}
689
693
  inn = internal_func.if_digit_or_string(profile)
690
694
  out = {}
691
695
  if inn[:body][:string]
@@ -693,10 +697,12 @@ class MongoIot
693
697
  else
694
698
  out = self.get_profile_name_by_id(profile.to_i)
695
699
  end
700
+ internal_func.printer_texter({:input_inf => input_inf, :out => out, :fun => "get_profile_universal"}, "debug")
696
701
  out
697
702
  end
698
703
 
699
704
  def modify_attr_mongo_universal(imei, attribute)
705
+ input_add = {:imei => imei, :attribute => attribute}
700
706
  out_resp = {}
701
707
  begin
702
708
  collection = client[:device_imei]
@@ -709,7 +715,25 @@ class MongoIot
709
715
  rescue
710
716
  out_resp = {:code => 507, :result => "modify_attr_mongo_universal: Unknown SDK error"}
711
717
  end
712
- internal_func.printer_texter(out_resp, "debug")
718
+ internal_func.printer_texter({:input_add => input_add, :out_resp => out_resp, :fun => "modify_attr_mongo_universal"}, "debug")
719
+ out_resp
720
+ end
721
+
722
+
723
+ def get_all_imei_from_db
724
+ out_resp = {}
725
+ begin
726
+ req2 = []
727
+ result_ps = []
728
+ collection = client[:device_imei]
729
+ collection.find({}, {:_id => 0}).each {|row|
730
+ result_ps.append(row)
731
+ }
732
+ out_resp = {:code => 200, :result => "get_all_imei_from_db: Request completed successfully", :body => result_ps}
733
+ rescue
734
+ out_resp = {:code => 507, :result => "get_all_imei_from_db: Unknown SDK error"}
735
+ end
736
+ #internal_func.printer_texter(out_resp, "debug")
713
737
  out_resp
714
738
  end
715
739
 
@@ -1,4 +1,4 @@
1
1
  module Imperituroard
2
- VERSION = "1.0.8"
2
+ VERSION = "1.1.3"
3
3
  end
4
4
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imperituroard
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.8
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dzmitry Buynovskiy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-09 00:00:00.000000000 Z
11
+ date: 2020-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler