jsonrpc-client 0.0.5 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cdc0de17501cfe5b82fa8ab093a3f55e2c396ac2
4
+ data.tar.gz: c24326d048f05722dcf4dd67918b4d971aa7f284
5
+ SHA512:
6
+ metadata.gz: 9310e8fd0f4ba0fe44f7e0337147ae88468297bf8a39f0c91c2c5fa3e06f6a75839eb763fa816da4df360428c9cc3574cf1f3bf1a7a26c6f5da8d0b65801cc1b
7
+ data.tar.gz: 4aad59795552a01e3d3957d9571dc2a995b781a0c190eef4e18cf2641ab27fdd32073cc077969c9c61891b08a4e01c37cd192aadbebfc6e9fc9ee9accb5f4a6a
@@ -24,6 +24,28 @@ module JSONRPC
24
24
 
25
25
  @decode_options = {}
26
26
 
27
+ class Helper
28
+ def initialize(options)
29
+ @options = options
30
+ @options[:content_type] ||= 'application/json'
31
+ end
32
+
33
+ def options(additional_options = nil)
34
+ if additional_options
35
+ additional_options.merge(@options)
36
+ else
37
+ @options
38
+ end
39
+ end
40
+
41
+ def connection
42
+ @options[:connection] || ::Faraday.new { |connection|
43
+ connection.response :logger, ::JSONRPC.logger
44
+ connection.adapter ::Faraday.default_adapter
45
+ }
46
+ end
47
+ end
48
+
27
49
  class Base < BasicObject
28
50
  JSON_RPC_VERSION = '2.0'
29
51
 
@@ -33,8 +55,7 @@ module JSONRPC
33
55
 
34
56
  def initialize(url, opts = {})
35
57
  @url = ::URI.parse(url).to_s
36
- @opts = opts
37
- @opts[:content_type] ||= 'application/json'
58
+ @helper = ::JSONRPC::Helper.new(opts)
38
59
  end
39
60
 
40
61
  def to_s
@@ -79,10 +100,7 @@ module JSONRPC
79
100
  private
80
101
  def send_batch_request(batch)
81
102
  post_data = ::MultiJson.encode(batch)
82
- resp = ::Faraday.new { |connection|
83
- connection.response :logger, ::JSONRPC.logger
84
- connection.adapter ::Faraday.default_adapter
85
- }.post(@url, post_data, @opts)
103
+ resp = @helper.connection.post(@url, post_data, @helper.options)
86
104
  if resp.nil? || resp.body.nil? || resp.body.empty?
87
105
  raise ::JSONRPC::Error::InvalidResponse.new
88
106
  end
@@ -148,10 +166,7 @@ module JSONRPC
148
166
  'params' => args,
149
167
  'id' => ::JSONRPC::Base.make_id
150
168
  })
151
- resp = ::Faraday.new { |connection|
152
- connection.response :logger, ::JSONRPC.logger
153
- connection.adapter ::Faraday.default_adapter
154
- }.post(@url, post_data, (options || {}).merge(@opts))
169
+ resp = @helper.connection.post(@url, post_data, @helper.options(options))
155
170
 
156
171
  if resp.nil? || resp.body.nil? || resp.body.empty?
157
172
  raise ::JSONRPC::Error::InvalidResponse.new
@@ -1,3 +1,3 @@
1
1
  module JSONRPC
2
- VERSION = '0.0.5'
2
+ VERSION = '0.1.0'
3
3
  end
@@ -5,8 +5,8 @@ module JSONRPC
5
5
  BOILERPLATE = {'jsonrpc' => '2.0', 'id' => 1}
6
6
 
7
7
  before(:each) do
8
- @resp_mock = mock('http_response')
9
- Base.stub!(:make_id).and_return(1)
8
+ @resp_mock = double('http_response')
9
+ Base.stub(:make_id).and_return(1)
10
10
  end
11
11
 
12
12
  after(:each) do
@@ -104,7 +104,7 @@ module JSONRPC
104
104
  {"jsonrpc" => "2.0", "result" => ["hello", 5], "id" => "9"}
105
105
  ])
106
106
 
107
- Base.stub!(:make_id).and_return('1', '2', '5', '9')
107
+ Base.stub(:make_id).and_return('1', '2', '5', '9')
108
108
  Faraday::Connection.any_instance.should_receive(:post).with(SPEC_URL, batch, {:content_type => 'application/json'}).and_return(@resp_mock)
109
109
  @resp_mock.should_receive(:body).at_least(:once).and_return(response)
