-
Notifications
You must be signed in to change notification settings - Fork 18
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
Support for named parameters #4
base: master
Are you sure you want to change the base?
Conversation
@mapuo +1 |
I don't like the solution. If the first argument is JSON object - you will not be able to pass it at all. |
What is the exact case? Can you provide an example? :) |
|
I've added a test for that case and it is passing, is this ok with you? :) |
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. |
Agrh! You are right, of course, but that don't leaves us with a lot of choices. |
Is that refactoring better now in your opinion? |
Hey, I was wondering did you had time to see the latest refactoring and will you merge them? |
@@ -91,7 +104,11 @@ def initialize(url, opts = {}) | |||
|
|||
def method_missing(sym, *args, &block) | |||
if @alive | |||
request = ::JSONRPC::Request.new(sym.to_s, args) | |||
if @helper.named_params? && args.first.is_a?(::Hash) |
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 need to check for the args.size == 1, because it can be [{foo: 'bar'}, 2]
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? |
It's trivial to build an RPC client using faraday and a simple middleware: |
@romanbsd Thank's for the suggestion, that looks perfect for my needs as a very basic client. |
@mattikus I added a usage example in a comment there |
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)
orclient.bar(1,2)
we should make an array, so the resultingparams
key should have[1]
or[1,2]
respectively.When the user asks for
client.foo(:bar => 'foo')
we should pass them directly, so the resultingparams
key should be{"bar": "foo"}
.