Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Combine Event and Message class into Event; cohesive and easier to un…

…derstand
  • Loading branch information...
commit 22757750736b8336ff0f9cced60e6e0044656959 1 parent 79b030e
@jasonm jasonm authored
View
12 lib/backbone_sync-rails/faye/event.rb
@@ -1,4 +1,4 @@
-require 'backbone_sync-rails/faye/message'
+require 'net/http'
module BackboneSync
module Rails
@@ -10,11 +10,19 @@ def initialize(model, event)
end
def broadcast
- Message.new(channel, data).send
+ Net::HTTP.post_form(uri, :message => message)
end
private
+ def uri
+ URI.parse("#{BackboneSync::Rails::Faye.root_address}/faye")
+ end
+
+ def message
+ { :channel => channel, :data => data }.to_json
+ end
+
def channel
"/sync/#{@model.class.table_name}"
end
View
31 lib/backbone_sync-rails/faye/message.rb
@@ -1,31 +0,0 @@
-require 'net/http'
-require 'json'
-
-module BackboneSync
- module Rails
- module Faye
- # To publish from outside of an `EM.run {}` loop:
- # http://groups.google.com/group/faye-users/browse_thread/thread/ae6e2a1cc37b3b07
- class Message
- def initialize(channel, data)
- @channel = channel
- @data = data
- end
-
- def send
- Net::HTTP.post_form(uri, :message => payload)
- end
-
- private
-
- def uri
- URI.parse("#{BackboneSync::Rails::Faye.root_address}/faye")
- end
-
- def payload
- {:channel => @channel, :data => @data}.to_json
- end
- end
- end
- end
-end
Please sign in to comment.
Something went wrong with that request. Please try again.