Class: AdditionalFunc

Inherits:
Object
  • Object
show all
Defined in:
lib/imperituroard/projects/iot/add_functions.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(telegram_api_url, telegram_chat_id) ⇒ AdditionalFunc

Returns a new instance of AdditionalFunc.



10
11
12
13
14
# File 'lib/imperituroard/projects/iot/add_functions.rb', line 10

def initialize(telegram_api_url, telegram_chat_id)
  @telegram_api_url = telegram_api_url
  @telegram_chat_id = telegram_chat_id
  @telegram_messanger = Telegram_2.new(telegram_api_url, telegram_chat_id)
end

Instance Attribute Details

#telegram_api_urlObject

Returns the value of attribute telegram_api_url.



8
9
10
# File 'lib/imperituroard/projects/iot/add_functions.rb', line 8

def telegram_api_url
  @telegram_api_url
end

#telegram_chat_idObject

Returns the value of attribute telegram_chat_id.



8
9
10
# File 'lib/imperituroard/projects/iot/add_functions.rb', line 8

def telegram_chat_id
  @telegram_chat_id
end

#telegram_messangerObject

Returns the value of attribute telegram_messanger.



8
9
10
# File 'lib/imperituroard/projects/iot/add_functions.rb', line 8

def telegram_messanger
  @telegram_messanger
end

Instance Method Details

#answ_dev_query_format_process(dev_list) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/imperituroard/projects/iot/add_functions.rb', line 17

def answ_dev_query_format_process(dev_list)
  dataaa_ok = []
  dataaa_failed = []
  final_answ = {}

  begin
    if dev_list[:approved_list]!=[]
      for i in dev_list[:approved_list][:body]
        begin
          imei =0
          imsi =0
          msisdn =0
          description = 'nil'
          note = "nil"
          type = "nil"
          profile ="nil"
          address ="nil"

          if i.key?("imei")
            imei=i["imei"]
          end
          if i.key?("imsi")
            imsi=i["imsi"]
          end
          if i.key?("msisdn")
            msisdn=i["msisdn"]
          end
          if i.key?("description")
            if i["description"] == nil
              description="nil"
            else
              description=i["description"]
            end
          end
          if i.key?("note")
            if i["note"] == nil
              note="nil"
            else
              note=i["note"]
            end
          end
          if i.key?("device_type")
            type=i["device_type"]
          end
          if i.key?("profile")
            profile=i["profile"]
          end
          if i.key?("address")
            address=i["address"]
          end
          dataaa_ok.append({:imei => imei,
                            :imsi => imsi,
                            :msisdn => msisdn,
                            :description => description,
                            :note => note,
                            :type => type,
                            :profile => profile,
                            :address => address})
        rescue
          dataaa_failed.append(i[:imei])
        end
      end
    end


    begin
      for i in dev_list[:unapproved_list]
        dataaa_failed.append(i[:imei])
      end
    rescue
      nil
    end

    final_answ = {:ok => dataaa_ok, :failed => dataaa_failed}
    {:code => 200, :result => "Request completed successfully", :body => final_answ}
  rescue
    {:code => 507, :result => "Unknown SDK error", :body => {}}
  end

end

#check_input_1(login, imei_list) ⇒ Object



98
99
100
# File 'lib/imperituroard/projects/iot/add_functions.rb', line 98

def check_input_1(, imei_list)
  {:code => 200, :result => "Request completed successfully", :body => "Data checked"}
end

#check_input_2(login, imei_list) ⇒ Object



102
103
104
# File 'lib/imperituroard/projects/iot/add_functions.rb', line 102

def check_input_2(, imei_list)
  {:code => 200, :result => "Request completed successfully", :body => "Data checked"}
end

#check_input_3(login, imei_list) ⇒ Object



106
107
108
# File 'lib/imperituroard/projects/iot/add_functions.rb', line 106

def check_input_3(, imei_list)
  {:code => 200, :result => "Request completed successfully", :body => "Data checked"}
end

#check_input_4(login, imei_list) ⇒ Object



110
111
112
# File 'lib/imperituroard/projects/iot/add_functions.rb', line 110

def check_input_4(, imei_list)
  {:code => 200, :result => "Request completed successfully", :body => "Data checked"}
end

#check_input_5(login, imei_list) ⇒ Object



114
115
116
# File 'lib/imperituroard/projects/iot/add_functions.rb', line 114

def check_input_5(, imei_list)
  {:code => 200, :result => "Request completed successfully", :body => "Data checked"}
end

#check_input_6(login, imei_list) ⇒ Object



118
119
120
# File 'lib/imperituroard/projects/iot/add_functions.rb', line 118

def check_input_6(, imei_list)
  {:code => 200, :result => "Request completed successfully", :body => "Data checked"}
end

#iot_query_dev_soapgw_answer(input_params, output_answer) ⇒ Object



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/imperituroard/projects/iot/add_functions.rb', line 122

def iot_query_dev_soapgw_answer(input_params, output_answer)

  answ = {}

  p output_answer

  begin

    if output_answer[:code]==200
      dataaa = []
      dataaa_failed = []

      ddd = answ_dev_query_format_process(output_answer[:data])[:body]
      p ddd

      answ = {:code => output_answer[:code],
              :result => output_answer[:result],
              :data => ddd[:ok],
              :error_list => ddd[:failed]
      }
    else
      answ = {:code => output_answer[:code],
              :result => output_answer[:result],
              :data => [],
              :error_list => input_params[:imei]
      }
    end
  rescue
    answ = {:code => 500,
            :result => "Unknown error"
    }
  end

  answ

end