imperituroard 1.0.5 → 1.1.1

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: 4f3be6181f0232b7cf9ffcbc83e64b250c193ba8
4
- data.tar.gz: 1bec083ea1a987aa71a5387f01ee66d414c82fc2
3
+ metadata.gz: d07f8ba8173fac1753c044f8f0e6e06a6598e7b5
4
+ data.tar.gz: 3170f430dec13119ba8ba95de2224b54cdc35d1e
5
5
  SHA512:
6
- metadata.gz: 3e2c3e4efb2ae8069803ddafaa4fcf55dda9b9cf6759444fe21ba829927d3c1067003df4a5c0ab51338e43cf2fb831035fee1c64a0b384869610078ad2c15842
7
- data.tar.gz: 0b4e145d35a75cbc40f75fe84fb1d72b6ae3fd749ab8a47ad6ecc405c50fee1e2972b03a2f1ca1e270107a645a72f9bc47f10e18c1e97c8121214528fa72b5e5
6
+ metadata.gz: fbb564b3afc160a77cc9b8e9e0dffb2675b5a89cfc9e7042ca62348aa29cd0057428c35090066ab80db51dbe3b2ee466817fb9a5f882a2cc5fe4082a0bbac184
7
+ data.tar.gz: 7ac4309248422d5d326b1e9c5ad98d1595ec79bc6f3e51bb9ae31632225e465b7b4677d201f149c32004c72b897e7c182d61e143be863ec63d70c311d9e2a59f
@@ -0,0 +1,21 @@
1
+ <component name="ProjectRunConfigurationManager">
2
+ <configuration default="false" name="version" type="RubyRunConfigurationType" factoryName="Ruby">
3
+ <module name="imperituroard" />
4
+ <RUBY_RUN_CONFIG NAME="RUBY_ARGS" VALUE="-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)" />
5
+ <RUBY_RUN_CONFIG NAME="WORK DIR" VALUE="$MODULE_DIR$/lib/imperituroard" />
6
+ <RUBY_RUN_CONFIG NAME="SHOULD_USE_SDK" VALUE="false" />
7
+ <RUBY_RUN_CONFIG NAME="ALTERN_SDK_NAME" VALUE="" />
8
+ <RUBY_RUN_CONFIG NAME="myPassParentEnvs" VALUE="true" />
9
+ <envs />
10
+ <EXTENSION ID="BundlerRunConfigurationExtension" bundleExecEnabled="true" />
11
+ <EXTENSION ID="JRubyRunConfigurationExtension" NailgunExecEnabled="false" />
12
+ <EXTENSION ID="RubyCoverageRunConfigurationExtension" enabled="false" sample_coverage="true" track_test_folders="true" runner="rcov">
13
+ <COVERAGE_PATTERN ENABLED="true">
14
+ <PATTERN REGEXPS="/.rvm/" INCLUDED="false" />
15
+ </COVERAGE_PATTERN>
16
+ </EXTENSION>
17
+ <RUBY_RUN_CONFIG NAME="SCRIPT_PATH" VALUE="$MODULE_DIR$/lib/imperituroard/version.rb" />
18
+ <RUBY_RUN_CONFIG NAME="SCRIPT_ARGS" VALUE="" />
19
+ <method />
20
+ </configuration>
21
+ </component>
@@ -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,10 @@ 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
311
+ p model_data
312
+ p "model_data"
144
313
  resss = hua_aceanconnect_connector.add_new_device_on_huawei(credentials[:body][:app_id],
145
314
  credentials[:body][:secret],
146
315
  aaa["imei"],
@@ -159,6 +328,8 @@ class IotFunctions_2
159
328
  s1 = aaa
160
329
  s1[:huadata] = resss
161
330
  s1[:created] = DateTime.now
331
+ s1["device_type"] = model_data[:body]["model"]
332
+ s1["profile"] = profile_data["profile_id"]
162
333
  added_on_iot_platf.append(s1)
163
334
  end
164
335
  else
@@ -198,7 +369,7 @@ class IotFunctions_2
198
369
  thr1.join
199
370
 
200
371
  resp_out[:body][:tosoapgw] = internal_func.iot_create_dev_soapgw_answer(input_json, resp_out)
201
- 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, {})
202
373
  resp_out
203
374
  end
204
375
 
