spaceborne 0.1.22 → 0.1.23
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/lib/spaceborne.rb +40 -21
- data/lib/spaceborne/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39591d03867f81e331613646b71adc30e118a4b74b7b69d2b5217f9dfef1a4fb
|
4
|
+
data.tar.gz: 1b82c816bbacd0207a0ad4e19f5ba548c0807fcbab33e210655de9c40e27eda3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c1d32293ddeac46fbd0fb20897b925ca71423a5c598255ef4353cfc41c2ebf987f7ab7448f0cf57af345574c77c707c631fa012a1b8e209a263f6a347936336
|
7
|
+
data.tar.gz: 2d53f4280e0d461d4cd3d1610e2e4ff95d59454b276d29c61658438b844d60d902336ce55dcd40213838c933ec3c2992fea997d149c704a8432853f3c3baf5ff
|
data/lib/spaceborne.rb
CHANGED
@@ -33,6 +33,7 @@ module Spaceborne
|
|
33
33
|
|
34
34
|
def response_body
|
35
35
|
return '' if response.request.method.casecmp('head').zero?
|
36
|
+
|
36
37
|
str = if json?(response.headers)
|
37
38
|
" JSON_BODY\n#{JSON.pretty_generate(json_body)}\n"
|
38
39
|
else
|
@@ -50,6 +51,7 @@ module Spaceborne
|
|
50
51
|
yield
|
51
52
|
rescue Exception => e
|
52
53
|
raise e unless response
|
54
|
+
|
53
55
|
e.message << request_info
|
54
56
|
raise e
|
55
57
|
end
|
@@ -87,17 +89,20 @@ module Airborne
|
|
87
89
|
headers = base_headers.merge(options[:headers] || {})
|
88
90
|
headers[:no_restclient_headers] = true
|
89
91
|
return headers unless local[:is_hash]
|
92
|
+
|
90
93
|
headers.delete('Content-Type') if options[:nonjson_data]
|
91
94
|
headers
|
92
95
|
end
|
93
96
|
|
94
97
|
def handle_proxy(_options, local)
|
95
98
|
return unless local[:proxy]
|
99
|
+
|
96
100
|
RestClient.proxy = local[:proxy]
|
97
101
|
end
|
98
102
|
|
99
103
|
def calc_body(options, local)
|
100
104
|
return '' unless options[:body]
|
105
|
+
|
101
106
|
if local[:nonjson_data] || !local[:is_hash]
|
102
107
|
options[:body]
|
103
108
|
else
|
@@ -120,6 +125,8 @@ module Airborne
|
|
120
125
|
hdrs = calc_headers(options, local_options)
|
121
126
|
@request_body = calc_body(options, local_options)
|
122
127
|
send_restclient(method, get_url(url), @request_body, hdrs)
|
128
|
+
rescue RestClient::ServerBrokeConnection => e
|
129
|
+
raise e
|
123
130
|
rescue RestClient::Exception => e
|
124
131
|
e.response
|
125
132
|
end
|
@@ -127,7 +134,7 @@ module Airborne
|
|
127
134
|
private
|
128
135
|
|
129
136
|
def base_headers
|
130
|
-
{
|
137
|
+
{ 'Content-Type' => 'application/json' }
|
131
138
|
.merge(Airborne.configuration.headers || {})
|
132
139
|
end
|
133
140
|
end
|
@@ -186,8 +193,37 @@ module Airborne
|
|
186
193
|
|
187
194
|
# extension to handle hash value checking
|
188
195
|
module PathMatcher
|
196
|
+
def do_process_json(part, json)
|
197
|
+
json = process_json(part, json)
|
198
|
+
rescue StandardError
|
199
|
+
raise PathError,
|
200
|
+
"Expected #{json.class}\nto be an object with property #{part}"
|
201
|
+
end
|
202
|
+
|
203
|
+
def handle_container(json, &block)
|
204
|
+
case json.class.name
|
205
|
+
when 'Array'
|
206
|
+
expect_all(json, &block)
|
207
|
+
when 'Hash'
|
208
|
+
json.each do |k, _v|
|
209
|
+
yield json[k]
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
def handle_type(type, path, json, &block)
|
215
|
+
if type == '*'
|
216
|
+
handle_container(json, &block)
|
217
|
+
elsif type == '?'
|
218
|
+
expect_one(path, json, &block)
|
219
|
+
else
|
220
|
+
yield json
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
189
224
|
def get_by_path(path, json, &block)
|
190
225
|
raise PathError, "Invalid Path, contains '..'" if /\.\./ =~ path
|
226
|
+
|
191
227
|
type = false
|
192
228
|
parts = path.to_s.split('.')
|
193
229
|
parts.each_with_index do |part, index|
|
@@ -199,31 +235,14 @@ module Airborne
|
|
199
235
|
end
|
200
236
|
next
|
201
237
|
end
|
202
|
-
|
203
|
-
json = process_json(part, json)
|
204
|
-
rescue StandardError
|
205
|
-
raise PathError,
|
206
|
-
"Expected #{json.class}\nto be an object with property #{part}"
|
207
|
-
end
|
208
|
-
end
|
209
|
-
if type == '*'
|
210
|
-
case json.class.name
|
211
|
-
when 'Array'
|
212
|
-
expect_all(json, &block)
|
213
|
-
when 'Hash'
|
214
|
-
json.each do |k, _v|
|
215
|
-
yield json[k]
|
216
|
-
end
|
217
|
-
end
|
218
|
-
elsif type == '?'
|
219
|
-
expect_one(path, json, &block)
|
220
|
-
else
|
221
|
-
yield json
|
238
|
+
json = do_process_json(part, json)
|
222
239
|
end
|
240
|
+
handle_type(type, path, json, &block)
|
223
241
|
end
|
224
242
|
|
225
243
|
def ensure_array_or_hash(path, json)
|
226
244
|
return if json.class == Array || json.class == Hash
|
245
|
+
|
227
246
|
raise RSpec::Expectations::ExpectationNotMetError,
|
228
247
|
"Expected #{path} to be array or hash, got #{json.class}"\
|
229
248
|
' from JSON response'
|
data/lib/spaceborne/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spaceborne
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.23
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Keith Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-11-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|