imperituroard 1.0.4 → 1.1.0

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: 64ac99c5a41209df78fa5f319ec47a51cb28b05b
4
- data.tar.gz: 004ea48aa310c5d3159ffa8f93b6451f6105fe0a
3
+ metadata.gz: dae0092e4f87b047adb62157ee51cb3e917bc3d7
4
+ data.tar.gz: be638036010d680252df866b5b09fb49bddd6628
5
5
  SHA512:
6
- metadata.gz: 97de046b4032c0751a046c4e1f57cbaffafd63936e53bfa08bcca6dc7216b6a5f73dcf1a68715c9a0a21b4f4ff5e1c116b3fabe0f450a264962543e68b6055b3
7
- data.tar.gz: 62ad29d69a43d0b0574c5249ac6777bc153a10472b9cce01298a80e27c8c956b6776aa86eef9d558d87acd1d260d5f7ca66428fa12ac8cfead71aab7fb0a7383
6
+ metadata.gz: a0e130dbe846d930dfe7da4a6290f76e4c1f6326e944ea4dbc693bafe90b9087ee4915e0e08dd83c346fb35c6a0ea68ce88ce5f690db27e47ab6b82e1ffaa3c6
7
+ data.tar.gz: f9c6ffd509148ae09d85fc4aac1439686612283d735fc020f3e45d76fd62e94d41b938d6a033fd93be6e2221612009b66d8a8da948e64fd32e0ee0c252baa93f
@@ -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>
@@ -33,6 +33,7 @@ require 'net/http'
33
33
  require 'uri'
34
34
 
35
35
  module Imperituroard
36
+
36
37
  class Error < StandardError;
37
38
  end
38
39
 
@@ -42,6 +43,7 @@ module Imperituroard
42
43
  def hhh(jjj)
43
44
  p jjj
44
45
  end
46
+
45
47
  # Your code goes here...
46
48
  end
47
49
 
@@ -239,6 +241,11 @@ class Iot
239
241
  iot_connector.get_available_types_2(login, real_ip, remote_ip)
240
242
  end
241
243
 
244
+ #9-1 get available types for login and profile
245
+ def get_available_types2(login, profile, real_ip, remote_ip)
246
+ iot_connector.get_available_types2_2(login, profile, real_ip, remote_ip)
247
+ end
248
+
242
249
  #10 get info for device type
243
250
  def get_info_data_type(type, real_ip, remote_ip)
244
251
  iot_connector.get_info_data_type_2(type, real_ip, remote_ip)
@@ -115,10 +115,9 @@ class IotFunctions_2
115
115
  end
116
116
  end
117
117
 
118
-
119
118
  begin
120
119
  added_on_iot_platf = []
121
- if for_insert!=[]
120
+ if for_insert != []
122
121
  ##Logic for IOT Platform connection###
123
122
 
124
123
 
@@ -132,16 +131,25 @@ class IotFunctions_2
132
131
 
133
132
  #########
134
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
135
138
 
136
- if credentials[:code] == 200
139
+ aaa = internal_func.hash_val_to_string(aaa)
137
140
 
141
+ if credentials[:code] == 200
138
142
 
139
143
  begin
140
144
  dev_name = aaa["imei"].to_s
141
145
 
142
146
  #get {"model"=>"BGT_PPMC", "ManufacturerID"=>"unknown", "ManufacturerNAME"=>"unknown", "device_type"=>"unknown"}
143
147
  #from database
