standardapi 5.2.0.7 → 5.2.0.8
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/README.md +65 -4
- data/lib/standard_api/controller.rb +3 -1
- data/lib/standard_api/includes.rb +1 -1
- data/lib/standard_api/version.rb +1 -1
- data/lib/standard_api/views/application/index.json.jbuilder +8 -4
- data/lib/standard_api/views/application/index.streamer +6 -2
- metadata +9 -10
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cc7347ed6a4d47843612e12b7278e2cf6f75f44b96b64ef5677ed04cee4e2974
|
|
4
|
+
data.tar.gz: a9d2e82efbf35bc54d0b21dd94de196a931d72dc1f58c36c8578abff69433909
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 41c4ba5e6bcc543fa8a823a6c4422b6773735a57fe1d5be418f712617b1d695c0cd4e437afeedd33dd686cdbed295f3e10fb0d27da165600d99576a8c7e49de2
|
|
7
|
+
data.tar.gz: 349e1314c7bc7f3a3955eb88bc906749e2217ba9edd3903ea210f82f02ff9ce78afd2ee521f43381bb68b81b3d4ba1034b3ec3b35fc40c40d51e1625fbcd6204
|
data/README.md
CHANGED
|
@@ -35,7 +35,7 @@ In `config/application.rb:
|
|
|
35
35
|
end
|
|
36
36
|
end
|
|
37
37
|
|
|
38
|
-
#
|
|
38
|
+
# Implementation
|
|
39
39
|
|
|
40
40
|
StandardAPI is a module that can be included into any controller to expose a API
|
|
41
41
|
for. Alternatly, it can be included into `ApplicationController`, giving all
|
|
@@ -102,12 +102,73 @@ Full Example:
|
|
|
102
102
|
Note how includes can also support nested includes. So in this case when
|
|
103
103
|
including the author, the photos that the author took can also be included.
|
|
104
104
|
|
|
105
|
-
#
|
|
105
|
+
# API Usage
|
|
106
|
+
Resources can be queried via REST style end points
|
|
107
|
+
```
|
|
108
|
+
GET /records/:id fetch record
|
|
109
|
+
PATCH /records/:id update record
|
|
110
|
+
GET /records fetch records
|
|
111
|
+
POST /records create record
|
|
112
|
+
DELETE /records destroy record
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
All resource end points can be filtered, ordered, limited, offset, and have includes. All options are passed via query string in a nested URI encoded format.
|
|
116
|
+
|
|
117
|
+
```javascript
|
|
118
|
+
// Example
|
|
119
|
+
params = {
|
|
120
|
+
limit: 5,
|
|
121
|
+
offset: 0,
|
|
122
|
+
where: {
|
|
123
|
+
region_ids: {
|
|
124
|
+
contains: newyork.id
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
include: {
|
|
128
|
+
property: {
|
|
129
|
+
addresses: true
|
|
130
|
+
},
|
|
131
|
+
photos: true
|
|
132
|
+
},
|
|
133
|
+
order: {
|
|
134
|
+
created_at: 'desc'
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
// should be
|
|
138
|
+
'limit=5&offset=0&where%5Bregion_ids%5D%5Bcontains%5D=20106&include%5Bproperty%5D%5Baddresses%5D=true&include%5Bphotos%5D=true&order%5Bcreated_at%5D=desc'
|
|
139
|
+
```
|
|
140
|
+
### Include Options
|
|
141
|
+
Preload some relationships and have it delivered with each record in the resource.
|
|
142
|
+
|
|
143
|
+
### Where Options
|
|
144
|
+
```
|
|
145
|
+
id: 5 WHERE properties.id = 5
|
|
146
|
+
id: [5, 10, 15] WHERE properties.id IN (5, 10, 15)
|
|
147
|
+
id: {gt: 5} WHERE properties.id > 5
|
|
148
|
+
id: {gte: 5} WHERE properties.id >= 5
|
|
149
|
+
id: {lt: 5} WHERE properties.id < 5
|
|
150
|
+
id: {lte: 5} WHERE properties.id <= 5
|
|
151
|
+
address_id: nil WHERE properties.address_id IS NULL
|
|
152
|
+
address_id: false WHERE properties.address_id IS NULL..."
|
|
153
|
+
address_id: true WHERE properties.address_id IS NOT NULL..."
|
|
154
|
+
|
|
155
|
+
// Array columns
|
|
156
|
+
tags: 'Skyscraper' WHERE properties.tags = {"Skyscraper"}
|
|
157
|
+
tags: ['Skyscraper', 'Brick'] WHERE properties.tags = '{"Skyscraper", "Brick"}'
|
|
158
|
+
tags: {overlaps: ['Skyscraper', 'Brick']} WHERE properties.tags && '{"Skyscraper", "Brick"}'
|
|
159
|
+
tags: {contains: ['Skyscraper', 'Brick']} WHERE accounts.tags @> '{"Skyscraper", "Brick"}'
|
|
160
|
+
|
|
161
|
+
// Geospatial
|
|
162
|
+
location: {within: 0106000020e6...} WHERE ST_Within("listings"."location", ST_GeomFromEWKB(E'\\x0106000020e6...)
|
|
163
|
+
|
|
164
|
+
// On Relationships
|
|
165
|
+
property: {size: 10000} JOIN properties WHERE properties.size = 10000"
|
|
166
|
+
|
|
167
|
+
//
|
|
168
|
+
```
|
|
106
169
|
|
|
107
170
|
# Testing
|
|
108
171
|
|
|
109
|
-
##
|
|
110
|
-
|
|
111
172
|
And example contoller and it's tests.
|
|
112
173
|
|
|
113
174
|
class PhotosController < ApplicationController
|
|
@@ -10,7 +10,9 @@ module StandardAPI
|
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
def tables
|
|
13
|
-
|
|
13
|
+
Rails.application.eager_load! if Rails.env == 'development'.freeze
|
|
14
|
+
|
|
15
|
+
controllers = ApplicationController.descendants
|
|
14
16
|
controllers.select! { |c| c.ancestors.include?(self.class) && c != self.class }
|
|
15
17
|
controllers.map!(&:model).compact!
|
|
16
18
|
controllers.map!(&:table_name)
|
data/lib/standard_api/version.rb
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
|
+
if !includes.empty?
|
|
2
|
+
instance_variable_set("@#{model.model_name.plural}", instance_variable_get("@#{model.model_name.plural}").preload(includes.keys))
|
|
3
|
+
end
|
|
4
|
+
|
|
1
5
|
if !includes.empty? && can_cache?(model, includes)
|
|
2
6
|
partial = model_partial(model)
|
|
3
7
|
record_name = partial.split('/').last.to_sym
|
|
4
|
-
locals = { record_name => nil, :includes => includes}
|
|
5
|
-
|
|
6
|
-
json.cache_collection! instance_variable_get("@#{model.model_name.plural}"), key: proc {|record| cache_key(record, includes) } do |record|
|
|
8
|
+
locals = { record_name => nil, :includes => includes }
|
|
9
|
+
|
|
10
|
+
json.cache_collection! instance_variable_get("@#{model.model_name.plural}"), key: proc { |record| cache_key(record, includes) } do |record|
|
|
7
11
|
locals[record_name] = record
|
|
8
12
|
json.partial! partial, locals
|
|
9
13
|
end
|
|
10
14
|
else
|
|
11
15
|
json.array! instance_variable_get("@#{model.model_name.plural}"), partial: model_partial(model), as: model_partial(model).split('/').last, includes: includes
|
|
12
|
-
end
|
|
16
|
+
end
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
if !includes.empty?
|
|
2
|
+
instance_variable_set("@#{model.model_name.plural}", instance_variable_get("@#{model.model_name.plural}").preload(includes.keys))
|
|
3
|
+
end
|
|
4
|
+
|
|
1
5
|
if !includes.empty? && can_cache?(model, includes)
|
|
2
6
|
partial = model_partial(model)
|
|
3
7
|
record_name = partial.split('/').last.to_sym
|
|
4
|
-
locals = { record_name => nil, :includes => includes}
|
|
8
|
+
locals = { record_name => nil, :includes => includes }
|
|
5
9
|
|
|
6
10
|
json.cache_collection! instance_variable_get("@#{model.model_name.plural}"), key: proc {|record| cache_key(record, includes) } do |record|
|
|
7
11
|
locals[record_name] = record
|
|
@@ -9,4 +13,4 @@ if !includes.empty? && can_cache?(model, includes)
|
|
|
9
13
|
end
|
|
10
14
|
else
|
|
11
15
|
json.array! instance_variable_get("@#{model.model_name.plural}"), partial: model_partial(model), as: model_partial(model).split('/').last, includes: includes
|
|
12
|
-
end
|
|
16
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: standardapi
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 5.2.0.
|
|
4
|
+
version: 5.2.0.8
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- James Bracy
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2019-01-28 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails
|
|
@@ -74,22 +74,22 @@ dependencies:
|
|
|
74
74
|
name: activerecord-sort
|
|
75
75
|
requirement: !ruby/object:Gem::Requirement
|
|
76
76
|
requirements:
|
|
77
|
-
- - "~>"
|
|
78
|
-
- !ruby/object:Gem::Version
|
|
79
|
-
version: '5.2'
|
|
80
77
|
- - ">="
|
|
81
78
|
- !ruby/object:Gem::Version
|
|
82
79
|
version: 5.2.0
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '5.2'
|
|
83
83
|
type: :runtime
|
|
84
84
|
prerelease: false
|
|
85
85
|
version_requirements: !ruby/object:Gem::Requirement
|
|
86
86
|
requirements:
|
|
87
|
-
- - "~>"
|
|
88
|
-
- !ruby/object:Gem::Version
|
|
89
|
-
version: '5.2'
|
|
90
87
|
- - ">="
|
|
91
88
|
- !ruby/object:Gem::Version
|
|
92
89
|
version: 5.2.0
|
|
90
|
+
- - "~>"
|
|
91
|
+
- !ruby/object:Gem::Version
|
|
92
|
+
version: '5.2'
|
|
93
93
|
- !ruby/object:Gem::Dependency
|
|
94
94
|
name: activerecord-filter
|
|
95
95
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -323,8 +323,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
323
323
|
- !ruby/object:Gem::Version
|
|
324
324
|
version: '0'
|
|
325
325
|
requirements: []
|
|
326
|
-
|
|
327
|
-
rubygems_version: 2.7.7
|
|
326
|
+
rubygems_version: 3.0.2
|
|
328
327
|
signing_key:
|
|
329
328
|
specification_version: 4
|
|
330
329
|
summary: StandardAPI makes it easy to expose a query interface for your Rails models
|