imperituroard 0.1.8 → 0.1.9

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: 6fb131c986ddab24b594df2acd6575d10fafd515
4
- data.tar.gz: dabb303f1d40dbc7741fa6d1e68337165d3fd551
3
+ metadata.gz: d1762929c72ac24fe31ae33aa251710b1faaa610
4
+ data.tar.gz: 80eec415adf4d755cc17ea6ad2a7bfcec3984901
5
5
  SHA512:
6
- metadata.gz: 6b9879f24087c8662cb1e6e81cde96b5945c4faeb9709da1da88206ec04269b010574dbe67da9755c7e52932cc91c1879ab3c1abe928cd8a65d6e43ff8a18f81
7
- data.tar.gz: 3ce55acd489a807ee9e1ff987d33ed0e4a03c8146bf6b01360f320d81a076cd15277f22a1c6e83ba139e6ede8cd0663372197381bd118502130bb5fc162b8b7e
6
+ metadata.gz: 8e874469cd9a098e43201ede8d7f120549a36c3f39fa3c396daf2b19abe60709cca051825dffb676f2d5ea20f95324c311d35ae78822603222aabda8961908d0
7
+ data.tar.gz: d1cb5442becd3ac0441248ee540fdfa74892dac0efa328874f368fa43e9c59b69f0000ce8ec4f22b1223159edbcb41e1da136a91fdfad43e28843b9a10f57f04
data/Gemfile CHANGED
@@ -3,10 +3,13 @@ source "https://rubygems.org"
3
3
  # Specify your gem's dependencies in imperituroard.gemspec
4
4
  gemspec
5
5
 
6
- gem "rake", "~> 12.0"
7
- gem "minitest", "~> 5.0"
6
+ gem "rake", ">= 12.3.3"
7
+ gem "minitest", "5.14.0"
8
8
  gem 'mysql2', '>= 0.3.13', '< 0.5'
9
- gem 'savon'
10
- gem 'json'
9
+ gem 'savon', '2.12.0'
10
+ gem 'json', '2.3.0'
11
11
  #gem 'uri'
12
- gem 'mongo'
12
+ gem 'mongo', '2.11.4'
13
+ gem 'nokogiri'
14
+ gem 'rails'
15
+
@@ -28,11 +28,12 @@ Gem::Specification.new do |spec|
28
28
  spec.require_paths = ["lib"]
29
29
 
30
30
  spec.add_development_dependency "bundler", "2.1.4"
31
- spec.add_development_dependency "rake", "12.3.3"
31
+ spec.add_development_dependency "rake", ">= 12.3.3"
32
32
  spec.add_development_dependency "net-ssh", '4.0.1'
33
33
  spec.add_development_dependency "mysql2", "0.4.10"
34
34
  spec.add_development_dependency "savon", "2.12.0"
35
35
  spec.add_development_dependency "json", "2.3.0"
36
36
  #spec.add_development_dependency "uri"
37
37
  spec.add_development_dependency "mongo", "2.11.4"
38
+ spec.add_development_dependency "nokogiri"
38
39
  end
@@ -2,31 +2,224 @@ require 'uri'
2
2
  require 'net/http'
3
3
  require 'net/https'
4
4
  require 'json'
5
+ require 'rubygems'
6
+ require 'nokogiri'
7
+ require 'rails'
5
8
 
6
9
 
7
10
  class HuaIot
8
11
 
9
- attr_accessor :platformip, :platformport, :client, :database
12
+ attr_accessor :platformip, :platformport, :client, :database, :cert_file, :key_file
10
13
 
11
- def initialize(platformip, platformport, iotip, database)
14
+ def initialize(platformip, platformport, iotip, database, cert_file, key_file)
12
15
  @database = database
13
16
  @platformip = platformip
14
17
  @platformport = platformport
15
18
  @iotip = iotip
19
+ @cert_file = cert_file
20
+ @key_file = key_file
16
21
  #client_host = [mongoip + ":" + mongoport]
17
22
  #@client = Mongo::Client.new(client_host, :database => database)
18
23
  end
19
24
 
