fastapi 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 68312e62ae3797dbc5cd672cc5cbc10766390ca3
4
- data.tar.gz: 021eab09bc923f07bcf54da04d012d7102c608a7
3
+ metadata.gz: f404875852a90f7b72255293e1ea77b775bebd50
4
+ data.tar.gz: 3c50ae17829b4838528e6bd199ddee967c241af4
5
5
  SHA512:
6
- metadata.gz: 0901d7eed24c1d75e5fa1be3c339a065c4e7b6c5a3d0bc8b1a51a508055e7b7e99ceef0a1508db682a4702c33d5cf2db06ee5617261a016c8e2fd1fc5ebff521
7
- data.tar.gz: 4c62611aa52b91a266e800bc3ffdeb803c28dca90dea3210f9b70b4db905a845216fba7f4094d85316f6c2e68197b7cb2cb05c23403c89e9c71459288fc686b1
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
- def data_json
93
- Oj.dump(@data)
94
- end
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
- def meta_json
101
- Oj.dump(meta)
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
- def fastapi_standard_interface_sub(fields)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keith Horwood