imperituroard 0.2.9 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b9caa5ad1572dee6c98500f3f462d24b1e33c380
4
- data.tar.gz: ad4f914e0ecaa6d3d2ad289af39d72d8d17d6b2a
3
+ metadata.gz: 5dd10455562230533ca66925146fc6277ad59e8d
4
+ data.tar.gz: da05bfe279194071153aa51c7fe9071051e4a8ef
5
5
  SHA512:
6
- metadata.gz: d25801d9cebc2a5ac5f1e4c80939f98187b9021424a3818a7ebd89f5b27e30cb74c4b0f01dff9a268c5489a5dbe9e628abdda7aac21edcde7f74419fe3c5f96d
7
- data.tar.gz: 1761bc8bd8a6fea80075c0de0616e3c3777a9f9b333cce4e38176e7ebb3307b392abf03d7693134412f84efb84ec89fdac5b3b8681223250abf509b3ff5aacf2
6
+ metadata.gz: b5ba1bb0d2403d224fc8e96ab1a7ceb36815c4340b35174a3b7211161ae8090e7a64c38f09c34d577bb2ea66de20e4f25d098a1769b3de65a3a5a6e1c06ad34e
7
+ data.tar.gz: 5ac36913151dd8637caf0aec3723e0f327e54d336e1c0387ff263f9d8ad2e74c74df41a222c06e83b57e161eff6a19fac2f7a3be79984cf9de7e67ae1e9f88b1
@@ -48,23 +48,60 @@ class HuaIot
48
48
  end
49
49
 
50
50
  def get_token(app_id, secret)