110
110
  client = Client.new(SPEC_URL)
metadata CHANGED
@@ -1,80 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsonrpc-client
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.0.5
4
+ version: 0.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Pavel Forkert
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-03-11 00:00:00.000000000 Z
11
+ date: 2014-01-31 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
- version_requirements: !ruby/object:Gem::Requirement
16
- none: false
17
- requirements:
18
- - - ! '>='
19
- - !ruby/object:Gem::Version
20
- version: '0'
21
14
  name: faraday
22
- prerelease: false
23
15
  requirement: !ruby/object:Gem::Requirement
24
- none: false
25
16
  requirements:
26
- - - ! '>='
17
+ - - ">="
27
18
  - !ruby/object:Gem::Version
28
19
  version: '0'
29
20
  type: :runtime
30
- - !ruby/object:Gem::Dependency
21
+ prerelease: false
31
22
  version_requirements: !ruby/object:Gem::Requirement
32
- none: false
33
23
  requirements:
34
- - - ! '>='
24
+ - - ">="
35
25
  - !ruby/object:Gem::Version
36
- version: 1.1.0
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
37
28
  name: multi_json
38
- prerelease: false
39
29
  requirement: !ruby/object:Gem::Requirement
40
- none: false
41
30
  requirements:
42
- - - ! '>='
31
+ - - ">="
43
32
  - !ruby/object:Gem::Version
44
33
  version: 1.1.0
45
34
  type: :runtime
46
- - !ruby/object:Gem::Dependency
35
+ prerelease: false
47
36
  version_requirements: !ruby/object:Gem::Requirement
48
- none: false
49
37
  requirements:
50
- - - ! '>='
38
+ - - ">="
51
39
  - !ruby/object:Gem::Version
52
- version: '0'
40
+ version: 1.1.0
41
+ - !ruby/object:Gem::Dependency
53
42
  name: rspec
54
- prerelease: false
55
43
  requirement: !ruby/object:Gem::Requirement
56
- none: false
57
44
  requirements:
58
- - - ! '>='
45
+ - - ">="
59
46
  - !ruby/object:Gem::Version
60
47
  version: '0'
61
48
  type: :development
62
- - !ruby/object:Gem::Dependency
49
+ prerelease: false
63
50
  version_requirements: !ruby/object:Gem::Requirement
64
- none: false
65
51
  requirements:
66
- - - ! '>='
52
+ - - ">="
67
53
  - !ruby/object:Gem::Version
68
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
69
56
  name: rake
70
- prerelease: false
71
57
  requirement: !ruby/object:Gem::Requirement
72
- none: false
73
58
  requirements:
74
- - - ! '>='
59
+ - - ">="
75
60
  - !ruby/object:Gem::Version
76
61
  version: '0'
77
62
  type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
78
69
  description: Simple JSON-RPC 2.0 client implementation
79
70
  email:
80
71
  - fxposter@gmail.com
@@ -82,7 +73,7 @@ executables: []
82
73
  extensions: []
83
74
  extra_rdoc_files: []
84
75
  files:
85
- - .gitignore
76
+ - ".gitignore"
86
77
  - Gemfile
87
78
  - LICENSE.txt
88
79
  - README.md
@@ -98,33 +89,26 @@ files:
98
89
  - spec/spec_helper.rb
99
90
  homepage: https://github.com/fxposter/jsonrpc-client
100
91
  licenses: []
92
+ metadata: {}
101
93
  post_install_message:
102
94
  rdoc_options: []
103
95
  require_paths:
104
96
  - lib
105
97
  required_ruby_version: !ruby/object:Gem::Requirement
106
- none: false
107
98
  requirements:
108
- - - ! '>='
99
+ - - ">="
109
100
  - !ruby/object:Gem::Version
110
- segments:
111
- - 0
112
- hash: -23030267990398906
113
101
  version: '0'
114
102
  required_rubygems_version: !ruby/object:Gem::Requirement
115
- none: false
116
103
  requirements:
117
- - - ! '>='
104
+ - - ">="
118
105
  - !ruby/object:Gem::Version
119
- segments:
120
- - 0
121
- hash: -23030267990398906
122
106
  version: '0'
123
107
  requirements: []
124
108
  rubyforge_project:
125
- rubygems_version: 1.8.25
109
+ rubygems_version: 2.2.1
126
110
  signing_key:
127
- specification_version: 3
111
+ specification_version: 4
128
112
  summary: JSON-RPC 2.0 client
129
113
  test_files:
130
114
  - spec/client_spec.rb