fastapi 0.1.1 → 0.1.2
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 +40 -6
- data/lib/fastapi/active_record_extension.rb +13 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f404875852a90f7b72255293e1ea77b775bebd50
|
4
|
+
data.tar.gz: 3c50ae17829b4838528e6bd199ddee967c241af4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0edb07fcd025e2663d52b2034dcb6167eec57c0820b915278232dc60a4822dd0bd1123e24528f4cd02795c38222fdc4133f562f31e75cddd0604f9bf9ece37f6
|
7
|
+
data.tar.gz: ecf66e27e516ea0847e795ef25e49e23666bd7acde5c4251245e11a630b95f6000af9e87447fab2a58b1d6bebbf35e8dcfb3e2e2ca68780bd8d61e3755c973b0
|
data/lib/fastapi.rb
CHANGED
@@ -35,6 +35,12 @@ class FastAPI
|
|
35
35
|
"<#{self.class}: #{@model}>"
|
36
36
|
end
|
37
37
|
|
38
|
+
|
39
|
+
# Create and execute an optimized SQL query based on specified filters
|
40
|
+
#
|
41
|
+
# @param filters [Hash] a hash containing the intended filters
|
42
|
+
# @param meta [Hash] a hash containing custom metadata
|
43
|
+
# @return [FastAPI] the current instance
|
38
44
|
def filter(filters = {}, meta = {})
|
39
45
|
|
40
46
|
result = fastapi_query(filters)
|
@@ -59,6 +65,12 @@ class FastAPI
|
|
59
65
|
|
60
66
|
end
|
61
67
|
|
68
|
+
# Create and execute an optimized SQL query based on specified object id.
|
69
|
+
# Provides customized error response if not found.
|
70
|
+
#
|
71
|
+
# @param id [Integer] the id of the object to retrieve
|
72
|
+
# @param meta [Hash] a hash containing custom metadata
|
73
|
+
# @return [FastAPI] the current instance
|
62
74
|
def fetch(id, meta = {})
|
63
75
|
|
64
76
|
result = fastapi_query({id: id})
|
@@ -89,22 +101,37 @@ class FastAPI
|
|
89
101
|
|
90
102
|
end
|
91
103
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
104
|
+
# Returns the data from the most recently executed `filter` or `fetch` call.
|
105
|
+
#
|
106
|
+
# @return [Array] available data
|
96
107
|
def data
|
97
108
|
@data
|
98
109
|
end
|
99
110
|
|
100
|
-
|
101
|
-
|
111
|
+
# Returns JSONified data from the most recently executed `filter` or `fetch` call.
|
112
|
+
#
|
113
|
+
# @return [String] available data in JSON format
|
114
|
+
def data_json
|
115
|
+
Oj.dump(@data)
|
102
116
|
end
|
103
117
|
|
118
|
+
# Returns the metadata from the most recently executed `filter` or `fetch` call.
|
119
|
+
#
|
120
|
+
# @return [Hash] available metadata
|
104
121
|
def meta
|
105
122
|
@metadata
|
106
123
|
end
|
107
124
|
|
125
|
+
# Returns JSONified metadata from the most recently executed `filter` or `fetch` call.
|
126
|
+
#
|
127
|
+
# @return [String] available metadata in JSON format
|
128
|
+
def meta_json
|
129
|
+
Oj.dump(meta)
|
130
|
+
end
|
131
|
+
|
132
|
+
# Returns both the data and metadata from the most recently executed `filter` or `fetch` call.
|
133
|
+
#
|
134
|
+
# @return [Hash] available data and metadata
|
108
135
|
def to_hash
|
109
136
|
{
|
110
137
|
meta: @metadata,
|
@@ -112,10 +139,17 @@ class FastAPI
|
|
112
139
|
}
|
113
140
|
end
|
114
141
|
|
142
|
+
# Intended to return the final API response
|
143
|
+
#
|
144
|
+
# @return [String] JSON data and metadata
|
115
145
|
def response
|
116
146
|
Oj.dump(self.to_hash)
|
117
147
|
end
|
118
148
|
|
149
|
+
# Returns a JSONified string representing a standardized empty API response, with a provided error message
|
150
|
+
#
|
151
|
+
# @param message [String] Error message to be used in response
|
152
|
+
# @return [String] JSON data and metadata, with error
|
119
153
|
def reject(message = 'Access denied')
|
120
154
|
Oj.dump({
|
121
155
|
meta: {
|
@@ -6,14 +6,26 @@ module FastAPIExtension
|
|
6
6
|
|
7
7
|
module ClassMethods
|
8
8
|
|
9
|
+
# Used to set the standard interface for the top level of a fastapi response
|
10
|
+
#
|
11
|
+
# @param fields [Array] a list of fields in the form of symbols
|
12
|
+
# @return [Array] the same array of fields
|
9
13
|
def fastapi_standard_interface(fields)
|
10
14
|
@fastapi_fields = fields
|
11
15
|
end
|
12
16
|
|
13
|
-
|
17
|
+
# Used to set the standard interface for the second level of a fastapi response (nested)
|
18
|
+
#
|
19
|
+
# @param fields [Array] a list of fields in the form of symbols
|
20
|
+
# @return [Array] the same array of fields
|
21
|
+
def fastapi_standard_interface_nested(fields)
|
14
22
|
@fastapi_fields_sub = fields
|
15
23
|
end
|
16
24
|
|
25
|
+
# Used to set any default filters for the top level fastapi response
|
26
|
+
#
|
27
|
+
# @param filters [Hash] a hash containing the intended filters
|
28
|
+
# @return [Hash] the same filters hash
|
17
29
|
def fastapi_default_filters(filters)
|
18
30
|
@fastapi_filters = filters
|
19
31
|
end
|