mqtt_rpc 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +4 -2
- data/lib/mqtt_rpc/client.rb +26 -12
- data/lib/mqtt_rpc/version.rb +1 -1
- data/lib/mqtt_rpc.rb +4 -0
- data/mqtt_rpc.gemspec +0 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a9d8c616d22e34f6349620e7e7d7fe1f3c6a98f
|
4
|
+
data.tar.gz: d56cc308d88a175e7ab3cfe0903f3bcd9882c6bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16e1a1dc6a110b518cb60724a1959c0aa2b3bbd51ca2d9fec5b716768f642a56e3b63700edba17e6c62a9543f48eb2e04d67b90cbb5abae1b5f422f7a8c7de7c
|
7
|
+
data.tar.gz: 0d30188b60d96be450d2d2fbb50c1dbe977286968aab65d95eaa1d8f991f5bf72ed7deab8590b7d37ce1f3bfd023998e8ae5100501470bb35742745c9a4bbb04
|
data/README.md
CHANGED
@@ -21,10 +21,12 @@ Or install it yourself as:
|
|
21
21
|
## Usage
|
22
22
|
|
23
23
|
```
|
24
|
-
require '
|
24
|
+
require 'mqtt_rpc'
|
25
25
|
|
26
26
|
client = MQTTRpc::Client.new(options)
|
27
27
|
|
28
|
+
3 seconds will timeout
|
29
|
+
client = MQTTRpc::Client.new(options, 3)
|
30
|
+
|
28
31
|
response_body = client.publish('request_topic', 'message', 'response_topic')
|
29
32
|
```
|
30
|
-
|
data/lib/mqtt_rpc/client.rb
CHANGED
@@ -2,30 +2,44 @@ require 'mqtt'
|
|
2
2
|
|
3
3
|
module MQTTRpc
|
4
4
|
class Client
|
5
|
-
def initialize(options = {})
|
5
|
+
def initialize(options = {}, timeout = 10)
|
6
6
|
@options = options
|
7
|
+
@timeout = timeout
|
7
8
|
end
|
8
9
|
|
9
10
|
def connect
|
10
11
|
MQTT::Client.connect(@options)
|
11
12
|
end
|
12
13
|
|
13
|
-
def
|
14
|
-
subscribe_connect = connect
|
15
|
-
|
14
|
+
def ready
|
15
|
+
@subscribe_connect = connect
|
16
|
+
@publish_connect = connect
|
17
|
+
end
|
16
18
|
|
17
|
-
|
18
|
-
|
19
|
+
def publish(publish_topic, message, subscribe_topic)
|
20
|
+
ready
|
19
21
|
|
20
|
-
subscribe_connect.
|
21
|
-
|
22
|
-
|
22
|
+
@subscribe_connect.subscribe(subscribe_topic)
|
23
|
+
@publish_connect.publish(publish_topic, message)
|
24
|
+
begin
|
25
|
+
Timeout.timeout(@timeout) do
|
26
|
+
@subscribe_connect.get do |_topic, payload|
|
27
|
+
@payload = payload
|
28
|
+
break
|
29
|
+
end
|
30
|
+
end
|
31
|
+
rescue
|
32
|
+
raise TimeoutException
|
33
|
+
ensure
|
34
|
+
destroy
|
23
35
|
end
|
24
36
|
|
25
|
-
subscribe_connect.disconnect
|
26
|
-
publish_connect.disconnect
|
27
|
-
|
28
37
|
@payload
|
29
38
|
end
|
39
|
+
|
40
|
+
def destroy
|
41
|
+
@subscribe_connect.disconnect
|
42
|
+
@publish_connect.disconnect
|
43
|
+
end
|
30
44
|
end
|
31
45
|
end
|
data/lib/mqtt_rpc/version.rb
CHANGED
data/lib/mqtt_rpc.rb
CHANGED
data/mqtt_rpc.gemspec
CHANGED
@@ -13,14 +13,6 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.description = 'mqtt_rpc'
|
14
14
|
spec.homepage = 'https://github.com/menghuanwd/mqtt_rpc'
|
15
15
|
spec.license = 'MIT'
|
16
|
-
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
-
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
-
# if spec.respond_to?(:metadata)
|
19
|
-
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
20
|
-
# else
|
21
|
-
# raise 'RubyGems 2.0 or newer is required to protect against ' \
|
22
|
-
# 'public gem pushes.'
|
23
|
-
# end
|
24
16
|
|
25
17
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
26
18
|
f.match(%r{^(test|spec|features)/})
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mqtt_rpc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- menghuanwd
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mqtt
|