woocommerce / wc-api-ruby

A Ruby wrapper for the WooCommerce API.
MIT License
69 stars 74 forks source link

only set request body if data parameter is filled #17

Closed mtmail closed 8 years ago

mtmail commented 8 years ago

When accessing a store (version 2.4.10, API version 3, http protocol) with URL http://.../wc-api/v3/products/count it always failed with oauth_consumer_key parameter is missing.When not setting the body the requests work. It seems sensible to skip the body as maybe the receiving end misinterprets it.

claudiosanches commented 8 years ago

.get don't have any body. I just tested and works fine.

If you tell me the steps to reproduce this I thank you. But does not seem to me an issue.

mtmail commented 8 years ago

True. The .get doesn't set any body. But in this commit https://github.com/woothemes/wc-api-ruby/commit/83038992e61ef7cdb719c6181f0be8c7e78a0b72#diff-e3fcfd658655b91ae40404aa7650daf3R94 def do_request method, endpoint, data = nil got changed to def do_request method, endpoint, data = {} and httparty will send a body of {} because the HTTP specification allows that (http://stackoverflow.com/questions/978061/http-get-with-request-body#983458). I think it's the target server not handling that correctly.

I tried pushing the request to http://requestb.in/ instead to inspect exactly what gets send but without the && !data.empty? requestb.in crashes (error 500, <title>Application Error</title>). So it might be another server (Ruby on Rails on Heroku it seems) that can't handle a body in a HTTP GET request.

I'm sending you the WooCommerce store details to reproduce via https://claudiosmweb.com/contato/ because I don't feel comfortable posting client URL and secrets on github.

Again, I think the wc-api-ruby sends correct request, but some target servers can't handle body in HTTP GET requests, so it's better to leave them out when possible.

claudiosanches commented 8 years ago

I'll not reply you by email!

claudiosanches commented 8 years ago

I don't feel comfortable posting client URL and secrets on github.

I don't need keys and so on.

mtmail commented 8 years ago

Hi Claudio, That's totally fine. I just used the contact form as an alternative to send you the steps to reproduce the issue without posting store URLs or secrets publicly. No worries. Thanks for your work! Much appreciated.

claudiosanches commented 8 years ago

I just tested and really sending the body. Update to 1.1.2 :)

Thanks.