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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d5c508252df0ffc2f5f92b49f94034b9e869ea59
4
- data.tar.gz: f8c316961a39b24f63c9608326336888a117a9be
3
+ metadata.gz: 20dac5a9f4d74b3148bbf1fead705e1475dda3e3
4
+ data.tar.gz: 9a557157816843bc4b827b26203086df1e746cc1
5
5
  SHA512:
6
- metadata.gz: '069f5e2925bd28ec63d1eef3b3ff926374ccfaeee6e74523f60e825c8ebc39a10718bc9e1977a12b3dbe0d2d37962e74b9a6a394e7e228713f5bf519d0fced51'
7
- data.tar.gz: 1906914eafafe526dbc65acfea27cf004feede44429dd4a65fd836336ed1208d07501161421027d2a445de0c5d028750f8ebc32013cfe115f01a2fd6290bb00b
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. Harness the power of WebSockets to receive push notifications in your own Ruby applications!
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
 
@@ -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'] && message['identifier']['channel']
29
- channel_handlers[message['identifier']['channel']].call(message)
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[:channel]] = block
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(channel, data)
50
- msg = create_publish_message(channel, data)
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(channel, data)
56
+ def create_publish_message(identifier, data)
56
57
  message = {
57
58
  command: 'message',
58
- identifier: { channel: channel }
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
@@ -1,3 +1,3 @@
1
1
  module SpaceElevator
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  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.1.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-03 00:00:00.000000000 Z
11
+ date: 2017-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eventmachine