kylejginavan / youtube_it

An object-oriented Ruby wrapper for the YouTube GData API
http://groups.google.com/group/ruby-youtube-library
595 stars 223 forks source link

mathn compatibility: Explicitly cast into Integers when they are expected for comparisons #127

Closed niels closed 12 years ago

niels commented 12 years ago

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.