Skip to content

Commit df220a8

Browse files
committed
feat(fetch-messages): add encode_channels parameter
Add the `encode_channels` parameter for `fetch` to enable or disable channel names percent-encoding in response.
1 parent e7812ec commit df220a8

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

lib/pubnub/event.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def create_variables_from_options(options)
178178
include_custom_message_type include_message_actions include_message_type
179179
replicate with_presence cipher_key_selector include_meta include_uuid join
180180
update get add remove push_token push_gateway environment topic
181-
authorized_uuid authorized_user_id token type status value]
181+
authorized_uuid authorized_user_id token type status value encode_channels]
182182

183183
options = options.each_with_object({}) { |option, obj| obj[option.first.to_sym] = option.last }
184184

lib/pubnub/events/fetch_messages.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ def initialize(options, app)
1313
@include_custom_message_type = options.fetch(:include_custom_message_type, false)
1414
@include_message_actions = options.fetch(:include_message_actions, false)
1515
@include_message_type = options.fetch(:include_message_type, true)
16+
@encode_channels = options.fetch(:encode_channels, true)
1617
@include_uuid = options.fetch(:include_uuid, true)
1718
@include_meta = options.fetch(:include_meta, false)
1819
@start = options[:start] if options.key?(:start)
@@ -52,6 +53,7 @@ def parameters(signature = false)
5253
parameters[:include_uuid] = 'true' if @include_uuid
5354
parameters[:include_custom_message_type] = 'true' if @include_custom_message_type
5455
parameters[:include_message_type] = 'true' if @include_message_type
56+
parameters[:encode_channels] = 'false' if !@encode_channels && !@include_message_actions
5557
parameters[:start] = @start unless @start.nil?
5658
parameters[:end] = @end unless @end.nil?
5759
parameters[:max] = @max unless @max.nil?

spec/examples/fetch_messages_examples_spec.rb

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,4 +596,60 @@
596596
] } })
597597
end
598598
end
599+
600+
it "__channel__channel|encoded::1___max__5___http_sync__true___callback__nil_" do
601+
VCR.use_cassette("examples/fetch_messages/encoded_channels", :record => :once) do
602+
channel = "channel|encoded::1"
603+
envelope = @pubnub.fetch_messages(channel: channel, max: 5, http_sync: true)
604+
expect(envelope.is_a?(Pubnub::Envelope)).to eq true
605+
expect(envelope.error?).to eq false
606+
607+
expect(envelope.status[:code]).to eq(200)
608+
expect(envelope.status[:category]).to eq(:ack)
609+
expect(envelope.status[:config]).to eq({ :tls => false, :uuid => "ruby-test-uuid-client-one", :auth_key => "ruby-test-auth-client-one", :origin => "ps.pndsn.com" })
610+
611+
expect(envelope.result[:code]).to eq(200)
612+
expect(envelope.result[:operation]).to eq(:fetch_messages)
613+
expect(envelope.result[:data]).to eq({
614+
:channels => {
615+
"channel%7Cencoded%3A%3A1" => [
616+
{
617+
"message_type" => nil,
618+
"message" => "Hello test world",
619+
"timetoken" => "17575837829949324",
620+
"uuid" => "ruby-test-uuid-client-one"
621+
}
622+
]
623+
}
624+
})
625+
end
626+
end
627+
628+
it "__channel__channel|encoded::2___max__5___encode_channels__false___http_sync__true___callback__nil_" do
629+
VCR.use_cassette("examples/fetch_messages/not_encoded_channels", :record => :once) do
630+
channel = "channel|encoded::2"
631+
envelope = @pubnub.fetch_messages(channel: channel, max: 5, encode_channels: false, http_sync: true)
632+
expect(envelope.is_a?(Pubnub::Envelope)).to eq true
633+
expect(envelope.error?).to eq false
634+
635+
expect(envelope.status[:code]).to eq(200)
636+
expect(envelope.status[:category]).to eq(:ack)
637+
expect(envelope.status[:config]).to eq({ :tls => false, :uuid => "ruby-test-uuid-client-one", :auth_key => "ruby-test-auth-client-one", :origin => "ps.pndsn.com" })
638+
639+
expect(envelope.result[:code]).to eq(200)
640+
expect(envelope.result[:operation]).to eq(:fetch_messages)
641+
expect(envelope.result[:data]).to eq({
642+
:channels => {
643+
"channel|encoded::2" => [
644+
{
645+
"message_type" => nil,
646+
"message" => "Hello test world",
647+
"timetoken" => "17575842502404510",
648+
"uuid" => "ruby-test-uuid-client-one",
649+
}
650+
]
651+
}
652+
})
653+
end
654+
end
599655
end

0 commit comments

Comments
 (0)