lib/pubnub/events/set_state.rb in pubnub-3.6.10 vs lib/pubnub/events/set_state.rb in pubnub-3.7.0
- old
+ new
@@ -13,39 +13,52 @@
app.env[:state][@origin] = Hash.new if app.env[:state][@origin].nil?
@channel.each do |channel|
app.env[:state][@origin][channel.to_s] = @state
end
+ @channel_group.each do |channel|
+ app.env[:state][@origin][channel.to_s] = @state
+ end
+
@allow_multiple_channels = true
@event = 'set_state'
end
def validate!
super
# check state
raise 'You can set state only as hash' unless (@state.is_a?(Hash) || @state.is_a?(NilClass))
# check channel/channels
- raise ArgumentError.new(:object => self, :message => 'SetState requires :channel or :channels argument') unless @channel
+ raise ArgumentError.new(:object => self, :message => 'SetState requires :channel, :channels or :group argument') if @channel.blank? && @channel_group.blank?
raise ArgumentError.new(:object => self, :message => 'Invalid channel(s) format! Should be type of: String, Symbol, or Array of both') unless valid_channel?
+
+ unless @channel_group.blank?
+ # check channel_group
+ raise ArgumentError.new(:object => self, :message => 'Invalid channel group format! Should be type of: String, Symbol') unless [String, Symbol, NilClass].include?(@channel_group.class)
+
+ # check channel_group
+ # raise ArgumentError.new(:object => self, :message => ':group argument has to be in format "ns:cg", "ns:" or ":cg"') if @channel_group.count(':') != 1
+ end
end
private
def parameters(app)
parameters = super(app)
- parameters.merge!({:state => encode_state(@state)})
+ parameters.merge!({ :state => encode_state(@state)})
+ parameters.merge!({ 'channel-group' => format_channel_group(@channel_group).join(',') }) unless @channel_group.blank?
parameters
end
def path(app)
'/' + [
'v2',
'presence',
'sub-key',
@subscribe_key,
'channel',
- @channel,
+ channels_for_url(@channel),
'uuid',
app.env[:uuid],
'data'
].join('/')
end