mosca 0.0.9 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/lib/mosca/client.rb +21 -16
- data/lib/mosca/version.rb +1 -1
- data/spec/mosca_spec.rb +5 -4
- 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: d27a9cc149fcd2c3204b832ece96c66329c7448d
|
4
|
+
data.tar.gz: 6219f4bb5be919658a32364dc5b755b93d7b6b9e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6463fdf1b45ac1fdfdb5a3e323ec7ec205ff773ae97c72b0e2ef5c31782da9d742fbc144a95306b9b06d8309dece9000df4b89b98ed2747fa99d1d167a837b60
|
7
|
+
data.tar.gz: 18696c8ff48bf8232fe1874524670e49d0ba2fda9729ea5fe364ba5d79efe8ebf7fa8c76492366a04f9a0334d90b6d7488c2e9ee5c93393b9f10e7a32e13d8a2
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
mosca (0.0
|
4
|
+
mosca (0.1.0)
|
5
5
|
json (~> 1.8.1)
|
6
6
|
mqtt (~> 0.3, >= 0.3.1)
|
7
7
|
|
@@ -13,7 +13,7 @@ GEM
|
|
13
13
|
coderay (1.1.0)
|
14
14
|
diff-lcs (1.2.5)
|
15
15
|
docile (1.1.5)
|
16
|
-
json (1.8.
|
16
|
+
json (1.8.2)
|
17
17
|
method_source (0.8.2)
|
18
18
|
mqtt (0.3.1)
|
19
19
|
multi_json (1.10.1)
|
data/lib/mosca/client.rb
CHANGED
@@ -7,28 +7,33 @@ module Mosca
|
|
7
7
|
class Client
|
8
8
|
extend Forwardable
|
9
9
|
|
10
|
-
DEFAULT_KEEP_ALIVE = 10
|
11
10
|
KEEP_ALIVE_MARGIN = 5
|
12
11
|
|
12
|
+
# class attributes
|
13
13
|
class << self
|
14
14
|
attr_accessor :default_broker, :default_timeout
|
15
15
|
end
|
16
16
|
|
17
|
-
|
18
|
-
|
17
|
+
attr_accessor :user, :pass, :topic_in, :topic_out, :broker, :topic_base,
|
18
|
+
:client, :keep_alive, :port, :time_out
|
19
19
|
|
20
|
-
attr_accessor :user, :pass, :topic_in, :topic_out, :broker, :topic_base, :client
|
21
20
|
def_delegators :connection, :subscribe
|
22
21
|
|
23
22
|
def initialize args = {}
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
23
|
+
default_attributes.merge(args).each do |k,v|
|
24
|
+
self.send("#{k}=", v)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def default_attributes
|
29
|
+
{ user: ENV["MOSCA_USER"],
|
30
|
+
pass: ENV["MOSCA_PASS"],
|
31
|
+
topic_base: "",
|
32
|
+
broker: ENV["MOSCA_BROKER"] || self.class.default_broker || "test.mosquitto.org",
|
33
|
+
client: MQTT::Client,
|
34
|
+
keep_alive: 10,
|
35
|
+
time_out: (ENV["MOSCA_TIMEOUT"] || self.class.default_timeout || 5).to_i
|
36
|
+
}
|
32
37
|
end
|
33
38
|
|
34
39
|
def publish! message, params = {}
|
@@ -77,7 +82,7 @@ module Mosca
|
|
77
82
|
private
|
78
83
|
|
79
84
|
def client_options
|
80
|
-
{remote_host: @broker, username: @user, password: @pass}
|
85
|
+
{remote_host: @broker, remote_port: @port, username: @user, password: @pass}
|
81
86
|
end
|
82
87
|
|
83
88
|
def connection
|
@@ -96,9 +101,9 @@ module Mosca
|
|
96
101
|
response
|
97
102
|
end
|
98
103
|
|
99
|
-
def timeout params
|
100
|
-
|
101
|
-
Timeout.timeout(
|
104
|
+
def timeout params, &b
|
105
|
+
seconds = params[:timeout] || time_out
|
106
|
+
Timeout.timeout(seconds) do
|
102
107
|
yield
|
103
108
|
end
|
104
109
|
end
|
data/lib/mosca/version.rb
CHANGED
data/spec/mosca_spec.rb
CHANGED
@@ -11,7 +11,7 @@ describe Mosca::Client do
|
|
11
11
|
}
|
12
12
|
|
13
13
|
let (:mosca) {
|
14
|
-
mosca = Mosca::Client.new topic_out: OUT, topic_in: IN, client: client, keep_alive: KEEP_ALIVE
|
14
|
+
mosca = Mosca::Client.new topic_out: OUT, topic_in: IN, client: client, keep_alive: KEEP_ALIVE, port: "port"
|
15
15
|
}
|
16
16
|
|
17
17
|
it "has a default broker" do
|
@@ -38,7 +38,8 @@ describe Mosca::Client do
|
|
38
38
|
end
|
39
39
|
|
40
40
|
it "should wait for a response on topic_in if it's specified" do
|
41
|
-
expect(client).to receive(:connect).
|
41
|
+
expect(client).to receive(:connect).with(hash_including(remote_port: "port"))
|
42
|
+
.once.and_call_original
|
42
43
|
expect(mosca.publish(MESSAGE, response: true)).to eq("response")
|
43
44
|
end
|
44
45
|
end
|
@@ -109,12 +110,12 @@ describe Mosca::Client do
|
|
109
110
|
|
110
111
|
describe "Timeout" do
|
111
112
|
it "has a default timeout of 5 seconds" do
|
112
|
-
expect(
|
113
|
+
expect(described_class.new.time_out).to eq(5)
|
113
114
|
end
|
114
115
|
|
115
116
|
it "can set a default timeout" do
|
116
117
|
described_class.default_timeout = 1
|
117
|
-
expect(described_class.
|
118
|
+
expect(described_class.new.time_out).to eq 1
|
118
119
|
end
|
119
120
|
|
120
121
|
it "calls timeout when getting a message" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mosca
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Armando Andini
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mqtt
|