introspective_grape 0.2.9 → 0.3.0

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: 66a8d39d065336f27862ed3f129510931bfc2d25
4
- data.tar.gz: 667b52d722d3ea2b348cfcb3c5ca2a901ea8362d
3
+ metadata.gz: cb071dc16f5b81676e9c1f8472729d13d6ac51b5
4
+ data.tar.gz: ff807faad54a81270717f30e7c46320f56147bbb
5
5
  SHA512:
6
- metadata.gz: 5287b37289410314b6d3993f80f852db914291eac20b10d3c322c65a1307fe27457a2b00fdd0844323d7d625765d35a04606dfbe38ad379f4e5cb721d15e97e3
7
- data.tar.gz: bb415d186d385970deae105c58b9685d56f646c5b0bc69d0bcc5b1e2973d5a9c1433a883c897d51abd7895469709b764f3d5ad64ebc3b3e6cbb2b6819609bfc9
6
+ metadata.gz: fcb4c96419246d601ebcc8c96ea5b1bad2ca4cdb44ec5e3fc2c89ce72a59b53778b21258160cde463c23bf7cb468fbec833cb2337c24e8b754a6530a7049ca21
7
+ data.tar.gz: fa6897a8637f5e58b2ace975324f4c186257046bb340774d11851268b0bd78cd1bc432b8b92eff4fcf6065cb74f1bec7e310085d4a33dec7731079fbc4f2327b
data/README.md CHANGED
@@ -70,6 +70,18 @@ IntrospectiveGrape::API.authentication_method = "whatever!"
70
70
 
71
71
  Pundit authorization is invoked against index?, show?, update?, create?, and destroy? methods with the model instance in question (or a new instance in the case of index).
72
72
 
73
+ The joke goes that you may find you need to allow an unauthenticated user to attempt a log in, which can be handled with something like:
74
+
75
+ ```
76
+ def authorize!
77
+ unauthorized! unless current_user || login_request?
78
+ end
79
+
80
+ def login_request?
81
+ # is it the session login endpoint?
82
+ self.method_name.start_with?('POST') && self.namespace == '/login'
83
+ end
84
+ ```
73
85
 
74
86
  ## Generate End Points for Models
75
87
 
@@ -152,11 +164,14 @@ class MyModelAPI < IntrospectiveGrape::API
152
164
  end
