imperituroard 0.4.8 → 0.4.9

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: 0c14a6e4b874b88dee7fcb385a9bdc1a3421171c
4
- data.tar.gz: e0db9b2f11a898a8eda22a0075da8f88c5902f6b
3
+ metadata.gz: 45ef3c7115d6ab674dcf9d14460a7b14388d16ef
4
+ data.tar.gz: 0c77a69151136f2d1377fffcaf1f29e6abacf49c
5
5
  SHA512:
6
- metadata.gz: 3c01ba2b79798b63b81137c34d410834b0d1814101c4b70dfb788b974b6835a07954c36e30f70a0dbc28d2aa46c3857542502527daf8fb978f0915ed953648e0
7
- data.tar.gz: 013d5fa3179ac944216c3c7ae87e96bbc54c3c65d03c069a45fa21b03bbb558ecf3a35725ef9704b74e132601e68ad718871fb44b4f3524c4e8449e49a793340
6
+ metadata.gz: '038bd9f35f37440b6c5bd7a288a2e06f8955258643ae113b647edbd6c7a0110506294e107718759a8c552a2690c2caf340dfc1a113734ad9a210c84cca64f8b1'
7
+ data.tar.gz: 845b39504e1c12da72ded315ac1ff49bb40a811eba8819283a7dff420b9e59f4c23c13df3e69716faf6927c52a69c53eb76bb8675228b25c1eb689b896efb1f7
Binary file
@@ -61,9 +61,9 @@ class InternalFunc
61
61
  end
62
62
  end
63
63
  if is_string == 0
64
- output_params = {:code => 200, :result => "if_digit_or_string: Request processed", :body => {:string => false}}
64
+ output_params = {:code => 200, :result => "if_digit_or_string: Request processed. Its digit", :body => {:string => false}}
65
65
  else
66
- output_params = {:code => 200, :result => "if_digit_or_string: Request processed", :body => {:string => true}}
66
+ output_params = {:code => 200, :result => "if_digit_or_string: Request processed. Its string", :body => {:string => true}}
67
67
  end
68
68
  output_params
69
69
 
@@ -475,6 +475,33 @@ class MongoIot
475
475
  end
476
476
 
477
477
 
478
+ #function for get iot platform credentials from profile
479
+ def get_iot_oceanconn_credent_2(profile)
480
+ out_resp = {}
481
+ begin
482
+ result_ps = []
483
+ collection = client[:device_profiles]
484
+
485
+ if internal_func.if_digit_or_string(profile.to_s)[:body][:string]
486
+ collection.find({"profile" => profile}).each {|row|
487
+ result_ps.append(row)
488
+ }
489
+ else
490
+ collection.find({"profile_id" => profile.to_i}).each {|row|
491
+ result_ps.append(row)
492
+ }
493
+ end
494
+
495
+ app_id = result_ps[0][:iot_data][:app_id]
496
+ secret = result_ps[0][:iot_data][:secret]
497
+ out_resp = {:code => 200, :result => "get_iot_oceanconn_credent_2: Request completed successfully", :body => {:app_id => app_id, :secret => secret}}
498
+ rescue
499
+ out_resp = {:code => 500, :result => "get_iot_oceanconn_credent_2: Process failed"}
500
+ end
501
+ internal_func.printer_texter(out_resp, "debug")
502
+ out_resp
503
+ end
504
+
478
505
  def get_device_type_info_by_model(device_model)
479
506
  out_resp = {}
480
507
  begin
@@ -497,30 +524,4 @@ class MongoIot
497
524
  end
498
525
 
499
526
 
500
- def ttt
501
- p "111111"
502
- begin
503
- puts(client.cluster.inspect)
504
- puts('Collection Names: ')
505
- puts(client.database.collection_names)
506
- puts('Connected!')
507
- collection = client[:audit]
508
- doc = {
509
- name: 'Steve',
510
- hobbies: ['hiking', 'tennis', 'fly fishing'],
511
- siblings: {
512
- brothers: 0,
513
- sisters: 1
514
- }
515
- }
516
- result = collection.insert_one(doc)
517
- p result
518
- client.close
519
- rescue StandardError => err
520
- puts('Error: ')
521
- puts(err)
522
- end
523
-
524
-
525
- end
526
527
  end
