sinatra-pubsub 0.0.5 → 0.0.6

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: 88b49616fc359844b36324f48ef20e8b200c4688
4
- data.tar.gz: 5111f02511e1e11e779fcb3f6abb8ae1dfaa55ac
3
+ metadata.gz: 678319b66eb37abf968fb94c42fb51f1afe76459
4
+ data.tar.gz: 2d9c574c2ca3bd5c8acc88f2810e8a3df79773b5
5
5
  SHA512:
6
- metadata.gz: b8f3bea75fb2626c0c6997625fa67ab96fe3e1ca8cd3469b622f70c0ab4e196b5f94a1a6cbd49997f47a10de6adf808e2d6b94f63abb6c5b692e60747edc6df4
7
- data.tar.gz: a37d54ba23e8ebad0177ba23412cd2c7e4f7a0d2ba6ac766c6b9ed605bde38555f93a06d01c836dae790a21e58c9f901be2cde786750396d69ee48fdf0b4974b
6
+ metadata.gz: baa43672e636cff9ae1def170106ec98b181dc39a9be8d0a355687c519995cfc054546eec0743ee3a0132b3e8c23be1de30e20d13c815b859a05bf6bcaf90976
7
+ data.tar.gz: 0990f6d4555f7689b19f3998c106ac14261e1855cae7cd93d20fcb0246768f97306b5a9c16b659d302cf1d7408689dc527dde1e3a01ed27fe985ed4c242af04a
data/.gitignore CHANGED
@@ -15,3 +15,5 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ examples/basic/Gemfile.lock
19
+ examples/tick/Gemfile.lock
data/README.md CHANGED
@@ -24,7 +24,7 @@ And publish to them:
24
24
 
25
25
  ## Requirements
26
26
 
27
- * An evented server, such as Thin
27
+ * Thin
28
28
  * Redis
29
29
  * Sinatra
30
30
 
@@ -57,10 +57,39 @@ You can publish to channels using the `Sinatra::PubSub.publish_all(msg)` or
57
57
  Messages will be automatically serialized to JSON - you'll need to parse them on the client.
58
58
  See the `./examples` dir for more use-cases.
59
59
 
60
- ## Contributing
60
+ ## Herkou 123
61
61
 
62
- 1. Fork it
63
- 2. Create your feature branch (`git checkout -b my-new-feature`)
64
- 3. Commit your changes (`git commit -am 'Add some feature'`)
65
- 4. Push to the branch (`git push origin my-new-feature`)
66
- 5. Create new Pull Request
62
+ It's often a good idea to create a separate streaming server on a subdomain, rather than
63
+ using your main application server for streaming. This gives you a bit more flexibility, like
64
+ letting you use a Unicorn for your application server, and Thin for your streaming server.
65
+ This is a quick guide to creating exactly that on Heroku.
66
+
67
+ First create your streaming server from the 'basic' example.
68
+
69
+ git clone https://github.com/maccman/sinatra-pubsub.git
70
+ cp -r sinatra-pubsub/examples/basic myapp-stream
71
+ cd myapp-stream
72
+ bundle install
73
+ heroku create myapp-stream
74
+ git push heroku master
75
+
76
+ Now the server is deployed, you need to setup Redis. If you already have Redis running
77
+ on your main application server, just run:
78
+
79
+ heroku config -a myapp | grep REDIS
80
+ heroku config:set REDIS_URL=YOUR_REDIS_URL -a myapp-stream
81
+
82
+ Otherwise install the Redis To Go addon:
83
+
84
+ heroku addons:add redis:basic -a myapp-stream
85
+
86
+ And you're finished! You can subscribe to a channel from any browser like this:
87
+
88
+ var es = new EventSource('http://myapp-stream.herokuapp.com/subscribe');
89
+ es.onmessage = function(e) {
90
+ console.log(JSON.parse(e.data));
91
+ };
92
+
93
+ And publish to the stream from any Ruby client connected to the same Redis server:
94
+
95
+ Sinatra::PubSub.publish_all('Hello World')
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+ ruby "2.0.0"
3
+
4
+ gem "sinatra"
5
+ gem "sinatra-pubsub"
6
+ gem "thin"
@@ -0,0 +1,9 @@
1
+ require 'sinatra'
2
+ require 'sinatra/pubsub'
3
+
4
+ register Sinatra::PubSub
5
+
6
+ Sinatra::PubSub.set(
7
+ cors: true,
8
+ origin: '*'
9
+ )
File without changes
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+ ruby "2.0.0"
3
+
4
+ gem "sinatra"
5
+ gem "sinatra-pubsub"
6
+ gem "thin"
@@ -1,11 +1,17 @@
1
- require 'sinatra'
2
- require 'sinatra/pubsub'
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ Bundler.require
3
5
 
