sinatra-rest-base 1.0.0 → 1.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 +4 -4
- data/lib/rest_base/application.rb +2 -0
- data/lib/rest_base/application_helper.rb +12 -4
- data/lib/rest_base/version.rb +1 -1
- data/spec/fixtures/test_forensics.rb +14 -0
- data/spec/lib/rest_base/application_spec.rb +38 -10
- data/spec/lib/rest_base/error_handeling_spec.rb +1 -2
- data/spec/lib/rest_base/error_status_handeling_spec.rb +1 -2
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b8c04a79fba6e26cc1309e58107b3e06d950364
|
4
|
+
data.tar.gz: fce5fc71f80bbbbb0a51c3b023fdd1eb220e01a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0077f646ba6a2b2056b4aa2a34e41c013133d60773b282b9a81e6e83172d71daa7e3c2384615ebf1c17d2d88d07b110966117bef00a3e807a3410cb04c46ac3d
|
7
|
+
data.tar.gz: 8f78662d0f61227f4265f4cd6747ee76598a3439eae312298b40aa8f565a7aab7a1b7516ab5f965587527e724ba409ed2df2895336b95acbd04d1011e087b92d
|
@@ -9,6 +9,7 @@ module RestBase
|
|
9
9
|
attr_reader :request_body
|
10
10
|
attr_reader :request_version
|
11
11
|
attr_reader :errored
|
12
|
+
attr_reader :forensics
|
12
13
|
|
13
14
|
configure do
|
14
15
|
disable :raise_errors
|
@@ -29,6 +30,7 @@ module RestBase
|
|
29
30
|
|
30
31
|
set_api_version if settings.header_versioning
|
31
32
|
set_request_body
|
33
|
+
setup_forensics
|
32
34
|
error 401 unless authenticated?
|
33
35
|
end
|
34
36
|
|
@@ -36,6 +36,14 @@ module RestBase
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
+
def setup_forensics
|
40
|
+
@forensics = []
|
41
|
+
end
|
42
|
+
|
43
|
+
def add_forensics_to_response?
|
44
|
+
!@env['Forensics'].nil? && @env['Forensics'].downcase == 'true'
|
45
|
+
end
|
46
|
+
|
39
47
|
def create_response()
|
40
48
|
content_type :json
|
41
49
|
content_type :xml if !request.accept?('*/*') && request.accept?('text/xml')
|
@@ -47,10 +55,10 @@ module RestBase
|
|
47
55
|
response.body = nil
|
48
56
|
end
|
49
57
|
|
50
|
-
response_hash = {
|
51
|
-
|
52
|
-
|
53
|
-
|
58
|
+
response_hash = { }
|
59
|
+
response_hash[:errors] = error_hash unless error_hash.nil? || error_hash.empty?
|
60
|
+
response_hash[:result] = response.body unless response.body.nil?
|
61
|
+
response_hash[:forensics] = @forensics if add_forensics_to_response? && !(@forensics.nil? || @forensics.empty?)
|
54
62
|
|
55
63
|
return '' if empty_body_status_code? && (response.body.empty?)
|
56
64
|
return response_hash.to_xml(:root => :response) if response.headers['Content-Type'].start_with? 'application/xml;'
|
data/lib/rest_base/version.rb
CHANGED
@@ -23,7 +23,7 @@ describe RestBase::Application do
|
|
23
23
|
|
24
24
|
expect(last_request.env["HTTP_ACCEPT"].include? expected_version).to be_truthy
|
25
25
|
expect(last_response.headers["Content-Type"].include? expected_version).to be_truthy
|
26
|
-
expect(last_response.body).to eq({:
|
26
|
+
expect(last_response.body).to eq({:result => { :gotten => "success" }}.to_json)
|
27
27
|
end
|
28
28
|
|
29
29
|
it "should get the version 2 version" do
|
@@ -34,7 +34,7 @@ describe RestBase::Application do
|
|
34
34
|
|
35
35
|
expect(last_request.env["HTTP_ACCEPT"].include? expected_version).to be_truthy
|
36
36
|
expect(last_response.headers["Content-Type"].include? expected_version).to be_truthy
|
37
|
-
expect(last_response.body).to eq({:
|
37
|
+
expect(last_response.body).to eq({:result => { :gotten => "success 2" }}.to_json)
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
@@ -56,7 +56,7 @@ describe RestBase::Application do
|
|
56
56
|
it "should return an empty string response" do
|
57
57
|
get '/empty', {}, @headers
|
58
58
|
|
59
|
-
expect(last_response.body).to eq({
|
59
|
+
expect(last_response.body).to eq({}.to_json)
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
@@ -79,7 +79,7 @@ describe RestBase::Application do
|
|
79
79
|
get '/created_with_body', {}, @headers
|
80
80
|
|
81
81
|
expect(last_response.status).to eq(201)
|
82
|
-
expect(last_response.body).to eq({:
|
82
|
+
expect(last_response.body).to eq({:result => {:created => true}}.to_json)
|
83
83
|
end
|
84
84
|
|
85
85
|
it "should return a not modified response with empty body" do
|
@@ -96,16 +96,44 @@ describe RestBase::Application do
|
|
96
96
|
expect(last_response.body).to be_empty
|
97
97
|
end
|
98
98
|
end
|
99
|
-
|
99
|
+
|
100
|
+
describe :forensics do
|
101
|
+
before(:each) do
|
102
|
+
@expected_hash = {:result => ["Forensics Test"], :forensics => ["Added Forensics"]}
|
103
|
+
@headers['Forensics'] = 'TRUE'
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should add forensics to body" do
|
107
|
+
get '/forensics', {}, @headers
|
108
|
+
|
109
|
+
expect(last_response.body).to eq(@expected_hash.to_json)
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should not add forensics to body" do
|
113
|
+
@headers.delete('Forensics')
|
114
|
+
get '/forensics', {}, @headers
|
115
|
+
|
116
|
+
@expected_hash.delete(:forensics)
|
117
|
+
expect(last_response.body).to eq(@expected_hash.to_json)
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should not add nil/empty forensics to body" do
|
121
|
+
get '/forensics_empty', {}, @headers
|
122
|
+
|
123
|
+
@expected_hash.delete(:forensics)
|
124
|
+
expect(last_response.body).to eq(@expected_hash.to_json)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
100
128
|
describe :json do
|
101
129
|
before(:each) do
|
102
130
|
@posted_body = { :success => true }
|
103
131
|
|
104
|
-
@expected_hash = {:
|
132
|
+
@expected_hash = {:result => { :posted => @posted_body }}
|
105
133
|
end
|
106
134
|
|
107
135
|
it "should get json" do
|
108
|
-
@expected_hash = {:
|
136
|
+
@expected_hash = {:result => { :gotten => "success" }}
|
109
137
|
|
110
138
|
get '/', {}, @headers
|
111
139
|
|
@@ -130,7 +158,7 @@ describe RestBase::Application do
|
|
130
158
|
it "should post empty json and return json" do
|
131
159
|
post '/', "", @headers
|
132
160
|
|
133
|
-
@expected_hash[:
|
161
|
+
@expected_hash[:result][:posted] = {}
|
134
162
|
expect(last_response.body).to eq(@expected_hash.to_json)
|
135
163
|
end
|
136
164
|
|
@@ -145,12 +173,12 @@ describe RestBase::Application do
|
|
145
173
|
before(:each) do
|
146
174
|
@posted_body = { :success => true }
|
147
175
|
|
148
|
-
@expected_hash = {:
|
176
|
+
@expected_hash = {:result => { :posted => @posted_body }}
|
149
177
|
end
|
150
178
|
|
151
179
|
it "should get xml" do
|
152
180
|
@headers['HTTP_ACCEPT'] = 'text/xml'
|
153
|
-
@expected_hash = {
|
181
|
+
@expected_hash = {:result => { :gotten => 'success'} }
|
154
182
|
|
155
183
|
get '/', {}, @headers
|
156
184
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-rest-base
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- bmills
|
@@ -177,6 +177,7 @@ files:
|
|
177
177
|
- spec/fixtures/test_application.rb
|
178
178
|
- spec/fixtures/test_end_points.rb
|
179
179
|
- spec/fixtures/test_errors_end_points.rb
|
180
|
+
- spec/fixtures/test_forensics.rb
|
180
181
|
- spec/lib/rest_base/application_spec.rb
|
181
182
|
- spec/lib/rest_base/authentication/authentication_base_spec.rb
|
182
183
|
- spec/lib/rest_base/authentication/basic_authentication_spec.rb
|
@@ -211,6 +212,7 @@ test_files:
|
|
211
212
|
- spec/fixtures/test_application.rb
|
212
213
|
- spec/fixtures/test_end_points.rb
|
213
214
|
- spec/fixtures/test_errors_end_points.rb
|
215
|
+
- spec/fixtures/test_forensics.rb
|
214
216
|
- spec/lib/rest_base/application_spec.rb
|
215
217
|
- spec/lib/rest_base/authentication/authentication_base_spec.rb
|
216
218
|
- spec/lib/rest_base/authentication/basic_authentication_spec.rb
|