Skip to content

Commit

Permalink
Merge pull request #7 from centrifugal/feature-broadcast
Browse files Browse the repository at this point in the history
Add broadcast method
  • Loading branch information
arrowcircle committed Mar 8, 2016
2 parents 8593a86 + cac0b7e commit 700108e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
4 changes: 4 additions & 0 deletions lib/centrifuge/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ def url(path = nil)
})
end

def broadcast(channels, data)
Centrifuge::Builder.new('broadcast', { channels: channels, data: data }, self).process
end

def publish(channel, data)
Centrifuge::Builder.new('publish', { channel: channel, data: data }, self).process
end
Expand Down
2 changes: 1 addition & 1 deletion lib/centrifuge/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Centrifuge
VERSION = "1.0.1"
VERSION = "1.1.0"
end
10 changes: 8 additions & 2 deletions spec/client_spec.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
require 'spec_helper'

describe Centrifuge::Client do
let(:options) { { scheme: :https, host: 'centrifugo-dev.herokuapp.com', port: 443, secret: 'secret' } }
let(:options) { { scheme: :https, host: 'centrifugo.herokuapp.com', port: 443, secret: 'secret' } }
let(:client) { Centrifuge::Client.new(options) }
let(:data) { { action: :test } }

it 'generates url' do
expect(client.url.to_s).to eq "https://centrifugo-dev.herokuapp.com:443/api/"
expect(client.url.to_s).to eq "https://centrifugo.herokuapp.com:443/api/"
end

it 'publishes data' do
channel = SecureRandom.hex
expect(client.publish(channel, data)).to eq [{"body" => nil, "error" => nil, "method" => "publish"}]
end

it 'broadcasts data' do
channel = SecureRandom.hex
channel1 = SecureRandom.hex
expect(client.broadcast([channel, channel1], data)).to eq [{"body" => nil, "error" => nil, "method" => "broadcast"}]
end

it 'unsubscribes user' do
channel = SecureRandom.hex
expect(client.unsubscribe(channel, "23")).to eq [{"body"=>nil, "error"=>nil, "method"=>"unsubscribe"}]
Expand Down

0 comments on commit 700108e

Please sign in to comment.