space_elevator 0.1.0 → 0.2.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 +4 -4
- data/README.md +3 -3
- data/lib/space_elevator.rb +9 -8
- data/lib/space_elevator/version.rb +1 -1
- 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: 20dac5a9f4d74b3148bbf1fead705e1475dda3e3
|
4
|
+
data.tar.gz: 9a557157816843bc4b827b26203086df1e746cc1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 466e6136b0018c67339b8a90283c75c41de0837cbc647488d61489f3f9df265c30e3deb63e363ec815816e426360703d576917048e493fed4afc64e1ad7dbcb9
|
7
|
+
data.tar.gz: b97ff62a9ebde6f5585465e36ba5e5f8423bdf7397e16f4028ee6f1613a706414f60de9f7a7837c1b10f71e0d637ef485338dabe20ab4f8b21a989ccdc343d76
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# space_elevator - The ActionCable Client for Ruby
|
2
2
|
|
3
|
-
space_elevator is a _client_ for integrating a ruby application with a remote ActionCable-based backend provided by Rails 5 or compatible framework. It allows for subscription and publication to multiple _channels_ simultaneously, and eavesdropping on wire-level messages
|
3
|
+
space_elevator is a _client_ for integrating a ruby application with a remote ActionCable-based backend provided by a Rails 5 application or compatible framework. It allows for subscription and publication to multiple _channels_ simultaneously, features automatic message routing to subscription-specific handlers, and supports eavesdropping on wire-level messages, allowing you to harness the power of WebSockets and receive push notifications in your own Ruby applications!
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -46,8 +46,8 @@ EventMachine.run do
|
|
46
46
|
puts "Received Chat Event: #{chat}"
|
47
47
|
if chat['type'] == 'confirm_subscription'
|
48
48
|
puts "Subscription to #{chat['identifier']['channel']} confirmed!"
|
49
|
-
# Broadcast to the channel!
|
50
|
-
client.publish('ChatChannel', {subject: 'Hi', text: "What's up, y'all!?!?"})
|
49
|
+
# Broadcast to the channel! The actual channel identifier and message payload is specific to your backend's WebSocket API.
|
50
|
+
client.publish({channel: 'ChatChannel'}, {subject: 'Hi', text: "What's up, y'all!?!?"})
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
data/lib/space_elevator.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'space_elevator/version'
|
2
|
+
require 'json'
|
2
3
|
|
3
4
|
module SpaceElevator
|
4
5
|
# Super-light utility for integrating with ActionCable-based backends.
|
@@ -25,8 +26,8 @@ module SpaceElevator
|
|
25
26
|
end
|
26
27
|
client.stream do |raw|
|
27
28
|
message = parse_message(raw.to_s)
|
28
|
-
if message['identifier']
|
29
|
-
channel_handlers[message['identifier']
|
29
|
+
if message['identifier']
|
30
|
+
channel_handlers[message['identifier'].to_json].call(message)
|
30
31
|
else
|
31
32
|
connection_handler.call(message)
|
32
33
|
end
|
@@ -39,23 +40,23 @@ module SpaceElevator
|
|
39
40
|
|
40
41
|
def subscribe(identifier, &block)
|
41
42
|
push(create_subscribe_message(identifier))
|
42
|
-
channel_handlers[identifier
|
43
|
+
channel_handlers[identifier.to_json] = block
|
43
44
|
end
|
44
45
|
|
45
46
|
def push(msg)
|
46
47
|
client.send_msg(msg)
|
47
48
|
end
|
48
49
|
|
49
|
-
def publish(
|
50
|
-
msg = create_publish_message(
|
50
|
+
def publish(identifier, data)
|
51
|
+
msg = create_publish_message(identifier, data)
|
51
52
|
# puts "PUSHING: #{msg}"
|
52
53
|
push(msg)
|
53
54
|
end
|
54
55
|
|
55
|
-
def create_publish_message(
|
56
|
+
def create_publish_message(identifier, data)
|
56
57
|
message = {
|
57
58
|
command: 'message',
|
58
|
-
identifier:
|
59
|
+
identifier: identifier
|
59
60
|
}
|
60
61
|
message[:data] = data.to_json if data
|
61
62
|
message[:identifier] = message[:identifier].to_json
|
@@ -81,4 +82,4 @@ module SpaceElevator
|
|
81
82
|
result
|
82
83
|
end
|
83
84
|
end
|
84
|
-
end
|
85
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: space_elevator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Preston Lee
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: eventmachine
|