@@ -108,10 +108,21 @@ class IotFunctions_2
108
108
  if for_insert!=[]
109
109
  ##Logic for IOT Platform connection###
110
110
 
111
- credentials = mongo_client.get_iot_oceanconnect_credent(login)
112
111
 
113
- if credentials[:code]==200
114
- for aaa in for_insert
112
+ for aaa in for_insert
113
+
114
+ #########change 2020.05.11. imperituroard
115
+ #########replace process for get iot app_id and password from users to profile
116
+
117
+ #credentials = mongo_client.get_iot_oceanconnect_credent(login)
118
+ credentials = mongo_client.get_iot_oceanconn_credent_2(aaa["profile"])
119
+
120
+ #########
121
+
122
+
123
+ if credentials[:code] == 200
124
+
125
+
115
126
  begin
116
127
  dev_name = aaa["imei"].to_s
117
128
 
@@ -146,18 +157,22 @@ class IotFunctions_2
146
157
  rescue
147
158
  not_processed_list.append({:imei => aaa["imei"], :error => "Unknown error with insertion imei on IOT platform"})
148
159
  end
149
- end
150
160
 
151
- #########end iot platform logic#######
152
161
 
153
- if added_on_iot_platf.length != 0
154
- mongo_client.imei_insert_list(added_on_iot_platf)
155
- resp_out = {:code => 200, :result => "Data processed", :body => {:imei_processed => added_on_iot_platf, :error_list => not_processed_list}}
162
+ #########end iot platform logic#######
163
+
156
164
  else
157
- resp_out = {:code => 202, :result => "Empty list. Nothing for insertion", :body => {:imei_processed => added_on_iot_platf, :error_list => not_processed_list}}
165
+ resss_err = {:code => 400, :result => "IOT platform credentials not found"}
166
+ not_processed_list.append({:imei => aaa["imei"], :error => resss_err})
158
167
  end
159
- else
160
- resp_out = {:code => 400, :result => "IOT platform credentials not found"}
168
+
169
+ end
170
+
171
+ if added_on_iot_platf.length != 0
172
+ mongo_client.imei_insert_list(added_on_iot_platf)
173
+ resp_out = {:code => 200, :result => "Data processed", :body => {:imei_processed => added_on_iot_platf, :error_list => not_processed_list}}
174
+ else
175
+ resp_out = {:code => 202, :result => "Empty list. Nothing for insertion", :body => {:imei_processed => added_on_iot_platf, :error_list => not_processed_list}}
161
176
  end
162
177
 
163
178
 
@@ -344,7 +359,7 @@ class IotFunctions_2
344
359
  internal_func.printer_texter({:function => "imei_replace Step6", :list_from_iot => list_from_iot, :description => "data from iot platform by old imei"}, "debug")
345
360
 
346
361
  #processing data. modifying data on iot platform and mongoDB
347
- if list_from_iot[:code]=="200"
362
+ if list_from_iot[:code]=="200" && list_from_iot[:body]["devices"] != nil
348
363
 
349
364
  for ard in list_from_iot[:body]["devices"]
350
365
  p ard
@@ -355,7 +370,19 @@ class IotFunctions_2
355
370
  new_data_cur_dev = ard["deviceInfo"]
356
371
  new_data_cur_dev["nodeId"] = old_new_translation[current_old_dev.to_i].to_s
357
372
 
358
- credentials = mongo_client.get_iot_oceanconnect_credent(login)
373
+ p list_from_iot
374
+ p "list_from_iot"
375
+
376
+
377
+ #########change 2020.05.11. imperituroard
378
+ #########replace process for get iot app_id and password from users to profile
379
+
380
+ #credentials = mongo_client.get_iot_oceanconnect_credent(login)
381
+ info_from_mongo = mongo_client.get_imei_info_from_db([current_old_dev.to_i])
382
+ credentials = mongo_client.get_iot_oceanconn_credent_2(info_from_mongo[:body][0]["profile"])
383
+
384
+ #########
385
+
359
386
 
360
387
  if credentials[:code]==200
361
388
  flag_remove=0
@@ -436,7 +463,14 @@ class IotFunctions_2
436
463
 
437
464
  ##Logic for IOT Platform connection###
438
465
 
