jsonrpc-client 0.0.1 → 0.0.2
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.
- data/lib/jsonrpc/client.rb +4 -4
- data/lib/jsonrpc/version.rb +1 -1
- data/spec/client_spec.rb +12 -3
- metadata +4 -4
data/lib/jsonrpc/client.rb
CHANGED
@@ -104,8 +104,8 @@ module JSONRPC
|
|
104
104
|
invoke(method, args)
|
105
105
|
end
|
106
106
|
|
107
|
-
def invoke(method, args)
|
108
|
-
resp = send_single_request(method.to_s, args)
|
107
|
+
def invoke(method, args, options = nil)
|
108
|
+
resp = send_single_request(method.to_s, args, options)
|
109
109
|
|
110
110
|
begin
|
111
111
|
data = ::MultiJson.decode(resp)
|
@@ -120,14 +120,14 @@ module JSONRPC
|
|
120
120
|
end
|
121
121
|
|
122
122
|
private
|
123
|
-
def send_single_request(method, args)
|
123
|
+
def send_single_request(method, args, options)
|
124
124
|
post_data = ::MultiJson.encode({
|
125
125
|
'jsonrpc' => JSON_RPC_VERSION,
|
126
126
|
'method' => method,
|
127
127
|
'params' => args,
|
128
128
|
'id' => ::JSONRPC::Base.make_id
|
129
129
|
})
|
130
|
-
resp = ::Faraday.post(@url, post_data, @opts)
|
130
|
+
resp = ::Faraday.post(@url, post_data, (options || {}).merge(@opts))
|
131
131
|
if resp.nil? || resp.body.nil? || resp.body.empty?
|
132
132
|
raise ::JSONRPC::Error::InvalidResponse.new
|
133
133
|
end
|
data/lib/jsonrpc/version.rb
CHANGED
data/spec/client_spec.rb
CHANGED
@@ -23,24 +23,33 @@ module JSONRPC
|
|
23
23
|
end
|
24
24
|
|
25
25
|
describe "#invoke" do
|
26
|
-
|
27
|
-
expected = MultiJson.encode({
|
26
|
+
let(:expected) { MultiJson.encode({
|
28
27
|
'jsonrpc' => '2.0',
|
29
28
|
'method' => 'foo',
|
30
29
|
'params' => [1,2,3],
|
31
30
|
'id' => 1
|
32
31
|
})
|
32
|
+
}
|
33
|
+
|
34
|
+
before(:each) do
|
33
35
|
response = MultiJson.encode(BOILERPLATE.merge({'result' => 42}))
|
34
|
-
Faraday.should_receive(:post).with(SPEC_URL, expected, {:content_type => 'application/json'}).and_return(@resp_mock)
|
35
36
|
@resp_mock.should_receive(:body).at_least(:once).and_return(response)
|
36
37
|
@client = Client.new(SPEC_URL)
|
37
38
|
end
|
38
39
|
|
39
40
|
context "when using an array of args" do
|
40
41
|
it "sends a request with the correct method and args" do
|
42
|
+
Faraday.should_receive(:post).with(SPEC_URL, expected, {:content_type => 'application/json'}).and_return(@resp_mock)
|
41
43
|
@client.invoke('foo', [1, 2, 3]).should == 42
|
42
44
|
end
|
43
45
|
end
|
46
|
+
|
47
|
+
context "with headers" do
|
48
|
+
it "adds additional headers" do
|
49
|
+
Faraday.should_receive(:post).with(SPEC_URL, expected, {:content_type => 'application/json', "X-FOO" => "BAR"}).and_return(@resp_mock)
|
50
|
+
@client.invoke('foo', [1, 2, 3], "X-FOO" => "BAR").should == 42
|
51
|
+
end
|
52
|
+
end
|
44
53
|
end
|
45
54
|
|
46
55
|
describe "sending a single request" do
|
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.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-09-
|
12
|
+
date: 2012-09-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
@@ -110,7 +110,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
110
110
|
version: '0'
|
111
111
|
segments:
|
112
112
|
- 0
|
113
|
-
hash:
|
113
|
+
hash: 1716510995999299040
|
114
114
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
115
|
none: false
|
116
116
|
requirements:
|
@@ -119,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
119
119
|
version: '0'
|
120
120
|
segments:
|
121
121
|
- 0
|
122
|
-
hash:
|
122
|
+
hash: 1716510995999299040
|
123
123
|
requirements: []
|
124
124
|
rubyforge_project:
|
125
125
|
rubygems_version: 1.8.24
|