jimson 0.12.0 → 0.13.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: 5745486a124bbc3d73284db9d6294aac57eb23d1815e2ad8c98f145f9fc124a9
4
- data.tar.gz: 258d62e7212cc0c559d167aacf1f511a5cbf88e2b022ff423634537cefa570a9
3
+ metadata.gz: 8a755a4bd134103ffcc9794d845c4bf6f97060060d7c4909a68c5c106fbb09df
4
+ data.tar.gz: e82997e74c772975dc46f337fb0660ca71b718e4364836c480dbb6b2fcf9e2f5
5
5
  SHA512:
6
- metadata.gz: 2f2c58014cf11afea61ed91cc2bbb6e4b57bd3622ac58b2c4b4372054ce72c25938bfa72bfbbdc233c4ec1afaa698103d8e889ab22496d580c161ee99858d49e
7
- data.tar.gz: c2b1642505d7ff5846c8cb9314be37ec95d409bf466eb126120870cb76ec5b5db0a5cb58693e4e50e932e05c148f5395890dffcd75ea397fb0d9c396fbc7a053
6
+ metadata.gz: b707a76bb0a4f229d6c54be74caed765d2452255b0c4f91d35f2cc56aa199af6168a6361ee23a203defe161e87ac1acafb76f9aaf396f96ecc054727ec2bce25
7
+ data.tar.gz: bcb8e158d88406523d0243b94507d3c6d45ad011ab7e637a60186275cf203c1218a61003e3714c5a062121d6330efa5ce2b875429160562f1842c389565860c1
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # 0.13.0 / 2021-05-10
2
+
3
+ * Major enhancements
4
+
5
+ * Added option to use strings as id instead of an int
6
+
1
7
  # 0.12.0 / 2021-05-05
2
8
 
3
9
  * Major enhancements
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 => @opts))
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 => @opts))
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
@@ -1,3 +1,3 @@
1
1
  module Jimson
2
- VERSION = '0.12.0'
2
+ VERSION = '0.13.0'
3
3
  end
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.12.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-05 00:00:00.000000000 Z
13
+ date: 2021-05-10 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: blankslate