woocommerce / wc-api-ruby

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

Support data params for GET and DELETE #10

Closed choubacha closed 9 years ago

choubacha commented 9 years ago

@claudiosmweb

This enables passing data into the get and delete routes (which would be needed for filters and forces) instead of using the query params as strings.

This:

client.delete('products/1', force: true)

rather than this:

client.delete('products/1?force=true)

For filters it's even more obvious why this form is better:

client.get('products', filter: { sku: '123' })
claudiosanches commented 9 years ago

Ok, I'll test tomorrow

choubacha commented 9 years ago

@claudiosmweb We're using my fork right now but wanted to ping to see if I could get eyes on this :smile:

claudiosanches commented 9 years ago

@kbacha This does not work fine yet, Has nothing organized by alphabetical order, then we have problem with oAuth...

choubacha commented 9 years ago

@claudiosmweb My understanding is that the ordering is only necessary for the signature of the oauth. So, it only needs to be ordered when doing http and generating the oauth URL to sign. This should still work (and does in our production environment) because the OAuth class will reorder the query params.

claudiosanches commented 9 years ago

@kbacha test it.

choubacha commented 9 years ago

@claudiosmweb done https://github.com/woothemes/wc-api-ruby/pull/10/files#diff-81f86f40f18ca5e6ba1943cb6f6ed4a3R42

claudiosanches commented 9 years ago

@kbacha this is broken!

Test:

woocommerce.get("customers", { page: 2, filter: { role: "all", limit: 1 } })

Response:

{"errors"=>[{"code"=>"woocommerce_api_authentication_error", "message"=>"Invalid Signature - provided signature does not match"}]}

Because of the wrong order!

choubacha commented 9 years ago

@claudiosmweb I believe this is a problem with the way the sort in the OAuth class is working, not the way i add query params:

2.2.2 :016 > r = client.get('products?page=2&filter[role]=all&filter[limit]=1') 2.2.2 :019 > JSON.parse(r.body) => {"errors"=>[{"code"=>"woocommerce_api_authentication_error", "message"=>"Invalid Signature - provided signature does not match"}]}

But I'll look into making it work correctly.

choubacha commented 9 years ago

@claudiosmweb

I fixed the OAuth class so that it always sorts the params that are passed in. 17fc2d17126dbbc93dd86049f82519165fee480c

claudiosanches commented 9 years ago

@kbacha Great now :) Thanks.