Module: SimpleFaye

Defined in:
lib/simple_faye.rb,
lib/simple_faye/version.rb

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.publish_message(subscription, message) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/simple_faye.rb', line 7

def publish_message(subscription, message)
    url = URI.parse("http://localhost:9292/faye")
    form = Net::HTTP::Post.new(url.path.empty? ? '/' : url.path)
    form.set_form_data(:message => "{\"channel\":\"#{subscription}\", \"data\":{\"message\":\"#{message}\"}}")
    http = Net::HTTP.new(url.host, url.port)
    http.start {|h| h.request(form)}
end