lib/imperituroard.rb in imperituroard-0.2.0 vs lib/imperituroard.rb in imperituroard-0.2.1
- old
+ new
@@ -82,11 +82,15 @@
@cert_path = cert_path
@key_path = key_path
@mongo_client = MongoIot.new(mongoip, mongoport, mongo_database)
end
+ #error list
+ #:code => 507, :result => "Unknown SDK error"
+
+
#1. Add device to profile
#login - login for client identification
#profile - profile for device
#imei_list - device identificator
#imei_list = {
@@ -99,40 +103,49 @@
# type: type,
# address: address
#}
#massive commands
#+
- def add_device_to_profile(login, profile, imei_list)
+ def add_device_to_profile(login, imei_list)
+ input_json = {:login => login, :imei_list =>imei_list}
+
+ begin
imei = []
list1 = {}
for_insert = []
for t in imei_list
imei.append(t["imei"])
list1[t["imei"]] = t
end
- get_login_info = mongo_client.check_login_profile_permiss(login, profile)[:code]
+ get_login_info = mongo_client.check_login_profile_permiss(login, "profile")[:code]
if get_login_info==200
list_exists = mongo_client.check_imei_exists(imei)
for_upload = imei - list_exists
for h in for_upload
for_insert.append(list1[h])
end
mongo_client.imei_insert_list(for_insert)
else get_login_info
end
+ rescue
+ return {:code => 507, :result => "Unknown SDK error"}
+ end
+ mongo_client.audit_logger("add_device_to_profile", "127.0.0.1", input_json, "resp")
end
#2 Find device (only mongo datebase. IOT platform not need)
# login
# imei
# imei_list =[41234,23452345,132412]
#+
def device_find(login, imei_list)
+ input_json = {:login => login, :imei_list =>imei_list}
ime_list_approved = []
ime_list_notapproved = []
+
begin
for t in imei_list
prof_name1 = mongo_client.get_profile_name_from_imei(t)
p "prof_name1"
p prof_name1
@@ -142,33 +155,44 @@
ime_list_approved.append(t)
end
end
end
data = mongo_client.get_imei_info_from_db(ime_list_approved)
- {:code=>507, :result => "Unknown error", :data => data}
+ {:code => 507, :result => "Unknown SDK error", :data => data}
rescue
- {:code=>507, :result => "Unknown error"}
+ {:code => 507, :result => "Unknown SDK error"}
end
+
+ mongo_client.audit_logger("add_device_to_profile", "127.0.0.1", input_json, "resp")
+
end
#3 device modify, change imei
#login
#imei_old
#imei_new
#massive commands
#im_list = [{:imei_old=>7967843245667, :imei_new=>7967843245665}]
#+
def imei_replace(login, im_list)
+ input_json = {:login => login, :imei_list =>im_list}
+ begin
for a in im_list
p a
prof_name1 = mongo_client.get_profile_name_from_imei(a[:imei_old])
p prof_name1
permiss1 = mongo_client.check_login_profile_permiss(login, prof_name1["profile"])[:code]
if permiss1==200
mongo_client.device_modify_any_attr_mongo(a[:imei_old],{:imei=>a[:imei_new]})
end
end
+ rescue
+ {:code => 507, :result => "Unknown SDK error"}
+ end
+
+ mongo_client.audit_logger("add_device_to_profile", "127.0.0.1", input_json, "resp")
+
end
#4 remove device
#login
@@ -176,44 +200,68 @@
# not massive commands
#imei=11341341234
#login="test"
#+
def device_remove(login, imei)
+
+ input_json = {:login => login, :imei_list =>imei}
+ resp = {}
+
+ begin
+
prof_name = mongo_client.get_profile_name_from_imei(imei)
permiss = mongo_client.check_login_profile_permiss(login, prof_name["profile"])[:code]
if permiss==200
- mongo_client.device_remove_single_mongo(imei)
+ resp = mongo_client.device_remove_single_mongo(imei)
end
+ rescue
+ {:code => 507, :result => "Unknown SDK error"}
+ end
+ mongo_client.audit_logger("device_remove", "127.0.0.1", input_json, "resp")
+ resp
end
#5 add address to device
#login
#imei = newdevice_list
#address = newdevice_list
#newdevice_list=[{:imei=>7967843245665, :address=>"Golubeva51"}]
#+
def device_add_address(login, newdevice_list)
+ input_json = {:login => login, :devices => newdevice_list}
+ begin
+ resp = {}
for p in newdevice_list
prof_name = mongo_client.get_profile_name_from_imei(p[:imei])
+
p "prof_name"
p prof_name
permiss = mongo_client.check_login_profile_permiss(login, prof_name["profile"])[:code]
if permiss==200
- mongo_client.device_modify_attr_mongo(p[:imei],p[:address])
+ resp = mongo_client.device_modify_attr_mongo(p[:imei],p[:address])
end
end
+ return resp
+ rescue
+ {:code => 507, :result => "Unknown SDK error"}
+ end
+ mongo_client.audit_logger("device_remove", "127.0.0.1", input_json, "resp")
end
#6 add service by SPA
#imei
#profile
#imsi
#msisdn
#newdevice_list=[{:imei=>7967843245665, :attributes=>{:address=>"Golubeva51", :profile=>"wqeqcqeqwev", :msisdn=>375298766719, :imsi=>25702858586756875}}]
#+
def add_service(login, device_list)
+ input_json = {:login => login, :devices => device_list}
+
+ begin
+
for g in device_list
prof_name1 = mongo_client.get_profile_name_from_imei(g[:imei])
p prof_name1
permiss1 = mongo_client.check_login_profile_permiss(login, prof_name1["profile"])[:code]
p permiss1
@@ -234,9 +282,15 @@
p attr
mongo_client.device_modify_any_attr_mongo(g[:imei],attr)
end
end
+ rescue
+ {:code => 507, :result => "Unknown SDK error"}
+ end
+
+ mongo_client.audit_logger("device_remove", "127.0.0.1", input_json, "resp")
+
end