jsonrpc-client 0.1.0 → 0.1.1

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
  SHA1:
3
- metadata.gz: cdc0de17501cfe5b82fa8ab093a3f55e2c396ac2
4
- data.tar.gz: c24326d048f05722dcf4dd67918b4d971aa7f284
3
+ metadata.gz: 16df1f4675b321e958dcc829f856d38cc7e070f5
4
+ data.tar.gz: 5d90364902453e6c0f8407d0fabe17aa7b92099e
5
5
  SHA512:
6
- metadata.gz: 9310e8fd0f4ba0fe44f7e0337147ae88468297bf8a39f0c91c2c5fa3e06f6a75839eb763fa816da4df360428c9cc3574cf1f3bf1a7a26c6f5da8d0b65801cc1b
7
- data.tar.gz: 4aad59795552a01e3d3957d9571dc2a995b781a0c190eef4e18cf2641ab27fdd32073cc077969c9c61891b08a4e01c37cd192aadbebfc6e9fc9ee9accb5f4a6a
6
+ metadata.gz: ce33b474fabf9f6a9f4ca64d3fe711a2a804e4d5ed7283d83912e96966fe0194d046540de44dedcb2ce13fd78c4af9cb2316cedbb87f51eb1fcd898ff21d0bbe
7
+ data.tar.gz: a766a37ba9bee715802abb5f0e1c2b9a660d47cdf85adcd1a19dc1b5221e3f27327ab589f1f4eb354bc9ae876361322b47454341608e5ca67c29ff952d9fe4e1
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # JSONRPC::Client
2
2
 
