jimson 0.13.0 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8a755a4bd134103ffcc9794d845c4bf6f97060060d7c4909a68c5c106fbb09df
4
- data.tar.gz: e82997e74c772975dc46f337fb0660ca71b718e4364836c480dbb6b2fcf9e2f5
3
+ metadata.gz: 796c16d539f0164203cf72d44e36f82ceb24c0fc110f1a6a31319d5fbb0dd393
4
+ data.tar.gz: 443273c640503427548b431d8da0e619d3bc5a65c57bb6be5cb75ffec0cde77f
5
5
  SHA512:
6
- metadata.gz: b707a76bb0a4f229d6c54be74caed765d2452255b0c4f91d35f2cc56aa199af6168a6361ee23a203defe161e87ac1acafb76f9aaf396f96ecc054727ec2bce25
7
- data.tar.gz: bcb8e158d88406523d0243b94507d3c6d45ad011ab7e637a60186275cf203c1218a61003e3714c5a062121d6330efa5ce2b875429160562f1842c389565860c1
6
+ metadata.gz: 96d7c724b0f3e0e764c09bbe57a4b4fc33caa2784835d0caeafdd8efe6532006be80754a970e2bab9558a3b17511602bf830a38863b53733b62e0c26834b17bc
7
+ data.tar.gz: 0ff8ecb09c52137decaaf34132974fcc3286e37a28a7f1a256ec5a4368df72fe55c0f51b9ea87602065d46716b5326f6f97d3e4e148937f70353b59d3342f1c6
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Jimson
2
2
 
3
- ### JSON-RPC 2.0 Client and Server for Ruby
3
+ ### [JSON-RPC 2.0](https://www.jsonrpc.org/specification) Client and Server for Ruby
4
4
 
5
5
  [![Build Status](https://github.com/chriskite/jimson/actions/workflows/ruby.yml/badge.svg?branch=main)](https://github.com/chriskite/jimson/actions/workflows/ruby.yml)
6
6
 
@@ -31,7 +31,7 @@ server.start # serve with webrick on http://0.0.0.0:8999/
31
31
 
32
32
  ## JSON Engine
33
33
 
34
- Jimson uses multi\_json, so you can load the JSON library of your choice in your application and Jimson will use it automatically.
34
+ Jimson uses [multi\_json](https://github.com/intridea/multi_json), so you can load the JSON library of your choice in your application and Jimson will use it automatically.
35
35
 
36
36
  For example, require the 'json' gem in your application:
37
37
 
@@ -39,3 +39,6 @@ For example, require the 'json' gem in your application:
39
39
  require 'json'
40
40
  ```
41
41
 
42
+ ## Previous maintainer
43
+
44
+ This gem was maintained by [Chris Kite](https://github.com/chriskite/) till April 2021.
data/lib/jimson/client.rb CHANGED
@@ -150,6 +150,7 @@ module Jimson
150
150
  end
151
151
 
152
152
  def method_missing(sym, *args, &block)
153
+ args = args.first if args.size == 1 && args.first.is_a?(Hash)
153
154
  request = Jimson::Request.new(sym.to_s, args)
154
155
  @helper.push_batch_request(request)
155
156
  end
@@ -184,6 +185,7 @@ module Jimson
184
185
  new_ns = @namespace.nil? ? "#{method}." : "#@namespace#{method}."
185
186
  return Client.new(@url, @opts, new_ns)
186
187
  end
188
+ args = args.first if args.size == 1 && args.first.is_a?(Hash)
187
189
  @helper.process_call(method, args)
188
190
  end
189
191
 
@@ -1,3 +1,3 @@
1
1
  module Jimson
2
- VERSION = '0.13.0'
2
+ VERSION = '0.14.0'
3
3
  end
data/spec/client_spec.rb CHANGED
@@ -56,6 +56,21 @@ module Jimson
56
56
  end
57
57
  end
58
58
 
59
+ context "when sending named paramaters" do
60
+ it "sends the the params as a hash" do
61
+ expected = MultiJson.encode({
62
+ 'jsonrpc' => '2.0',
63
+ 'method' => 'foo.sum',
64
+ 'params' => { :first_number => 5, :second_number => 6 },
65
+ 'id' => 1
66
+ })
67
+ response = MultiJson.encode(BOILERPLATE.merge({'result' => 11}))
68
+ RestClient::Request.should_receive(:execute).with(method: :post, url: SPEC_URL, payload: expected, headers: {:content_type => 'application/json'}).and_return(@resp_mock)
69
+ @resp_mock.should_receive(:body).at_least(:once).and_return(response)
70
+ @client[:foo].sum({:first_number => 5, :second_number => 6}).should == 11
71
+ end
72
+ end
73
+
59
74
  it "sends the id as string" do
60
75
  expected = MultiJson.encode({
61
76
  'jsonrpc' => '2.0',
@@ -160,7 +175,7 @@ module Jimson
160
175
  client.foo([1,2],3).should == 42
161
176
  end
162
177
  end
163
-
178
+
164
179
  context "when one of the parameters is a hash" do
165
180
  it "sends a correct JSON-RPC request (array is preserved with hash) and returns the results" do
166
181
  expected = MultiJson.encode({
@@ -176,14 +191,14 @@ module Jimson
176
191
  client.foo(1, {'bar' => 'baz'}, 3).should == 42
177
192
  end
178
193
  end
179
-
194
+
180
195
  context "when using named parameters" do
181
196
  it "sends a correct JSON-RPC request (named parameters are preserved) and returns the result" do
182
197
  expected = MultiJson.encode({
183
198
  'jsonrpc' => '2.0',
184
199
  'method' => 'foo',
185
200
  'params' => {'bar' => 'baz'},
186
- 'id' => 1
201
+ 'id' => 1
187
202
  })
188
203
  response = MultiJson.encode(BOILERPLATE.merge({'result' => 42}))
189
204
  RestClient::Request.should_receive(:execute).with(method: :post, url: SPEC_URL, payload: expected, headers: {:content_type => 'application/json'}).and_return(@resp_mock)
@@ -199,7 +214,7 @@ module Jimson
199
214
  batch = MultiJson.encode([
200
215
  {"jsonrpc" => "2.0", "method" => "sum", "params" => [1,2,4], "id" => "1"},
201
216
  {"jsonrpc" => "2.0", "method" => "subtract", "params" => [42,23], "id" => "2"},
202
- {"jsonrpc" => "2.0", "method" => "foo_get", "params" => [{"name" => "myself"}], "id" => "5"},
217
+ {"jsonrpc" => "2.0", "method" => "foo_get", "params" => {"name" => "myself"}, "id" => "5"},
203
218
  {"jsonrpc" => "2.0", "method" => "get_data", "id" => "9"}
204
219
  ])
205
220
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jimson
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.0
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Kite
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2021-05-10 00:00:00.000000000 Z
13
+ date: 2021-08-16 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: blankslate