jimson 0.12.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/jimson/client.rb +17 -6
- data/lib/jimson/version.rb +1 -1
- data/spec/client_spec.rb +14 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a755a4bd134103ffcc9794d845c4bf6f97060060d7c4909a68c5c106fbb09df
|
4
|
+
data.tar.gz: e82997e74c772975dc46f337fb0660ca71b718e4364836c480dbb6b2fcf9e2f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b707a76bb0a4f229d6c54be74caed765d2452255b0c4f91d35f2cc56aa199af6168a6361ee23a203defe161e87ac1acafb76f9aaf396f96ecc054727ec2bce25
|
7
|
+
data.tar.gz: bcb8e158d88406523d0243b94507d3c6d45ad011ab7e637a60186275cf203c1218a61003e3714c5a062121d6330efa5ce2b875429160562f1842c389565860c1
|
data/CHANGELOG.md
CHANGED
data/lib/jimson/client.rb
CHANGED
@@ -13,13 +13,16 @@ module Jimson
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def initialize(url, opts = {}, namespace = nil, client_opts = {})
|
16
|
+
URI.parse(url) # for the sake of validating the url
|
16
17
|
@url = url
|
17
|
-
URI.parse(@url) # for the sake of validating the url
|
18
|
-
@batch = []
|
19
18
|
@opts = opts
|
19
|
+
@opts[:id_type] ||= :int # Possible id types: :int, :string
|
20
20
|
@namespace = namespace
|
21
|
-
@opts[:content_type] ||= 'application/json'
|
22
21
|
@client_opts = client_opts
|
22
|
+
|
23
|
+
@batch = []
|
24
|
+
@headers = opts.slice( * opts.keys - [:id_type] )
|
25
|
+
@headers[:content_type] ||= 'application/json'
|
23
26
|
end
|
24
27
|
|
25
28
|
def process_call(sym, args)
|
@@ -44,9 +47,9 @@ module Jimson
|
|
44
47
|
'jsonrpc' => JSON_RPC_VERSION,
|
45
48
|
'method' => namespaced_method,
|
46
49
|
'params' => args,
|
47
|
-
'id' => self.class.make_id
|
50
|
+
'id' => format_post_id(self.class.make_id)
|
48
51
|
})
|
49
|
-
resp = RestClient::Request.execute(@client_opts.merge(:method => :post, :url => @url, :payload => post_data, :headers => @
|
52
|
+
resp = RestClient::Request.execute(@client_opts.merge(:method => :post, :url => @url, :payload => post_data, :headers => @headers))
|
50
53
|
if resp.nil? || resp.body.nil? || resp.body.empty?
|
51
54
|
raise Client::Error::InvalidResponse.new(resp)
|
52
55
|
end
|
@@ -56,7 +59,7 @@ module Jimson
|
|
56
59
|
|
57
60
|
def send_batch_request(batch)
|
58
61
|
post_data = MultiJson.encode(batch)
|
59
|
-
resp = RestClient::Request.execute(@client_opts.merge(:method => :post, :url => @url, :payload => post_data, :headers => @
|
62
|
+
resp = RestClient::Request.execute(@client_opts.merge(:method => :post, :url => @url, :payload => post_data, :headers => @headers))
|
60
63
|
if resp.nil? || resp.body.nil? || resp.body.empty?
|
61
64
|
raise Client::Error::InvalidResponse.new(resp)
|
62
65
|
end
|
@@ -130,6 +133,14 @@ module Jimson
|
|
130
133
|
@batch = []
|
131
134
|
end
|
132
135
|
|
136
|
+
def format_post_id(id)
|
137
|
+
if @opts[:id_type] == :string
|
138
|
+
id.to_s
|
139
|
+
else
|
140
|
+
id
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
133
144
|
end
|
134
145
|
|
135
146
|
class BatchClient < BlankSlate
|
data/lib/jimson/version.rb
CHANGED
data/spec/client_spec.rb
CHANGED
@@ -55,6 +55,20 @@ module Jimson
|
|
55
55
|
@client[:foo][:bar].sum(1, 2, 3).should == 42
|
56
56
|
end
|
57
57
|
end
|
58
|
+
|
59
|
+
it "sends the id as string" do
|
60
|
+
expected = MultiJson.encode({
|
61
|
+
'jsonrpc' => '2.0',
|
62
|
+
'method' => 'foo.sum',
|
63
|
+
'params' => [1,2,3],
|
64
|
+
'id' => "1"
|
65
|
+
})
|
66
|
+
response = MultiJson.encode(BOILERPLATE.merge({'result' => 42}))
|
67
|
+
RestClient::Request.should_receive(:execute).with(method: :post, url: SPEC_URL, payload: expected, headers: {:content_type => 'application/json'}).and_return(@resp_mock)
|
68
|
+
@resp_mock.should_receive(:body).at_least(:once).and_return(response)
|
69
|
+
client = Client.new(SPEC_URL, {id_type: :string})
|
70
|
+
client[:foo].sum(1, 2, 3).should == 42
|
71
|
+
end
|
58
72
|
end
|
59
73
|
|
60
74
|
context "when sending positional arguments" do
|
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.
|
4
|
+
version: 0.13.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-
|
13
|
+
date: 2021-05-10 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: blankslate
|