imperituroard 0.4.7 → 0.4.8

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: b51bce400dffd4ca919cb7295742c17015350408
4
- data.tar.gz: 68b2e9f01ba2b35953ddf8f47a91bdeb153144b1
3
+ metadata.gz: 0c14a6e4b874b88dee7fcb385a9bdc1a3421171c
4
+ data.tar.gz: e0db9b2f11a898a8eda22a0075da8f88c5902f6b
5
5
  SHA512:
6
- metadata.gz: b660a1144c483fdf9f49cd46790e33b54d525c7a81eebe664d8dc623b8bb769ef8a0811e92de4e4e2d3d138f8ee99a585e0a75be466b80eee25f5fee1a29e291
7
- data.tar.gz: a8f58183102edd7bbd8a003bb4b557ddc27264f7bed4a8e96e566ad1b26a17a053b95e6f048031da5ea3553dc78c41929b584ea0bf70d26b1043cb030a290cce
6
+ metadata.gz: 3c01ba2b79798b63b81137c34d410834b0d1814101c4b70dfb788b974b6835a07954c36e30f70a0dbc28d2aa46c3857542502527daf8fb978f0915ed953648e0
7
+ data.tar.gz: 013d5fa3179ac944216c3c7ae87e96bbc54c3c65d03c069a45fa21b03bbb558ecf3a35725ef9704b74e132601e68ad718871fb44b4f3524c4e8449e49a793340
@@ -213,6 +213,7 @@ class HuaIot
213
213
  request['Authorization'] = 'Bearer ' + token
214
214
  request['app_key'] = app_id
215
215
  res = https.request(request)
216
+ p "res.code"
216
217
  p res.code
217
218
  p res.body
218
219
  if res.body != nil
@@ -509,7 +510,6 @@ class HuaIot
509
510
  p uri.port
510
511
  p uri.path
511
512
 
512
-
513
513
  cert_file = "/Users/imperituroard/Desktop/cert.crt"
514
514
  key_file = "/Users/imperituroard/Desktop/key.pem"
515
515
 
@@ -526,7 +526,6 @@ class HuaIot
526
526
  :secret => "ppeMsOq6zdb2fSUH4GoRooS_FgEa"
527
527
  }
528
528
 
529
-
530
529
  #request['app_key'] = 'ppeMsOq6zdb2fSUH4GoRooS_FgEa'
531
530
  #request['Authorization'] = 'Bearer ppeMsOq6zdb2fSUH4GoRooS_FgEa'
532
531
  request.content_type = 'application/x-www-form-urlencoded'
@@ -535,9 +534,7 @@ class HuaIot
535
534
  res = https.request(request)
536
535
  p res.code
537
536
  p res.message
538
-
539
537
  p parse_token(res.body)
540
-
541
538
  end
542
539
 
543
540
  # App ID
@@ -135,8 +135,25 @@ class InternalFunc
135
135
  end
136
136
 
137
137
 
138
+ #procedure for check input imei
139
+ def imei_validate(imei)
138
140
 
141
+ input = {:imei => imei}
139
142
 
143
+ answer = {}
144
+ if imei.is_a? Integer
145
+
146
+ if imei.to_s.length>=14 && imei.to_s.length<=17
147
+ answer = {:code => 200, :result => "IMEI correct.", :checked => true}
148
+ else
149
+ answer = {:code => 401, :result => "invalid IMEI length.", :checked => false}
150
+ end
151
+ else
152
+ answer = {:code => 400, :result => "Invalid IMEI. Data is not integer", :checked => false}
153
+ end
154
+ printer_texter({:answer => answer, :input => input}, "debug")
155
+ answer
156
+ end
140
157
 
141
158
  def test()
142
159
  p "eeeeeeeeeeeeeeeeeeeeeeee"
@@ -72,27 +72,37 @@ class IotFunctions_2
72
72
  processed_list = []
73
73
 
74
74
  for ii in imei_list
75
- list1[ii["imei"]] = ii
76
- imei.append(ii["imei"])
77
- end
78
- list_checked = mongo_client.check_imei_exists(imei)
79
- for ss in list_checked[:body][:exists]
80
- not_processed_list.append({:imei => ss, :error => "Device exists in database"})
75
+ valid_resp = internal_func.imei_validate(ii["imei"])
76
+ if valid_resp[:checked]
77
+ list1[ii["imei"]] = ii
78
+ imei.append(ii["imei"])
79
+ else
80
+ not_processed_list.append({:imei => ii["imei"], :error => valid_resp[:result]})
81
+ end
81
82
  end
82
83
 
83
- for jj in list_checked[:body][:not_exists]
84
- begin
85
- get_login_info = mongo_client.check_login_prof_perm_id_one(login, list1[jj]["profile"])[:code]
86
- if get_login_info==200
87
- for_insert.append(list1[jj])
88
- else
89
- not_processed_list.append({:imei => list1[jj], :error => "Permission denied for this profile"})
84
+ if imei != []
85
+ list_checked = mongo_client.check_imei_exists(imei)
86
+
87
+ for ss in list_checked[:body][:exists]
88
+ not_processed_list.append({:imei => ss, :error => "Device exists in database"})
89
+ end
90
+
91
+ for jj in list_checked[:body][:not_exists]
92
+ begin
93
+ get_login_info = mongo_client.check_login_prof_perm_id_one(login, list1[jj]["profile"])[:code]
94
+ if get_login_info==200
95
+ for_insert.append(list1[jj])
96
+ else
97
+ not_processed_list.append({:imei => list1[jj], :error => "Permission denied for this profile"})
98
+ end
99
+ rescue
100
+ not_processed_list.append({:imei => list1[jj], :error => "Unknown error"})
90
101
  end
91
- rescue
92
- not_processed_list.append({:imei => list1[jj], :error => "Unknown error"})
93
102
  end
94
103
  end
95
104
 
105
+
96
106
  begin
97
107
  added_on_iot_platf = []
98
108
  if for_insert!=[]
@@ -433,8 +443,12 @@ class IotFunctions_2
433
443
 
434
444
  imei_data = mongo_client.get_imei_info_from_db([imei])
435
445
  if imei_data[:body]!=[]
436
- ans = hua_aceanconnect_connector.remove_one_device_from_iot(credentials[:body][:app_id], credentials[:body][:secret], imei_data[:body][0]["huadata"]["body"]["deviceId"])
437
- p ans
446
+ ans = {}
447
+ if imei_data[:body][0]["huadata"]["body"]["deviceId"] != nil
448
+ ans = hua_aceanconnect_connector.remove_one_device_from_iot(credentials[:body][:app_id], credentials[:body][:secret], imei_data[:body][0]["huadata"]["body"]["deviceId"])
449
+ else
450
+ ans = {:code => "204", :result => "Not processed by iot platform. deviceId not found in mongoDB"}
451
+ end
438
452
  if ans[:code]=="204" or ans[:code]=="200"
439
453
  resp = mongo_client.device_remove_single_mongo(imei)
440
454
  else
@@ -1,3 +1,3 @@
1
1
  module Imperituroard
2
- VERSION = "0.4.7"
2
+ VERSION = "0.4.8"
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.7
4
+ version: 0.4.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dzmitry Buynovskiy