4
6
  register Sinatra::PubSub
5
7
 
8
+ Sinatra::PubSub.set(
9
+ cors: false
10
+ )
11
+
6
12
  EventMachine.next_tick do
7
13
  EventMachine::PeriodicTimer.new(1) do
8
- Sinatra::PubSub.publish_all(type: 'tick')
14
+ Sinatra::PubSub.publish('tick', type: 'tick')
9
15
  end
10
16
  end
11
17
 
@@ -21,6 +27,6 @@ __END__
21
27
 
22
28
  <script>
23
29
  // reading
24
- var es = new EventSource('/subscribe');
30
+ var es = new EventSource('/subscribe/tick');
25
31
  es.onmessage = function(e) { log.innerHTML += "\n" + e.data };
26
32
  </script>
@@ -0,0 +1,3 @@
1
+ require File.expand_path('../app', __FILE__)
2
+
3
+ run Sinatra::Application
@@ -4,6 +4,7 @@ module Sinatra
4
4
  configure do
5
5
  set :cors, true
6
6
  set :origin, '*'
7
+ set :server, 'thin'
7
8
  end
8
9
 
9
10
  helpers do
@@ -19,7 +20,7 @@ module Sinatra
19
20
  secure = origin =~ /\Ahttps/
20
21
 
21
22
  allow = settings.origin
22
- allow.gsub!(/\Ahttp:\/\//, 'https://') if secure
23
+ allow = allow.gsub(/\Ahttp:\/\//, 'https://') if secure
23
24
 
24
25
  headers['Access-Control-Allow-Origin'] = allow
25
26
  headers['Access-Control-Allow-Methods'] = 'GET'
@@ -30,7 +31,7 @@ module Sinatra
30
31
  error 402 unless Stream.enabled?
31
32
 
32
33
  stream :keep_open do |out|
33
- stream = Stream.new(out)
34
+ stream = Stream.new(out)
34
35
 
35
36
  if channels = params[:splat]
36
37
  stream.subscribe(channels.join('/'))
@@ -34,8 +34,8 @@ module Sinatra
34
34
  attr_reader :out, :id
35
35
 
36
36
  def initialize(out)
37
- @id = SecureRandom.uuid
38
- @out = out
37
+ @id = SecureRandom.uuid
38
+ @out = out
39
39
 
40
40
  subscribe :all
41
41
 
@@ -1,5 +1,5 @@
1
1
  module Sinatra
2
2
  module PubSub
3
- VERSION = "0.0.5"
3
+ VERSION = "0.0.6"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-pubsub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex MacCaw
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-21 00:00:00.000000000 Z
11
+ date: 2013-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -92,10 +92,14 @@ files:
92
92
  - LICENSE.txt
93
93
  - README.md
94
94
  - Rakefile
95
- - examples/app.rb
96
- - examples/config.ru
97
- - examples/events.module.coffee
98
- - examples/stream.module.coffee
95
+ - examples/basic/Gemfile
96
+ - examples/basic/app.rb
97
+ - examples/basic/config.ru
98
+ - examples/frontend/events.module.coffee
99
+ - examples/frontend/stream.module.coffee
100
+ - examples/tick/Gemfile
101
+ - examples/tick/app.rb
102
+ - examples/tick/config.ru
99
103
  - lib/sinatra/pubsub.rb
100
104
  - lib/sinatra/pubsub/app.rb
101
105
  - lib/sinatra/pubsub/helpers.rb