@@ -261,7 +432,7 @@ class IotFunctions_2
261
432
 
262
433
  resp_out[:data][:tosoapgw] = add_functions_connector.iot_query_dev_soapgw_answer(input_json, resp_out)
263
434
 
264
- 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, {})
265
436
  resp_out
266
437
 
267
438
  end
@@ -433,7 +604,7 @@ class IotFunctions_2
433
604
  end
434
605
 
435
606
  thr3.join
436
- 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, {})
437
608
 
438
609
  resp_out
439
610
 
@@ -520,7 +691,7 @@ class IotFunctions_2
520
691
  resp_out = {:code => 507, :result => "Unknown SDK error"}
521
692
  end
522
693
  thr4.join
523
- 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, {})
524
695
  resp_out
525
696
  end
526
697
 
@@ -600,7 +771,7 @@ class IotFunctions_2
600
771
  resp_out = {:code => 507, :result => "Unknown SDK error"}
601
772
  end
602
773
  thr5.join
603
- 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, {})
604
775
  resp_out
605
776
  end
606
777
 
@@ -678,7 +849,7 @@ class IotFunctions_2
678
849
  resp_out = {:code => 507, :result => "Unknown SDK error"}
679
850
  end
680
851
  thr6.join
681
- 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, {})
682
853
  resp_out
683
854
  end
684
855
 
@@ -706,7 +877,7 @@ class IotFunctions_2
706
877
  end
707
878
  end
708
879
  thr7.join
709
- 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, {})
710
881
  resp_out
711
882
  end
712
883
 
@@ -764,7 +935,7 @@ class IotFunctions_2
764
935
  }
765
936
  resp_out = {:code => 507, :result => "Unknown SDK error", :body => {:tosoapgw => tosoapgw}}
766
937
  end
767
- 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, {})
768
939
  resp_out
769
940
  end
770
941
 
@@ -820,7 +991,7 @@ class IotFunctions_2
820
991
  }
821
992
  resp_out = {:code => 507, :result => "Unknown SDK error", :body => {:tosoapgw => tosoapgw}}
822
993
  end
823
- 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, {})
824
995
  resp_out
825
996
  end
826
997
 
@@ -891,7 +1062,7 @@ class IotFunctions_2
891
1062
  }
892
1063
  resp_out = {:code => 507, :result => "Unknown SDK error", :body => {:tosoapgw => tosoapgw}}
893
1064
  end
894
- 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, {})
895
1066
  resp_out
896
1067
  end
897
1068
 
@@ -921,7 +1092,7 @@ class IotFunctions_2
921
1092
  rescue
922
1093
  output_answ = {:code => 507, :result => "Unknown SDK error"}
923
1094
  end
924
- 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, {})
925
1096
  output_answ
926
1097
  end
927
1098
 
@@ -952,7 +1123,7 @@ class IotFunctions_2
952
1123
  rescue
953
1124
  output_answ = {:code => 507, :result => "Unknown SDK error"}
954
1125
  end
955
- 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, {})
956
1127
  output_answ
957
1128
  end
958
1129
 
@@ -1059,11 +1230,12 @@ class IotFunctions_2
1059
1230
  if resss[:body].key?("error_code") && resss[:body]["error_code"] != 200
1060
1231
  not_processed_list.append({:imei => curr_dev["imei"], :error => resss})
1061
1232
  else
1233
+ p resss
1062
1234
  new_id_iot = resss[:body]
1063
1235
  new_profile_id = prof_new_id
1064
1236
  now_date = DateTime.now
1065
1237
  #finished success. update database
1066
- attribute = {profile: new_profile_id, device_type: model_data[:body]["model"], huadata: {body: new_id_iot}, updated: now_date}
1238
+ attribute = {profile: new_profile_id, device_type: model_data[:body]["model"], huadata: resss, updated: now_date}
1067
1239
  answ_mongo = mongo_client.modify_attr_mongo_universal(curr_dev["imei"].to_i, attribute)
1068
1240
  if answ_mongo[:code] != 200
1069
1241
  not_processed_list.append({:imei => curr_dev["imei"], :error => "Critical error. Mongo not updated", :mongo_err => answ_mongo})
@@ -1077,6 +1249,8 @@ class IotFunctions_2
1077
1249
  rescue
1078
1250
  not_processed_list.append({:imei => curr_dev["imei"], :error => "Unknown error with insertion imei on IOT platform"})
