Skip to content

Commit 4ebf4d8

Browse files
authored
feat(fetch-messages): add encode_channels parameter (#170)
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 4ebf4d8

File tree

10 files changed

+237
-8
lines changed

10 files changed

+237
-8
lines changed

.pubnub.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
---
2-
version: "5.5.1"
2+
version: "5.6.0"
33
changelog:
4+
- date: 2025-09-11
5+
version: v5.6.0
6+
changes:
7+
- type: feature
8+
text: "Add the `encode_channels` parameter for `fetch` to enable or disable channel names percent-encoding in response."
49
- date: 2025-09-08
510
version: v5.5.1
611
changes:
@@ -608,7 +613,7 @@ sdks:
608613
- x86-64
609614
- distribution-type: package
610615
distribution-repository: RubyGems
611-
package-name: pubnub-5.5.1.gem
616+
package-name: pubnub-5.6.0.gem
612617
location: https://rubygems.org/gems/pubnub
613618
requires:
614619
- name: addressable
@@ -713,8 +718,8 @@ sdks:
713718
- x86-64
714719
- distribution-type: library
715720
distribution-repository: GitHub release
716-
package-name: pubnub-5.5.1.gem
717-
location: https://github.com/pubnub/ruby/releases/download/v5.5.1/pubnub-5.5.1.gem
721+
package-name: pubnub-5.6.0.gem
722+
location: https://github.com/pubnub/ruby/releases/download/v5.6.0/pubnub-5.6.0.gem
718723
requires:
719724
- name: addressable
720725
min-version: 2.0.0

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## v5.6.0
2+
September 11 2025
3+
4+
#### Added
5+
- Add the `encode_channels` parameter for `fetch` to enable or disable channel names percent-encoding in response.
6+
17
## v5.5.1
28
September 08 2025
39

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
pubnub (5.5.1)
4+
pubnub (5.6.0)
55
addressable (>= 2.0.0)
66
concurrent-ruby (~> 1.3.4)
77
concurrent-ruby-edge (~> 0.7.1)

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5.5.1
1+
5.6.0

fixtures/vcr_cassettes/examples/fetch_messages/encoded_channels.yml

Lines changed: 80 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fixtures/vcr_cassettes/examples/fetch_messages/not_encoded_channels.yml

Lines changed: 80 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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?

lib/pubnub/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Toplevel Pubnub module.
22
module Pubnub
3-
VERSION = '5.5.1'.freeze
3+
VERSION = '5.6.0'.freeze
44
end

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)