restify 1.13.0 → 1.14.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a52b89b2f13d578bc3ee09444ed5a01e6e80597b13f8fed2a10135f482fde561
|
4
|
+
data.tar.gz: 6e98b2d97468fe186a8500e7b88e72e8e174ef13840a76fcf152d2a8dcc57b4d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c61229244ba3cfeb64d37f4328059e2f9c91f394dea86abe522cb2a4b2ce422ce107ca81a5cd5c55ec2d99b9c1409bd1f4fa6ca7ab13d86697e00dda02abb42
|
7
|
+
data.tar.gz: 1dc873a2867f9cb91e55419c7bf831486b3ad86ec28186b7a2d8bac14653518a496f1cd8369a432fa1c74600b0ad91cd25c3094ffd392a9982dac2128a224484
|
data/CHANGELOG.md
CHANGED
@@ -18,6 +18,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
|
18
18
|
### Breaks
|
19
19
|
|
20
20
|
|
21
|
+
## 1.14.0 - (2020-12-15)
|
22
|
+
|
23
|
+
### New
|
24
|
+
* Allow making requests with non-JSON bodies and custom content types (#42)
|
25
|
+
|
26
|
+
|
21
27
|
## 1.13.0 - (2020-06-12)
|
22
28
|
---
|
23
29
|
|
data/lib/restify/request.rb
CHANGED
@@ -34,18 +34,26 @@ module Restify
|
|
34
34
|
@uri = opts.fetch(:uri) { raise ArgumentError.new ':uri required.' }
|
35
35
|
@data = opts.fetch(:data, nil)
|
36
36
|
@timeout = opts.fetch(:timeout, 300)
|
37
|
-
@headers = opts.fetch(:headers, {})
|
38
|
-
|
37
|
+
@headers = opts.fetch(:headers, {})
|
38
|
+
|
39
|
+
@headers['Content-Type'] ||= 'application/json' if json?
|
39
40
|
end
|
40
41
|
|
41
42
|
def body
|
42
|
-
@body ||=
|
43
|
-
JSON.dump(data) unless data.nil?
|
44
|
-
end
|
43
|
+
@body ||= json? ? JSON.dump(@data) : @data
|
45
44
|
end
|
46
45
|
|
47
46
|
def to_s
|
48
47
|
"#<#{self.class} #{method.upcase} #{uri}>"
|
49
48
|
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def json?
|
53
|
+
return false if @data.nil?
|
54
|
+
return false if @data.is_a? String
|
55
|
+
|
56
|
+
true
|
57
|
+
end
|
50
58
|
end
|
51
59
|
end
|
data/lib/restify/version.rb
CHANGED
@@ -0,0 +1,86 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Restify do
|
6
|
+
let!(:request_stub) do
|
7
|
+
stub_request(:post, 'http://localhost/base')
|
8
|
+
.to_return do
|
9
|
+
<<-RESPONSE.gsub(/^ {8}/, '')
|
10
|
+
HTTP/1.1 200 OK
|
11
|
+
Content-Length: 333
|
12
|
+
Transfer-Encoding: chunked
|
13
|
+
Link: <http://localhost/other>; rel="neat"
|
14
|
+
RESPONSE
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'Request body' do
|
19
|
+
subject { Restify.new('http://localhost/base').post(body, {}, {headers: headers}).value! }
|
20
|
+
let(:headers) { {} }
|
21
|
+
|
22
|
+
context 'with JSON-like data structures' do
|
23
|
+
let(:body) { {a: 'b', c: 'd'} }
|
24
|
+
|
25
|
+
it 'is serialized as JSON' do
|
26
|
+
subject
|
27
|
+
|
28
|
+
expect(
|
29
|
+
request_stub.with(body: '{"a":"b","c":"d"}')
|
30
|
+
).to have_been_requested
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'gets a JSON media type for free' do
|
34
|
+
subject
|
35
|
+
|
36
|
+
expect(
|
37
|
+
request_stub.with(headers: {'Content-Type' => 'application/json'})
|
38
|
+
).to have_been_requested
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'with overridden media type' do
|
42
|
+
let(:headers) { {'Content-Type' => 'application/vnd.api+json'} }
|
43
|
+
|
44
|
+
it 'respects the override' do
|
45
|
+
subject
|
46
|
+
|
47
|
+
expect(
|
48
|
+
request_stub.with(headers: {'Content-Type' => 'application/vnd.api+json'})
|
49
|
+
).to have_been_requested
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context 'with strings' do
|
55
|
+
let(:body) { 'a=b&c=d' }
|
56
|
+
|
57
|
+
it 'is sent as provided' do
|
58
|
+
subject
|
59
|
+
|
60
|
+
expect(
|
61
|
+
request_stub.with(body: 'a=b&c=d')
|
62
|
+
).to have_been_requested
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'does not get a JSON media type' do
|
66
|
+
subject
|
67
|
+
|
68
|
+
expect(
|
69
|
+
request_stub.with {|req| req.headers['Content-Type'].nil? }
|
70
|
+
).to have_been_requested
|
71
|
+
end
|
72
|
+
|
73
|
+
context 'with overridden media type' do
|
74
|
+
let(:headers) { {'Content-Type' => 'application/x-www-form-urlencoded'} }
|
75
|
+
|
76
|
+
it 'respects the override' do
|
77
|
+
subject
|
78
|
+
|
79
|
+
expect(
|
80
|
+
request_stub.with(headers: {'Content-Type' => 'application/x-www-form-urlencoded'})
|
81
|
+
).to have_been_requested
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: restify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.14.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Graichen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -194,8 +194,9 @@ files:
|
|
194
194
|
- spec/restify/context_spec.rb
|
195
195
|
- spec/restify/error_spec.rb
|
196
196
|
- spec/restify/features/head_requests_spec.rb
|
197
|
+
- spec/restify/features/request_bodies_spec.rb
|
197
198
|
- spec/restify/features/request_headers_spec.rb
|
198
|
-
- spec/restify/features/
|
199
|
+
- spec/restify/features/response_errors_spec.rb
|
199
200
|
- spec/restify/global_spec.rb
|
200
201
|
- spec/restify/link_spec.rb
|
201
202
|
- spec/restify/processors/base_spec.rb
|
@@ -227,7 +228,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
227
228
|
- !ruby/object:Gem::Version
|
228
229
|
version: '0'
|
229
230
|
requirements: []
|
230
|
-
rubygems_version: 3.
|
231
|
+
rubygems_version: 3.0.8
|
231
232
|
signing_key:
|
232
233
|
specification_version: 4
|
233
234
|
summary: An experimental hypermedia REST client.
|
@@ -236,8 +237,9 @@ test_files:
|
|
236
237
|
- spec/restify/context_spec.rb
|
237
238
|
- spec/restify/error_spec.rb
|
238
239
|
- spec/restify/features/head_requests_spec.rb
|
240
|
+
- spec/restify/features/request_bodies_spec.rb
|
239
241
|
- spec/restify/features/request_headers_spec.rb
|
240
|
-
- spec/restify/features/
|
242
|
+
- spec/restify/features/response_errors_spec.rb
|
241
243
|
- spec/restify/global_spec.rb
|
242
244
|
- spec/restify/link_spec.rb
|
243
245
|
- spec/restify/processors/base_spec.rb
|