faraday_middleware-multi_json 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# FaradayMiddleware::MultiJson
|
2
2
|
|
3
|
-
|
3
|
+
A simple Faraday middleware that parses JSON responses with MultiJson for unobtrusiveness.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -18,7 +18,24 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
The same as FaradayMiddleware::ParseJson:
|
22
|
+
|
23
|
+
```
|
24
|
+
require 'faraday_middleware/multi_json'
|
25
|
+
|
26
|
+
connection = Faraday.new do |conn|
|
27
|
+
conn.response :multi_json
|
28
|
+
conn.adapter Faraday.default_adapter
|
29
|
+
end
|
30
|
+
|
31
|
+
connection.get('http://example.com/example.json')
|
32
|
+
```
|
33
|
+
|
34
|
+
### Passing parser options
|
35
|
+
|
36
|
+
```
|
37
|
+
conn.response :multi_json, symbolize_keys: true
|
38
|
+
```
|
22
39
|
|
23
40
|
## Contributing
|
24
41
|
|
@@ -12,7 +12,7 @@ Gem::Specification.new do |gem|
|
|
12
12
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
13
13
|
gem.name = 'faraday_middleware-multi_json'
|
14
14
|
gem.require_paths = ['lib']
|
15
|
-
gem.version = '0.0.
|
15
|
+
gem.version = '0.0.2'
|
16
16
|
|
17
17
|
gem.add_dependency 'faraday_middleware'
|
18
18
|
gem.add_dependency 'multi_json'
|
@@ -3,8 +3,9 @@ require 'faraday_middleware/response_middleware'
|
|
3
3
|
module FaradayMiddleware
|
4
4
|
class MultiJson < ResponseMiddleware
|
5
5
|
dependency 'multi_json'
|
6
|
-
|
7
|
-
|
6
|
+
|
7
|
+
def parse(body)
|
8
|
+
::MultiJson.load(body, @options) unless body.strip.empty?
|
8
9
|
end
|
9
10
|
end
|
10
11
|
end
|
@@ -1,18 +1,24 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe FaradayMiddleware::MultiJson do
|
4
|
-
|
5
|
-
body = ::MultiJson.dump a: 1, b: 2
|
4
|
+
let(:json) { ::MultiJson.dump(a:1, b:2) }
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
def connection(options={})
|
7
|
+
Faraday.new do |builder|
|
8
|
+
builder.response :multi_json, options
|
9
|
+
builder.adapter :test do |stub|
|
10
10
|
stub.get('/') do
|
11
|
-
[200, {},
|
11
|
+
[200, {}, json]
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should parse the response body' do
|
18
|
+
connection.get('/').body.should == {'a'=>1, 'b'=>2}
|
19
|
+
end
|
15
20
|
|
16
|
-
|
21
|
+
it 'should delegate options given by builder' do
|
22
|
+
connection(symbolize_keys: true).get('/').body.should == {a:1, b:2}
|
17
23
|
end
|
18
24
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faraday_middleware-multi_json
|
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-07-
|
12
|
+
date: 2012-07-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday_middleware
|