Class: InternalFunc
- Inherits:
-
Object
- Object
- InternalFunc
- Defined in:
- lib/imperituroard/projects/iot/internal_functions.rb
Instance Method Summary collapse
- #check_pass_format(passw) ⇒ Object
-
#compare_dict(dict1, dict2) ⇒ Object
compare dictionaries.
- #datetimenow ⇒ Object
-
#delete_key_hash(hash_f, delete_key) ⇒ Object
delete one key from hash.
-
#hash_val_to_string(hash_full) ⇒ Object
process hash array.
- #if_digit_or_string(data) ⇒ Object
-
#imei_validate(imei) ⇒ Object
procedure for check input imei.
-
#iot_create_dev_soapgw_answer(input_params, output_answer) ⇒ Object
make answer in format that soapgw receive.
- #printer_texter(text, log_level) ⇒ Object
- #prof_id_list_transform_mongo(id_list) ⇒ Object
- #test ⇒ Object
- #type_id_list_transform_mongo(id_list) ⇒ Object
Instance Method Details
#check_pass_format(passw) ⇒ Object
15 16 17 18 19 20 21 |
# 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) ⇒ Object
compare dictionaries
161 162 163 164 165 166 |
# 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 ⇒ Object
7 8 9 10 11 12 13 |
# 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) ⇒ Object
delete one key from hash
170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# 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) ⇒ Object
process hash array. Transform keys to string keys
187 188 189 190 191 192 193 |
# 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) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# 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) ⇒ Object
procedure for check input imei
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# 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) ⇒ Object
make answer in format that soapgw receive
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# 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) ⇒ Object
23 24 25 26 27 28 |
# 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) ⇒ Object
30 31 32 33 34 35 36 |
# 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 ⇒ Object
196 197 198 |
# File 'lib/imperituroard/projects/iot/internal_functions.rb', line 196 def test p "eeeeeeeeeeeeeeeeeeeeeeee" end |
#type_id_list_transform_mongo(id_list) ⇒ Object
39 40 41 42 43 44 45 |
# 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 |