jsonrpc-client icon indicating copy to clipboard operation
jsonrpc-client copied to clipboard

Support for named parameters

Open mapuo opened this issue 11 years ago • 13 comments

We should have support for named parameters when making JSON RPC calls, this patch makes it possible to do just that with minimal modifications. When the user asks for client.foo(1) or client.bar(1,2) we should make an array, so the resulting params key should have [1] or [1,2] respectively. When the user asks for client.foo(:bar => 'foo') we should pass them directly, so the resulting params key should be {"bar": "foo"}.

mapuo avatar Feb 17 '14 12:02 mapuo

@mapuo +1

marjaimate avatar Feb 19 '14 16:02 marjaimate

I don't like the solution. If the first argument is JSON object - you will not be able to pass it at all.

fxposter avatar Feb 19 '14 19:02 fxposter

What is the exact case? Can you provide an example? :)

mapuo avatar Feb 19 '14 21:02 mapuo

client.foo(:some => { :nested => :hash }) - this is the call of method foo with the first parameter { :some => { :nested => :hash } }

fxposter avatar Feb 19 '14 21:02 fxposter

I've added a test for that case and it is passing, is this ok with you? :)

mapuo avatar Feb 19 '14 21:02 mapuo

No, I mean that my hash is not named params, but just the first parameter of the method. In your implementation we cannot do this anymore.

fxposter avatar Feb 19 '14 22:02 fxposter

Agrh! You are right, of course, but that don't leaves us with a lot of choices. What I was thinking about is will it be better to make the user decide in which mode the parameters are sent to the endpoint. I mean something like this: JSONRPC::Client.new('http://example.com', :named_params => true) and that way for that particular endpoint we know to communicate with named params and not positional. Will leave the option false by default for compatibility. Can we do that?

mapuo avatar Feb 19 '14 22:02 mapuo

Is that refactoring better now in your opinion?

mapuo avatar Feb 20 '14 09:02 mapuo

Hey, I was wondering did you had time to see the latest refactoring and will you merge them? And if not how can I change it to make it better?

mapuo avatar Apr 01 '14 15:04 mapuo

Hi, I've got an API I'm attempting to use jsonrpc-client for and it requires named parameters and will explicitly reject requests that are nested inside an array. Will there be any further progress on this PR?

mattikus avatar Jul 01 '16 21:07 mattikus

It's trivial to build an RPC client using faraday and a simple middleware: https://gist.github.com/romanbsd/f3af3addc88405a55a9c4c577b5525dc

romanbsd avatar Jul 02 '16 10:07 romanbsd

@romanbsd Thank's for the suggestion, that looks perfect for my needs as a very basic client.

mattikus avatar Jul 02 '16 23:07 mattikus

@mattikus I added a usage example in a comment there

romanbsd avatar Jul 03 '16 12:07 romanbsd