From df220a8060256cff2e071b5725dc22e583636885 Mon Sep 17 00:00:00 2001 From: Serhii Mamontov Date: Thu, 11 Sep 2025 12:56:09 +0300 Subject: [PATCH 1/3] feat(fetch-messages): add `encode_channels` parameter Add the `encode_channels` parameter for `fetch` to enable or disable channel names percent-encoding in response. --- lib/pubnub/event.rb | 2 +- lib/pubnub/events/fetch_messages.rb | 2 + spec/examples/fetch_messages_examples_spec.rb | 56 +++++++++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) diff --git a/lib/pubnub/event.rb b/lib/pubnub/event.rb index f82b40789..9f684e1f7 100644 --- a/lib/pubnub/event.rb +++ b/lib/pubnub/event.rb @@ -178,7 +178,7 @@ def create_variables_from_options(options) include_custom_message_type include_message_actions include_message_type replicate with_presence cipher_key_selector include_meta include_uuid join update get add remove push_token push_gateway environment topic - authorized_uuid authorized_user_id token type status value] + authorized_uuid authorized_user_id token type status value encode_channels] options = options.each_with_object({}) { |option, obj| obj[option.first.to_sym] = option.last } diff --git a/lib/pubnub/events/fetch_messages.rb b/lib/pubnub/events/fetch_messages.rb index 0e681bf08..3183b9d19 100644 --- a/lib/pubnub/events/fetch_messages.rb +++ b/lib/pubnub/events/fetch_messages.rb @@ -13,6 +13,7 @@ def initialize(options, app) @include_custom_message_type = options.fetch(:include_custom_message_type, false) @include_message_actions = options.fetch(:include_message_actions, false) @include_message_type = options.fetch(:include_message_type, true) + @encode_channels = options.fetch(:encode_channels, true) @include_uuid = options.fetch(:include_uuid, true) @include_meta = options.fetch(:include_meta, false) @start = options[:start] if options.key?(:start) @@ -52,6 +53,7 @@ def parameters(signature = false) parameters[:include_uuid] = 'true' if @include_uuid parameters[:include_custom_message_type] = 'true' if @include_custom_message_type parameters[:include_message_type] = 'true' if @include_message_type + parameters[:encode_channels] = 'false' if !@encode_channels && !@include_message_actions parameters[:start] = @start unless @start.nil? parameters[:end] = @end unless @end.nil? parameters[:max] = @max unless @max.nil? diff --git a/spec/examples/fetch_messages_examples_spec.rb b/spec/examples/fetch_messages_examples_spec.rb index 502ad4599..6dc8b17e9 100644 --- a/spec/examples/fetch_messages_examples_spec.rb +++ b/spec/examples/fetch_messages_examples_spec.rb @@ -596,4 +596,60 @@ ] } }) end end + + it "__channel__channel|encoded::1___max__5___http_sync__true___callback__nil_" do + VCR.use_cassette("examples/fetch_messages/encoded_channels", :record => :once) do + channel = "channel|encoded::1" + envelope = @pubnub.fetch_messages(channel: channel, max: 5, http_sync: true) + expect(envelope.is_a?(Pubnub::Envelope)).to eq true + expect(envelope.error?).to eq false + + expect(envelope.status[:code]).to eq(200) + expect(envelope.status[:category]).to eq(:ack) + 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" }) + + expect(envelope.result[:code]).to eq(200) + expect(envelope.result[:operation]).to eq(:fetch_messages) + expect(envelope.result[:data]).to eq({ + :channels => { + "channel%7Cencoded%3A%3A1" => [ + { + "message_type" => nil, + "message" => "Hello test world", + "timetoken" => "17575837829949324", + "uuid" => "ruby-test-uuid-client-one" + } + ] + } + }) + end + end + + it "__channel__channel|encoded::2___max__5___encode_channels__false___http_sync__true___callback__nil_" do + VCR.use_cassette("examples/fetch_messages/not_encoded_channels", :record => :once) do + channel = "channel|encoded::2" + envelope = @pubnub.fetch_messages(channel: channel, max: 5, encode_channels: false, http_sync: true) + expect(envelope.is_a?(Pubnub::Envelope)).to eq true + expect(envelope.error?).to eq false + + expect(envelope.status[:code]).to eq(200) + expect(envelope.status[:category]).to eq(:ack) + 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" }) + + expect(envelope.result[:code]).to eq(200) + expect(envelope.result[:operation]).to eq(:fetch_messages) + expect(envelope.result[:data]).to eq({ + :channels => { + "channel|encoded::2" => [ + { + "message_type" => nil, + "message" => "Hello test world", + "timetoken" => "17575842502404510", + "uuid" => "ruby-test-uuid-client-one", + } + ] + } + }) + end + end end \ No newline at end of file From 175930be90485f20c91784a05e428499221db28e Mon Sep 17 00:00:00 2001 From: Serhii Mamontov Date: Thu, 11 Sep 2025 13:14:19 +0300 Subject: [PATCH 2/3] test: add missing fixtures --- .../fetch_messages/encoded_channels.yml | 80 +++++++++++++++++++ .../fetch_messages/not_encoded_channels.yml | 80 +++++++++++++++++++ 2 files changed, 160 insertions(+) create mode 100644 fixtures/vcr_cassettes/examples/fetch_messages/encoded_channels.yml create mode 100644 fixtures/vcr_cassettes/examples/fetch_messages/not_encoded_channels.yml diff --git a/fixtures/vcr_cassettes/examples/fetch_messages/encoded_channels.yml b/fixtures/vcr_cassettes/examples/fetch_messages/encoded_channels.yml new file mode 100644 index 000000000..04a1af64f --- /dev/null +++ b/fixtures/vcr_cassettes/examples/fetch_messages/encoded_channels.yml @@ -0,0 +1,80 @@ +--- +http_interactions: +- request: + method: get + uri: http://ps.pndsn.com/publish/pub-a-mock-key/sub-a-mock-key/0/channel%7Cencoded::1/0/%22Hello%20test%20world%22?auth=ruby-test-auth-client-one&ortt=%7B%22t%22:17575837822786440%7D&pnsdk=PubNub-Ruby/5.5.1&seqn=1&ttl=10&uuid=ruby-test-uuid-client-one + body: + encoding: UTF-8 + string: '' + headers: + User-Agent: + - HTTPClient/1.0 (2.8.3, ruby 3.2.2 (2023-03-30)) + Accept: + - "*/*" + Date: + - Thu, 11 Sep 2025 09:43:02 GMT + response: + status: + code: 200 + message: OK + headers: + Date: + - Thu, 11 Sep 2025 09:43:02 GMT + Content-Type: + - text/javascript; charset=UTF-8 + Content-Length: + - '30' + Connection: + - keep-alive + Cache-Control: + - no-cache + Access-Control-Allow-Methods: + - GET + Access-Control-Allow-Credentials: + - 'true' + Access-Control-Expose-Headers: + - "*" + body: + encoding: UTF-8 + string: '[1,"Sent","17575837829949324"]' + recorded_at: Thu, 11 Sep 2025 09:43:02 GMT +- request: + method: get + uri: http://ps.pndsn.com/v3/history/sub-key/sub-a-mock-key/channel/channel%7Cencoded::1?auth=ruby-test-auth-client-one&include_message_type=true&include_uuid=true&max=5&pnsdk=PubNub-Ruby/5.5.1&uuid=ruby-test-uuid-client-one + body: + encoding: UTF-8 + string: '' + headers: + User-Agent: + - HTTPClient/1.0 (2.8.3, ruby 3.2.2 (2023-03-30)) + Accept: + - "*/*" + Date: + - Thu, 11 Sep 2025 09:43:02 GMT + response: + status: + code: 200 + message: OK + headers: + Date: + - Thu, 11 Sep 2025 09:43:03 GMT + Content-Type: + - text/javascript; charset="UTF-8" + Content-Length: + - '214' + Connection: + - keep-alive + Cache-Control: + - no-cache + Access-Control-Allow-Methods: + - GET, POST, DELETE, OPTIONS + Access-Control-Allow-Credentials: + - 'true' + Access-Control-Expose-Headers: + - "*" + body: + encoding: UTF-8 + string: '{"status": 200, "error": false, "error_message": "", "channels": {"channel%7Cencoded%3A%3A1":[{"message":"Hello + test world","timetoken":"17575837829949324","message_type":null,"uuid":"ruby-test-uuid-client-one"}]}}' + recorded_at: Thu, 11 Sep 2025 09:43:02 GMT +recorded_with: VCR 6.3.1 diff --git a/fixtures/vcr_cassettes/examples/fetch_messages/not_encoded_channels.yml b/fixtures/vcr_cassettes/examples/fetch_messages/not_encoded_channels.yml new file mode 100644 index 000000000..fd4167338 --- /dev/null +++ b/fixtures/vcr_cassettes/examples/fetch_messages/not_encoded_channels.yml @@ -0,0 +1,80 @@ +--- +http_interactions: +- request: + method: get + uri: http://ps.pndsn.com/publish/pub-a-mock-key/sub-a-mock-key/0/channel%7Cencoded::2/0/%22Hello%20test%20world%22?auth=ruby-test-auth-client-one&ortt=%7B%22t%22:17575842495785020%7D&pnsdk=PubNub-Ruby/5.5.1&seqn=1&ttl=10&uuid=ruby-test-uuid-client-one + body: + encoding: UTF-8 + string: '' + headers: + User-Agent: + - HTTPClient/1.0 (2.8.3, ruby 3.2.2 (2023-03-30)) + Accept: + - "*/*" + Date: + - Thu, 11 Sep 2025 09:50:49 GMT + response: + status: + code: 200 + message: OK + headers: + Date: + - Thu, 11 Sep 2025 09:50:50 GMT + Content-Type: + - text/javascript; charset=UTF-8 + Content-Length: + - '30' + Connection: + - keep-alive + Cache-Control: + - no-cache + Access-Control-Allow-Methods: + - GET + Access-Control-Allow-Credentials: + - 'true' + Access-Control-Expose-Headers: + - "*" + body: + encoding: UTF-8 + string: '[1,"Sent","17575842502404510"]' + recorded_at: Thu, 11 Sep 2025 09:50:49 GMT +- request: + method: get + uri: http://ps.pndsn.com/v3/history/sub-key/sub-a-mock-key/channel/channel%7Cencoded::2?auth=ruby-test-auth-client-one&encode_channels=false&include_message_type=true&include_uuid=true&max=5&pnsdk=PubNub-Ruby/5.5.1&uuid=ruby-test-uuid-client-one + body: + encoding: UTF-8 + string: '' + headers: + User-Agent: + - HTTPClient/1.0 (2.8.3, ruby 3.2.2 (2023-03-30)) + Accept: + - "*/*" + Date: + - Thu, 11 Sep 2025 09:50:49 GMT + response: + status: + code: 200 + message: OK + headers: + Date: + - Thu, 11 Sep 2025 09:50:50 GMT + Content-Type: + - text/javascript; charset="UTF-8" + Content-Length: + - '208' + Connection: + - keep-alive + Cache-Control: + - no-cache + Access-Control-Allow-Methods: + - GET, POST, DELETE, OPTIONS + Access-Control-Allow-Credentials: + - 'true' + Access-Control-Expose-Headers: + - "*" + body: + encoding: UTF-8 + string: '{"status": 200, "error": false, "error_message": "", "channels": {"channel|encoded::2":[{"message":"Hello + test world","timetoken":"17575842502404510","message_type":null,"uuid":"ruby-test-uuid-client-one"}]}}' + recorded_at: Thu, 11 Sep 2025 09:50:50 GMT +recorded_with: VCR 6.3.1 From e762f47527af34a4d46f2b4c8c0deab81698e764 Mon Sep 17 00:00:00 2001 From: PubNub Release Bot <120067856+pubnub-release-bot@users.noreply.github.com> Date: Thu, 11 Sep 2025 10:52:29 +0000 Subject: [PATCH 3/3] PubNub SDK v5.6.0 release. --- .pubnub.yml | 13 +++++++++---- CHANGELOG.md | 6 ++++++ Gemfile.lock | 2 +- VERSION | 2 +- lib/pubnub/version.rb | 2 +- 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/.pubnub.yml b/.pubnub.yml index ebc761e8b..379020cb8 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,6 +1,11 @@ --- -version: "5.5.1" +version: "5.6.0" changelog: + - date: 2025-09-11 + version: v5.6.0 + changes: + - type: feature + text: "Add the `encode_channels` parameter for `fetch` to enable or disable channel names percent-encoding in response." - date: 2025-09-08 version: v5.5.1 changes: @@ -608,7 +613,7 @@ sdks: - x86-64 - distribution-type: package distribution-repository: RubyGems - package-name: pubnub-5.5.1.gem + package-name: pubnub-5.6.0.gem location: https://rubygems.org/gems/pubnub requires: - name: addressable @@ -713,8 +718,8 @@ sdks: - x86-64 - distribution-type: library distribution-repository: GitHub release - package-name: pubnub-5.5.1.gem - location: https://github.com/pubnub/ruby/releases/download/v5.5.1/pubnub-5.5.1.gem + package-name: pubnub-5.6.0.gem + location: https://github.com/pubnub/ruby/releases/download/v5.6.0/pubnub-5.6.0.gem requires: - name: addressable min-version: 2.0.0 diff --git a/CHANGELOG.md b/CHANGELOG.md index f95953097..2ede2cdb8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## v5.6.0 +September 11 2025 + +#### Added +- Add the `encode_channels` parameter for `fetch` to enable or disable channel names percent-encoding in response. + ## v5.5.1 September 08 2025 diff --git a/Gemfile.lock b/Gemfile.lock index eeb54f907..298e24362 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - pubnub (5.5.1) + pubnub (5.6.0) addressable (>= 2.0.0) concurrent-ruby (~> 1.3.4) concurrent-ruby-edge (~> 0.7.1) diff --git a/VERSION b/VERSION index 7acd1cb0e..1bc788d3b 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -5.5.1 +5.6.0 diff --git a/lib/pubnub/version.rb b/lib/pubnub/version.rb index 18022e8d8..05d6655b2 100644 --- a/lib/pubnub/version.rb +++ b/lib/pubnub/version.rb @@ -1,4 +1,4 @@ # Toplevel Pubnub module. module Pubnub - VERSION = '5.5.1'.freeze + VERSION = '5.6.0'.freeze end