IanMitchell / discord-notifier

A ruby wrapper around Discord webhooks
MIT License
14 stars 4 forks source link

400 HTTPBadRequest for non file posts #13

Closed Srules closed 4 years ago

Srules commented 4 years ago

I believe the Net::HTTP is rejecting requests to https endpoints without setting the http.use_ssl = true flag on your post. I was able to resolve my issue with the following update:

https://github.com/Confidist/discord-notifier/commit/55d364f2ba75a7f330a7777c639f92ceb591947c

I am using ruby 2.5.1 https://ruby-doc.org/stdlib-2.5.1/libdoc/net/http/rdoc/Net/HTTP.html

I am curious if others are running into this same issue. Ian can you confirm?

IanMitchell commented 4 years ago

Hm interesting. Does your config URL have https in the URL? I'll be able to check this out more tomorrow!

Srules commented 4 years ago

Hm interesting. Does your config URL have https in the URL? I'll be able to check this out more tomorrow!

Yeah.

Discord::Notifier.setup do |config| config.url = 'https://discordapp.com/api/webhooks/....

Thanks, Ian. I very much appreciate your work and response. Kind regards -Nicholas

IanMitchell commented 4 years ago

Can you post an example script for the failure? I'm not seeing it on Ruby 2.7.1 with an embed -

Discord::Notifier.setup do |config|
  config.url = 'WEBHOOK'
  config.username = 'Discord Notifier Gem Local Test'
end

embed = Discord::Embed.new do
  title "Discord Ruby Notification"
  description "Will it work?"
end

Discord::Notifier.message(embed)

I'm on MacOS. Installing Ruby 2.5.1 right now to try that

IanMitchell commented 4 years ago

Hm, works for me with an embed and text message

Srules commented 4 years ago
2.5.1 :001 > embed = Discord::Embed.new do
2.5.1 :002 >       title "Discord Ruby Notification"
2.5.1 :003?>     description "Will it work?"
2.5.1 :004?>   end
 => #<Discord::Embed:0x00007fddc51b0ee0 @data={:title=>"Discord Ruby Notification", :description=>"Will it work?"}>
2.5.1 :005 > Discord::Notifier.message(embed)
 => #<Net::HTTPBadRequest 400 BAD REQUEST readbody=true>

It has to be some kind of namespace conflict with another dependency of mine. Feel free to close this issue and I'll come back if I find any serious concern with a major dependency.

Srules commented 4 years ago

Worked for me in a fresh project. Apologies for bubbling this up so soon. Thanks for your time Ian.

IanMitchell commented 4 years ago

No worries at all! Very curious what's going on still... Are you on the latest version of the gem in your project?

Srules commented 4 years ago

It is actually 1.0.2 and not 1.0.3. Let me try the update.

IanMitchell commented 4 years ago

Really hoping this is #11 again in a slightly different form :D

Srules commented 4 years ago

I think actually that did fix it. 💯

IanMitchell commented 4 years ago

Awesome! I'll go ahead and close this then, glad things are working 😄