meshruby 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -9
- data/lib/meshruby.rb +4 -3
- data/spec/helpers.rb +14 -0
- data/spec/lib/meshruby_spec.rb +20 -1
- data/spec/spec_helper.rb +2 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb0be396c50c6ee06313e7c2fa474c7a9abe8f12
|
4
|
+
data.tar.gz: afce47f8d170800a5a202705ffd15930280ee2ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d76412c563ec9129058c19c64eb1d75bd1377b4497db24566ca4ec0ab95546e196b8e3bcbed1408a701f883d4859fce57c6ee122925f199d44b058fa65ee548
|
7
|
+
data.tar.gz: b8c61d3806fc3fe8f96a883744e5b6ed6b62830afa9f73c76c11e5aca9b8bd1ed14f8cb82db199140cbeca092d1a27cd8abdd7a43fe28134365200c6c2edfded
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# MeshRuby
|
2
2
|
|
3
|
-
Ruby library for the MeshBlu IoT messaging platform.
|
3
|
+
Ruby library for the MeshBlu IoT messaging platform. We're [on Rubygems.org](https://rubygems.org/gems/meshruby). Tell everybody.
|
4
4
|
|
5
5
|
## Technical Details
|
6
6
|
|
@@ -11,23 +11,24 @@ Pushes incoming messages (background thread) into an EM::Queue object that execu
|
|
11
11
|
|
12
12
|
## Project Status: Active
|
13
13
|
|
14
|
-
Under active maintenance but still in early development.
|
14
|
+
Under active maintenance but still in early development. API is likely to change in future releases.
|
15
|
+
|
16
|
+
The only event that is currently implemented is `onmessage`. Support the project by submitting an issue (you'll win our friendship forever)!
|
15
17
|
|
16
18
|
## Example
|
17
19
|
|
18
|
-
Receive messages from MeshBlu and send a response:
|
20
|
+
Receive messages from MeshBlu and send a response to sender:
|
19
21
|
|
20
22
|
```ruby
|
21
|
-
|
22
|
-
|
23
|
-
token = '22222222222222222222222222222222'
|
23
|
+
uid = '11111111-1111-1111-1111-111111111111'
|
24
|
+
token = '22222222222222222222222222222222'
|
24
25
|
|
25
26
|
EM.run do
|
26
|
-
mesh = EM::MeshRuby.new(uid, token)
|
27
|
-
mesh.onmessage { |msg| mesh.emit(
|
27
|
+
mesh = EM::MeshRuby.new(uid, token).connect
|
28
|
+
mesh.onmessage { |msg| mesh.emit(msg["fromUuid"], {wow: "Thanks! :)"}) }
|
28
29
|
end
|
29
30
|
```
|
30
31
|
|
31
32
|
## Otherstuff
|
32
33
|
|
33
|
-
Licensed under [the Ruby License](https://www.ruby-lang.org/en/about/license.txt). Built with love by [DataMelon](http://www.datamelon.io)
|
34
|
+
Licensed under [the Ruby License](https://www.ruby-lang.org/en/about/license.txt). Built with love by [DataMelon](http://www.datamelon.io).
|
data/lib/meshruby.rb
CHANGED
@@ -9,12 +9,13 @@ module EventMachine
|
|
9
9
|
|
10
10
|
def initialize(uuid, token, url = 'wss://meshblu.octoblu.com:443')
|
11
11
|
@uuid, @token, @url, @queue = uuid, token, url, EventMachine::Queue.new
|
12
|
-
@socket = SocketIO::Client::Simple.
|
12
|
+
@socket = SocketIO::Client::Simple::Client.new url
|
13
13
|
end
|
14
14
|
|
15
15
|
def connect
|
16
16
|
socket.connect
|
17
17
|
create_socket_events
|
18
|
+
self
|
18
19
|
end
|
19
20
|
|
20
21
|
### Bootstraps all the events for MeshBlu in the correct order.
|
@@ -25,12 +26,12 @@ module EventMachine
|
|
25
26
|
auth = {uuid: this.uuid, token: this.token, socketid: data['socketid']}
|
26
27
|
emit :identity, auth
|
27
28
|
end
|
28
|
-
socket.on(:message) { |msg| this.
|
29
|
+
socket.on(:message) { |msg| this.push(msg) }
|
29
30
|
end
|
30
31
|
|
31
32
|
# Sanitize messages, making a best effort attempt to hashify them, otherwise
|
32
33
|
# returns message as-is.
|
33
|
-
def
|
34
|
+
def push(message)
|
34
35
|
@queue.push message.is_a?(String) ? JSON.parse(message) : message
|
35
36
|
rescue JSON::ParserError
|
36
37
|
@queue.push message
|
data/spec/helpers.rb
ADDED
data/spec/lib/meshruby_spec.rb
CHANGED
@@ -1,6 +1,25 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
|
2
3
|
describe EM::MeshRuby do
|
3
|
-
let(:mesh)
|
4
|
+
let(:mesh) do
|
5
|
+
EM::MeshRuby.new('123', '456', '3rdPartyMeshBlueGateway.com')
|
6
|
+
end
|
7
|
+
|
4
8
|
it "initializes" do
|
9
|
+
expect(mesh).to be_kind_of(EM::MeshRuby)
|
10
|
+
expect(mesh.socket).to be_kind_of(SocketIO::Client::Simple::Client)
|
11
|
+
expect(mesh.queue).to be_kind_of(EM::Queue)
|
12
|
+
expect(mesh.uuid).to eq('123')
|
13
|
+
expect(mesh.token).to eq('456')
|
14
|
+
expect(mesh.url).to eq('3rdPartyMeshBlueGateway.com')
|
15
|
+
end
|
16
|
+
|
17
|
+
it "Pushes all kinds of messages" do
|
18
|
+
# Good JSON
|
19
|
+
expect(push_onto(mesh, '{"abc": 123}')).to eq({"abc" => 123})
|
20
|
+
# Bad JSON
|
21
|
+
expect(push_onto(mesh, '{{{')).to eq('{{{')
|
22
|
+
# Unidentified Flying Objects
|
23
|
+
expect(push_onto(mesh, Thread)).to eq(Thread)
|
5
24
|
end
|
6
25
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -5,8 +5,9 @@ SimpleCov.start do
|
|
5
5
|
end
|
6
6
|
require 'pry'
|
7
7
|
require 'meshruby'
|
8
|
-
|
8
|
+
require_relative 'helpers'
|
9
9
|
RSpec.configure do |config|
|
10
|
+
config.include Helpers
|
10
11
|
config.expect_with :rspec do |expectations|
|
11
12
|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
12
13
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: meshruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rick Carlino
|
@@ -121,6 +121,7 @@ files:
|
|
121
121
|
- Rakefile
|
122
122
|
- lib/meshruby.rb
|
123
123
|
- license.txt
|
124
|
+
- spec/helpers.rb
|
124
125
|
- spec/lib/meshruby_spec.rb
|
125
126
|
- spec/spec_helper.rb
|
126
127
|
homepage: http://github.com/datamelon/meshruby
|
@@ -148,5 +149,6 @@ signing_key:
|
|
148
149
|
specification_version: 4
|
149
150
|
summary: Provides ability to connect to the MeshBlu IoT service using EventMachine
|
150
151
|
test_files:
|
152
|
+
- spec/helpers.rb
|
151
153
|
- spec/lib/meshruby_spec.rb
|
152
154
|
- spec/spec_helper.rb
|