439
- credentials = mongo_client.get_iot_oceanconnect_credent(login)
466
+ #########change 2020.05.11. imperituroard
467
+ #########replace process for get iot app_id and password from users to profile
468
+
469
+ #credentials = mongo_client.get_iot_oceanconnect_credent(login)
470
+ credentials = mongo_client.get_iot_oceanconn_credent_2(prof_name[:body]["profile"])
471
+
472
+ #########
473
+
440
474
  resp = {}
441
475
 
442
476
  if credentials[:code]==200
@@ -518,13 +552,21 @@ class IotFunctions_2
518
552
  if permiss[:code]==200
519
553
 
520
554
  ##Logic for IOT Platform connection###
521
- credentials = mongo_client.get_iot_oceanconnect_credent(login)
555
+
556
+ #########change 2020.05.11. imperituroard
557
+ #########replace process for get iot app_id and password from users to profile
558
+
559
+ #credentials = mongo_client.get_iot_oceanconnect_credent(login)
560
+ credentials = mongo_client.get_iot_oceanconn_credent_2(prof_name[:body]["profile"])
561
+
562
+ #########
563
+
522
564
  resp = {}
523
565
 
524
566
  if credentials[:code]==200
525
567
  imei_data = mongo_client.get_imei_info_from_db([p[:imei]])
526
568
  if imei_data[:body]!=[]
527
- ans =hua_aceanconnect_connector.modify_location_iot(credentials[:body][:app_id], credentials[:body][:secret], imei_data[:body][0]["huadata"]["body"]["deviceId"], p[:address])
569
+ ans = hua_aceanconnect_connector.modify_location_iot(credentials[:body][:app_id], credentials[:body][:secret], imei_data[:body][0]["huadata"]["body"]["deviceId"], p[:address])
528
570
 
529
571
  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")
530
572
  end
@@ -700,24 +742,24 @@ class IotFunctions_2
700
742
  data_soapgw.append({:id => ff["profile_id"], :form => ff["form"], :description => ff["description"], :profile => ff["profile"]})
701
743
 
702
744
  end