25
+ def parse_token(str)
26
+ begin
27
+ dd = str.split(",")
28
+ acc_token = ""
29
+ refr_token = ""
30
+ exp_in = ""
31
+
32
+ access_token = /\"accessToken\":\"(\S+)\"/
33
+ refresh_token = /\"refreshToken\":\"(.+)\"/
34
+ expires_in = /\"expiresIn\":(\d+)/
35
+
36
+ for i in dd
37
+ if i.to_s.include?("accessToken")
38
+ acc_token = access_token.match(i)
39
+ elsif i.to_s.include?("refreshToken")
40
+ refr_token = refresh_token.match(i)
41
+ elsif i.to_s.include?("expiresIn")
42
+ exp_in = expires_in.match(i)
43
+ end
44
+ end
45
+ {:status=> 200, :result=>"OK", :accessToken=>acc_token[1], :refreshToken=>refr_token[1], :expiresIn => exp_in[1] }
46
+ rescue
47
+ {:status=> 500, :result=>"failed"}
48
+ end
49
+ end
50
+
51
+ def get_token(app_id, secret)
52
+ path = "/iocm/app/sec/v1.1.0/login"
53
+ url_string = "https://" + platformip + ":" + platformport + path
54
+ uri = URI.parse url_string
55
+ https = Net::HTTP.new(uri.host, uri.port)
56
+ https.use_ssl = true
57
+ https.cert = OpenSSL::X509::Certificate.new( File.read(cert_file) )
58
+ https.key = OpenSSL::PKey::RSA.new( File.read(key_file) )
59
+ https.verify_mode = OpenSSL::SSL::VERIFY_NONE
60
+ request = Net::HTTP::Post.new( uri.path)
61
+ data = {
62
+ :appId => app_id,
63
+ :secret => secret
64
+ }
65
+ request.content_type = 'application/x-www-form-urlencoded'
66
+ request.body = URI.encode_www_form(data)
67
+ res = https.request(request)
68
+ {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
69
+ end
70
+
71
+ #Registering a Directly Connected Device (Verification Code Mode) (V2)
72
+ def dev_register_verif_code_mode(app_id, secret, node_id)
73
+ token = get_token(app_id, secret)[:body]["accessToken"]
74
+ path = "/iocm/app/reg/v1.1.0/deviceCredentials?appId=" + app_id
75
+ url_string = "https://" + platformip + ":" + platformport + path
76
+ uri = URI.parse url_string
77
+ https = Net::HTTP.new(uri.host, uri.port)
78
+ https.use_ssl = true
79
+ https.cert = OpenSSL::X509::Certificate.new( File.read(cert_file) )
80
+ https.key = OpenSSL::PKey::RSA.new( File.read(key_file) )
81
+ https.verify_mode = OpenSSL::SSL::VERIFY_NONE
82
+ request = Net::HTTP::Post.new( uri.path)
83
+ request.content_type = 'application/json'
84
+ request['Authorization'] = 'Bearer ' + token
85
+ request['app_key'] = app_id
86
+ request.body = {nodeId: node_id}.to_json
87
+ res = https.request(request)
88
+ p res.body.to_s
89
+ {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
90
+ end
91
+
92
+
93
+ def dev_delete(app_id, secret, node_id)
94
+ token = get_token(app_id, secret)[:body]["accessToken"]
95
+ path = "/iocm/app/dm/v1.1.0/devices/" + node_id + "?app_Id=" + app_id + "&cascade=true"
96
+ url_string = "https://" + platformip + ":" + platformport + path
97
+ uri = URI.parse url_string
98
+ https = Net::HTTP.new(uri.host, uri.port)
99
+ https.use_ssl = true
100
+ https.cert = OpenSSL::X509::Certificate.new( File.read(cert_file) )
101
+ https.key = OpenSSL::PKey::RSA.new( File.read(key_file))
102
+ https.verify_mode = OpenSSL::SSL::VERIFY_NONE
103
+ request = Net::HTTP::Delete.new( uri.path)
104
+ request.content_type = 'application/json'
105
+ request['Authorization'] = 'Bearer ' + token
106
+ request['app_key'] = app_id
107
+ res = https.request(request)
108
+ {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
109
+ end
110
+
111
+
112
+ #2.2.44 Querying the Device ID
113
+ def querying_device_id(app_id, secret, node_id)
114
+ token = get_token(app_id, secret)[:body]["accessToken"]
115
+ path = "/iocm/app/dm/v1.1.0/queryDeviceIdByNodeId?nodeId=" + node_id
116
+ p path
117
+ url_string = "https://" + platformip + ":" + platformport + path
118
+ uri = URI.parse url_string
119
+ https = Net::HTTP.new(uri.host, uri.port)
120
+ https.use_ssl = true
121
+ https.cert = OpenSSL::X509::Certificate.new( File.read(cert_file) )
122
+ https.key = OpenSSL::PKey::RSA.new( File.read(key_file))
123
+ https.verify_mode = OpenSSL::SSL::VERIFY_NONE
124
+ request = Net::HTTP::Get.new( uri.path)
125
+ request.content_type = 'application/json'
126
+ request['Authorization'] = 'Bearer ' + token
127
+ request['app_key'] = app_id
128
+ res = https.request(request)
129
+ p res.body.to_s
130
+ {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
131
+ end
132
+
133
+ #2.2.14 Querying Device Activation Status
134
+ def querying_device_activ_status(app_id, secret, device_id)
135
+ token = get_token(app_id, secret)[:body]["accessToken"]
136
+ path = "/iocm/app/reg/v1.1.0/devices/" + device_id + "?app_Id=" + app_id
137
+ url_string = "https://" + platformip + ":" + platformport + path
138
+ uri = URI.parse url_string
139
+ https = Net::HTTP.new(uri.host, uri.port)
140
+ https.use_ssl = true
141
+ https.cert = OpenSSL::X509::Certificate.new( File.read(cert_file) )
142
+ https.key = OpenSSL::PKey::RSA.new( File.read(key_file))
143
+ https.verify_mode = OpenSSL::SSL::VERIFY_NONE
144
+ request = Net::HTTP::Get.new( uri.path)
145
+ request.content_type = 'application/json'
146
+ request['Authorization'] = 'Bearer ' + token
147
+ request['app_key'] = app_id
148
+ res = https.request(request)
149
+ {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
150
+ end
151
+
152
+
153
+ #2.9.1 Querying Information About a Device
154
+ def querying_device_info(app_id, secret, device_id)
155
+ token = get_token(app_id, secret)[:body]["accessToken"]
156
+ path = "/iocm/app/dm/v1.1.0/devices/" + device_id + "?app_Id=" + app_id
157
+ url_string = "https://" + platformip + ":" + platformport + path
158
+ uri = URI.parse url_string
159
+ https = Net::HTTP.new(uri.host, uri.port)
160
+ https.use_ssl = true
161
+ https.cert = OpenSSL::X509::Certificate.new( File.read(cert_file) )
162
+ https.key = OpenSSL::PKey::RSA.new( File.read(key_file))
163
+ https.verify_mode = OpenSSL::SSL::VERIFY_NONE
164
+ request = Net::HTTP::Get.new( uri.path)
165
+ request.content_type = 'application/json'
166
+ request['Authorization'] = 'Bearer ' + token
167
+ request['app_key'] = app_id
168
+ res = https.request(request)
169
+ {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
170
+ end
171
+
172
+ #2.9.6 Querying Directly Connected Devices and Their Mounted Devices in Batches
173
+ def querying_device_direct_conn(app_id, secret, dev_list)
174
+ token = get_token(app_id, secret)[:body]["accessToken"]
175
+ path = "/iocm/app/dm/v1.1.0/queryDevicesByIds"
176
+ url_string = "https://" + platformip + ":" + platformport + path
177
+ uri = URI.parse url_string
178
+ https = Net::HTTP.new(uri.host, uri.port)
179
+ https.use_ssl = true
180
+ https.cert = OpenSSL::X509::Certificate.new( File.read(cert_file) )
181
+ https.key = OpenSSL::PKey::RSA.new( File.read(key_file))
182
+ https.verify_mode = OpenSSL::SSL::VERIFY_NONE
183
+ request = Net::HTTP::Post.new( uri.path)
184
+ request.content_type = 'application/json'
185
+ request['Authorization'] = 'Bearer ' + token
186
+ request['app_key'] = app_id
187
+ request.body = {deviceIds: dev_list}.to_json
188
+ res = https.request(request)
189
+ {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
190
+ end
191
+
192
+
193
+ #2.9.19 Querying the Complete Device Type List of All Device Capabilities
194
+ def querying_device_type_list(app_id, secret)
195
+ token = get_token(app_id, secret)[:body]["accessToken"]
196
+ path = "/iocm/app/profile/v1.1.0/allDeviceTypes"
197
+ url_string = "https://" + platformip + ":" + platformport + path
198
+ uri = URI.parse url_string
199
+ https = Net::HTTP.new(uri.host, uri.port)
200
+ https.use_ssl = true
201
+ https.cert = OpenSSL::X509::Certificate.new( File.read(cert_file) )
202
+ https.key = OpenSSL::PKey::RSA.new( File.read(key_file))
203
+ https.verify_mode = OpenSSL::SSL::VERIFY_NONE
204
+ request = Net::HTTP::Get.new( uri.path)
205
+ request.content_type = 'application/json'
206
+ request['Authorization'] = 'Bearer ' + token
207
+ request['app_key'] = app_id
208
+ res = https.request(request)
209
+ {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
210
+ end
211
+
20
212
  def test()
21
213
 
22
- url_string = "https://134.17.93.4:8743/iocm/app/authorize/v1.3.0/app"
214
+ url_string = "https://134.17.93.4:8743/iocm/app/sec/v1.1.0/login"
23
215
  headers = {
24
- 'Authorization'=>'Bearer O2k2aMStOweZOeSoVDYjI3c6uaMa',
216
+ 'Authorization'=>'Bearer ppeMsOq6zdb2fSUH4GoRooS_FgEa',
25
217
  'Content-Type' =>'application/json',
26
218
  'Accept'=>'application/json'
27
219
  }
28
220
 
29
- req = {"dstAppId": "Cd1v0k2gTBCbpQlMVlW1FVqOSqga" }
221
+ req = {"dstAppId": "bCRahH5zSi9SNmyfqv3BkJABAq8a" }
222
+ post_data = URI.encode_www_form(req)
30
223
 
31
224
  uri = URI.parse url_string
32
225
 
@@ -34,18 +227,35 @@ class HuaIot
34
227
  p uri.port
35
228
  p uri.path
36
229
 
230
+
231
+ cert_file = "/Users/imperituroard/Desktop/cert.crt"
232
+ key_file = "/Users/imperituroard/Desktop/key.pem"
233
+
37
234
  p https = Net::HTTP.new(uri.host, uri.port)
38
235
  https.use_ssl = true
236
+ https.cert = OpenSSL::X509::Certificate.new( File.read(cert_file) )
237
+ https.key = OpenSSL::PKey::RSA.new( File.read(key_file) )
238
+ https.verify_mode = OpenSSL::SSL::VERIFY_NONE
39
239
 
40
- request = Net::HTTP::Post.new( uri.path, headers)
240
+ request = Net::HTTP::Post.new( uri.path)
41
241
 
42
- p request.body = req
43
- request['app_key'] = ''
44
- request['Authorization'] = 'Bearer O2k2aMStOweZOeSoVDYjI3c6uaMa'
45
- request.content_type = 'application/json'
242
+ data = {
243
+ :appId => "bCRahH5zSi9SNmyfqv3BkJABAq8a",
244
+ :secret => "ppeMsOq6zdb2fSUH4GoRooS_FgEa"
245
+ }
246
+
247
+
248
+ #request['app_key'] = 'ppeMsOq6zdb2fSUH4GoRooS_FgEa'
249
+ #request['Authorization'] = 'Bearer ppeMsOq6zdb2fSUH4GoRooS_FgEa'
250
+ request.content_type = 'application/x-www-form-urlencoded'
251
+ #p request.body = req
252
+ request.body = URI.encode_www_form(data)
46
253
  res = https.request(request)
254
+ p res.code
47
255
  p res.message
48
256
 
257
+ p parse_token(res.body)
258
+
49
259
  end
50
260
 
51
261
  # App ID
@@ -12,14 +12,30 @@ class MongoIot
12
12
  @iotip = iotip
13
13
  client_host = [mongoip + ":" + mongoport]
14
14
  @client = Mongo::Client.new(client_host, :database => database)
15
+ end
15
16
 
17
+ def audit_logger(proc_name)
18
+ begin
19
+ collection = client[:audit]
20
+ doc = {
21
+ proc_name: proc_name,
22
+ hobbies: [ 'hiking', 'tennis', 'fly fishing' ],
23
+ siblings: {
24
+ brothers: 0,
25
+ sisters: 1
26
+ }
27
+ }
28
+ result = collection.insert_one(doc)
29
+ p result
30
+ rescue
31
+ continue
32
+ end
16
33
  end
17
34
 
18
35
  def ttt
19
36
  p "111111"
20
37
  begin
21
38
  puts(client.cluster.inspect)
22
- puts
23
39
  puts('Collection Names: ')
24
40
  puts(client.database.collection_names)
25
41
  puts('Connected!')
@@ -1,3 +1,3 @@
1
1
  module Imperituroard
2
- VERSION = "0.1.8"
2
+ VERSION = "0.1.9"
3
3
  end
data/lib/imperituroard.rb CHANGED
@@ -6,6 +6,7 @@ require "imperituroard/phpipamdb"
6
6
  require "imperituroard/phpipamcps"
7
7
  require "imperituroard/projects/iot/mongoconnector"
8
8
  require "imperituroard/projects/iot/hua_oceanconnect_adapter"
9
+ require 'json'
9
10
 
10
11
  module Imperituroard
11
12
  class Error < StandardError; end
@@ -80,17 +81,37 @@ class Iot
80
81
  @iotplatform_port = iotplatform_port
81
82
  end
82
83
 
84
+
85
+
83
86
  def test()
84
87
  ddd = MongoIot.new(mongoip, mongoport, iotip, database)
85
88
  ddd.ttt
86
89
  end
87
90
 
88
91
  def testhua()
89
- ddd1 = HuaIot.new(iotplatform_ip, iotplatform_port, "", "")
90
- ddd1.test
91
-
92
+ cert_file = "/Users/imperituroard/Desktop/cert.crt"
93
+ key_file = "/Users/imperituroard/Desktop/key.pem"
94
+ ddd1 = HuaIot.new(iotplatform_ip, iotplatform_port, "", "", cert_file, key_file)
95
+ #p ddd1.dev_register_verif_code_mode("Cd1v0k2gTBCbpQlMVlW1FVqOSqga", "kbfo5JlBxTIhjVwtjHleWS5Iw5wa", "7521234165452")
96
+ #ddd1.querying_device_id("Cd1v0k2gTBCbpQlMVlW1FVqOSqga", "kbfo5JlBxTIhjVwtjHleWS5Iw5wa", "a8834c5e-4b4d-4f0f-ad87-14e916f3d0bb")
97
+ #ddd1.querying_device_activ_status("Cd1v0k2gTBCbpQlMVlW1FVqOSqga", "kbfo5JlBxTIhjVwtjHleWS5Iw5wa", "7521234165452")
98
+ #ddd1.querying_device_info("Cd1v0k2gTBCbpQlMVlW1FVqOSqga", "kbfo5JlBxTIhjVwtjHleWS5Iw5wa", "a8834c5e-4b4d-4f0f-ad87-14e916f3d0bb")
99
+ list = ["41c0ba82-d771-4669-b766-fcbfbedc17f4", "7521234165452", "feb9c4d1-4944-4b04-a717-df87dfde30f7", "9868e121-c309-4f4f-8ab3-0aa69072caff", "b3b82f35-0723-4a83-90af-d4ea40017194"]
100
+ #p ddd1.querying_device_direct_conn("Cd1v0k2gTBCbpQlMVlW1FVqOSqga", "kbfo5JlBxTIhjVwtjHleWS5Iw5wa", list)
101
+ #p ddd1.querying_device_type_list("Cd1v0k2gTBCbpQlMVlW1FVqOSqga", "kbfo5JlBxTIhjVwtjHleWS5Iw5wa")
102
+ p ddd1.querying_device_id("Cd1v0k2gTBCbpQlMVlW1FVqOSqga", "kbfo5JlBxTIhjVwtjHleWS5Iw5wa", "7521234165452")
103
+ #ddd1.dev_delete("Cd1v0k2gTBCbpQlMVlW1FVqOSqga", "kbfo5JlBxTIhjVwtjHleWS5Iw5wa", "484114f6-a49c-4bab-88e6-4ddaf1cc1c8f")
92
104
  end
93
105
 
94
106
 
107
+ def testhua2()
108
+ tt = "{\"deviceId\":\"fad0a417-b6a3-4b0b-abfc-fa2b0af9691a\",\"verifyCode\":\"6cb6dcca\",\"timeout\":180,\"psk\":\"1d16b55d577bc1f2e5e75d416ce6b8a2\"}"
109
+ #tt = tt.gsub("\\","")
110
+ #p tt
111
+ ff = tt.to_s
112
+ p ff
113
+ gg = JSON.parse(ff)
114
+ p gg
115
+ end
95
116
 
96
117
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imperituroard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dzmitry Buynovskiy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-04-05 00:00:00.000000000 Z
11
+ date: 2020-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -28,14 +28,14 @@ dependencies:
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: 12.3.3
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: 12.3.3
41
41
  - !ruby/object:Gem::Dependency
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - '='
109
109
  - !ruby/object:Gem::Version
110
110
  version: 2.11.4
111
+ - !ruby/object:Gem::Dependency
112
+ name: nokogiri
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
111
125
  description: Gem from imperituroard for different actions
112
126
  email:
113
127
  - imperituro.ard@gmail.com