faraday_middleware-active_support_json 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +5 -0
- data/LICENSE +22 -0
- data/README.md +57 -0
- data/Rakefile +11 -0
- data/faraday_middleware-active_support_json.gemspec +21 -0
- data/lib/faraday_middleware-active_support_json.rb +1 -0
- data/lib/faraday_middleware/active_support_json.rb +29 -0
- data/spec/faraday_middleware/active_support_json_spec.rb +46 -0
- data/spec/spec_helper.rb +19 -0
- metadata +101 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 93486162bb5c2f3ee7361708565629bf51fce65e
|
4
|
+
data.tar.gz: 290264c2593eeab406bda2ccfec1db910d033185
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1c9da8a3489145aa727485582158a802a66453b70ba773e14e32dc0c1b43e5f62bf2d681aa05fae61378c07b9e51008376cb20312e41340b45419bf6e2e9e06b
|
7
|
+
data.tar.gz: ca75cace855c37ece4049b7c3ab036af8d37836b350f9034c6de999c887cb3cef66f89baf5c31cb7a79a5173bd973c4c160cbe413715f06e048666de016e3e14
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 David Butler
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# FaradayMiddleware::ActiveSupportJson
|
2
|
+
|
3
|
+
[](https://travis-ci.org/dwbutler/faraday_middleware-active_support_json)
|
4
|
+
|
5
|
+
Simple Faraday middleware that uses ActiveSupport::JSON to unobtrusively encode JSON requests and parse JSON responses.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'faraday_middleware-active_support_json'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install faraday_middleware-active_support_json
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
The same as FaradayMiddleware::ParseJson:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
require 'faraday_middleware/active_support_json'
|
27
|
+
|
28
|
+
connection = Faraday.new do |conn|
|
29
|
+
conn.request :active_support_json
|
30
|
+
conn.response :active_support_json
|
31
|
+
conn.adapter Faraday.default_adapter
|
32
|
+
end
|
33
|
+
|
34
|
+
connection.get('http://example.com/example.json')
|
35
|
+
|
36
|
+
resp = connection.post 'http://example.com/example.json' do |req|
|
37
|
+
req.body = {:hello => 'world'}
|
38
|
+
end
|
39
|
+
```
|
40
|
+
|
41
|
+
### Passing parser options
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
conn.response :active_support_json, symbolize_keys: true
|
45
|
+
```
|
46
|
+
|
47
|
+
## Credits
|
48
|
+
|
49
|
+
This gem is a fork of [FaradayMiddleware::MultiJson](https://github.com/denro/faraday_middleware-multi_json)
|
50
|
+
|
51
|
+
## Contributing
|
52
|
+
|
53
|
+
1. Fork it
|
54
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
55
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
56
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
57
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
#
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.authors = ['Dennis Rogenius', 'David Butler']
|
5
|
+
gem.email = ['dwbutler@ucla.edu']
|
6
|
+
gem.description = %q{Faraday middleware for handling JSON using ActiveSupport::JSON}
|
7
|
+
gem.summary = %q{JSON request generator and response parser using ActiveSupport::JSON and FaradayMiddleware}
|
8
|
+
gem.homepage = 'https://github.com/dwbutler/faraday_middleware-active_support_json'
|
9
|
+
|
10
|
+
gem.files = `git ls-files`.split($\)
|
11
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
12
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
13
|
+
gem.name = 'faraday_middleware-active_support_json'
|
14
|
+
gem.require_paths = ['lib']
|
15
|
+
gem.version = '0.0.1'
|
16
|
+
|
17
|
+
gem.add_dependency 'faraday_middleware'
|
18
|
+
gem.add_dependency 'activesupport'
|
19
|
+
|
20
|
+
gem.add_development_dependency 'rspec'
|
21
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'faraday_middleware/active_support_json'
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'faraday_middleware/response_middleware'
|
2
|
+
require 'faraday_middleware/request/encode_json'
|
3
|
+
|
4
|
+
module FaradayMiddleware
|
5
|
+
module ActiveSupport
|
6
|
+
class ParseJson < FaradayMiddleware::ResponseMiddleware
|
7
|
+
dependency 'active_support/json'
|
8
|
+
|
9
|
+
def parse(body)
|
10
|
+
::ActiveSupport::JSON.decode(body, @options) rescue body
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class EncodeJson < FaradayMiddleware::EncodeJson
|
15
|
+
dependency 'active_support/json'
|
16
|
+
|
17
|
+
def initialize(app, *)
|
18
|
+
super(app)
|
19
|
+
end
|
20
|
+
|
21
|
+
def encode(data)
|
22
|
+
::ActiveSupport::JSON.encode(data)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
Faraday.register_middleware :response, :active_support_json => FaradayMiddleware::ActiveSupport::ParseJson
|
29
|
+
Faraday.register_middleware :request, :active_support_json => FaradayMiddleware::ActiveSupport::EncodeJson
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FaradayMiddleware::ActiveSupport::ParseJson do
|
4
|
+
let(:response) { {:a => 1, :b => 2} }
|
5
|
+
let(:json) { ::ActiveSupport::JSON.encode(response) }
|
6
|
+
|
7
|
+
def connection(options={})
|
8
|
+
Faraday.new do |builder|
|
9
|
+
builder.response :active_support_json, options
|
10
|
+
builder.adapter :test do |stub|
|
11
|
+
stub.get('/') do
|
12
|
+
[200, {}, json]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should parse the response body' do
|
19
|
+
connection.get('/').body.should == {'a'=>1, 'b'=>2}
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should delegate options given by builder' do
|
23
|
+
connection(:symbolize_keys => true).get('/').body.should == response
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe FaradayMiddleware::ActiveSupport::EncodeJson do
|
28
|
+
let(:request) { {:a => 1, :b => 2} }
|
29
|
+
let(:json) { ::ActiveSupport::JSON.encode(request) }
|
30
|
+
|
31
|
+
def connection
|
32
|
+
Faraday.new do |builder|
|
33
|
+
builder.request :active_support_json
|
34
|
+
builder.adapter :test do |stub|
|
35
|
+
stub.post('/update', json) do
|
36
|
+
[200, {}, json]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should parse the request body' do
|
43
|
+
resp = connection.post('/update', request)
|
44
|
+
resp.body.should == json
|
45
|
+
end
|
46
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
9
|
+
config.run_all_when_everything_filtered = true
|
10
|
+
config.filter_run :focus
|
11
|
+
|
12
|
+
# Run specs in random order to surface order dependencies. If you find an
|
13
|
+
# order dependency and want to debug it, you can fix the order by providing
|
14
|
+
# the seed, which is printed after each run.
|
15
|
+
# --seed 1234
|
16
|
+
config.order = 'random'
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'faraday_middleware/active_support_json'
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: faraday_middleware-active_support_json
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dennis Rogenius
|
8
|
+
- David Butler
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-08-13 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: faraday_middleware
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - '>='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - '>='
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: activesupport
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rspec
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
description: Faraday middleware for handling JSON using ActiveSupport::JSON
|
57
|
+
email:
|
58
|
+
- dwbutler@ucla.edu
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- .gitignore
|
64
|
+
- .rspec
|
65
|
+
- .travis.yml
|
66
|
+
- Gemfile
|
67
|
+
- LICENSE
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- faraday_middleware-active_support_json.gemspec
|
71
|
+
- lib/faraday_middleware-active_support_json.rb
|
72
|
+
- lib/faraday_middleware/active_support_json.rb
|
73
|
+
- spec/faraday_middleware/active_support_json_spec.rb
|
74
|
+
- spec/spec_helper.rb
|
75
|
+
homepage: https://github.com/dwbutler/faraday_middleware-active_support_json
|
76
|
+
licenses: []
|
77
|
+
metadata: {}
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 2.0.3
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: JSON request generator and response parser using ActiveSupport::JSON and
|
98
|
+
FaradayMiddleware
|
99
|
+
test_files:
|
100
|
+
- spec/faraday_middleware/active_support_json_spec.rb
|
101
|
+
- spec/spec_helper.rb
|