mosca 0.0.5 → 0.0.6

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: cb5e5ed870c959777ce1d362f9d20d12df283979
4
- data.tar.gz: b9cc31952645221be2a57aff70a0668622da5d04
3
+ metadata.gz: be37d740f97e3b761ff8d222716858cf9dfceaed
4
+ data.tar.gz: c0732450bb5002f2bde911257cc7bb7a9a910376
5
5
  SHA512:
6
- metadata.gz: 2eea2347c5c2ea015ed02a99e8ecf51bb9cb685dc0565a506992bb7eff13511233213aa8b1b1b39a27a499169cf5194ab449c689e0a4185358e039773ea962d3
7
- data.tar.gz: 4fa10abd1bc6c7cfed3f6419543ac35ceb7d7dd98c347d65d1e87e80af9f9705fdfc6a8b14f0e3fe2e92231df85faa2240cb7bbbe107fdb0f25f7553aa11ef7a
6
+ metadata.gz: 0c7bafbe52a95e3daa9a382a7b8d0db0ffaca2f6a2dba52e8b3475b28c09ecbaf513fa18e8063cfb5ffda55659385e309b4f7a5184b58cdfc90a6ad6e997ba08
7
+ data.tar.gz: 872e8bf2434bdd71bead8d3ae5a29b817b89778a8b21c46abf563ff3fa09254016e1cf9e8361fe090a523fda0fe2062070d326ddb27e056deb9d5aaf449a72a6
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mosca (0.0.5)
4
+ mosca (0.0.6)
5
5
  json (~> 1.8.1)
6
6
  mqtt (~> 0.3.0)
7
7
 
data/README.md CHANGED
@@ -42,6 +42,14 @@ The following environment variables are used when creating clients, so you can u
42
42
  ### New instance
43
43
 
44
44
  ```ruby
45
+ # Params (all optional)
46
+ # user
47
+ # pass
48
+ # broker
49
+ # topic_in
50
+ # topic_out
51
+ # topic_base (topics out and in are appended to this)
52
+
45
53
  client = Mosca::Client.new user: "username", pass: "password", topic_in: "readings", topic_out: "commands", topic_base: "/device/"
46
54
  ```
47
55
 
data/lib/mosca/client.rb CHANGED
@@ -8,8 +8,8 @@ module Mosca
8
8
  attr_accessor :default_broker, :default_timeout
9
9
  end
10
10
 
11
- self.default_broker = ENV["MOSCA_BROKER"] || "test.mosquitto.org"
12
- self.default_timeout = 5 || ENV["MOSCA_TIMEOUT"]
11
+ self.default_broker = ENV["MOSCA_BROKER"] || "test.mosquitto.org"
12
+ self.default_timeout = ENV["MOSCA_TIMEOUT"] || 5
13
13
 
14
14
  attr_accessor :user, :pass, :topic_in, :topic_out, :broker, :topic_base, :client
15
15
 
@@ -58,6 +58,10 @@ module Mosca
58
58
  topic_base + topic_name
59
59
  end
60
60
 
61
+ def refresh_connection
62
+ connection
63
+ end
64
+
61
65
  private
62
66
 
63
67
  def client_options
@@ -0,0 +1,36 @@
1
+ require 'json'
2
+
3
+ module Mosca
4
+ module CommandBuilder
5
+ def method_missing(method, *args)
6
+ json = full_hash(method, *args).to_json
7
+ client.publish json
8
+ end
9
+
10
+ protected
11
+
12
+ def default_hash
13
+ {}
14
+ end
15
+
16
+ def process_command command, args
17
+ {command: command}
18
+ end
19
+
20
+ private
21
+
22
+ def specific_hash method, args
23
+ hash = {}
24
+ if respond_to? "#{method}_hash"
25
+ hash.merge! send("#{method}_hash", args)
26
+ end
27
+ hash
28
+ end
29
+
30
+ def full_hash method, *args
31
+ command_default = process_command(method, *args)
32
+ command_specific = specific_hash(method, *args)
33
+ default_hash.merge(command_default).merge(command_specific)
34
+ end
35
+ end
36
+ end
data/lib/mosca/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Mosca
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
data/spec/mosca_spec.rb CHANGED
@@ -125,11 +125,15 @@ describe Mosca::Client do
125
125
  end
126
126
 
127
127
  it "publish returns nil" do
128
- expect(mosca.publish).to be nil
128
+ expect(mosca.publish 123).to be nil
129
129
  end
130
130
 
131
131
  it "get! raises the timed out exception" do
132
- expect(mosca.get!).to raise_error
132
+ expect{ mosca.get! }.to raise_error Timeout::Error
133
+ end
134
+
135
+ it "publish! raises the timed out exception" do
136
+ expect{ mosca.publish! 123 }.to raise_error Timeout::Error
133
137
  end
134
138
  end
135
139
  end
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.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Armando Andini
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-11 00:00:00.000000000 Z
11
+ date: 2014-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mqtt
@@ -106,9 +106,9 @@ files:
106
106
  - Gemfile.lock
107
107
  - README.md
108
108
  - Rakefile
109
- - lib/command_builder.rb
110
109
  - lib/mosca.rb
111
110
  - lib/mosca/client.rb
111
+ - lib/mosca/command_builder.rb
112
112
  - lib/mosca/exceptions.rb
113
113
  - lib/mosca/version.rb
114
114
  - mosca.gemspec
@@ -1,38 +0,0 @@
1
- require 'json'
2
-
3
- module CommandBuilder
4
- public
5
-
6
- def method_missing(method, *args)
7
- json = full_hash(method, *args).to_json
8
- client.publish json
9
- end
10
-
11
- protected
12
-
13
- def default_hash
14
- {}
15
- end
16
-
17
- def process_command command, args
18
- {command: command}
19
- end
20
-
21
- private
22
-
23
- def specific_hash method, args
24
- hash = {}
25
- if respond_to? "#{method}_hash"
26
- hash.merge! send("#{method}_hash", args)
27
- end
28
- hash
29
- end
30
-
31
- def full_hash method, *args
32
- command_default = process_command(method, *args)
33
- command_specific = specific_hash(method, *args)
34
- default_hash.merge(command_default).merge(command_specific)
35
- end
36
-
37
-
38
- end