websocket-rails 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # WebsocketRails Change Log
2
2
 
3
+ ## Version 0.1.8
4
+
5
+ July 18
6
+
7
+ * Fix bug in Channel#trigger preventing the data from coming through
8
+ properly.
9
+
10
+ ## Version 0.1.7
11
+
12
+ July 17
13
+
14
+ * Fixed botched release of 0.1.6
15
+ * Reorganized directory structure
16
+
3
17
  ## Version 0.1.6
4
18
 
5
19
  July 17 2012
data/README.md CHANGED
@@ -2,22 +2,11 @@
2
2
 
3
3
  [![Build Status](https://secure.travis-ci.org/DanKnox/websocket-rails.png)](https://secure.travis-ci.org/DanKnox/websocket-rails)
4
4
 
5
- If you haven't done so yet, check out the [Project Page](http://danknox.github.com/websocket-rails/) to get a feel for the project direction. Feedback is very much appreciated. Post an issue on the issue tracker or [shoot us an email](mailto://support@threedotloft.com) to give us your thoughts.
5
+ If you haven't done so yet, check out the [Project Page](http://danknox.github.com/websocket-rails/) to get a feel for the project direction. Feedback is very much appreciated. Post an issue on the issue tracker or [shoot us an email](mailto:support@threedotloft.com) to give us your thoughts.
6
6
 
7
- ## IMPORTANT NOTE
7
+ ## Recent Updates
8
8
 
9
- Not sure what happened when I released last night, but version 0.1.6 is
10
- currently broken if you download it from Rubygems. Please use `gem
11
- 'websocket-rails', :git =>
12
- 'git://github.com/DanKnox/websocket-rails.git'` in your Gemfile until I
13
- resolve the broken package.
14
-
15
- ## Update July 17 2012
16
-
17
- We just released a new version containing significant new functionality.
18
- We will be updating the documentation and wiki guides to cover it all over the next day
19
- or two but check out the
20
- [CHANGELOG](https://github.com/DanKnox/websocket-rails/blob/master/CHANGELOG.md) to get an early preview.
9
+ Check out the [CHANGELOG](https://github.com/DanKnox/websocket-rails/blob/master/CHANGELOG.md) to find out what's new.
21
10
 
22
11
  ## Overview
23
12
 
@@ -27,7 +16,25 @@ aren't quite universal yet. That's why we also support streaming HTTP.
27
16
  Oh, and if you don't mind running a separate process, you can support
28
17
  just about any browser with Flash sockets.
29
18
 
30
- ## Respond Quicker with Socket Events
19
+ ## Installation and Usage Guides
20
+
21
+ Check out the [Example Application](https://github.com/DanKnox/websocket-rails-Example-Project) for an example implementation.
22
+
23
+ * [Installation
24
+ Guide](https://github.com/DanKnox/websocket-rails/wiki/Installation-and-Setup)
25
+ * [Event
26
+ Router](https://github.com/DanKnox/websocket-rails/wiki/The-Event-Router)
27
+ * [WebsocketRails Controllers](https://github.com/DanKnox/websocket-rails/wiki/WebsocketRails Controllers)
28
+ * [Using the JavaScript
29
+ Client](https://github.com/DanKnox/websocket-rails/wiki/Using-the-JavaScript-Client)
30
+ * [Using
31
+ Channels](https://github.com/DanKnox/websocket-rails/wiki/Working-with-Channels)
32
+ * [Using Private Channels](https://github.com/DanKnox/websocket-rails/wiki/Using-Private-Channels)
33
+ * [The
34
+ DataStore](https://github.com/DanKnox/websocket-rails/wiki/Using-the-DataStore)
35
+ * [Reloading Controllers In Development](https://github.com/DanKnox/websocket-rails/wiki/Reloading-Controllers-In-Development)
36
+
37
+ ## Handle Events With Class
31
38
 
32
39
  Map events to controller actions using an Event Router.
33
40
 
@@ -46,7 +53,9 @@ var task = {
46
53
  name: 'Start taking advantage of WebSockets',
47
54
  completed: false
48
55
  }
49
- dispatcher = new WebSocketRails('localhost:3000/websocket');
56
+
57
+ var dispatcher = new WebSocketRails('localhost:3000/websocket');
58
+
50
59
  dispatcher.trigger('tasks.create', task);
51
60
  ````
52
61
 
@@ -74,6 +83,54 @@ dispatcher.bind('tasks.create_successful', function(task) {
74
83
  });
75
84
  ````
76
85
 
86
+ Or just attach success and failure callbacks to your client events.
87
+
88
+ ````javascript
89
+ var success = function(task) { console.log("Created: " + task.name); }
90
+
91
+ var failure = function(task) {
92
+ console.log("Failed to create Product: " + product.name)
93
+ }
94
+
95
+ dispatcher.trigger('products.create', success, failure);
96
+ ````
97
+
98
+ Then trigger them in your controller:
99
+
100
+ ````ruby
101
+ def create
102
+ task = Task.create message
103
+ if task.save
104
+ trigger_success task
105
+ else
106
+ trigger_failure task
107
+ end
108
+ end
109
+ ````
110
+
111
+ If you're feeling truly lazy, just trigger the failure callback with an
112
+ exception.
113
+
114
+ ````ruby
115
+ def create
116
+ task = Task.create! message
117
+ trigger_success task # trigger success if the save went alright
118
+ end
119
+ ````
120
+
121
+ That controller is starting to look pretty clean.
122
+
123
+ Now in the failure callback on the client we have access to the record
124
+ and the errors.
125
+
126
+ ````javascript
127
+ var failureCallback = function(task) {
128
+ console.log( task.name );
129
+ console.log( task.errors );
130
+ console.log( "You have " + task.errors.length + " errors." );
131
+ }
132
+ ````
133
+
77
134
  ## Channel Support
78
135
 
79
136
  Keep your users up to date without waiting for them to refresh the page.
@@ -94,24 +151,41 @@ controller.
94
151
 
95
152
  ````ruby
96
153
  latest_post = Post.latest
97
- WebsocketRails[:posts].trigger('new', latest_post)
154
+ WebsocketRails[:posts].trigger 'new', latest_post
98
155
  ````
99
156
 
100
- ## Installation and Usage Guides
157
+ ## Private Channel Support
101
158
 
102
- Check out the [Example Application](https://github.com/DanKnox/websocket-rails-Example-Project) for an example implementation.
159
+ Need to restrict access to a particular channel? No problem. We've got
160
+ that.
103
161
 
104
- * [Installation
105
- Guide](https://github.com/DanKnox/websocket-rails/wiki/Installation-and-Setup)
106
- * [Event
107
- Router](https://github.com/DanKnox/websocket-rails/wiki/The-Event-Router)
108
- * [WebsocketRails Controllers](https://github.com/DanKnox/websocket-rails/wiki/WebsocketRails Controllers)
109
- * [Using the JavaScript
110
- Client](https://github.com/DanKnox/websocket-rails/wiki/Using-the-JavaScript-Client)
111
- * [Using
112
- Channels](https://github.com/DanKnox/websocket-rails/wiki/Working-with-Channels)
113
- * [The
114
- DataStore](https://github.com/DanKnox/websocket-rails/wiki/Using-the-DataStore)
162
+ Private channels give you the ability to authorize a user's
163
+ subscription using the authorization mechanism of your choice.
164
+
165
+ Just tell WebsocketRails which channels you would like to make private by using the `private_channel` method in the Event Router.
166
+ Then handle the channel authorization by subscribing to the `websocket_rails.subscribe_private` event.
167
+
168
+ ````ruby
169
+ WebsocketRails::EventMap.describe do
170
+ private_channel :secret_posts
171
+
172
+ namespace :websocket_rails
173
+ subscribe :subscribe_private, :to => AuthorizationController, :with_method => :authorize_channels
174
+ end
175
+ ````
176
+
177
+ Or you can always mark any channel as private later on.
178
+
179
+ ````ruby
180
+ WebsocketRails[:secret_posts].make_private
181
+ ````
182
+
183
+ On the client side, you can use the `dispatcher.subscribe_private()`
184
+ method to subscribe to a private channel.
185
+
186
+ Read the [Private Channel Wiki](https://github.com/DanKnox/websocket-rails/wiki/Using-Private-Channels) for more information on subscribing to
187
+ private channels from the JavaScript client and handling the
188
+ authorization in your controller.
115
189
 
116
190
  ## Development
117
191
 
@@ -14,9 +14,9 @@ module WebsocketRails
14
14
  end
15
15
 
16
16
  def trigger(event_name,data={})
17
- data.merge! :channel => name
18
- event = Event.new event_name, data
19
- send_data event
17
+ event_data = {:data => data, :channel => name}
18
+ channel_event = Event.new event_name, event_data
19
+ send_data channel_event
20
20
  end
21
21
 
22
22
  def trigger_event(event)
@@ -1,3 +1,3 @@
1
1
  module WebsocketRails
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.8"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: websocket-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-07-17 00:00:00.000000000Z
14
+ date: 2012-07-19 00:00:00.000000000Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rails
@@ -232,7 +232,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
232
232
  version: '0'
233
233
  segments:
234
234
  - 0
235
- hash: -1609185237032377191
235
+ hash: -2237718608609938640
236
236
  required_rubygems_version: !ruby/object:Gem::Requirement
237
237
  none: false
238
238
  requirements:
@@ -241,7 +241,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
241
241
  version: '0'
242
242
  segments:
243
243
  - 0
244
- hash: -1609185237032377191
244
+ hash: -2237718608609938640
245
245
  requirements: []
246
246
  rubyforge_project: websocket-rails
247
247
  rubygems_version: 1.8.19