1079
1251
  end
1252
+ else
1253
+ not_processed_list.append({:imei => curr_dev["imei"], :error => "Something wrong with IOT platform"})
1080
1254
  end
1081
1255
  else
1082
1256
  not_processed_list.append({:imei => curr_dev["imei"], :error => "Not processed by iot platform. deviceId not found in mongoDB"})
@@ -1125,7 +1299,7 @@ class IotFunctions_2
1125
1299
  thr13set.join
1126
1300
 
1127
1301
  output_answ = {:code => 200, :result => "Success", :body => {:to_soap_gw => answ_to_soapgw, :not_processed_list => not_processed_list, :processed_list => processed_list}}
1128
- 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, {})
1129
1303
  output_answ
1130
1304
  end
1131
1305
 
@@ -1207,6 +1381,31 @@ class IotFunctions_2
1207
1381
  end
1208
1382
 
1209
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
+
1210
1409
  #for internal use. Add new device model
1211
1410
  def add_model_to_mongo(model, manufacture_id, manufacture_name, device_type, description, note)
1212
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(",")
@@ -54,6 +60,9 @@ class HuaIot
54
60
  def get_token(app_id, secret)
55
61
  internal_func.printer_texter("get_token: start. Step1, iput: app_id: #{app_id.to_s}, secret: #{secret.to_s}", "debug")
56
62
  out_resp = {}
63
+ fff = {}
64
+ data = {}
65
+ url_string = ""
57
66
  begin
58
67
  path = "/iocm/app/sec/v1.1.0/login"
59
68
  url_string = "https://" + platformip + ":" + platformport + path
@@ -73,16 +82,21 @@ class HuaIot
73
82
  request.content_type = 'application/x-www-form-urlencoded'
74
83
  request.body = URI.encode_www_form(data)
75
84
  res = https.request(request)
76
- out_resp = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
85
+ p res.code
86
+ p res.message
87
+ p res.body.to_s
88
+
89
+ out_resp = {:code => res.code, :message => res.message, :body => valid_json?(res.body.to_s)}
90
+
77
91
  fff = {:func => "get_token",
78
92
  :iot_fun => "",
79
93
  :req_header => {:content_type => 'application/x-www-form-urlencoded',
80
94
  :platform => "Huawei oceanconnect"
81
95
  }}
82
- client_iot_mongo.audit_iot_logger(fff, url_string, data, out_resp)
83
96
  rescue
84
97
  out_resp = {:code => 500, :message => "failed get token"}
85
98
  end
99
+ client_iot_mongo.audit_iot_logger(fff, url_string, data, out_resp)
86
100
  jjj = {:procedure => "get_token", :answ => out_resp}
87
101
  internal_func.printer_texter(jjj, "debug")
88
102
  out_resp
@@ -93,6 +107,9 @@ class HuaIot
93
107
 
94
108
  internal_func.printer_texter("token_logout Step1 token: #{token}", "debug")
95
109
  out_resp = {}
110
+ fff = {}
111
+ data = {}
112
+ url_string = ""
96
113
  begin
97
114
  path = "/iocm/app/sec/v1.1.0/logout"
98
115
  url_string = "https://" + platformip + ":" + platformport + path
@@ -111,15 +128,21 @@ class HuaIot
111
128
  request.content_type = 'application/json'
112
129
  request.body = URI.encode_www_form(data)
113
130
  res = https.request(request)
114
- 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
+
115
134
  fff = {:func => "token_logout",
116
135
  :iot_fun => "logout",
117
136
  :platform => "Huawei oceanconnect"
118
137
  }
119
- client_iot_mongo.audit_iot_logger(fff, url_string, data, out_resp)
138
+ p res.code
139
+ p res.message
140
+ p res.body.to_s
141
+
120
142
  rescue
121
143
  out_resp = {:code => 500, :message => "failed logout token"}
122
144
  end
145
+ client_iot_mongo.audit_iot_logger(fff, url_string, data, out_resp)
123
146
  jjj = {:procedure => "token_logout", :answ => out_resp}
124
147
  internal_func.printer_texter(jjj, "debug")
125
148
  out_resp
@@ -144,7 +167,7 @@ class HuaIot
144
167
  data = {nodeId: node_id}
145
168
  request.body = data.to_json
