standardapi 5.2.0.7 → 5.2.0.8

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
  SHA256:
3
- metadata.gz: f3957c161eeaacb9d65db690f90ed3f229b4a09518fe76a9b43e76b60118892c
4
- data.tar.gz: 74be1b993b808bb6f91abdcf3da4558c65873ca4a4201d138bdbdc19808ae401
3
+ metadata.gz: cc7347ed6a4d47843612e12b7278e2cf6f75f44b96b64ef5677ed04cee4e2974
4
+ data.tar.gz: a9d2e82efbf35bc54d0b21dd94de196a931d72dc1f58c36c8578abff69433909
5
5
  SHA512:
6
- metadata.gz: b54ce14e9c544ea3b2cc6cb555ea5c58da2ba920818e33c595d4c15ae03b6b0856c9755ff1f7e15b9d75e8518fb5c7fb90ab09dd77a7971d650c80bb8e703209
7
- data.tar.gz: 53ec52f5704a7cb2fef62df2160c496799a6bfd6f47dba72f985cdf201f79a447606fa80c5966dcfc5a5993075cd90c02324575e5d4ae5f6c15b62e7d7e145c7
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
- # Usage
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
- # Interface Specification
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
- controllers = ApplicationController.descendants# Dir[Rails.root.join('app/controllers/*_controller.rb')].map{ |path| path.match(/(\w+)_controller.rb/)[1].camelize+"Controller" }.map(&:safe_constantize)
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)
@@ -69,4 +69,4 @@ module StandardAPI
69
69
  end
70
70
 
71
71
  end
72
- end
72
+ end
@@ -1,3 +1,3 @@
1
1
  module StandardAPI
2
- VERSION = '5.2.0.7'
2
+ VERSION = '5.2.0.8'
3
3
  end
@@ -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.7
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: 2018-11-19 00:00:00.000000000 Z
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
- rubyforge_project:
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