class InternalFunc

Public Instance Methods

check_pass_format(passw) click to toggle source
# File lib/imperituroard/projects/iot/internal_functions.rb, line 15
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
compare_dict(dict1, dict2) click to toggle source

compare dictionaries

# File lib/imperituroard/projects/iot/internal_functions.rb, line 161
def compare_dict(dict1, dict2)
  v1 = dict1 - dict2
  v2 = dict2 - dict1
  v3 = dict2 + dict1
  v3.uniq - v2.uniq - v1.uniq
end
datetimenow() click to toggle source
# File lib/imperituroard/projects/iot/internal_functions.rb, line 7
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
delete_key_hash(hash_f, delete_key) click to toggle source

delete one key from hash

# File lib/imperituroard/projects/iot/internal_functions.rb, line 170
def delete_key_hash(hash_f, delete_key)
  inp_fun = {:hash_f => hash_f, :delete_key => delete_key}
  hash_f = hash_f.to_h
  out_data = {}
  res = {}
  hash_f.each do |ggg|
    if ggg[0].to_s != delete_key.to_s
      res[ggg[0]] = ggg[1]
    end
  end
  out_data = res
  printer_texter({:out_data => out_data, :inp_fun => inp_fun, :fun => "delete_key_hash"}, "debug")
  out_data
end
hash_val_to_string(hash_full) click to toggle source

process hash array. Transform keys to string keys

# File lib/imperituroard/projects/iot/internal_functions.rb, line 187
def hash_val_to_string(hash_full)
  resp = {}
  hash_full.each do |hsh|
    resp[hsh[0].to_s] = hsh[1]
  end
  resp
end
if_digit_or_string(data) click to toggle source
# File lib/imperituroard/projects/iot/internal_functions.rb, line 48
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
  printer_texter({:input_params => input_params, :output_params => output_params}, 'debug')
  output_params

end
imei_validate(imei) click to toggle source

procedure for check input imei

# File lib/imperituroard/projects/iot/internal_functions.rb, line 141
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, :fun => "imei_validate"}, "debug")
  answer
end
iot_create_dev_soapgw_answer(input_params, output_answer) click to toggle source

make answer in format that soapgw receive

# File lib/imperituroard/projects/iot/internal_functions.rb, line 76
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
printer_texter(text, log_level) click to toggle source
# File lib/imperituroard/projects/iot/internal_functions.rb, line 23
def printer_texter(text, log_level)
  if log_level == "debug"
    mess = {:datetime => datetimenow, :sdk => "imperituroard", :sdk_version => Imperituroard::VERSION, :message => text}
    p mess
  end
end
prof_id_list_transform_mongo(id_list) click to toggle source
# File lib/imperituroard/projects/iot/internal_functions.rb, line 30
def prof_id_list_transform_mongo(id_list)
  res = []
  for gh in id_list
    res.append({"profile_id" => gh})
  end
  res
end
test() click to toggle source
# File lib/imperituroard/projects/iot/internal_functions.rb, line 196
def test
  p "eeeeeeeeeeeeeeeeeeeeeeee"
end
type_id_list_transform_mongo(id_list) click to toggle source
# File lib/imperituroard/projects/iot/internal_functions.rb, line 39
def type_id_list_transform_mongo(id_list)
  res = []
  for gh in id_list
    res.append({"type_id" => gh})
  end
  res
end