-
Notifications
You must be signed in to change notification settings - Fork 964
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HTTParty::Request::Body#multipart? fixes #626
Conversation
ed248ff
to
891ca8d
Compare
@TheSmartnik It'd be great to have this PR merged as soon as you feel confident with it. I'm maintaining the gem https://github.com/smartinez87/exception_notification which relies on HTTParty in several notifiers and they are not working if updating HTTParty version. The last working version is on tag: https://github.com/jnunemaker/httparty/releases/tag/v0.15.7 It'd be great to merge this #multipart? fix so we don't need to lock our users to versions prior to the multipart refactor. Cheers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for the PR, sorry it took a long time to respond. It looks good, a few minor comments about naming and we are good to go.
lib/httparty/request/body.rb
Outdated
else | ||
file?(value) | ||
end | ||
def file?(value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like #has_file?
is better a naming for this method, anyway.
You still ask whether the params
have a file or not. You're right that it can be file
, but it can also be hash, array and #has_file?
is a more inclusive naming
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, you are right. I changed here 5a778ed
lib/httparty/request/body.rb
Outdated
elsif value.respond_to?(:to_ary) | ||
value.to_ary.any? { |v| file?(v) } | ||
else | ||
value.respond_to?(:path) && value.respond_to?(:read) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previous use of a method was more readable and understandable , imho.
It showed that if value responds to path
and read
it is a file, which is exactly what we are looking for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you mean this method?
def file?(object)
object.respond_to?(:path) && object.respond_to?(:read)
end
if that's what you meant, i think it makes sense, and also would help for the generate_multipart
which should only check if the value is a file (not recursive) if i understand it correctly.
I changed it here as well: 5a778ed
891ca8d
to
5a778ed
Compare
@TheSmartnik thanks for the review! |
Thanks! Look good. I'll run a few more tests later today and bump the version |
This PR intends to fix a few issues with the
multipart?
method:#to_hash
but not to#detect
(likeActionDispatch::Request::Session
). Same for params that respond to#to_ary
but not to#detect
(
includes_hash?(value)
was always returningtrue
for not empty arrays, because all objects respond to#hash
, and then it was doinghash.detect do |key, value|
with an array which actually yields only one arg)