146
169
  res = https.request(request)
147
- 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)}
148
171
  fff = {:func => "dev_register_verif_code_mode",
149
172
  :iot_fun => "Registering a Directly Connected Device (Verification Code Mode) (V2)",
150
173
  :req_header => {:content_type => 'application/json',
@@ -182,7 +205,7 @@ class HuaIot
182
205
  internal_func.printer_texter({:procedure => "dev_register_passw_code_mode2", :data => {:body => data_out, :url => url_string}}, "debug")
183
206
  request.body = data_out.to_json
184
207
  res = https.request(request)
185
- 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)}
186
209
  fff = {:func => "dev_register_passw_code_mode2",
187
210
  :iot_fun => "2.2.4",
188
211
  :req_header => {:authorization => 'Bearer ' + token,
@@ -217,7 +240,7 @@ class HuaIot
217
240
  request.body = data_out
218
241
  res = https.request(request)
219
242
  p res.body.to_s
220
- 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)}
221
244
  fff = {:func => "dev_reg_passw_code_mode2_2",
222
245
  :iot_fun => "2.2.4",
223
246
  :req_header => {:content_type => 'application/json',
@@ -249,7 +272,7 @@ class HuaIot
249
272
  request['app_key'] = app_id
250
273
  res = https.request(request)
251
274
  if res.body != nil
252
- 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)}}
253
276
  else
254
277
  out_resp = {:code => res.code, :message => res.message, :body => {:answ => "no data"}}
255
278
  end
@@ -290,7 +313,7 @@ class HuaIot
290
313
  res = https.request(request)
291
314
  p res.body.to_s
292
315
  p res.code
293
- {: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)}
294
317
  end
295
318
 
296
319
  #2.2.14 Querying Device Activation Status
@@ -310,7 +333,7 @@ class HuaIot
310
333
  request['Authorization'] = 'Bearer ' + token
311
334
  request['app_key'] = app_id
312
335
  res = https.request(request)
313
- 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)}
314
337
  fff = {:func => "querying_device_activ_status",
315
338
  :iot_fun => "2.2.14",
316
339
  :req_header => {:content_type => 'application/json',
@@ -340,7 +363,7 @@ class HuaIot
340
363
  request['Authorization'] = 'Bearer ' + token
341
364
  request['app_key'] = app_id
342
365
  res = https.request(request)
343
- 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)}
344
367
  fff = {:func => "querying_device_info",
345
368
  :iot_fun => "2.9.1",
346
369
  :req_header => {:authorization => 'Bearer ' + token,
@@ -371,7 +394,7 @@ class HuaIot
371
394
  req_body = {deviceIds: dev_list}
372
395
  request.body = req_body.to_json
373
396
  res = https.request(request)
374
- 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)}
375
398
  fff = {:func => "querying_device_direct_conn",
376
399
  :iot_fun => "2.9.6",
377
400
  :req_header => {:authorization => 'Bearer ' + token,
@@ -401,7 +424,7 @@ class HuaIot
401
424
  request['Authorization'] = 'Bearer ' + token
402
425
  request['app_key'] = app_id
403
426
  res = https.request(request)
404
- 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)}
405
428
 
406
429
  fff = {:func => "querying_device_type_list",
407
430
  :iot_fun => "2.9.19",
@@ -435,7 +458,7 @@ class HuaIot
435
458
  data = {deviceIds: dev_list}
436
459
  request.body = data.to_json
437
460
  res = https.request(request)
438
- 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)}
439
462
  fff = {:func => "quer_dev_direct_conn_batches",
440
463
  :iot_fun => "2.9.6",
441
464
  :req_header => {:content_type => 'application/json',
@@ -472,7 +495,7 @@ class HuaIot
472
495
  p res.code
473
496
  p res.body
474
497
  if res.body != nil
475
- 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)}}
476
499
  else
477
500
  out_resp = {:code => res.code, :message => res.message, :body => {:answ => "no data"}}
478
501
  end
@@ -163,6 +163,30 @@ 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
+ res = {}
170
+ hash_f.each do |ggg|
171
+ if ggg[0].to_s != delete_key.to_s
172
+ res[ggg[0]] = ggg[1]
173
+ end
174
+ end
175
+ res
176
+ end
177
+
178
+
179
+ #process hash array. Transform keys to string keys
180
+ def hash_val_to_string(hash_full)
181
+ resp = {}
182
+ hash_full.each do |hsh|
183
+ resp[hsh[0].to_s] = hsh[1]
184
+ end
185
+ resp
186
+ end
187
+
188
+
189
+
166
190
  def test()