144
- model_data = mongo_client.get_device_type_info_by_model(aaa["device_type"])
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"
145
153
  resss = hua_aceanconnect_connector.add_new_device_on_huawei(credentials[:body][:app_id],
146
154
  credentials[:body][:secret],
147
155
  aaa["imei"],
@@ -160,7 +168,8 @@ class IotFunctions_2
160
168
  s1 = aaa
161
169
  s1[:huadata] = resss
162
170
  s1[:created] = DateTime.now
163
- s1[:type] = s1["device_type"]
171
+ s1["device_type"] = model_data[:body]["model"]
172
+ s1["profile"] = profile_data["profile_id"]
164
173
  added_on_iot_platf.append(s1)
165
174
  end
166
175
  else
@@ -199,9 +208,7 @@ class IotFunctions_2
199
208
  end
200
209
  thr1.join
201
210
 
202
-
203
211
  resp_out[:body][:tosoapgw] = internal_func.iot_create_dev_soapgw_answer(input_json, resp_out)
204
-
205
212
  mongo_client.audit_logger("add_device_to_profile", remote_ip, input_json, resp_out, real_ip)
206
213
  resp_out
207
214
  end
@@ -221,16 +228,16 @@ class IotFunctions_2
221
228
  resp_out = {}
222
229
  begin
223
230
  thr2 = Thread.new do
224
- if add_functions_connector.check_input_2(login, imei_list)[:code]==200
231
+ if add_functions_connector.check_input_2(login, imei_list)[:code] == 200
225
232
 
226
233
  for t in imei_list
227
234
  prof_name1 = mongo_client.get_profile_name_from_imei(t)
228
- if prof_name1[:code]==200
235
+ if prof_name1[:code] == 200
229
236
  begin
230
237
  permiss1 = mongo_client.check_login_profile_permiss(login, prof_name1[:body]["profile"])
231
238
  p "permiss1"
232
239
  p permiss1
233
- if permiss1[:code]==200
240
+ if permiss1[:code] == 200
234
241
  ime_list_approved.append(t)
235
242
  else
236
243
  ime_list_notapproved.append({:imei => t, :error => permiss1})
@@ -460,12 +467,12 @@ class IotFunctions_2
460
467
  begin
461
468
  thr4 = Thread.new do
462
469
 
463
- if add_functions_connector.check_input_4(login, imei)[:code]==200
470
+ if add_functions_connector.check_input_4(login, imei)[:code] == 200
464
471
 
465
472
  prof_name = mongo_client.get_profile_name_from_imei(imei)
466
- if prof_name[:code]==200
473
+ if prof_name[:code] == 200
467
474
  permiss = mongo_client.check_login_profile_permiss(login, prof_name[:body]["profile"])
468
- if permiss[:code]==200
475
+ if permiss[:code] == 200
469
476
 
470
477
  ##Logic for IOT Platform connection###
471
478
 
@@ -479,17 +486,17 @@ class IotFunctions_2
479
486
 
480
487
  resp = {}
481
488
 
482
- if credentials[:code]==200
489
+ if credentials[:code] == 200
483
490
 
484
491
  imei_data = mongo_client.get_imei_info_from_db([imei])
485
- if imei_data[:body]!=[]
492
+ if imei_data[:body] != []
486
493
  ans = {}
487
494
  if imei_data[:body][0]["huadata"]["body"]["deviceId"] != nil
488
495
  ans = hua_aceanconnect_connector.remove_one_device_from_iot(credentials[:body][:app_id], credentials[:body][:secret], imei_data[:body][0]["huadata"]["body"]["deviceId"])
489
496
  else
490
497
  ans = {:code => "204", :result => "Not processed by iot platform. deviceId not found in mongoDB"}
491
498
  end
492
- if ans[:code]=="204" or ans[:code]=="200"
499
+ if ans[:code] == "204" or ans[:code] == "200"
493
500
  resp = mongo_client.device_remove_single_mongo(imei)
494
501
  else
495
502
  resp = {:code => 500, :result => "Unknown IOT platform error", :body => ans}
@@ -573,10 +580,8 @@ class IotFunctions_2
573
580
  imei_data = mongo_client.get_imei_info_from_db([p[:imei]])
574
581
  if imei_data[:body]!=[]
575
582
  ans = hua_aceanconnect_connector.modify_location_iot(credentials[:body][:app_id], credentials[:body][:secret], imei_data[:body][0]["huadata"]["body"]["deviceId"], p[:address])
576
-
577
583
  internal_func.printer_texter({:function => "device_add_address Step2", :ans => ans, :descrition => "answer from hua IOT", :input => {:did => imei_data[:body][0]["huadata"]["body"]["deviceId"], :appid => credentials[:body][:app_id], :secret => credentials[:body][:secret], :address => p[:address]}}, "debug")
578
584
  end
579
-
580
585
  end
581
586
 
582
587
  #########end iot platform logic#######
@@ -651,7 +656,7 @@ class IotFunctions_2
651
656
  if attr["profile"].is_a? Integer
652
657
  p "Ok"
653
658
  else
654
- p new = mongo_client.get_profile_id_by_name(attr["profile"])
659
+ p new = mongo_client.get_profile_universal(attr["profile"])
655
660
  attr["profile"] = new["profile_id"]
656
661
  end
657
662
  end
@@ -736,6 +741,7 @@ class IotFunctions_2
736
741
  permit_profiles = login_info[:body]["permit_profiles"]
737
742
  permit_types = login_info[:body]["permit_types"]
738
743
  data_from_mongo = mongo_client.get_profile_list_by_id(permit_profiles)
744
+ p data_from_mongo
739
745
 
740
746
  for ff in data_from_mongo
741
747
  data_processed.append({:profile_id => ff["profile_id"],
@@ -840,33 +846,47 @@ class IotFunctions_2
840
846
  data_processed = []
841
847
  data_soapgw = []
842
848
  login_info = mongo_client.get_login_inf2_select(login)
849
+ prof_data = mongo_client.get_profile_universal(profile)
843
850
  if login_info[:code]==200
844
851
 
845
852
  permit_profiles = login_info[:body]["permit_profiles"]
846
853
  permit_types = login_info[:body]["permit_types"]
854
+ perm_tp_prof = prof_data["permit_types"]
855
+
856
+ if permit_profiles.include?(prof_data["profile_id"])
857
+ res_types_permitted = internal_func.compare_dict(permit_types, perm_tp_prof)
858
+ data_from_mongo = mongo_client.get_type_list_by_id(res_types_permitted)
859
+
860
+ for ff in data_from_mongo
861
+ data_processed.append({:type_id => ff["type_id"],
862
+ :description => ff["description"],
863
+ :note => ff["note"],
864
+ :form => ff["form"],
865
+ :ManufacturerID => ff["ManufacturerID"],
866
+ :ManufacturerNAME => ff["ManufacturerNAME"],
867
+ :device_type => ff["device_type"],
868
+ :model => ff["model"],
869
+ :info => ff["info"]
870
+ })
871
+ data_soapgw.append({:name => ff["model"], :form => ff["form"], :description => ff["description"], :type_id => ff["type_id"]})
872
+ end
847
873
 
848
- data_from_mongo = mongo_client.get_type_list_by_id(permit_types)
874
+ tosoapgw = {:code => 200,
875
+ :result => "Request completed successfully",
876
+ :types => data_soapgw
877
+ }
849
878
 
850
- for ff in data_from_mongo
851
- data_processed.append({:type_id => ff["type_id"],
852
- :description => ff["description"],
853
- :note => ff["note"],
854
- :form => ff["form"],
855
- :ManufacturerID => ff["ManufacturerID"],
856
- :ManufacturerNAME => ff["ManufacturerNAME"],
857
- :device_type => ff["device_type"],
858
- :model => ff["model"],
859
- :info => ff["info"]
860
- })
861
- data_soapgw.append({:name => ff["model"], :form => ff["form"], :description => ff["description"], :type_id => ff["type_id"]})
879
+ resp_out = {:code => 200, :result => "Request completed successfully", :body => {:data => data_processed, :tosoapgw => tosoapgw}}
880
+
881
+ else
882
+ tosoapgw = {:code => 700,
883
+ :result => "Profile not permitted",
884
+ :types => data_soapgw
885
+ }
886
+ resp_out = {:code => 700, :result => "Profile not permitted", :body => {:tosoapgw => tosoapgw}}
862
887
  end
863
888
 
864
- tosoapgw = {:code => 200,
865
- :result => "Request completed successfully",
866
- :types => data_soapgw
867
- }
868
889
 
869
- resp_out = {:code => 200, :result => "Request completed successfully", :body => {:data => data_processed, :tosoapgw => tosoapgw}}
870
890
  else
871
891
  tosoapgw = {:code => login_info[:code],
872
892
  :result => login_info[:result],
@@ -930,6 +950,8 @@ class IotFunctions_2
930
950
  mon_answer = mongo_client.get_profile_name_by_id(profile)
931
951
  end
932
952
 
953
+ p mon_answer
954
+
933
955
  if mon_answer != {} && mon_answer != []
934
956
  output_answ = {:code => 200, :result => "Request completed successfully", :body => {:data => {:info => mon_answer["info"],
935
957
  :profile => mon_answer["profile"],
@@ -943,7 +965,6 @@ class IotFunctions_2
943
965
  end
944
966
  mongo_client.audit_logger("get_info_data_profile_2", remote_ip, input_params, output_answ, real_ip)
945
967
  output_answ
946
-
947
968
  end
948
969
 
949
970
 
@@ -1002,7 +1023,7 @@ class IotFunctions_2
1002
1023
  cur_comp1 = mongo_client.compare_profiles(prof_name1[:body]["profile_id"], prof_new_id)
1003
1024
  p cur_comp1
1004
1025
  p "cur_comp1"
1005
- cur_comp2 = mongo_client.compare_device_types(prof_name1[:imei_info][:body][0]["type"], type_new_pr)
1026
+ cur_comp2 = mongo_client.compare_device_types(prof_name1[:imei_info][:body][0]["device_type"], type_new_pr)
1006
1027
 
1007
1028
 
1008
1029
  p cur_comp2
@@ -1049,11 +1070,12 @@ class IotFunctions_2
1049
1070
  if resss[:body].key?("error_code") && resss[:body]["error_code"] != 200
1050
1071
  not_processed_list.append({:imei => curr_dev["imei"], :error => resss})
1051
1072
  else
1073
+ p resss
1052
1074
  new_id_iot = resss[:body]
1053
1075
  new_profile_id = prof_new_id
1054
1076
  now_date = DateTime.now
1055
1077
  #finished success. update database
1056
- attribute = {profile: new_profile_id, type: model_data[:body]["model"], huadata: {body: new_id_iot}, updated: now_date}
1078
+ attribute = {profile: new_profile_id, device_type: model_data[:body]["model"], huadata: resss, updated: now_date}
1057
1079
  answ_mongo = mongo_client.modify_attr_mongo_universal(curr_dev["imei"].to_i, attribute)
1058
1080
  if answ_mongo[:code] != 200
1059
1081
  not_processed_list.append({:imei => curr_dev["imei"], :error => "Critical error. Mongo not updated", :mongo_err => answ_mongo})
@@ -1067,6 +1089,8 @@ class IotFunctions_2
1067
1089
  rescue
1068
1090
  not_processed_list.append({:imei => curr_dev["imei"], :error => "Unknown error with insertion imei on IOT platform"})
1069
1091
  end
1092
+ else
1093
+ not_processed_list.append({:imei => curr_dev["imei"], :error => "Something wrong with IOT platform"})
1070
1094
  end
1071
1095
  else
1072
1096
  not_processed_list.append({:imei => curr_dev["imei"], :error => "Not processed by iot platform. deviceId not found in mongoDB"})
@@ -54,6 +54,9 @@ class HuaIot
54
54
  def get_token(app_id, secret)
55
55
  internal_func.printer_texter("get_token: start. Step1, iput: app_id: #{app_id.to_s}, secret: #{secret.to_s}", "debug")
56
56
  out_resp = {}
57
+ fff = {}
58
+ data = {}
59
+ url_string = ""
57
60
  begin
58
61
  path = "/iocm/app/sec/v1.1.0/login"
59
62
  url_string = "https://" + platformip + ":" + platformport + path
@@ -73,15 +76,19 @@ class HuaIot
73
76
  request.content_type = 'application/x-www-form-urlencoded'
74
77
  request.body = URI.encode_www_form(data)
75
78
  res = https.request(request)
79
+ p res.code
80
+ p res.message
81
+ p res.body.to_s
76
82
  out_resp = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
77
83
  fff = {:func => "get_token",
78
84
  :iot_fun => "",
79
- :req_header => {:content_type => 'application/x-www-form-urlencoded'
85
+ :req_header => {:content_type => 'application/x-www-form-urlencoded',
86
+ :platform => "Huawei oceanconnect"
80
87
  }}
81
- client_iot_mongo.audit_iot_logger(fff, url_string, data, out_resp)
82
88
  rescue
83
89
  out_resp = {:code => 500, :message => "failed get token"}
84
90
  end
91
+ client_iot_mongo.audit_iot_logger(fff, url_string, data, out_resp)
85
92
  jjj = {:procedure => "get_token", :answ => out_resp}
86
93
  internal_func.printer_texter(jjj, "debug")
87
94
  out_resp
@@ -92,6 +99,9 @@ class HuaIot
92
99
 
93
100
  internal_func.printer_texter("token_logout Step1 token: #{token}", "debug")
94
101
  out_resp = {}
102
+ fff = {}
103
+ data = {}
104
+ url_string = ""
95
105
  begin
96
106
  path = "/iocm/app/sec/v1.1.0/logout"
97
107
  url_string = "https://" + platformip + ":" + platformport + path
@@ -112,12 +122,17 @@ class HuaIot
112
122
  res = https.request(request)
113
123
  out_resp = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
114
124
  fff = {:func => "token_logout",
115
- :iot_fun => "logout"
125
+ :iot_fun => "logout",
126
+ :platform => "Huawei oceanconnect"
116
127
  }
117
- client_iot_mongo.audit_iot_logger(fff, url_string, data, out_resp)
128
+ p res.code
129
+ p res.message
130
+ p res.body.to_s
131
+
118
132
  rescue
119
133
  out_resp = {:code => 500, :message => "failed logout token"}
120
134
  end
135
+ client_iot_mongo.audit_iot_logger(fff, url_string, data, out_resp)
121
136
  jjj = {:procedure => "token_logout", :answ => out_resp}
122
137
  internal_func.printer_texter(jjj, "debug")
123
138
  out_resp
@@ -125,6 +140,7 @@ class HuaIot
125
140
 
126
141
  #Registering a Directly Connected Device (Verification Code Mode) (V2)
127
142
  def dev_register_verif_code_mode(app_id, secret, node_id)
143
+ out_resp = {}
128
144
  token = get_token(app_id, secret)[:body]["accessToken"]
129
145
  path = "/iocm/app/reg/v1.1.0/deviceCredentials?appId=" + app_id
130
146
  url_string = "https://" + platformip + ":" + platformport + path
@@ -138,9 +154,17 @@ class HuaIot
138
154
  request.content_type = 'application/json'
139
155
  request['Authorization'] = 'Bearer ' + token
140
156
  request['app_key'] = app_id
141
- request.body = {nodeId: node_id}.to_json
157
+ data = {nodeId: node_id}
158
+ request.body = data.to_json
142
159
  res = https.request(request)
143
- {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
160
+ out_resp = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
161
+ fff = {:func => "dev_register_verif_code_mode",
162
+ :iot_fun => "Registering a Directly Connected Device (Verification Code Mode) (V2)",
163
+ :req_header => {:content_type => 'application/json',
164
+ :platform => "Huawei oceanconnect"
165
+ }}
166
+ client_iot_mongo.audit_iot_logger(fff, url_string, data, out_resp)
167
+ out_resp
144
168
  end
145
169
 
146
170
  #2.2.4 Registering a Directly Connected Device (Password Mode) (V2)
@@ -176,7 +200,8 @@ class HuaIot
176
200
  :iot_fun => "2.2.4",
177
201
  :req_header => {:authorization => 'Bearer ' + token,
178
202
  :content_type => 'application/json',
179
- :app_key => app_id
203
+ :app_key => app_id,
204
+ :platform => "Huawei oceanconnect"
180
205
  }}
181
206
  client_iot_mongo.audit_iot_logger(fff, url_string, data_out, out_resp)
182
207
  out_resp
@@ -199,13 +224,21 @@ class HuaIot
199
224
  request.content_type = 'application/json'
200
225
  request['Authorization'] = 'Bearer ' + token
201
226
  request['app_key'] = app_id
202
- data_out = {deviceInfo: attr_list}.to_json
227
+ data = {deviceInfo: attr_list}
228
+ data_out = data.to_json
203
229
  internal_func.printer_texter({:procedure => "dev_register_passw_code_mode2", :data => {:body => data_out, :url => url_string}}, "debug")
204
230
  request.body = data_out
205
231
  res = https.request(request)
206
232
  p res.body.to_s
207
233
  out_resp = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
208
- p out_resp
234
+ fff = {:func => "dev_reg_passw_code_mode2_2",
235
+ :iot_fun => "2.2.4",
236
+ :req_header => {:content_type => 'application/json',
237
+ :authorization => 'Bearer ' + token,
238
+ :app_key => app_id,
239
+ :platform => "Huawei oceanconnect"
240
+ }}
241
+ client_iot_mongo.audit_iot_logger(fff, url_string, data, out_resp)
209
242
  out_resp
210
243
  end
211
244
 
@@ -237,7 +270,8 @@ class HuaIot
237
270
  :iot_fun => "2.2.12",
238
271
  :req_header => {:authorization => 'Bearer ' + token,
239
272
  :content_type => 'application/json',
240
- :app_key => app_id
273
+ :app_key => app_id,
274
+ :platform => "Huawei oceanconnect"
241
275
  }}
242
276
  client_iot_mongo.audit_iot_logger(fff, url_string, "Delete", out_resp)
243
277
  rescue
@@ -274,6 +308,7 @@ class HuaIot
274
308
 
275
309
  #2.2.14 Querying Device Activation Status
276
310
  def querying_device_activ_status(app_id, secret, device_id)
311
+ output_ans = {}
277
312
  token = get_token(app_id, secret)[:body]["accessToken"]
278
313
  path = "/iocm/app/reg/v1.1.0/devices/" + device_id + "?app_Id=" + app_id
279
314
  url_string = "https://" + platformip + ":" + platformport + path
@@ -288,12 +323,22 @@ class HuaIot
288
323
  request['Authorization'] = 'Bearer ' + token
289
324
  request['app_key'] = app_id
290
325
  res = https.request(request)
291
- {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
326
+ output_ans = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
327
+ fff = {:func => "querying_device_activ_status",
328
+ :iot_fun => "2.2.14",
329
+ :req_header => {:content_type => 'application/json',
330
+ :authorization => 'Bearer ' + token,
331
+ :app_key => app_id,
332
+ :platform => "Huawei oceanconnect"
333
+ }}
334
+ client_iot_mongo.audit_iot_logger(fff, url_string, data, output_ans)
335
+ output_ans
292
336
  end
293
337
 
294
338
 
295
339
  #2.9.1 Querying Information About a Device
296
340
  def querying_device_info(app_id, secret, device_id)
341
+ out_resp = {}
297
342
  token = get_token(app_id, secret)[:body]["accessToken"]
298
343
  path = "/iocm/app/dm/v1.1.0/devices/" + device_id + "?app_Id=" + app_id
299
344
  url_string = "https://" + platformip + ":" + platformport + path
@@ -308,7 +353,16 @@ class HuaIot
308
353
  request['Authorization'] = 'Bearer ' + token
309
354
  request['app_key'] = app_id
310
355
  res = https.request(request)
311
- {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
356
+ out_resp = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
357
+ fff = {:func => "querying_device_info",
358
+ :iot_fun => "2.9.1",
359
+ :req_header => {:authorization => 'Bearer ' + token,
360
+ :content_type => 'application/json',
361
+ :app_key => app_id,
362
+ :platform => "Huawei oceanconnect"
363
+ }}
364
+ client_iot_mongo.audit_iot_logger(fff, url_string, "Get", out_resp)
365
+ out_resp
312
366
  end
313
367
 
314
368
  #2.9.6 Querying Directly Connected Devices and Their Mounted Devices in Batches
@@ -335,7 +389,8 @@ class HuaIot
335
389
  :iot_fun => "2.9.6",
336
390
  :req_header => {:authorization => 'Bearer ' + token,
337
391
  :content_type => 'application/json',
338
- :app_key => app_id
392
+ :app_key => app_id,
393
+ :platform => "Huawei oceanconnect"
339
394
  }}
340
395
  client_iot_mongo.audit_iot_logger(fff, url_string, req_body, output_str)
341
396
  output_str
@@ -344,6 +399,7 @@ class HuaIot
344
399
 
345
400
  #2.9.19 Querying the Complete Device Type List of All Device Capabilities
346
401
  def querying_device_type_list(app_id, secret)
402
+ output_ans = {}
347
403
  token = get_token(app_id, secret)[:body]["accessToken"]
348
404
  path = "/iocm/app/profile/v1.1.0/allDeviceTypes"
349
405
  url_string = "https://" + platformip + ":" + platformport + path
@@ -358,13 +414,24 @@ class HuaIot
358
414
  request['Authorization'] = 'Bearer ' + token
359
415
  request['app_key'] = app_id
360
416
  res = https.request(request)
361
- {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
417
+ output_ans = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
418
+
419
+ fff = {:func => "querying_device_type_list",
420
+ :iot_fun => "2.9.19",
421
+ :req_header => {:content_type => 'application/json',
422
+ :authorization => 'Bearer ' + token,
423
+ :app_key => app_id,
424
+ :platform => "Huawei oceanconnect"
425
+ }}
426
+ client_iot_mongo.audit_iot_logger(fff, url_string, "Get", output_ans)
427
+ output_ans
428
+
362
429
  end
363
430
 
364
431
 
365
432
  #2.9.6 Querying Directly Connected Devices and Their Mounted Devices in Batches
366
433
  def quer_dev_direct_conn_batches(app_id, dev_list, token)
367
-
434
+ output_ans = {}
368
435
  path = "/iocm/app/dm/v1.1.0/queryDevicesByIds"
369
436
  url_string = "https://" + platformip + ":" + platformport + path
370
437
  p url_string
@@ -378,10 +445,19 @@ class HuaIot
378
445
  request.content_type = 'application/json'
379
446
  request['Authorization'] = 'Bearer ' + token
380
447
  request['app_key'] = app_id
381
- request.body = {deviceIds: dev_list}.to_json
448
+ data = {deviceIds: dev_list}
449
+ request.body = data.to_json
382
450
  res = https.request(request)
383
- {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
384
-
451
+ output_ans = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
452
+ fff = {:func => "quer_dev_direct_conn_batches",
453
+ :iot_fun => "2.9.6",
454
+ :req_header => {:content_type => 'application/json',
455
+ :authorization => 'Bearer ' + token,
456
+ :app_key => app_id,
457
+ :platform => "Huawei oceanconnect"
458
+ }}
459
+ client_iot_mongo.audit_iot_logger(fff, url_string, data, output_ans)
460
+ output_ans
385
461
  end
386
462
 
387
463
 
@@ -417,7 +493,8 @@ class HuaIot
417
493
  :iot_fun => "2.2.11",
418
494
  :req_header => {:authorization => 'Bearer ' + token,
419
495
  :content_type => 'application/json',
420
- :app_key => app_id
496
+ :app_key => app_id,
497
+ :platform => "Huawei oceanconnect"
421
498
  }}
422
499
  client_iot_mongo.audit_iot_logger(fff, url_string, req_b, out_resp)
423
500
  rescue
@@ -155,6 +155,38 @@ class InternalFunc
155
155
  answer
156
156
  end
157
157
 
158
+ #compare dictionaries
159
+ def compare_dict(dict1, dict2)
160
+ v1 = dict1 - dict2
161
+ v2 = dict2 - dict1
162
+ v3 = dict2 + dict1
163
+ v3.uniq - v2.uniq - v1.uniq
164
+ end
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
+
158
190
  def test()
159
191
  p "eeeeeeeeeeeeeeeeeeeeeeee"
160
192
  end
@@ -194,7 +194,7 @@ class MongoIot
194
194
  begin
195
195
  result_ps = []
196
196
  collection = client[:device_profiles]
197
- collection.find({"profile_id" => profile_id}).each {|row|
197
+ collection.find({"profile_id" => profile_id.to_i}).each {|row|
198
198
  result_ps.append(row)
199
199
  }
200
200
  result_ps[0]
@@ -238,7 +238,7 @@ class MongoIot
238
238
  begin
239
239
  result_ps = []
240
240
  collection = client[:device_types]
241
- collection.find({"type_id" => type_id}).each {|row|
241
+ collection.find({"type_id" => type_id.to_i}).each {|row|
242
242
  result_ps.append(row)
243
243
  }
244
244
  result_ps[0]
@@ -260,19 +260,20 @@ class MongoIot
260
260
  end
261
261
  end
262
262
 
263
+ #universal procedure. might be profile id or name
263
264
  def check_login_profile_permiss(login, profile)
264
265
  out_resp = {}
265
266
  get_login_info = get_profiles_by_login(login)
266
- if get_login_info[:code]==200
267
- dst_profile = get_profile_id_by_name(profile)
268
- access=1
269
- if get_login_info[:body]!=[]
270
- if dst_profile!=[]
267
+ if get_login_info[:code] == 200
268
+ dst_profile = get_profile_universal(profile)
269
+ access = 1
270
+ if get_login_info[:body] != []
271
+ if dst_profile != []
271
272
  for j in get_login_info[:body]
272
- if j["profile_id"].to_i==dst_profile["profile_id"].to_i
273
- access=0
273
+ if j["profile_id"].to_i == dst_profile["profile_id"].to_i
274
+ access = 0
274
275
  end
275
- if access==0
276
+ if access == 0
276
277
  out_resp = {:code => 200, :result => "check_login_profile_permiss: Permission granted"}
277
278
  else
278
279
  out_resp = {:code => 400, :result => "check_login_profile_permiss: Access denied. This incident will be reported."}
@@ -292,13 +293,15 @@ class MongoIot
292
293
  end
293
294
 
294
295
 
296
+ #universal procedure. You can use profile id or profile name as profile_id (string or int)
295
297
  def check_login_prof_perm_id_one(login, profile_id)
296
298
  out_resp = {}
297
299
  get_login_info = get_profiles_by_login(login)
300
+ profile_data = self.get_profile_universal(profile_id)
298
301
  access=1
299
302
  if get_login_info[:body]!=[]
300
303
  for j in get_login_info[:body]
301
- if j["profile_id"].to_i==profile_id.to_i
304
+ if j["profile_id"].to_i==profile_data["profile_id"]
302
305
  access=0
303
306
  end
304
307
  if access==0
@@ -340,7 +343,6 @@ class MongoIot
340
343
  description: "test imei",
341
344
  note: "second description",
342
345
  profile: 0,
343
- type: 0,
344
346
  device_type: 0,
345
347
  address: "unknown"
346
348
  }
@@ -364,7 +366,6 @@ class MongoIot
364
366
  description: "test imei",
365
367
  note: "second description",
366
368
  profile: 0,
367
- type: 0,
368
369
  device_type: 0,
369
370
  address: "unknown"
370
371
  }
@@ -503,6 +504,7 @@ class MongoIot
503
504
 
504
505
 
505
506
  #function for get iot platform credentials from profile
507
+ #universal procedure. use profile or profile id
506
508
  def get_iot_oceanconn_credent_2(profile)
507
509
  out_resp = {}
508
510
  begin
@@ -538,7 +540,7 @@ class MongoIot
538
540
  result_ps.append(row)
539
541
  }
540
542
  dattaa = result_ps[0]
541
- if dattaa!=nil
543
+ if dattaa != nil
542
544
  out_resp = {:code => 200, :result => "get_device_type_info_by_model: Request completed successfully", :body => dattaa}
543
545
  else
544
546
  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"}}
@@ -550,6 +552,7 @@ class MongoIot
550
552
  out_resp
551
553
  end
552
554
 
555
+ #universal procedure. Use id or name
553
556
  def get_device_type_info_universal(device_model)
554
557
  out_resp = {}
555
558
  begin
@@ -563,9 +566,9 @@ class MongoIot
563
566
  }
564
567
  dattaa = result_ps[0]
565
568
  if dattaa!=nil
566
- out_resp = {:code => 200, :result => "get_device_type_info_by_model: Request completed successfully", :body => dattaa}
569
+ out_resp = {:code => 200, :result => "get_device_type_info_universal: Request completed successfully", :body => dattaa}
567
570
  else
568
- 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"}}
571
+ 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"}}
569
572
  end
570
573
  else
571
574
  result_ps2 = []
@@ -575,9 +578,9 @@ class MongoIot
575
578
  }
576
579
  dattaa = result_ps2[0]
577
580
  if dattaa!=nil
578
- out_resp = {:code => 200, :result => "get_device_type_info_by_model: Request completed successfully", :body => dattaa}
581
+ out_resp = {:code => 200, :result => "get_device_type_info_universal: Request completed successfully", :body => dattaa}
579
582
  else
580
- 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"}}
583
+ 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"}}
581
584
  end
582
585
  end
583
586
 
@@ -681,6 +684,7 @@ class MongoIot
681
684
  end
682
685
 
683
686
 
687
+ #universal procedure. put there profile name or id in string or int
684
688
  def get_profile_universal(profile)
685
689
  inn = internal_func.if_digit_or_string(profile)
686
690
  out = {}
@@ -1,4 +1,4 @@
1
1
  module Imperituroard
2
- VERSION = "1.0.4"
2
+ VERSION = "1.1.0"
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.4
4
+ version: 1.1.0
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-09 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"