153
165
  ```
154
166
 
155
- Multiple values can be specified at once for Integer attributes that end in "id" (i.e. conventional primary and foreign keys) by passing a comma separated list of IDs.
167
+ Multiple values can be specified at once for Integer attributes that end in "id" (i.e.
168
+ conventional primary and foreign keys) by passing a comma separated list of IDs.
156
169
 
157
- For timestamp attributes it will generate `<name_of_timestamp>_start` and `<name_of_timestamp>_end` constraints.
170
+ For timestamp attributes it will generate `<name_of_timestamp>_start` and
171
+ `<name_of_timestamp>_end` range constraints.
158
172
 
159
- There is also a special "filter" filter, that allows a JSON hash to be passed of attributes and values: this allows more complex filtering if one is familiar with ActiveRecord's query conventions.
173
+ There is also a special "filter" filter that accepts a JSON hash of attributes and values:
174
+ this allows more complex filtering if one is familiar with ActiveRecord's query conventions.
160
175
 
161
176
  ### Overriding Filter Queries
162
177
 
@@ -199,7 +214,8 @@ end
199
214
 
200
215
  ## Documenting Endpoints
201
216
 
202
- If you wish to provide additional documentation for end points you can define `<action>_documentation` methods in the API class.
217
+ If you wish to provide additional documentation for end points you can define
218
+ `<action>_documentation` methods in the API class.
203
219
 
204
220
  ## Pagination
205
221
 
@@ -210,7 +226,7 @@ The index action by default will not be paginated, simply declared `paginate` be
210
226
  By default any association included in the strong params argument will have all
211
227
  RESTful (`:index,:show,:create,:update, :destroy`) endpoints defined. These can
212
228
  be excluded (or conversely included) with the `exclude_actions` or `include_actions`
213
- declarations on the model. You can also include or exclude :all or :none as shorthand.
229
+ declarations in the API class. You can also include or exclude :all or :none as shorthand.
214
230
 
215
231
  ## Grape Hooks
216
232
 
@@ -5,6 +5,7 @@ module IntrospectiveGrape
5
5
  autoload :Doc, 'introspective_grape/doc'
6
6
  autoload :Filters, 'introspective_grape/filters'
7
7
  autoload :Helpers, 'introspective_grape/helpers'
8
+ autoload :SnakeParams, 'introspective_grape/snake_params'
8
9
  autoload :Traversal, 'introspective_grape/traversal'
9
10
 
10
11
  module Formatter
@@ -12,6 +12,7 @@ module IntrospectiveGrape
12
12
  extend IntrospectiveGrape::Filters
13
13
  extend IntrospectiveGrape::Traversal
14
14
  extend IntrospectiveGrape::Doc
15
+ extend IntrospectiveGrape::SnakeParams
15
16
 
16
17
  # Allow files to be uploaded through ActionController:
17
18
  ActionController::Parameters::PERMITTED_SCALAR_TYPES.push Rack::Multipart::UploadedFile, ActionController::Parameters
@@ -57,18 +58,7 @@ module IntrospectiveGrape
57
58
  self.send(IntrospectiveGrape::API.authentication_method(self))
58
59
  end
59
60
 
60
- if IntrospectiveGrape.config.camelize_parameters
61
- child.before_validation do
62
- # We have to snake case the Rack params then re-assign @params to the
63
- # request.params, because of the I-think-very-goofy-and-inexplicable
64
- # way Grape interacts with both independently of each other
65
- (params.try(:with_snake_keys)||{}).each do |k,v|
66
- request.delete_param(k.camelize(:lower))
67
- request.update_param(k, v)
68
- end
69
- @params = request.params
70
- end
71
- end
61
+ child.snake_params_before_validation if IntrospectiveGrape.config.camelize_parameters
72
62
  end
73
63
 
74
64
  # We will probably need before and after hooks eventually, but haven't yet...
@@ -0,0 +1,16 @@
1
+ module IntrospectiveGrape
2
+ module SnakeParams
3
+ def snake_params_before_validation
4
+ before_validation do
5
+ # We have to snake case the Rack params then re-assign @params to the
6
+ # request.params, because of the I-think-very-goofy-and-inexplicable
7
+ # way Grape interacts with both independently of each other
8
+ (params.try(:with_snake_keys)||{}).each do |k,v|
9
+ request.delete_param(k.camelize(:lower))
10
+ request.update_param(k, v)
11
+ end
12
+ @params = request.params
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,3 +1,3 @@
1
1
  module IntrospectiveGrape
2
- VERSION = "0.2.9".freeze
2
+ VERSION = "0.3.0".freeze
3
3
  end
@@ -1,14 +1,14 @@
1
1
  module ApiHelpers
2
- def warden
3
- env['warden']
4
- end
5
-
6
2
  def current_user
7
- warden.user || params[:api_key].present? && @user = User.find_by_authentication_token(params[:api_key])
3
+ params[:api_key].present? && @user = User.find_by_authentication_token(params[:api_key])
8
4
  end
9
5
 
10
6
  def authenticate!
11
- unauthenticated! unless current_user
7
+ unauthenticated! unless login_request? || current_user
8
+ end
9
+
10
+ def login_request?
11
+ self.method_name.start_with?('POST') && self.namespace == '/sessions'
12
12
  end
13
13
 
14
14
  # returns an 'unauthenticated' response
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: introspective_grape
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.9
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Buermann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-20 00:00:00.000000000 Z
11
+ date: 2017-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -264,6 +264,7 @@ files:
264
264
  - lib/introspective_grape/filters.rb
265
265
  - lib/introspective_grape/formatter/camel_json.rb
266
266
  - lib/introspective_grape/helpers.rb
267
+ - lib/introspective_grape/snake_params.rb
267
268
  - lib/introspective_grape/traversal.rb
268
269
  - lib/introspective_grape/validators.rb
269
270
  - lib/introspective_grape/version.rb