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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 93c1f7910c6463e3dab0333c2cbbeb2e0ffa92b2
4
- data.tar.gz: d497e1431d068d1e5ffdcc56cff555e524daf99e
3
+ metadata.gz: 5a9d8c616d22e34f6349620e7e7d7fe1f3c6a98f
4
+ data.tar.gz: d56cc308d88a175e7ab3cfe0903f3bcd9882c6bd
5
5
  SHA512:
6
- metadata.gz: e548649221cba1c2a3b05668be760c49dc3542769c65107320bf90e72e410e2e9e9eb5ff447f9b1ab59f7e1a342dd85793e2b1a07009b431cdd41083a34c7659
7
- data.tar.gz: c8d0aa7bc9e6e55a246b9c0c388f33114b0248f55ac29b17566c28fff2a0322dab04acf3f7698a1fb9cd1cf670cd0286687739e7d89eee3c63a0b53bf272a81c
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 'bunny_rpc'
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
-
@@ -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 publish(publish_topic, message, subscribe_topic)
14
- subscribe_connect = connect
15
- subscribe_connect.subscribe(subscribe_topic)
14
+ def ready
15
+ @subscribe_connect = connect
16
+ @publish_connect = connect
17
+ end
16
18
 
17
- publish_connect = connect
18
- publish_connect.publish(publish_topic, message)
19
+ def publish(publish_topic, message, subscribe_topic)
20
+ ready
19
21
 
20
- subscribe_connect.get do |_topic, message|
21
- @payload = message
22
- break
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
@@ -1,3 +1,3 @@
1
1
  module MQTTRpc
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
data/lib/mqtt_rpc.rb CHANGED
@@ -1,2 +1,6 @@
1
1
  require 'mqtt_rpc/version'
2
2
  require 'mqtt_rpc/client'
3
+
4
+ module MQTTRpc
5
+ class TimeoutException < StandardError; end
6
+ end
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.1.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-07 00:00:00.000000000 Z
11
+ date: 2016-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mqtt