703
- tosoapgw = { :code => 200,
704
- :result => "Request completed successfully",
705
- :profiles => data_soapgw
745
+ tosoapgw = {:code => 200,
746
+ :result => "Request completed successfully",
747
+ :profiles => data_soapgw
706
748
  }
707
749
 
708
750
  resp_out = {:code => 200, :result => "Request completed successfully", :body => {:data => data_processed, :tosoapgw => tosoapgw}}
709
751
  else
710
- tosoapgw = { :code => login_info[:code],
711
- :result => login_info[:result],
712
- :profiles => data_soapgw
752
+ tosoapgw = {:code => login_info[:code],
753
+ :result => login_info[:result],
754
+ :profiles => data_soapgw
713
755
  }
714
756
  resp_out = {:code => login_info[:code], :result => login_info[:result], :body => {:tosoapgw => tosoapgw}}
715
757
  end
716
758
 
717
759
  rescue
718
- tosoapgw = { :code => 507,
719
- :result => "Unknown SDK error",
720
- :profiles => data_soapgw
760
+ tosoapgw = {:code => 507,
761
+ :result => "Unknown SDK error",
762
+ :profiles => data_soapgw
721
763
  }
722
764
  resp_out = {:code => 507, :result => "Unknown SDK error", :body => {:tosoapgw => tosoapgw}}
723
765
  end
@@ -756,24 +798,24 @@ class IotFunctions_2
756
798
  data_soapgw.append({:name => ff["model"], :form => ff["form"], :description => ff["description"], :type_id => ff["type_id"]})
757
799
  end
758
800
 
759
- tosoapgw = { :code => 200,
760
- :result => "Request completed successfully",
761
- :types => data_soapgw
801
+ tosoapgw = {:code => 200,
802
+ :result => "Request completed successfully",
803
+ :types => data_soapgw
762
804
  }
763
805
 
764
806
  resp_out = {:code => 200, :result => "Request completed successfully", :body => {:data => data_processed, :tosoapgw => tosoapgw}}
765
807
  else
766
- tosoapgw = { :code => login_info[:code],
767
- :result => login_info[:result],
768
- :types => data_soapgw
808
+ tosoapgw = {:code => login_info[:code],
809
+ :result => login_info[:result],
810
+ :types => data_soapgw
769
811
  }
770
812
  resp_out = {:code => login_info[:code], :result => login_info[:result], :body => {:tosoapgw => tosoapgw}}
771
813
  end
772
814
 
773
815
  rescue
774
- tosoapgw = { :code => 507,
775
- :result => "Unknown SDK error",
776
- :types => data_soapgw
816
+ tosoapgw = {:code => 507,
817
+ :result => "Unknown SDK error",
818
+ :types => data_soapgw
777
819
  }
778
820
  resp_out = {:code => 507, :result => "Unknown SDK error", :body => {:tosoapgw => tosoapgw}}
779
821
  end
@@ -842,25 +884,74 @@ class IotFunctions_2
842
884
  end
843
885
 
844
886
 
845
-
846
-
847
887
  #additional procedure for checking status on iot platform
848
888
  def get_info_by_imeilist_from_iot(login, imei_list)
849
889
  resp_out={}
850
890
  begin
851
891
  dev_id_list = []
892
+ for_process_list = {}
852
893
  resss = {}
853
894
  data_from_db = mongo_client.get_imei_info_from_db(imei_list)
854
895
  p data_from_db
896
+ profile = 0
855
897
  for g in data_from_db[:body]
898
+ p g
899
+ p "ggggg"
856
900
  dev_id_list.append(g["huadata"]["body"]["deviceId"])
901
+
902
+ if for_process_list[g["profile"]] == nil
903
+ for_process_list[g["profile"]] = [g["huadata"]["body"]["deviceId"]]
904
+ else
905
+ for_process_list[g["profile"]].append(g["huadata"]["body"]["deviceId"])
906
+ end
907
+
908
+ if g["profile"] != nil && g["profile"] != ""
909
+ profile = g["profile"]
910
+ end
857
911
  end
858
- credentials = mongo_client.get_iot_oceanconnect_credent(login)
859
- if credentials[:code]==200
860
- p apid = credentials[:body][:app_id]
861
- p secre = credentials[:body][:secret]
862
- resp_out = hua_aceanconnect_connector.quer_dev_query_list(apid, secre, dev_id_list)
912
+
913
+ p dev_id_list
914
+ p "dev_id_list"
915
+ p for_process_list
916
+
917
+ for ard in for_process_list
918
+ ##Logic for IOT Platform connection###
919
+
920
+ #########change 2020.05.11. imperituroard
921
+ #########replace process for get iot app_id and password from users to profile
922
+
923
+ #credentials = mongo_client.get_iot_oceanconnect_credent(login)
924
+ credentials = mongo_client.get_iot_oceanconn_credent_2(ard[0])
925
+
926
+ #########
927
+
928
+ if credentials[:code] == 200
929
+ resp_out[:code] = "200"
930
+ resp_out[:result] = "Processed"
931
+ p apid = credentials[:body][:app_id]
932
+ p secre = credentials[:body][:secret]
933
+ resp_out_1 = hua_aceanconnect_connector.quer_dev_query_list(apid, secre, ard[1])
934
+ p resp_out_1
935
+ p "resp_out_1"
936
+ p resp_out[:body]
937
+ p "resp_out[:body][\"devices\"]"
938
+
939
+ if resp_out[:body] == nil || resp_out[:body] == {} || resp_out[:body] == {"devices"=>nil}
940
+ p "step1111"
941
+ p resp_out_1[:body]["devices"]
942
+ resp_out[:body] = { 'devices' => resp_out_1[:body]["devices"]}
943
+ p "step22222"
944
+ else
945
+ if resp_out_1[:body]["devices"] != nil
946
+ resp_out[:body]["devices"] = resp_out[:body]["devices"] + resp_out_1[:body]["devices"]
947
+ end
948
+ end
949
+ end
863
950
  end
951
+
952
+ p resp_out
953
+ p "resp_out"
954
+
864
955
  rescue
865
956
  resp_out = {:code => "500", :message => "get_info_by_imeilist_from_iot: Something wrong", :body => {"devices" => []}}
866
957
  end
@@ -899,5 +990,4 @@ class IotFunctions_2
899
990
  end
900
991
 
901
992
 
902
-
903
993
  end
@@ -1,3 +1,3 @@
1
1
  module Imperituroard
2
- VERSION = "0.4.8"
2
+ VERSION = "0.4.9"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imperituroard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.8
4
+ version: 0.4.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dzmitry Buynovskiy