class Faye::Publisher
Public Class Methods
channels()
click to toggle source
# File lib/faye/publisher/testing.rb, line 10 def self.channels @channels ||= Hash.new { |hash, key| hash[key] = [] } end
new(faye_endpoint)
click to toggle source
# File lib/faye/publisher.rb, line 9 def initialize(faye_endpoint) @faye_uri = URI.parse(faye_endpoint) end
Public Instance Methods
publish(channel, data)
click to toggle source
Sends an event to given chanel with the given data.
@raise [PublicationError] if the publication fails.
# File lib/faye/publisher.rb, line 16 def publish(channel, data) http = Net::HTTP.new(@faye_uri.host, @faye_uri.port) path = if @faye_uri.path.empty? '/' else @faye_uri.path end headers = { 'Content-Type' => 'application/json' } message = { :channel => channel, :data => data } response, _ = http.post(path, JSON(message), headers) unless response.kind_of?(Net::HTTPSuccess) raise PublicationError end end