We started consistently seeing UploadErrors after adding ruby-units to our project.
Turns out that youtube_it defines request success as response_code / 10 == 20. mathn (part of the standard library, required by ruby-units) changes Numeric#/ to always return Rationals instead of Integers. E.g. without mathn 201 / 10 # => 20 whereas with mathn 201 / 10 # => (201/10).
The attached pull request explicitly casts these into Integers again for the check to continue working. An alternative would be something like response_code.divmod(20).first == 20; not sure what's more readable.
I haven't updated the tests as I didn't know whether the mathn dependency would be desirable. Just stick a require "mathn" anywhere in the current version and then in my branch to see the before/after.
Note that I've also removed VideoUpload#raise_on_faulty_response. It doesn't seem to be used anywhere.
We started consistently seeing UploadErrors after adding ruby-units to our project.
Turns out that youtube_it defines request success as
response_code / 10 == 20
. mathn (part of the standard library, required by ruby-units) changes Numeric#/ to always return Rationals instead of Integers. E.g. without mathn201 / 10 # => 20
whereas with mathn201 / 10 # => (201/10)
.The attached pull request explicitly casts these into Integers again for the check to continue working. An alternative would be something like
response_code.divmod(20).first == 20
; not sure what's more readable.I haven't updated the tests as I didn't know whether the mathn dependency would be desirable. Just stick a
require "mathn"
anywhere in the current version and then in my branch to see the before/after.Note that I've also removed
VideoUpload#raise_on_faulty_response
. It doesn't seem to be used anywhere.