meshruby 0.0.3 → 0.0.4
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/console.rb +43 -0
- data/lib/meshruby.rb +13 -0
- data/spec/helpers.rb +1 -0
- data/spec/lib/meshruby_spec.rb +7 -3
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa3cc6739fcfddceafad7ab4cb186f91f099e102
|
4
|
+
data.tar.gz: 236cfea3eb0b7b516a4e3f199b9fa0e5709d2307
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 19f7eca899cab0afb1b628bbee1a0f550efb4a3aaf60ce2dc0a89510c2e408707706d9a20ed17074dd279895df5ba9baf931a5df5f6f02065aebd90de9eedb7c
|
7
|
+
data.tar.gz: 2178fa732361491a61c32ffb6eafcd07fb56865bf4d0a94584c611e3934589ef21ca13dc0377d27620a4f0c4ab4b1b48bf6491562e76b8ceeaf089deb9f6599d
|
data/console.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require_relative 'lib/meshruby'
|
2
|
+
require 'pry'
|
3
|
+
|
4
|
+
uid = "f6cffb60-da03-11e4-b0bb-ed16156c6fa4"
|
5
|
+
token = "7655d4abf306ca5cccbc79ee36f0fac02a230873"
|
6
|
+
|
7
|
+
mesh = EM::MeshRuby.new(uid, token)
|
8
|
+
|
9
|
+
mesh.toggle_debug!
|
10
|
+
|
11
|
+
# http get https://meshblu.octoblu.com/data/f6cffb60-da03-11e4-b0bb-ed16156c6fa4 meshblu_auth_uuid:f6cffb60-da03-11e4-b0bb-ed16156c6fa4 meshblu_auth_token:7655d4abf306ca5cccbc79ee36f0fac02a230873
|
12
|
+
class KeyboardHandler < EM::Connection
|
13
|
+
include EM::Protocols::LineText2
|
14
|
+
|
15
|
+
attr_reader :mesh
|
16
|
+
|
17
|
+
def initialize(mesh)
|
18
|
+
@mesh = mesh
|
19
|
+
end
|
20
|
+
|
21
|
+
def receive_line(data)
|
22
|
+
puts (mesh.instance_eval(data) || "OK")
|
23
|
+
print "> "
|
24
|
+
rescue Exception => exc
|
25
|
+
exit(0) if data.start_with?('q')
|
26
|
+
puts "#{exc.message}"
|
27
|
+
print "> "
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
EM.run do
|
32
|
+
mesh.connect
|
33
|
+
mesh.onmessage do |msg|
|
34
|
+
begin
|
35
|
+
mesh.emit(msg["fromUuid"], {wow: "Thanks! :)"})
|
36
|
+
rescue => e
|
37
|
+
binding.pry
|
38
|
+
end
|
39
|
+
end
|
40
|
+
puts "Ready."
|
41
|
+
print "> "
|
42
|
+
EM.open_keyboard(KeyboardHandler, mesh)
|
43
|
+
end
|
data/lib/meshruby.rb
CHANGED
@@ -41,10 +41,23 @@ module EventMachine
|
|
41
41
|
@queue.pop(&@onmessage) if @onmessage
|
42
42
|
end
|
43
43
|
|
44
|
+
# TODO: Rename to 'message', since this is not the only thing we're emitting
|
44
45
|
def emit(devices, message_hash)
|
45
46
|
socket.emit("message", devices: devices, message: message_hash)
|
46
47
|
end
|
47
48
|
|
49
|
+
def credentials
|
50
|
+
@credentials ||= {uuid: @uuid, token: @token}
|
51
|
+
end
|
52
|
+
|
53
|
+
def data(telemetry)
|
54
|
+
case telemetry
|
55
|
+
when Hash then nil # do stuff
|
56
|
+
else telemetry = {data: telemetry}
|
57
|
+
end
|
58
|
+
socket.emit("data", telemetry.merge!(credentials))
|
59
|
+
end
|
60
|
+
|
48
61
|
def onmessage(&blk)
|
49
62
|
@onmessage = blk
|
50
63
|
end
|
data/spec/helpers.rb
CHANGED
data/spec/lib/meshruby_spec.rb
CHANGED
@@ -15,11 +15,15 @@ describe EM::MeshRuby do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
it "Pushes all kinds of messages" do
|
18
|
+
mesh.queue = []
|
18
19
|
# Good JSON
|
19
|
-
|
20
|
+
mesh.push '{"abc": 123}'
|
21
|
+
expect(mesh.queue.pop).to eq({"abc" => 123})
|
20
22
|
# Bad JSON
|
21
|
-
|
23
|
+
mesh.push('{{{')
|
24
|
+
expect(mesh.queue.pop).to eq('{{{')
|
22
25
|
# Unidentified Flying Objects
|
23
|
-
|
26
|
+
mesh.push(Thread)
|
27
|
+
expect(mesh.queue.pop).to eq(Thread)
|
24
28
|
end
|
25
29
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rick Carlino
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-06-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -119,6 +119,7 @@ files:
|
|
119
119
|
- ".rspec"
|
120
120
|
- README.md
|
121
121
|
- Rakefile
|
122
|
+
- console.rb
|
122
123
|
- lib/meshruby.rb
|
123
124
|
- license.txt
|
124
125
|
- spec/helpers.rb
|
@@ -152,3 +153,4 @@ test_files:
|
|
152
153
|
- spec/helpers.rb
|
153
154
|
- spec/lib/meshruby_spec.rb
|
154
155
|
- spec/spec_helper.rb
|
156
|
+
has_rdoc:
|