faraday_hal_middleware 0.1.0 → 0.1.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 +5 -5
- data/.rspec +1 -0
- data/.rubocop.yml +5 -0
- data/.rubocop_todo.yml +36 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.md +14 -0
- data/CONTRIBUTING.md +125 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +1 -1
- data/README.md +24 -13
- data/RELEASING.md +61 -0
- data/Rakefile +5 -2
- data/faraday_hal_middleware.gemspec +4 -7
- data/lib/faraday_hal_middleware.rb +3 -4
- data/lib/faraday_hal_middleware/version.rb +1 -1
- data/lib/faraday_middleware/request/encode_hal_json.rb +2 -2
- data/spec/spec_helper.rb +9 -9
- data/spec/unit/encode_hal_json_spec.rb +25 -20
- data/spec/unit/parse_hal_json_spec.rb +20 -20
- metadata +13 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a7e094397fe655ac925713ff3747b751f468b1c7581b42b08784caafe1f58790
|
4
|
+
data.tar.gz: 1cc42cd8fe10bb81be514aa2a8a1a3cafad1ed7ced10a2ad0b774e721968cf2f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69362407c7e92bd6f24bd174dfc8dc3fa79a43e67f5b978618615c993497606a6d77d72de8ca9a2fa224b834dd6f5bfc8782b30b6243a641bbd147a724ffa7fc
|
7
|
+
data.tar.gz: 1d50efa0d668beb116a9a891442911a2d6b132bcbe06a6140ee16d2d2604ff9375458e0debc6c55d2cac1721cc51d8828e9d638423556066e342b43ff222be9a
|
data/.rspec
CHANGED
data/.rubocop.yml
ADDED
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2018-01-10 10:44:07 -0500 using RuboCop version 0.52.1.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 2
|
10
|
+
# Configuration parameters: CountComments, ExcludedMethods.
|
11
|
+
Metrics/BlockLength:
|
12
|
+
Max: 72
|
13
|
+
|
14
|
+
# Offense count: 1
|
15
|
+
# Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist, MethodDefinitionMacros.
|
16
|
+
# NamePrefix: is_, has_, have_
|
17
|
+
# NamePrefixBlacklist: is_, has_, have_
|
18
|
+
# NameWhitelist: is_a?
|
19
|
+
# MethodDefinitionMacros: define_method, define_singleton_method
|
20
|
+
Naming/PredicateName:
|
21
|
+
Exclude:
|
22
|
+
- 'spec/**/*'
|
23
|
+
- 'lib/faraday_middleware/request/encode_hal_json.rb'
|
24
|
+
|
25
|
+
# Offense count: 2
|
26
|
+
Style/Documentation:
|
27
|
+
Exclude:
|
28
|
+
- 'spec/**/*'
|
29
|
+
- 'test/**/*'
|
30
|
+
- 'lib/faraday_hal_middleware.rb'
|
31
|
+
|
32
|
+
# Offense count: 1
|
33
|
+
# Configuration parameters: MinBodyLength.
|
34
|
+
Style/GuardClause:
|
35
|
+
Exclude:
|
36
|
+
- 'lib/faraday_middleware/request/encode_hal_json.rb'
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
### 0.1.1 (2020/05/10)
|
2
|
+
|
3
|
+
* [#6](https://github.com/fetch/faraday_hal_middleware/pull/6): Added CHANGELOG, CONTRIBUTING and RELEASING - [@dblock](https://github.com/dblock).
|
4
|
+
* [#5](https://github.com/fetch/faraday_hal_middleware/pull/5): Added RuboCop, Ruby-style linter - [@dblock](https://github.com/dblock).
|
5
|
+
* [#4](https://github.com/fetch/faraday_hal_middleware/pull/4): Added Travis-CI - [@dblock](https://github.com/dblock).
|
6
|
+
* [#7](https://github.com/fetch/faraday_hal_middleware/pull/7): Require `faraday_middleware` >= 0.9 - [@dblock](https://github.com/dblock).
|
7
|
+
|
8
|
+
### 0.1.0 (2018/01/10)
|
9
|
+
|
10
|
+
* [#1](https://github.com/fetch/faraday_hal_middleware/pull/1): Loosen Faraday dependency - [@espen](https://github.com/espen).
|
11
|
+
|
12
|
+
### 0.0.1 (2014/12/01)
|
13
|
+
|
14
|
+
* Initial public release - [@koenpunt](https://github.com/koenpunt).
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
# Contributing to FaradayHalMiddleware
|
2
|
+
|
3
|
+
This project is work of [many contributors](https://github.com/fetch/faraday_hal_middleware/graphs/contributors).
|
4
|
+
|
5
|
+
You're encouraged to submit [pull requests](https://github.com/fetch/faraday_hal_middleware/pulls), [propose features and discuss issues](https://github.com/fetch/faraday_hal_middleware/issues).
|
6
|
+
|
7
|
+
In the examples below, substitute your Github username for `contributor` in URLs.
|
8
|
+
|
9
|
+
### Fork the Project
|
10
|
+
|
11
|
+
Fork the [project on Github](https://github.com/fetch/faraday_hal_middleware) and check out your copy.
|
12
|
+
|
13
|
+
```
|
14
|
+
git clone https://github.com/contributor/faraday_hal_middleware.git
|
15
|
+
cd faraday_hal_middleware
|
16
|
+
git remote add upstream https://github.com/fetch/faraday_hal_middleware.git
|
17
|
+
```
|
18
|
+
|
19
|
+
### Bundle Install and Test
|
20
|
+
|
21
|
+
Ensure that you can build the project and run tests.
|
22
|
+
|
23
|
+
```
|
24
|
+
bundle install
|
25
|
+
bundle exec rake
|
26
|
+
```
|
27
|
+
|
28
|
+
## Contribute Code
|
29
|
+
|
30
|
+
### Create a Topic Branch
|
31
|
+
|
32
|
+
Make sure your fork is up-to-date and create a topic branch for your feature or bug fix.
|
33
|
+
|
34
|
+
```
|
35
|
+
git checkout master
|
36
|
+
git pull upstream master
|
37
|
+
git checkout -b my-feature-branch
|
38
|
+
```
|
39
|
+
|
40
|
+
### Write Tests
|
41
|
+
|
42
|
+
Try to write a test that reproduces the problem you're trying to fix or describes a feature that you want to build. Add tests to [spec](spec).
|
43
|
+
|
44
|
+
We definitely appreciate pull requests that highlight or reproduce a problem, even without a fix.
|
45
|
+
|
46
|
+
### Write Code
|
47
|
+
|
48
|
+
Implement your feature or bug fix.
|
49
|
+
|
50
|
+
Ruby style is enforced with [Rubocop](https://github.com/bbatsov/rubocop). Run `bundle exec rubocop` and fix any style issues highlighted, auto-correct issues when possible with `bundle exec rubocop -a`. To silence generally ingored issues, including line lengths or code complexity metrics, run `bundle exec rubocop --auto-gen-config`.
|
51
|
+
|
52
|
+
Make sure that `bundle exec rake` completes without errors.
|
53
|
+
|
54
|
+
### Write Documentation
|
55
|
+
|
56
|
+
Document any external behavior in the [README](README.md).
|
57
|
+
|
58
|
+
### Update Changelog
|
59
|
+
|
60
|
+
Add a line to [CHANGELOG](CHANGELOG.md) under *Next Release*. Don't remove *Your contribution here*.
|
61
|
+
|
62
|
+
Make it look like every other line, including a link to the issue being fixed, your name and link to your Github account.
|
63
|
+
|
64
|
+
### Commit Changes
|
65
|
+
|
66
|
+
Make sure git knows your name and email address:
|
67
|
+
|
68
|
+
```
|
69
|
+
git config --global user.name "Your Name"
|
70
|
+
git config --global user.email "contributor@example.com"
|
71
|
+
```
|
72
|
+
|
73
|
+
Writing good commit logs is important. A commit log should describe what changed and why.
|
74
|
+
|
75
|
+
```
|
76
|
+
git add ...
|
77
|
+
git commit
|
78
|
+
```
|
79
|
+
|
80
|
+
### Push
|
81
|
+
|
82
|
+
```
|
83
|
+
git push origin my-feature-branch
|
84
|
+
```
|
85
|
+
|
86
|
+
### Make a Pull Request
|
87
|
+
|
88
|
+
Go to https://github.com/contributor/faraday_hal_middleware and select your feature branch. Click the 'Pull Request' button and fill out the form. Pull requests are usually reviewed within a few days.
|
89
|
+
|
90
|
+
### Update CHANGELOG Again
|
91
|
+
|
92
|
+
Update the [CHANGELOG](CHANGELOG.md) with the pull request number. A typical entry looks as follows.
|
93
|
+
|
94
|
+
```
|
95
|
+
* [#123](https://github.com/fetch/faraday_hal_middleware/pull/123): Reticulated splines - [@contributor](https://github.com/contributor).
|
96
|
+
```
|
97
|
+
|
98
|
+
Amend your previous commit and force push the changes.
|
99
|
+
|
100
|
+
```
|
101
|
+
git commit --amend
|
102
|
+
git push origin my-feature-branch -f
|
103
|
+
```
|
104
|
+
|
105
|
+
### Rebase
|
106
|
+
|
107
|
+
If you've been working on a change for a while, rebase with upstream/master.
|
108
|
+
|
109
|
+
```
|
110
|
+
git fetch upstream
|
111
|
+
git rebase upstream/master
|
112
|
+
git push origin my-feature-branch -f
|
113
|
+
```
|
114
|
+
|
115
|
+
### Check on Your Pull Request
|
116
|
+
|
117
|
+
Go back to your pull request after a few minutes and see whether it passed muster with Travis-CI. Everything should look green, otherwise fix issues and amend your commit as described above.
|
118
|
+
|
119
|
+
### Be Patient
|
120
|
+
|
121
|
+
It's likely that your change will not be merged and that the nitpicky maintainers will ask you to do more, or fix seemingly benign problems. Hang on there!
|
122
|
+
|
123
|
+
## Thank You
|
124
|
+
|
125
|
+
Please do know that we really appreciate and value your time and work. We love you, really.
|
data/Gemfile
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,29 +1,40 @@
|
|
1
1
|
# FaradayHalMiddleware
|
2
2
|
|
3
|
-
Faraday Middleware for JSON HAL requests and responses
|
3
|
+
[Faraday](https://github.com/lostisland/faraday) Middleware for JSON HAL requests and responses with `application/hal+json` content-type.
|
4
|
+
|
5
|
+
[](https://travis-ci.org/fetch/faraday_hal_middleware)
|
4
6
|
|
5
7
|
## Installation
|
6
8
|
|
7
9
|
Add this line to your application's Gemfile:
|
8
10
|
|
9
|
-
|
11
|
+
```ruby
|
12
|
+
gem 'faraday_hal_middleware'
|
13
|
+
```
|
10
14
|
|
11
|
-
|
15
|
+
## Usage
|
12
16
|
|
13
|
-
|
17
|
+
Use `faraday_hal_middleware` in a similar way to [other Faraday middleware](https://github.com/lostisland/faraday_middleware).
|
14
18
|
|
15
|
-
|
19
|
+
```ruby
|
20
|
+
require 'faraday_hal_middleware'
|
16
21
|
|
17
|
-
|
22
|
+
connection = Faraday.new 'http://example.com/api' do |conn|
|
23
|
+
conn.request :hal_json
|
24
|
+
conn.response :hal_json, content_type: /\bjson$/
|
18
25
|
|
19
|
-
|
26
|
+
conn.adapter Faraday.default_adapter
|
27
|
+
end
|
28
|
+
```
|
20
29
|
|
21
|
-
|
30
|
+
This gem is notably used in [Hyperclient](https://github.com/codegram/hyperclient), see [hyperclient#81](https://github.com/codegram/hyperclient/pull/81) for details.
|
22
31
|
|
23
32
|
## Contributing
|
24
33
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
34
|
+
See [CONTRIBUTING](CONTRIBUTING.md).
|
35
|
+
|
36
|
+
## Copyright & License
|
37
|
+
|
38
|
+
Copyright (c) 2014-2018 Koen Punt <koen@fetch.nl> and contributors.
|
39
|
+
|
40
|
+
MIT License, see [LICENSE.txt](LICENSE.txt) for details.
|
data/RELEASING.md
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# Releasing FaradayHalMiddleware
|
2
|
+
|
3
|
+
There're no hard rules about when to release faraday_hal_middleware. Release bug fixes frequently, features not so frequently and breaking API changes rarely.
|
4
|
+
|
5
|
+
### Release
|
6
|
+
|
7
|
+
Run tests, check that all tests succeed locally.
|
8
|
+
|
9
|
+
```
|
10
|
+
bundle install
|
11
|
+
rake
|
12
|
+
```
|
13
|
+
|
14
|
+
Check that the last build succeeded in [Travis CI](https://travis-ci.org/fetch/faraday_hal_middleware) for all supported platforms.
|
15
|
+
|
16
|
+
Change "Next" in [CHANGELOG.md](CHANGELOG.md) to the current date.
|
17
|
+
|
18
|
+
```
|
19
|
+
### 0.2.2 (7/10/2015)
|
20
|
+
```
|
21
|
+
|
22
|
+
Remove the line with "Your contribution here.", since there will be no more contributions to this release.
|
23
|
+
|
24
|
+
Commit your changes.
|
25
|
+
|
26
|
+
```
|
27
|
+
git add CHANGELOG.md
|
28
|
+
git commit -m "Preparing for release, 0.2.2."
|
29
|
+
git push origin master
|
30
|
+
```
|
31
|
+
|
32
|
+
Release.
|
33
|
+
|
34
|
+
```
|
35
|
+
$ rake release
|
36
|
+
|
37
|
+
faraday_hal_middleware 0.2.2 built to pkg/faraday_hal_middleware-0.2.2.gem.
|
38
|
+
Tagged v0.2.2.
|
39
|
+
Pushed git commits and tags.
|
40
|
+
Pushed faraday_hal_middleware 0.2.2 to rubygems.org.
|
41
|
+
```
|
42
|
+
|
43
|
+
### Prepare for the Next Version
|
44
|
+
|
45
|
+
Add the next release to [CHANGELOG.md](CHANGELOG.md).
|
46
|
+
|
47
|
+
```
|
48
|
+
### 0.2.3 (Next)
|
49
|
+
|
50
|
+
* Your contribution here.
|
51
|
+
```
|
52
|
+
|
53
|
+
Increment the third version number in [lib/google-finance/version.rb](lib/google-finance/version.rb).
|
54
|
+
|
55
|
+
Commit your changes.
|
56
|
+
|
57
|
+
```
|
58
|
+
git add CHANGELOG.md lib/google-finance/version.rb
|
59
|
+
git commit -m "Preparing for next development iteration, 0.2.3."
|
60
|
+
git push origin master
|
61
|
+
```
|
data/Rakefile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
4
|
require 'faraday_hal_middleware/version'
|
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = FaradayHalMiddleware::VERSION
|
9
9
|
spec.authors = ['Koen Punt']
|
10
10
|
spec.email = ['koen@fetch.nl']
|
11
|
-
spec.summary =
|
12
|
-
spec.description =
|
11
|
+
spec.summary = 'Faraday Middleware for JSON HAL requests and responses.'
|
12
|
+
spec.description = 'Faraday Middleware for JSON HAL requests and responses.'
|
13
13
|
spec.homepage = 'https://github.com/fetch/faraday_hal_middleware'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
|
@@ -18,8 +18,5 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.
|
22
|
-
|
23
|
-
spec.add_dependency 'faraday_middleware', ['~> 0.9']
|
24
|
-
|
21
|
+
spec.add_dependency 'faraday_middleware', '>= 0.9'
|
25
22
|
end
|
@@ -3,7 +3,6 @@ require 'faraday'
|
|
3
3
|
require 'faraday_middleware'
|
4
4
|
|
5
5
|
module FaradayHalMiddleware
|
6
|
-
|
7
6
|
end
|
8
7
|
|
9
8
|
module FaradayMiddleware
|
@@ -12,9 +11,9 @@ module FaradayMiddleware
|
|
12
11
|
|
13
12
|
if Faraday::Middleware.respond_to? :register_middleware
|
14
13
|
Faraday::Request.register_middleware \
|
15
|
-
|
14
|
+
hal_json: -> { EncodeHalJson }
|
16
15
|
|
17
16
|
Faraday::Response.register_middleware \
|
18
|
-
|
17
|
+
hal_json: -> { ParseHalJson }
|
19
18
|
end
|
20
|
-
end
|
19
|
+
end
|
@@ -36,11 +36,11 @@ module FaradayMiddleware
|
|
36
36
|
|
37
37
|
def process_request?(env)
|
38
38
|
type = request_type(env)
|
39
|
-
has_body?(env)
|
39
|
+
has_body?(env) && (type.empty? || (type == MIME_TYPE))
|
40
40
|
end
|
41
41
|
|
42
42
|
def has_body?(env)
|
43
|
-
body = env[:body]
|
43
|
+
(body = env[:body]) && !(body.respond_to?(:to_str) && body.empty?)
|
44
44
|
end
|
45
45
|
|
46
46
|
def request_type(env)
|
data/spec/spec_helper.rb
CHANGED
@@ -14,20 +14,20 @@ end
|
|
14
14
|
|
15
15
|
module ResponseMiddlewareExampleGroup
|
16
16
|
def self.included(base)
|
17
|
-
base.let(:options) {
|
18
|
-
base.let(:headers) {
|
19
|
-
base.let(:middleware)
|
20
|
-
described_class.new(lambda {|env|
|
17
|
+
base.let(:options) { {} }
|
18
|
+
base.let(:headers) { {} }
|
19
|
+
base.let(:middleware) do
|
20
|
+
described_class.new(lambda { |env|
|
21
21
|
Faraday::Response.new(env)
|
22
22
|
}, options)
|
23
|
-
|
23
|
+
end
|
24
24
|
end
|
25
25
|
|
26
26
|
def process(body, content_type = nil, options = {})
|
27
27
|
env = {
|
28
|
-
:
|
29
|
-
:
|
30
|
-
:
|
28
|
+
body: body, request: options,
|
29
|
+
request_headers: Faraday::Utils::Headers.new,
|
30
|
+
response_headers: Faraday::Utils::Headers.new(headers)
|
31
31
|
}
|
32
32
|
env[:response_headers]['content-type'] = content_type if content_type
|
33
33
|
yield(env) if block_given?
|
@@ -37,7 +37,7 @@ end
|
|
37
37
|
|
38
38
|
RSpec.configure do |config|
|
39
39
|
config.include EnvCompatibility
|
40
|
-
config.include ResponseMiddlewareExampleGroup, :
|
40
|
+
config.include ResponseMiddlewareExampleGroup, type: :response
|
41
41
|
config.expect_with :rspec do |c|
|
42
42
|
c.syntax = :expect
|
43
43
|
end
|
@@ -1,18 +1,23 @@
|
|
1
1
|
require 'faraday_middleware/request/encode_hal_json'
|
2
2
|
|
3
3
|
describe FaradayMiddleware::EncodeHalJson do
|
4
|
-
let(:middleware) { described_class.new(
|
4
|
+
let(:middleware) { described_class.new(->(env) { env }) }
|
5
5
|
|
6
6
|
def process(body, content_type = nil)
|
7
|
-
env = {:
|
7
|
+
env = { body: body, request_headers: Faraday::Utils::Headers.new }
|
8
8
|
env[:request_headers]['content-type'] = content_type if content_type
|
9
9
|
middleware.call(faraday_env(env))
|
10
10
|
end
|
11
11
|
|
12
|
-
def result_body
|
13
|
-
|
12
|
+
def result_body
|
13
|
+
result[:body]
|
14
|
+
end
|
15
|
+
|
16
|
+
def result_type
|
17
|
+
result[:request_headers]['content-type']
|
18
|
+
end
|
14
19
|
|
15
|
-
context
|
20
|
+
context 'no body' do
|
16
21
|
let(:result) { process(nil) }
|
17
22
|
|
18
23
|
it "doesn't change body" do
|
@@ -24,7 +29,7 @@ describe FaradayMiddleware::EncodeHalJson do
|
|
24
29
|
end
|
25
30
|
end
|
26
31
|
|
27
|
-
context
|
32
|
+
context 'empty body' do
|
28
33
|
let(:result) { process('') }
|
29
34
|
|
30
35
|
it "doesn't change body" do
|
@@ -36,42 +41,42 @@ describe FaradayMiddleware::EncodeHalJson do
|
|
36
41
|
end
|
37
42
|
end
|
38
43
|
|
39
|
-
context
|
44
|
+
context 'string body' do
|
40
45
|
let(:result) { process('{"a":1}') }
|
41
46
|
|
42
47
|
it "doesn't change body" do
|
43
48
|
expect(result_body).to eq('{"a":1}')
|
44
49
|
end
|
45
50
|
|
46
|
-
it
|
51
|
+
it 'adds content type' do
|
47
52
|
expect(result_type).to eq('application/hal+json')
|
48
53
|
end
|
49
54
|
end
|
50
55
|
|
51
|
-
context
|
52
|
-
let(:result) { process(
|
56
|
+
context 'object body' do
|
57
|
+
let(:result) { process(a: 1) }
|
53
58
|
|
54
|
-
it
|
59
|
+
it 'encodes body' do
|
55
60
|
expect(result_body).to eq('{"a":1}')
|
56
61
|
end
|
57
62
|
|
58
|
-
it
|
63
|
+
it 'adds content type' do
|
59
64
|
expect(result_type).to eq('application/hal+json')
|
60
65
|
end
|
61
66
|
end
|
62
67
|
|
63
|
-
context
|
68
|
+
context 'empty object body' do
|
64
69
|
let(:result) { process({}) }
|
65
70
|
|
66
|
-
it
|
71
|
+
it 'encodes body' do
|
67
72
|
expect(result_body).to eq('{}')
|
68
73
|
end
|
69
74
|
end
|
70
75
|
|
71
|
-
context
|
72
|
-
let(:result) { process({:
|
76
|
+
context 'object body with json type' do
|
77
|
+
let(:result) { process({ a: 1 }, 'application/hal+json; charset=utf-8') }
|
73
78
|
|
74
|
-
it
|
79
|
+
it 'encodes body' do
|
75
80
|
expect(result_body).to eq('{"a":1}')
|
76
81
|
end
|
77
82
|
|
@@ -80,11 +85,11 @@ describe FaradayMiddleware::EncodeHalJson do
|
|
80
85
|
end
|
81
86
|
end
|
82
87
|
|
83
|
-
context
|
84
|
-
let(:result) { process({:
|
88
|
+
context 'object body with incompatible type' do
|
89
|
+
let(:result) { process({ a: 1 }, 'application/xml; charset=utf-8') }
|
85
90
|
|
86
91
|
it "doesn't change body" do
|
87
|
-
expect(result_body).to eq(
|
92
|
+
expect(result_body).to eq(a: 1)
|
88
93
|
end
|
89
94
|
|
90
95
|
it "doesn't change content type" do
|
@@ -1,71 +1,71 @@
|
|
1
1
|
require 'faraday_middleware/response/parse_hal_json'
|
2
2
|
|
3
|
-
describe FaradayMiddleware::ParseHalJson, :
|
4
|
-
context
|
3
|
+
describe FaradayMiddleware::ParseHalJson, type: :response do
|
4
|
+
context 'no type matching' do
|
5
5
|
it "doesn't change nil body" do
|
6
6
|
expect(process(nil).body).to be_nil
|
7
7
|
end
|
8
8
|
|
9
|
-
it
|
9
|
+
it 'nullifies empty body' do
|
10
10
|
expect(process('').body).to be_nil
|
11
11
|
end
|
12
12
|
|
13
|
-
it
|
13
|
+
it 'parses json body' do
|
14
14
|
response = process('{"a":1}')
|
15
15
|
expect(response.body).to eq('a' => 1)
|
16
16
|
expect(response.env[:raw_body]).to be_nil
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
context
|
21
|
-
let(:options) { {:
|
20
|
+
context 'with preserving raw' do
|
21
|
+
let(:options) { { preserve_raw: true } }
|
22
22
|
|
23
|
-
it
|
23
|
+
it 'parses json body' do
|
24
24
|
response = process('{"a":1}')
|
25
25
|
expect(response.body).to eq('a' => 1)
|
26
26
|
expect(response.env[:raw_body]).to eq('{"a":1}')
|
27
27
|
end
|
28
28
|
|
29
|
-
it
|
30
|
-
response = process('{"a":1}', nil, :
|
29
|
+
it 'can opt out of preserving raw' do
|
30
|
+
response = process('{"a":1}', nil, preserve_raw: false)
|
31
31
|
expect(response.env[:raw_body]).to be_nil
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
context
|
36
|
-
let(:options) { {:
|
35
|
+
context 'with regexp type matching' do
|
36
|
+
let(:options) { { content_type: /\bjson$/ } }
|
37
37
|
|
38
|
-
it
|
38
|
+
it 'parses json body of correct type' do
|
39
39
|
response = process('{"a":1}', 'application/x-json')
|
40
40
|
expect(response.body).to eq('a' => 1)
|
41
41
|
end
|
42
42
|
|
43
|
-
it
|
43
|
+
it 'ignores json body of incorrect type' do
|
44
44
|
response = process('{"a":1}', 'text/json-xml')
|
45
45
|
expect(response.body).to eq('{"a":1}')
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
-
context
|
50
|
-
let(:options) { {:
|
49
|
+
context 'with array type matching' do
|
50
|
+
let(:options) { { content_type: %w[a/b c/d] } }
|
51
51
|
|
52
|
-
it
|
52
|
+
it 'parses json body of correct type' do
|
53
53
|
expect(process('{"a":1}', 'a/b').body).to be_a(Hash)
|
54
54
|
expect(process('{"a":1}', 'c/d').body).to be_a(Hash)
|
55
55
|
end
|
56
56
|
|
57
|
-
it
|
57
|
+
it 'ignores json body of incorrect type' do
|
58
58
|
expect(process('{"a":1}', 'a/d').body).not_to be_a(Hash)
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
|
-
it
|
62
|
+
it 'chokes on invalid json' do
|
63
63
|
['{!', '"a'].each do |data|
|
64
|
-
expect{ process(data) }.to raise_error(Faraday::ParsingError)
|
64
|
+
expect { process(data) }.to raise_error(Faraday::ParsingError)
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
|
-
context
|
68
|
+
context 'HEAD responses' do
|
69
69
|
it "nullifies the body if it's only one space" do
|
70
70
|
response = process(' ')
|
71
71
|
expect(response.body).to be_nil
|
metadata
CHANGED
@@ -1,44 +1,30 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faraday_hal_middleware
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Koen Punt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: bundler
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1.6'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '1.6'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: faraday_middleware
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
30
16
|
requirements:
|
31
|
-
- - "
|
17
|
+
- - ">="
|
32
18
|
- !ruby/object:Gem::Version
|
33
19
|
version: '0.9'
|
34
20
|
type: :runtime
|
35
21
|
prerelease: false
|
36
22
|
version_requirements: !ruby/object:Gem::Requirement
|
37
23
|
requirements:
|
38
|
-
- - "
|
24
|
+
- - ">="
|
39
25
|
- !ruby/object:Gem::Version
|
40
26
|
version: '0.9'
|
41
|
-
description: Faraday Middleware for JSON HAL requests and responses
|
27
|
+
description: Faraday Middleware for JSON HAL requests and responses.
|
42
28
|
email:
|
43
29
|
- koen@fetch.nl
|
44
30
|
executables: []
|
@@ -47,9 +33,15 @@ extra_rdoc_files: []
|
|
47
33
|
files:
|
48
34
|
- ".gitignore"
|
49
35
|
- ".rspec"
|
36
|
+
- ".rubocop.yml"
|
37
|
+
- ".rubocop_todo.yml"
|
38
|
+
- ".travis.yml"
|
39
|
+
- CHANGELOG.md
|
40
|
+
- CONTRIBUTING.md
|
50
41
|
- Gemfile
|
51
42
|
- LICENSE.txt
|
52
43
|
- README.md
|
44
|
+
- RELEASING.md
|
53
45
|
- Rakefile
|
54
46
|
- faraday_hal_middleware.gemspec
|
55
47
|
- lib/faraday_hal_middleware.rb
|
@@ -78,11 +70,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
78
70
|
- !ruby/object:Gem::Version
|
79
71
|
version: '0'
|
80
72
|
requirements: []
|
81
|
-
|
82
|
-
rubygems_version: 2.6.8
|
73
|
+
rubygems_version: 3.0.3
|
83
74
|
signing_key:
|
84
75
|
specification_version: 4
|
85
|
-
summary: Faraday Middleware for JSON HAL requests and responses
|
76
|
+
summary: Faraday Middleware for JSON HAL requests and responses.
|
86
77
|
test_files:
|
87
78
|
- spec/spec_helper.rb
|
88
79
|
- spec/unit/encode_hal_json_spec.rb
|