airborne 0.3.0 → 0.3.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 +4 -4
- data/.dependabot/config.yml +8 -0
- data/README.md +8 -1
- data/airborne.gemspec +1 -1
- data/lib/airborne/rest_client_requester.rb +6 -1
- data/spec/airborne/client_requester_spec.rb +21 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 90e549d9b143f595ddd2549a2d3c3ed73a87070da7c4f3e500f94e7617a3a5b9
|
4
|
+
data.tar.gz: ff9e58e5865cb84137f24139a343a500cc3e7e0f4994916715a1cacb7565f19c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d77b67f75dcc2fdba964bda66506f0680cf694edc0b0793abae1ccc5260e1429974473ce71cb45adb3adde3a894f414a17923fa0887fe3d5fa0a36bc7ae8561
|
7
|
+
data.tar.gz: 3e1c7d000e82533784199e3b18fd67f5c946f02b3832dba65a3425975e88d24dc9c3650da8a7516933f6cd23c9707fcd1ee871c8999392ab5ae6ebdaf8718813
|
data/README.md
CHANGED
@@ -137,12 +137,19 @@ When calling any of the methods above, you can pass request headers to be used.
|
|
137
137
|
get 'http://example.com/api/v1/my_api', { 'x-auth-token' => 'my_token' }
|
138
138
|
```
|
139
139
|
|
140
|
-
For requests that require a body (`post`, `put`, `patch`) you can pass the body as
|
140
|
+
For requests that require a body (`post`, `put`, `patch`) you can pass the body as well:
|
141
141
|
|
142
142
|
```ruby
|
143
143
|
post 'http://example.com/api/v1/my_api', { :name => 'John Doe' }, { 'x-auth-token' => 'my_token' }
|
144
144
|
```
|
145
145
|
|
146
|
+
The body may be any JSON-serializable type, as long as you want to post `application/json` content type.
|
147
|
+
You may set a different content type and post a string body this way:
|
148
|
+
|
149
|
+
```ruby
|
150
|
+
post 'http://example.com/api/v1/my_api', "Hello there!", { content_type: 'text/plain' }
|
151
|
+
```
|
152
|
+
|
146
153
|
For requests that require Query params you can pass a params hash into headers.
|
147
154
|
|
148
155
|
```ruby
|
data/airborne.gemspec
CHANGED
@@ -7,7 +7,7 @@ module Airborne
|
|
7
7
|
res = if method == :post || method == :patch || method == :put
|
8
8
|
begin
|
9
9
|
request_body = options[:body].nil? ? '' : options[:body]
|
10
|
-
request_body = request_body.to_json if
|
10
|
+
request_body = request_body.to_json if is_json_request(headers)
|
11
11
|
RestClient.send(method, get_url(url), request_body, headers)
|
12
12
|
rescue RestClient::Exception => e
|
13
13
|
e.response
|
@@ -24,6 +24,11 @@ module Airborne
|
|
24
24
|
|
25
25
|
private
|
26
26
|
|
27
|
+
def is_json_request(headers)
|
28
|
+
header = headers.fetch(:content_type)
|
29
|
+
header == :json || /application\/([a-zA-Z0-9\.\_\-]*\+?)json/ =~ header
|
30
|
+
end
|
31
|
+
|
27
32
|
def base_headers
|
28
33
|
{ content_type: :json }.merge(Airborne.configuration.headers || {})
|
29
34
|
end
|
@@ -33,4 +33,25 @@ describe 'client requester' do
|
|
33
33
|
expect(RestClient).to have_received(:send)
|
34
34
|
.with(:get, 'http://www.example.com/foo', { content_type: 'text/plain' })
|
35
35
|
end
|
36
|
+
|
37
|
+
it 'should serialize body to json when :content_type is (default) :json' do
|
38
|
+
post '/foo', { test: 'serialized' }
|
39
|
+
|
40
|
+
expect(RestClient).to have_received(:send)
|
41
|
+
.with(:post, 'http://www.example.com/foo', '{"test":"serialized"}', { content_type: :json })
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should serialize body to json when :content_type is any enhanced JSON content type' do
|
45
|
+
post '/foo', { test: 'serialized' }, { content_type: 'application/vnd.airborne.2+json' }
|
46
|
+
|
47
|
+
expect(RestClient).to have_received(:send)
|
48
|
+
.with(:post, 'http://www.example.com/foo', '{"test":"serialized"}', { content_type: 'application/vnd.airborne.2+json' })
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should not serialize body to json when :content_type does not match JSON' do
|
52
|
+
post '/foo', { test: 'not serialized' }, { content_type: 'text/plain' }
|
53
|
+
|
54
|
+
expect(RestClient).to have_received(:send)
|
55
|
+
.with(:post, 'http://www.example.com/foo', { test: 'not serialized' }, { content_type: 'text/plain' })
|
56
|
+
end
|
36
57
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: airborne
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Friedman
|
@@ -116,6 +116,7 @@ extensions: []
|
|
116
116
|
extra_rdoc_files: []
|
117
117
|
files:
|
118
118
|
- ".coveralls.yml"
|
119
|
+
- ".dependabot/config.yml"
|
119
120
|
- ".gitignore"
|
120
121
|
- ".rspec"
|
121
122
|
- ".travis.yml"
|
@@ -199,7 +200,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
199
200
|
- !ruby/object:Gem::Version
|
200
201
|
version: '0'
|
201
202
|
requirements: []
|
202
|
-
rubygems_version: 3.0.
|
203
|
+
rubygems_version: 3.0.1
|
203
204
|
signing_key:
|
204
205
|
specification_version: 4
|
205
206
|
summary: RSpec driven API testing framework
|