51
- path = "/iocm/app/sec/v1.1.0/login"
52
- url_string = "https://" + platformip + ":" + platformport + path
53
- uri = URI.parse url_string
54
- https = Net::HTTP.new(uri.host, uri.port)
55
- https.use_ssl = true
56
- https.cert = OpenSSL::X509::Certificate.new(File.read(cert_file))
57
- https.key = OpenSSL::PKey::RSA.new(File.read(key_file))
58
- https.verify_mode = OpenSSL::SSL::VERIFY_NONE
59
- request = Net::HTTP::Post.new(uri.path)
60
- data = {
61
- :appId => app_id,
62
- :secret => secret
63
- }
64
- request.content_type = 'application/x-www-form-urlencoded'
65
- request.body = URI.encode_www_form(data)
66
- res = https.request(request)
67
- {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
51
+ out_resp = {}
52
+ begin
53
+ path = "/iocm/app/sec/v1.1.0/login"
54
+ url_string = "https://" + platformip + ":" + platformport + path
55
+ uri = URI.parse url_string
56
+ https = Net::HTTP.new(uri.host, uri.port)
57
+ https.use_ssl = true
58
+ https.cert = OpenSSL::X509::Certificate.new(File.read(cert_file))
59
+ https.key = OpenSSL::PKey::RSA.new(File.read(key_file))
60
+ https.verify_mode = OpenSSL::SSL::VERIFY_NONE
61
+ request = Net::HTTP::Post.new(uri.path)
62
+ data = {
63
+ :appId => app_id,
64
+ :secret => secret
65
+ }
66
+ request.content_type = 'application/x-www-form-urlencoded'
67
+ request.body = URI.encode_www_form(data)
68
+ res = https.request(request)
69
+ out_resp = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
70
+ rescue
71
+ out_resp = {:code => 500, :message => "failed get token"}
72
+ end
73
+ p jjj = {:procedure => "get_token", :answ => out_resp}
74
+ out_resp
75
+ end
76
+
77
+
78
+ def token_logout(token)
79
+
80
+ p "token_logout token: #{token}"
81
+
82
+ out_resp = {}
83
+ begin
84
+ path = "/iocm/app/sec/v1.1.0/logout"
85
+ url_string = "https://" + platformip + ":" + platformport + path
86
+ uri = URI.parse url_string
87
+ https = Net::HTTP.new(uri.host, uri.port)
88
+ https.use_ssl = true
89
+ https.cert = OpenSSL::X509::Certificate.new(File.read(cert_file))
90
+ https.key = OpenSSL::PKey::RSA.new(File.read(key_file))
91
+ https.verify_mode = OpenSSL::SSL::VERIFY_NONE
92
+ request = Net::HTTP::Post.new(uri.path)
93
+ data = {
94
+ :accessToken => token
95
+ }
96
+ request.content_type = 'application/json'
97
+ request.body = URI.encode_www_form(data)
98
+ res = https.request(request)
99
+ out_resp = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
100
+ rescue
101
+ out_resp = {:code => 500, :message => "failed logout token"}
102
+ end
103
+ p jjj = {:procedure => "token_logout", :answ => out_resp}
104
+ out_resp
68
105
  end
69
106
 
70
107
  #Registering a Directly Connected Device (Verification Code Mode) (V2)
@@ -88,7 +125,7 @@ class HuaIot
88
125
  {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
89
126
  end
90
127
 
91
- #2.2.4 Registering a Directly Connected Device (Password Mode) (V2)
128
+ #2.2.4 Registering a Directly Connected Device (Password Mode) (V2)
92
129
  def dev_register_passw_code_mode2(app_id, secret, node_id, name_p, description_p, device_type, profile)
93
130
  out_resp = {}
94
131
  token = get_token(app_id, secret)[:body]["accessToken"]
@@ -113,32 +150,34 @@ class HuaIot
113
150
  end
114
151
 
115
152
 
116
-
117
153
  #2.2.12 Deleting a Directly Connected Device
118
- def dev_delete(app_id, secret, dev_id)
154
+ def dev_delete(app_id, dev_id, token)
119
155
  out_resp = {}
120
- token = get_token(app_id, secret)[:body]["accessToken"]
121
- path = "/iocm/app/dm/v1.1.0/devices/" + dev_id + "?app_Id=" + app_id + "&cascade=true"
122
- url_string = "https://" + platformip + ":" + platformport + path
123
- uri = URI.parse url_string
124
- https = Net::HTTP.new(uri.host, uri.port)
125
- https.use_ssl = true
126
- https.cert = OpenSSL::X509::Certificate.new(File.read(cert_file))
127
- https.key = OpenSSL::PKey::RSA.new(File.read(key_file))
128
- https.verify_mode = OpenSSL::SSL::VERIFY_NONE
129
- request = Net::HTTP::Delete.new(uri.path)
130
- request.content_type = 'application/json'
131
- request['Authorization'] = 'Bearer ' + token
132
- request['app_key'] = app_id
133
- res = https.request(request)
134
- p res.code
135
- p res.body
136
- if res.body != nil
137
- out_resp = {:code => res.code, :message => res.message, :body => {:answ => JSON.parse(res.body.to_s)}}
138
- else
139
- out_resp = {:code => res.code, :message => res.message, :body => {:answ => "no data"}}
140
- end
141
156
 
157
+ begin
158
+ path = "/iocm/app/dm/v1.1.0/devices/" + dev_id + "?app_Id=" + app_id + "&cascade=true"
159
+ url_string = "https://" + platformip + ":" + platformport + path
160
+ uri = URI.parse url_string
161
+ https = Net::HTTP.new(uri.host, uri.port)
162
+ https.use_ssl = true
163
+ https.cert = OpenSSL::X509::Certificate.new(File.read(cert_file))
164
+ https.key = OpenSSL::PKey::RSA.new(File.read(key_file))
165
+ https.verify_mode = OpenSSL::SSL::VERIFY_NONE
166
+ request = Net::HTTP::Delete.new(uri.path)
167
+ request.content_type = 'application/json'
168
+ request['Authorization'] = 'Bearer ' + token
169
+ request['app_key'] = app_id
170
+ res = https.request(request)
171
+ p res.code
172
+ p res.body
173
+ if res.body != nil
174
+ out_resp = {:code => res.code, :message => res.message, :body => {:answ => JSON.parse(res.body.to_s)}}
175
+ else
176
+ out_resp = {:code => res.code, :message => res.message, :body => {:answ => "no data"}}
177
+ end
178
+ rescue
179
+ out_resp = {:code => 500, :message => "dev_delete: Unknown IOT error"}
180
+ end
142
181
  p out_resp
143
182
  out_resp
144
183
 
@@ -273,21 +312,41 @@ class HuaIot
273
312
  end
274
313
 
275
314
 
276
-
277
315
  ##2.10.7 Adding Members to a Device Group
278
316
 
279
317
 
280
- ##############################################################3
318
+ ##############################################################3
281
319
 
282
320
 
283
321
  ########final procedures###############
284
322
  def add_new_device_on_huawei(app_id, secret, node_id, name_p, description_p, device_type, profile)
285
- dev_register_passw_code_mode2(app_id, secret, node_id, name_p, description_p, device_type, profile)
323
+ self.dev_register_passw_code_mode2(app_id, secret, node_id, name_p, description_p, device_type, profile)
286
324
  end
287
325
 
288
326
 
289
327
  def remove_one_device_from_iot(app_id, secret, dev_id)
290
- dev_delete(app_id, secret, dev_id)
328
+ out_resp = {}
329
+ begin
330
+ token = self.get_token(app_id, secret)
331
+ if token[:code] != 500 && token[:body]["accessToken"]!=nil
332
+ out_resp = self.dev_delete(app_id, dev_id, token[:body]["accessToken"])
333
+ if out_resp[:code].to_i == 200 || out_resp[:code].to_i == 204
334
+ ###logout#
335
+ begin
336
+ self.token_logout(token[:body]["accessToken"])
337
+ rescue
338
+ nil
339
+ end
340
+ ##########
341
+ end
342
+ else
343
+ out_resp = {:code => 500, :message => "remove_one_device_from_iot: Invalid IOT platform token"}
344
+ end
345
+ rescue
346
+ out_resp = {:code => 500, :message => "remove_one_device_from_iot: Unknown error"}
347
+ end
348
+ p jjj = {:procedure => "remove_one_device_from_iot", :answ => out_resp}
349
+ out_resp
291
350
  end
292
351
 
293
352
 
@@ -271,35 +271,45 @@ class MongoIot
271
271
  id = ""
272
272
  begin
273
273
  info = get_imei_info_from_db([imei])
274
+ p info
275
+ p "info"
274
276
  if info[:body]==[]
275
277
  out_resp = {:code => 505, :result => "get_profile_name_from_imei: get_imei_info_from_db returned empty list from database. IMEIS not found"}
276
278
  else
277
279
  p "fshhsdf"
278
280
  p info
279
281
  id = info[:body][0]["profile"]
280
- end
281
- rescue
282
- out_resp = {:code => 506, :result => "get_profile_name_from_imei: Function get_imei_info_from_db not processed correctly and returned: #{info.to_s}"}
283
- end
284
- begin
285
- res = get_profile_name_by_id(id)
286
- if res.key?("profile")
287
- res=res
288
- else
289
- out_resp = {:code => 505, :result => "get_profile_name_from_imei: Function get_profile_name_by_id not returned profile. Invalid data in database and returned: #{res.to_s}"}
290
- end
282
+ p id
283
+ p "id"
284
+
285
+ begin
286
+ p id
287
+ res = get_profile_name_by_id(id)
288
+ p res
289
+ if res.key?("profile")
290
+ res=res
291
+ else
292
+ out_resp = {:code => 505, :result => "get_profile_name_from_imei: Function get_profile_name_by_id not returned profile. Invalid data in database and returned: #{res.to_s}"}
293
+ end
294
+
295
+ rescue
296
+ out_resp = {:code => 506, :result => "get_profile_name_from_imei: Function get_profile_name_by_id not processed correctly and returned: #{res.to_s}"}
297
+
298
+ end
299
+ begin
300
+ if res["profile"]!=nil
301
+ out_resp = {:code => 200, :result => "get_profile_name_from_imei: Request completed successfully", :body => res}
302
+ end
303
+ rescue
304
+ out_resp = {:code => 506, :result => "get_profile_name_from_imei: Function get_profile_name_by_id not processed correctly and returned: #{res.to_s}"}
305
+ end
291
306
 
292
- rescue
293
- out_resp = {:code => 506, :result => "get_profile_name_from_imei: Function get_profile_name_by_id not processed correctly and returned: #{res.to_s}"}
294
307
 
295
- end
296
- begin
297
- if res["profile"]!=nil
298
- out_resp = {:code => 200, :result => "get_profile_name_from_imei: Request completed successfully", :body => res}
299
308
  end
300
309
  rescue
301
- out_resp = {:code => 506, :result => "get_profile_name_from_imei: Function get_profile_name_by_id not processed correctly and returned: #{res.to_s}"}
310
+ out_resp = {:code => 506, :result => "get_profile_name_from_imei: Function get_imei_info_from_db not processed correctly and returned: #{info.to_s}"}
302
311
  end
312
+
303
313
  rescue
304
314
  out_resp = {:code => 507, :result => "get_profile_name_from_imei: Unknown SDK error"}
305
315
  end
@@ -1,3 +1,3 @@
1
1
  module Imperituroard
2
- VERSION = "0.2.9"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imperituroard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.9
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dzmitry Buynovskiy