167
191
  p "eeeeeeeeeeeeeeeeeeeeeeee"
168
192
  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}
@@ -540,7 +541,7 @@ class MongoIot
540
541
  result_ps.append(row)
541
542
  }
542
543
  dattaa = result_ps[0]
543
- if dattaa!=nil
544
+ if dattaa != nil
544
545
  out_resp = {:code => 200, :result => "get_device_type_info_by_model: Request completed successfully", :body => dattaa}
545
546
  else
546
547
  out_resp = {:code => 404, :result => "get_device_type_info_by_model: Device info not found", :body => {"model" => device_model, "ManufacturerID" => "unknown", "ManufacturerNAME" => "unknown", "device_type" => "unknown"}}
@@ -566,9 +567,9 @@ class MongoIot
566
567
  }
567
568
  dattaa = result_ps[0]
568
569
  if dattaa!=nil
569
- out_resp = {:code => 200, :result => "get_device_type_info_by_model: Request completed successfully", :body => dattaa}
570
+ out_resp = {:code => 200, :result => "get_device_type_info_universal: Request completed successfully", :body => dattaa}
570
571
  else
571
- out_resp = {:code => 404, :result => "get_device_type_info_by_model: Device info not found", :body => {"model" => device_model, "ManufacturerID" => "unknown", "ManufacturerNAME" => "unknown", "device_type" => "unknown"}}
572
+ out_resp = {:code => 404, :result => "get_device_type_info_universal: Device info not found", :body => {"model" => device_model, "ManufacturerID" => "unknown", "ManufacturerNAME" => "unknown", "device_type" => "unknown"}}
572
573
  end
573
574
  else
574
575
  result_ps2 = []
@@ -578,9 +579,9 @@ class MongoIot
578
579
  }
579
580
  dattaa = result_ps2[0]
580
581
  if dattaa!=nil
581
- out_resp = {:code => 200, :result => "get_device_type_info_by_model: Request completed successfully", :body => dattaa}
582
+ out_resp = {:code => 200, :result => "get_device_type_info_universal: Request completed successfully", :body => dattaa}
582
583
  else
583
- out_resp = {:code => 404, :result => "get_device_type_info_by_model: Device info not found", :body => {"model" => device_model, "ManufacturerID" => "unknown", "ManufacturerNAME" => "unknown", "device_type" => "unknown"}}
584
+ out_resp = {:code => 404, :result => "get_device_type_info_universal: Device info not found", :body => {"model" => device_model, "ManufacturerID" => "unknown", "ManufacturerNAME" => "unknown", "device_type" => "unknown"}}
584
585
  end
585
586
  end
586
587
 
@@ -713,5 +714,23 @@ class MongoIot
713
714
  out_resp
714
715
  end
715
716
 
717
+
718
+ def get_all_imei_from_db
719
+ out_resp = {}
720
+ begin
721
+ req2 = []
722
+ result_ps = []
723
+ collection = client[:device_imei]
724
+ collection.find({}, {:_id => 0}).each {|row|
725
+ result_ps.append(row)
726
+ }
727
+ out_resp = {:code => 200, :result => "get_all_imei_from_db: Request completed successfully", :body => result_ps}
728
+ rescue
729
+ out_resp = {:code => 507, :result => "get_all_imei_from_db: Unknown SDK error"}
730
+ end
731
+ #internal_func.printer_texter(out_resp, "debug")
732
+ out_resp
733
+ end
734
+
716
735
  end
717
736
 
@@ -1,4 +1,4 @@
1
1
  module Imperituroard
2
- VERSION = "1.0.5"
2
+ VERSION = "1.1.1"
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.5
4
+ version: 1.1.1
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-08 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
@@ -187,6 +187,7 @@ extra_rdoc_files: []
187
187
  files:
188
188
  - ".gitignore"
189
189
  - ".idea/runConfigurations/hua_oceanconnect_adapter.xml"
190
+ - ".idea/runConfigurations/version.xml"
190
191
  - ".ruby-gemset"
191
192
  - ".ruby-version"
192
193
  - ".travis.yml"