$LOAD_PATH.unshift File.expand_path("../projects/iot", __dir__) require 'date' class InternalFunc def datetimenow() d_curr = DateTime.now time_zone = 'Europe/Minsk' DateTime.new .in_time_zone(time_zone) .change(year: d_curr.year, month: d_curr.month, day: d_curr.day, hour: d_curr.hour, min: d_curr.min, sec: d_curr.sec) end def check_pass_format(passw) if passw!=nil && passw!="" {:code => 200, :result => "Request completed successfully", :body => "Data checked"} else {:code => 500, :result => "Request completed", :body => "invalid password"} end end def printer_texter(text, log_level) mess = {:datetime => datetimenow, :sdk => "imperituroard", :sdk_version => Imperituroard::VERSION, :message => text} p mess end def prof_id_list_transform_mongo(id_list) res = [] for gh in id_list res.append({"profile_id" => gh}) end res end def type_id_list_transform_mongo(id_list) res = [] for gh in id_list res.append({"type_id" => gh}) end res end def if_digit_or_string(data) input_params = {:data => data} output_params = {} data = data.to_s str_incr = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' ] d_a_t_a = data.split('') is_string = 0 for ddd in d_a_t_a if str_incr.include?(ddd) is_string = 1 end end if is_string == 0 output_params = {:code => 200, :result => "if_digit_or_string: Request processed. Its digit", :body => {:string => false}} else output_params = {:code => 200, :result => "if_digit_or_string: Request processed. Its string", :body => {:string => true}} end output_params end #make answer in format that soapgw receive def iot_create_dev_soapgw_answer(input_params, output_answer) printer_texter({:input_params => input_params, :output_answer => output_answer, :function => "iot_create_dev_soapgw_answer"}, "debug") output_info = {} begin if output_answer[:code] != 200 deviceserr = [] failednum = input_params[:imei_list].length for gg in input_params[:imei_list] if gg.key?(:imei) deviceserr.append({:failedimei => gg[:imei]}) else deviceserr.append({:failedimei => gg["imei"]}) end end output_info = {:code => output_answer[:code], :result => output_answer[:result], :processednum => 0, :failednum => failednum, :deviceserr => deviceserr } else deviceserr = [] failednum = output_answer[:body][:error_list].length processednum = output_answer[:body][:imei_processed].length for gg in output_answer[:body][:error_list] if gg.key?(:imei) deviceserr.append({:failedimei => gg[:imei]}) else deviceserr.append({:failedimei => gg["imei"]}) end end output_info = {:code => output_answer[:code], :result => output_answer[:result], :processednum => processednum, :failednum => failednum, :deviceserr => deviceserr } end rescue output_info = {:code => 500, :result => "iot_create_dev_soapgw_answer: Unknown SDK error", :processednum => 0, :failednum => 0, :deviceserr => [] } end # example = { :code => :integer, # :result => :string, # :processednum => :integer, # :failednum => :integer, # :deviceserr => [{:failedimei=>:integer}] # } printer_texter(output_info, "debug") output_info end #procedure for check input imei def imei_validate(imei) input = {:imei => imei} answer = {} if imei.is_a? Integer if imei.to_s.length>=14 && imei.to_s.length<=17 answer = {:code => 200, :result => "IMEI correct.", :checked => true} else answer = {:code => 401, :result => "invalid IMEI length.", :checked => false} end else answer = {:code => 400, :result => "Invalid IMEI. Data is not integer", :checked => false} end printer_texter({:answer => answer, :input => input}, "debug") answer end #compare dictionaries def compare_dict(dict1, dict2) v1 = dict1 - dict2 v2 = dict2 - dict1 v3 = dict2 + dict1 v3.uniq - v2.uniq - v1.uniq end #delete one key from hash def delete_key_hash(hash_f, delete_key) res = {} hash_f.each do |ggg| if ggg[0].to_s != delete_key.to_s res[ggg[0]] = ggg[1] end end res end #process hash array. Transform keys to string keys def hash_val_to_string(hash_full) resp = {} hash_full.each do |hsh| resp[hsh[0].to_s] = hsh[1] end resp end def test() p "eeeeeeeeeeeeeeeeeeeeeeee" end end