3
- TODO: Write a gem description
3
+ Simple JSON-RPC 2.0 client implementation. See the [specification](http://www.jsonrpc.org/specification).
4
4
 
5
5
  ## Installation
6
6
 
@@ -18,7 +18,10 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- TODO: Write usage instructions here
21
+ ```
22
+ client = JSONRPC::Client.new('http://example.com')
23
+ client.add_numbers(1, 2, 3)
24
+ ```
22
25
 
23
26
  ## Contributing
24
27
 
@@ -28,6 +28,7 @@ module JSONRPC
28
28
  def initialize(options)
29
29
  @options = options
30
30
  @options[:content_type] ||= 'application/json'
31
+ @connection = @options.delete(:connection)
31
32
  end
32
33
 
33
34
  def options(additional_options = nil)
@@ -39,7 +40,7 @@ module JSONRPC
39
40
  end
40
41
 
41
42
  def connection
42
- @options[:connection] || ::Faraday.new { |connection|
43
+ @connection || ::Faraday.new { |connection|
43
44
  connection.response :logger, ::JSONRPC.logger
44
45
  connection.adapter ::Faraday.default_adapter
45
46
  }
@@ -1,3 +1,3 @@
1
1
  module JSONRPC
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
@@ -4,6 +4,8 @@ module JSONRPC
4
4
  describe Client do
5
5
  BOILERPLATE = {'jsonrpc' => '2.0', 'id' => 1}
6
6
 
7
+ let(:connection) { double('connection') }
8
+
7
9
  before(:each) do
8
10
  @resp_mock = double('http_response')
9
11
  Base.stub(:make_id).and_return(1)
@@ -34,19 +36,19 @@ module JSONRPC
34
36
  before(:each) do
35
37
  response = MultiJson.encode(BOILERPLATE.merge({'result' => 42}))
36
38
  @resp_mock.should_receive(:body).at_least(:once).and_return(response)
37
- @client = Client.new(SPEC_URL)
39
+ @client = Client.new(SPEC_URL, :connection => connection)
38
40
  end
39
41
 
40
42
  context "when using an array of args" do
41
43
  it "sends a request with the correct method and args" do
42
- Faraday::Connection.any_instance.should_receive(:post).with(SPEC_URL, expected, {:content_type => 'application/json'}).and_return(@resp_mock)
44
+ connection.should_receive(:post).with(SPEC_URL, expected, {:content_type => 'application/json'}).and_return(@resp_mock)
43
45
  @client.invoke('foo', [1, 2, 3]).should == 42
44
46
  end
45
47
  end
46
48
 
47
49
  context "with headers" do
48
50
  it "adds additional headers" do
49
- Faraday::Connection.any_instance.should_receive(:post).with(SPEC_URL, expected, {:content_type => 'application/json', "X-FOO" => "BAR"}).and_return(@resp_mock)
51
+ connection.should_receive(:post).with(SPEC_URL, expected, {:content_type => 'application/json', "X-FOO" => "BAR"}).and_return(@resp_mock)
50
52
  @client.invoke('foo', [1, 2, 3], "X-FOO" => "BAR").should == 42
51
53
  end
52
54
  end
@@ -64,25 +66,25 @@ module JSONRPC
64
66
  end
65
67
  it "sends a valid JSON-RPC request and returns the result" do
66
68
  response = MultiJson.encode(BOILERPLATE.merge({'result' => 42}))
67
- Faraday::Connection.any_instance.should_receive(:post).with(SPEC_URL, @expected, {:content_type => 'application/json'}).and_return(@resp_mock)
69
+ connection.should_receive(:post).with(SPEC_URL, @expected, {:content_type => 'application/json'}).and_return(@resp_mock)
68
70
  @resp_mock.should_receive(:body).at_least(:once).and_return(response)
69
- client = Client.new(SPEC_URL)
71
+ client = Client.new(SPEC_URL, :connection => connection)
70
72
  client.foo(1,2,3).should == 42
71
73
  end
72
74
 
73
75
  it "sends a valid JSON-RPC request with custom options" do
74
76
  response = MultiJson.encode(BOILERPLATE.merge({'result' => 42}))
75
- Faraday::Connection.any_instance.should_receive(:post).with(SPEC_URL, @expected, {:content_type => 'application/json', :timeout => 10000}).and_return(@resp_mock)
77
+ connection.should_receive(:post).with(SPEC_URL, @expected, {:content_type => 'application/json', :timeout => 10000}).and_return(@resp_mock)
76
78
  @resp_mock.should_receive(:body).at_least(:once).and_return(response)
77
- client = Client.new(SPEC_URL, :timeout => 10000)
79
+ client = Client.new(SPEC_URL, :timeout => 10000, :connection => connection)
78
80
  client.foo(1,2,3).should == 42
79
81
  end
80
82
 
81
83
  it "sends a valid JSON-RPC request with custom content_type" do
82
84
  response = MultiJson.encode(BOILERPLATE.merge({'result' => 42}))
83
- Faraday::Connection.any_instance.should_receive(:post).with(SPEC_URL, @expected, {:content_type => 'application/json-rpc', :timeout => 10000}).and_return(@resp_mock)
85
+ connection.should_receive(:post).with(SPEC_URL, @expected, {:content_type => 'application/json-rpc', :timeout => 10000}).and_return(@resp_mock)
84
86
  @resp_mock.should_receive(:body).at_least(:once).and_return(response)
85
- client = Client.new(SPEC_URL, :timeout => 10000, :content_type => 'application/json-rpc')
87
+ client = Client.new(SPEC_URL, :timeout => 10000, :content_type => 'application/json-rpc', :connection => connection)
86
88
  client.foo(1,2,3).should == 42
87
89
  end
88
90
  end
@@ -105,12 +107,12 @@ module JSONRPC
105
107
  ])
106
108
 
107
109
  Base.stub(:make_id).and_return('1', '2', '5', '9')
108
- Faraday::Connection.any_instance.should_receive(:post).with(SPEC_URL, batch, {:content_type => 'application/json'}).and_return(@resp_mock)
110
+ connection.should_receive(:post).with(SPEC_URL, batch, {:content_type => 'application/json'}).and_return(@resp_mock)
109
111
  @resp_mock.should_receive(:body).at_least(:once).and_return(response)
110
- client = Client.new(SPEC_URL)
112
+ client = Client.new(SPEC_URL, :connection => connection)
111
113
 
112
114
  sum = subtract = foo = data = nil
113
- client = BatchClient.new(SPEC_URL) do |batch|
115
+ client = BatchClient.new(SPEC_URL, :connection => connection) do |batch|
114
116
  sum = batch.sum(1,2,4)
115
117
  subtract = batch.subtract(42,23)
116
118
  foo = batch.foo_get('name' => 'myself')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsonrpc-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Forkert
@@ -113,3 +113,4 @@ summary: JSON-RPC 2.0 client
113
113
  test_files:
114
114
  - spec/client_spec.rb
115
115
  - spec/spec_helper.rb
116
+ has_rdoc: