meshruby 0.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 69d5216a1145620af4ae8c7426e0b90576529e73
4
+ data.tar.gz: 706f4690c484c33165794975acb510b0235721c1
5
+ SHA512:
6
+ metadata.gz: 4e8b46a916151e455dec6c7ce2ae08b27f77dfc5cbd7f2efcd0eeee346bf1c80bc2800ffa3fd683e67528e1dd72b30e9f5de6aab44a21aefefb2c3568085833e
7
+ data.tar.gz: 859b30918b20408ee423eba795abd4b7795c9c955a4fa94dca16621d9634374d553bc1a2f67d70ecafda5e0c5eae890e6b5aa63d7d97e37187335e69d078fa82
data/.gitignore ADDED
@@ -0,0 +1,46 @@
1
+ *.rbc
2
+ *.swp
3
+ .bundle/*
4
+ .DS_Store
5
+ .idea/*
6
+ .loadpath
7
+ .project
8
+ .ruby-gemset
9
+ .ruby-version
10
+ /.bundle
11
+ /.bundle/
12
+ /.yardoc/
13
+ /_yardoc/
14
+ /coverage/
15
+ /coverage/
16
+ /db/*.sqlite3
17
+ /db/*.sqlite3-journal
18
+ /doc/
19
+ /InstalledFiles
20
+ /lib/.build
21
+ /lib/bundler/man/
22
+ /log/*.log
23
+ /pkg/
24
+ /rdoc/
25
+ /spec/reports/
26
+ /test/tmp/
27
+ /test/version_tmp/
28
+ /tmp
29
+ /tmp/
30
+ config.yml
31
+ coverage/**
32
+ credentials.yml
33
+ doc/*
34
+ doc/**/*
35
+ Gemfile.lock
36
+ log/*
37
+ notes.rb
38
+ settings.rb
39
+ /lib/.build
40
+ write_db_settings.rb
41
+ snippet.coffee
42
+ snippets.rb
43
+ tmp/**/*
44
+ *.rb~
45
+ Gemfile.lock
46
+ idea.rb
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --require spec_helper
3
+ --format documentation
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # MeshRuby
2
+
3
+ Ruby library for the MeshBlu IoT messaging platform.
4
+
5
+ ## Technical Details
6
+
7
+ * [socket.io-client-simple](https://github.com/shokai/ruby-socket.io-client-simple) as a [SocketIO](http://socket.io/) client.
8
+ * [EventMachine](https://github.com/eventmachine/eventmachine) for single threaded concurrency goodness.
9
+
10
+ Pushes incoming messages (background thread) into an EM::Queue object that executes in the main thread.
11
+
12
+ ## Project Status: Active
13
+
14
+ Under active maintenance but still in early development. The only event that is currently implemented is `onmessage`. Support the project by submitting an issue (you'll win our friendship forever)!
15
+
16
+ ## Example
17
+
18
+ Receive messages from MeshBlu and send a response:
19
+
20
+ ```ruby
21
+ friends = ['00000000-0000-0000-0000-000000000000']
22
+ uid = '11111111-1111-1111-1111-111111111111'
23
+ token = '22222222222222222222222222222222'
24
+
25
+ EM.run do
26
+ mesh = EM::MeshRuby.new(uid, token)
27
+ mesh.onmessage { |msg| mesh.emit(friends, "Thanks! :)") }
28
+ end
29
+ ```
30
+
31
+ ## Otherstuff
32
+
33
+ Licensed under [the Ruby License](https://www.ruby-lang.org/en/about/license.txt). Built with love by [DataMelon](http://www.datamelon.io)
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.libs << 'test'
5
+ t.test_files = Dir.glob('test/**/*_test.rb')
6
+ end
7
+
8
+ desc "Run tests"
9
+ task :default => :test
data/lib/meshruby.rb ADDED
@@ -0,0 +1,47 @@
1
+ require 'json'
2
+ require 'socket.io-client-simple'
3
+ require 'eventmachine'
4
+
5
+ module EventMachine
6
+ # Communicates with MeshBlu(tm) via websocket connection.
7
+ class MeshRuby
8
+ attr_accessor :socket, :uuid, :token, :queue, :url
9
+
10
+ def initialize(uuid, token, url = 'wss://meshblu.octoblu.com:443')
11
+ @uuid, @token, @url, @queue = uuid, token, url, EventMachine::Queue.new
12
+ @socket = SocketIO::Client::Simple.connect url
13
+ end
14
+
15
+ def connect
16
+ socket.connect
17
+ create_socket_events
18
+ end
19
+
20
+ ### Bootstraps all the events for MeshBlu in the correct order.
21
+ def create_socket_events
22
+ #OTHER EVENTS: :identify, :identity, :ready, :disconnect, :message
23
+ this = self
24
+ socket.on :identify do |data|
25
+ auth = {uuid: this.uuid, token: this.token, socketid: data['socketid']}
26
+ emit :identity, auth
27
+ end
28
+ socket.on(:message) { |msg| this.handle_message(msg) }
29
+ end
30
+
31
+ # Sanitize messages, making a best effort attempt to hashify them, otherwise
32
+ # returns message as-is.
33
+ def handle_message(message)
34
+ @queue.push message.is_a?(String) ? JSON.parse(message) : message
35
+ rescue JSON::ParserError
36
+ @queue.push message
37
+ end
38
+
39
+ def emit(devices, message_hash)
40
+ socket.emit("message", devices: devices, message: message_hash)
41
+ end
42
+
43
+ def onmessage(&blk)
44
+ queue.pop(&blk)
45
+ end
46
+ end
47
+ end
data/license.txt ADDED
@@ -0,0 +1,57 @@
1
+
2
+ Ruby is copyrighted free software by Yukihiro Matsumoto <matz@netlab.jp>.
3
+ You can redistribute it and/or modify it under either the terms of the
4
+ 2-clause BSDL (see the file BSDL), or the conditions below:
5
+
6
+ 1. You may make and give away verbatim copies of the source form of the
7
+ software without restriction, provided that you duplicate all of the
8
+ original copyright notices and associated disclaimers.
9
+
10
+ 2. You may modify your copy of the software in any way, provided that
11
+ you do at least ONE of the following:
12
+
13
+ a) place your modifications in the Public Domain or otherwise
14
+ make them Freely Available, such as by posting said
15
+ modifications to Usenet or an equivalent medium, or by allowing
16
+ the author to include your modifications in the software.
17
+
18
+ b) use the modified software only within your corporation or
19
+ organization.
20
+
21
+ c) give non-standard binaries non-standard names, with
22
+ instructions on where to get the original software distribution.
23
+
24
+ d) make other distribution arrangements with the author.
25
+
26
+ 3. You may distribute the software in object code or binary form,
27
+ provided that you do at least ONE of the following:
28
+
29
+ a) distribute the binaries and library files of the software,
30
+ together with instructions (in the manual page or equivalent)
31
+ on where to get the original distribution.
32
+
33
+ b) accompany the distribution with the machine-readable source of
34
+ the software.
35
+
36
+ c) give non-standard binaries non-standard names, with
37
+ instructions on where to get the original software distribution.
38
+
39
+ d) make other distribution arrangements with the author.
40
+
41
+ 4. You may modify and include the part of the software into any other
42
+ software (possibly commercial). But some files in the distribution
43
+ are not written by the author, so that they are not under these terms.
44
+
45
+ For the list of those files and their copying conditions, see the
46
+ file LEGAL.
47
+
48
+ 5. The scripts and library files supplied as input to or produced as
49
+ output from the software do not automatically fall under the
50
+ copyright of the software, but belong to whomever generated them,
51
+ and may be sold commercially, and may be aggregated with this
52
+ software.
53
+
54
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
55
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
56
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
57
+ PURPOSE.
@@ -0,0 +1,6 @@
1
+ require 'spec_helper'
2
+ describe EM::MeshRuby do
3
+ let(:mesh) { EM::MeshRuby.new }
4
+ it "initializes" do
5
+ end
6
+ end
@@ -0,0 +1,17 @@
1
+ require 'simplecov'
2
+
3
+ SimpleCov.start do
4
+ add_filter "/spec/"
5
+ end
6
+ require 'pry'
7
+ require 'meshruby'
8
+
9
+ RSpec.configure do |config|
10
+ config.expect_with :rspec do |expectations|
11
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
12
+ end
13
+
14
+ config.mock_with :rspec do |mocks|
15
+ mocks.verify_partial_doubles = true
16
+ end
17
+ end
metadata ADDED
@@ -0,0 +1,152 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: meshruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Rick Carlino
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: eventmachine
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: socket.io-client-simple
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: 3rd party MeshBlu library for Ruby
112
+ email:
113
+ - rick.carlino@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - README.md
121
+ - Rakefile
122
+ - lib/meshruby.rb
123
+ - license.txt
124
+ - spec/lib/meshruby_spec.rb
125
+ - spec/spec_helper.rb
126
+ homepage: http://github.com/datamelon/meshruby
127
+ licenses:
128
+ - Ruby
129
+ metadata: {}
130
+ post_install_message:
131
+ rdoc_options: []
132
+ require_paths:
133
+ - lib
134
+ required_ruby_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ required_rubygems_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ requirements: []
145
+ rubyforge_project:
146
+ rubygems_version: 2.4.5
147
+ signing_key:
148
+ specification_version: 4
149
+ summary: Provides ability to connect to the MeshBlu IoT service using EventMachine
150
+ test_files:
151
+ - spec/lib/meshruby_spec.rb
152
+ - spec/spec_helper.rb