pusher / pusher-http-ruby

Ruby library for Pusher Channels HTTP API
https://pusher.com/channels
MIT License
665 stars 123 forks source link

Requesting `channel_info` without `info:` raises an error from the previous request #193

Open rmosolgo opened 2 months ago

rmosolgo commented 2 months ago

Hi! I'm working on a custom dashboard for GraphQL subscriptions which are backed by Pusher. My dashboard shows information about the state of the GraphQL system (like query string, variables, query context, etc) and information about the underlying transport system -- Pusher in this case.

To improve this dashboard, I want to be able to count subscribers on a Pusher channel ... but I don't know if the manager of the Pusher app has turned on subscription counting yet.

I thought I would just try -- I could request channel_info(channel, info: "subscription_count"), and if that raises a Pusher::Error, then I would re-fetch without info: and only display :occupied from the response. But, I found that my second request to channel_info raised the same error (Bad request: Cannot retrieve the subscription count because subscription counting is not enabled), even though it was called without an info: option. I tried info: nil and info: "", but neither of those made it work.

Here's a small replication script of this issue:


require 'pusher'

# this app doesn't have subscription_count turned on yet:
pusher = Pusher::Client.new(
  app_id: "my-app-id",
  key: "my-app-key",
  secret: "my-app-secret",
  cluster: 'us2',
  use_tls: true
)

begin
  pusher.channel_info("abcdef", info: "subscription_count")
rescue Pusher::Error => err
  puts "Encountered an error: #{err.message.inspect}"
end

pusher.channel_info("abcdef")

When I run that script, it rescues the first error, but the second .channel_info call raises another error:

$ ruby pusher_test.rb
Encountered an error: "Bad request: Cannot retrieve the subscription count because subscription counting is not enabled"
/Users/rmosolgo/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/pusher-2.0.3/lib/pusher/request.rb:89:in `handle_response': Bad request: Cannot retrieve the subscription count because subscription counting is not enabled (Pusher::Error)
    from /Users/rmosolgo/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/pusher-2.0.3/lib/pusher/request.rb:39:in `send_sync'
    from /Users/rmosolgo/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/pusher-2.0.3/lib/pusher/resource.rb:9:in `get'
    from /Users/rmosolgo/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/pusher-2.0.3/lib/pusher/client.rb:168:in `get'
    from /Users/rmosolgo/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/pusher-2.0.3/lib/pusher/client.rb:255:in `channel_info'
    from pusher_test.rb:18:in `<main>'

Is there a way to either:

Thanks so much for taking a look! Let me know if there's anything else I can do on my side to help with this.