muxinc / mux-ruby

Official Mux API wrapper for ruby projects, supporting both Mux Data and Mux Video.
MIT License
51 stars 14 forks source link

Space API endpoints include extra $ in paths when variable substitution occurs #47

Closed murraysum closed 2 years ago

murraysum commented 2 years ago

Issue

In several of the Space API endpoints when variable substitution occurs for the SPACE_ID or BROADCAST_ID there is a $ prepended to the identifier which makes the path incorrect. As a result the API rejects the request. For example, the create a space broadcast endpoint instead of making a request to https://api.mux.com/video/v1/spaces/my_space_id/broadcasts it makes a request to https://api.mux.com/video/v1/spaces/$my_space_id/broadcasts:

The following endpoints are effected:

How to reproduce

The default spaces example for creating a broadcast should show you the error:

api_instance = MuxRuby::SpacesApi.new
space_id = 'space_id_example' # String | The space ID.
create_broadcast_request = MuxRuby::CreateBroadcastRequest.new({live_stream_id: 'live_stream_id_example'}) # CreateBroadcastRequest | 

begin
  # Create a space broadcast
  result = api_instance.create_space_broadcast(space_id, create_broadcast_request)
  p result
rescue MuxRuby::ApiError => e
  puts "Error when calling SpacesApi->create_space_broadcast: #{e}"
end

You should get API response something like this (redacted the space_id):

ETHON: performed EASY effective_url=https://api.mux.com/video/v1/spaces/$redacted_space_id/broadcasts response_code=400 return_code=ok total_time=0.563622
Error when calling SpacesApi->create_space_broadcast:
HTTP status code: 400
Response headers: {"cache-control"=>"max-age=0, private, must-revalidate", "content-type"=>"application/json; charset=utf-8", "date"=>"Mon, 13 Jun 2022 16:04:47 GMT", "server"=>"Mux API Server v1.157.23", "x-request-id"=>"Fvg5rxBASuUuMp8DfAMF", "content-length"=>"88"}
Response body: {"error":{"type":"invalid_parameters","messages":["Invalid space id, failed to parse"]}}

Expected behaviour

When variable substitution occurs in the API paths $ is not prepended to identifiers and API requests are not rejected.

Actual behaviour

When variable substitution occurs in the API paths $ is prepended to identifiers and API requests are rejected.

eropple commented 2 years ago

Well, this is wild. Thanks for reporting it, and in such a detailed manner. We'll look into it ASAP.

eropple commented 2 years ago

Fix located. Will be deploying today.

eropple commented 2 years ago

And fix is out with mux-ruby 3.5.2. Thanks for bringing this to our attention with such a detailed bug report, it really helped.

clearlyTHUYDOAN commented 2 years ago

@murraysum thanks for the great bug report! πŸŽ‰

As part of our OSS contribution program, we'd love to send you some swag as our way of saying thank you and recognizing your work. Please email me at tdoan@mux.com with your details and we'll get something sent out to you! 🎁

murraysum commented 2 years ago

@eropple No problem at all. Thanks for fixing this so quickly, much appreciated. Loving the Mux real time API so far, it is awesome. πŸ‘

@clearlyTHUYDOAN Thank you very much, that is very kind of you. I'll email you my details. πŸ‘