fastapi 0.1.12 → 0.1.13
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/fastapi.rb +43 -5
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ba0c12e4611669b10f73a01b8a5e110ef758ccdb
|
|
4
|
+
data.tar.gz: 53c6ffd87455ec983d450fb29895ce2de5ad72fd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 20a56afcae9788f0f624ff7d221aff8f26af0275d8888f6c85ef924824c6fe20e5ff05f1269446f090d4fa065243c72ba0e19550490a97e88367f579005829b6
|
|
7
|
+
data.tar.gz: df3323130567c3f99e0fdf6a9b5e5e6dcaeae38bc43444b80763021656e49f70e341ff5ef9eded466510584ec1b68c720b58642a83533ec1fbaf4c43e8756398
|
data/lib/fastapi.rb
CHANGED
|
@@ -112,7 +112,7 @@ class FastAPI
|
|
|
112
112
|
end
|
|
113
113
|
|
|
114
114
|
if result[:total] == 0
|
|
115
|
-
error = @model.to_s + ' id does not exist'
|
|
115
|
+
error = {message: @model.to_s + ' id does not exist'}
|
|
116
116
|
else
|
|
117
117
|
error = result[:error]
|
|
118
118
|
end
|
|
@@ -179,10 +179,46 @@ class FastAPI
|
|
|
179
179
|
# Spoofs data from Model
|
|
180
180
|
#
|
|
181
181
|
# @return [String] JSON data and metadata
|
|
182
|
-
def spoof(data, meta)
|
|
182
|
+
def spoof(data = [], meta = {})
|
|
183
|
+
|
|
184
|
+
if not meta.has_key? :total
|
|
185
|
+
meta[:total] = data.count
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
if not meta.has_key? :offset
|
|
189
|
+
meta[:offset] = 0
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
if not meta.has_key? :count
|
|
193
|
+
meta[:count] = data.count
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
Oj.dump({
|
|
197
|
+
meta: meta,
|
|
198
|
+
data: data
|
|
199
|
+
}, mode: :compat)
|
|
183
200
|
|
|
184
201
|
end
|
|
185
202
|
|
|
203
|
+
# Returns a JSONified string representing a rejected API response with invalid fields parameters
|
|
204
|
+
#
|
|
205
|
+
# @param fields [Hash] Hash containing fields and their related errors
|
|
206
|
+
# @return [String] JSON data and metadata, with error
|
|
207
|
+
def invalid(fields)
|
|
208
|
+
Oj.dump({
|
|
209
|
+
meta: {
|
|
210
|
+
total: 0,
|
|
211
|
+
offset: 0,
|
|
212
|
+
count: 0,
|
|
213
|
+
error: {
|
|
214
|
+
message: 'invalid',
|
|
215
|
+
fields: fields
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
data: [],
|
|
219
|
+
}, mode: :compat)
|
|
220
|
+
end
|
|
221
|
+
|
|
186
222
|
# Returns a JSONified string representing a standardized empty API response, with a provided error message
|
|
187
223
|
#
|
|
188
224
|
# @param message [String] Error message to be used in response
|
|
@@ -193,7 +229,9 @@ class FastAPI
|
|
|
193
229
|
total: 0,
|
|
194
230
|
offset: 0,
|
|
195
231
|
count: 0,
|
|
196
|
-
error:
|
|
232
|
+
error: {
|
|
233
|
+
message: message.to_s
|
|
234
|
+
}
|
|
197
235
|
},
|
|
198
236
|
data: [],
|
|
199
237
|
}, mode: :compat)
|
|
@@ -230,7 +268,7 @@ class FastAPI
|
|
|
230
268
|
total: 0,
|
|
231
269
|
count: 0,
|
|
232
270
|
offset: offset,
|
|
233
|
-
error: error.message
|
|
271
|
+
error: {message: error.message}
|
|
234
272
|
}
|
|
235
273
|
end
|
|
236
274
|
|
|
@@ -255,7 +293,7 @@ class FastAPI
|
|
|
255
293
|
total: 0,
|
|
256
294
|
count: 0,
|
|
257
295
|
offset: offset,
|
|
258
|
-
error: 'Query failed'
|
|
296
|
+
error: {message: 'Query failed'}
|
|
259
297
|
}
|
|
260
298
|
end
|
|
261
299
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: fastapi
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.13
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Keith Horwood
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2014-11-
|
|
11
|
+
date: 2014-11-17 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: oj
|