tramway-api 1.4.4 → 1.5
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be852b8025894c89dbc01109337011ac3178b1fcc14cb8d7655bebfcbf8083ec
|
4
|
+
data.tar.gz: 8a13ec95aee745c0b262664658cf14807eb823ada87d845ae34e21a4b3c4720c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47512dbe567f7b258f2f1b411545503bf0c7a964b822030061e328dee94865c9d93a4c549183ef00386af44177b818fcd2339b3658f78bd81225246256188489
|
7
|
+
data.tar.gz: d45547b8ca370a7357a6123330f51a90451d48663408f682fabe81ff1081955b219cef6608c0eda484284c0f6863371f456c419905513b5632b394b40ea09390
|
data/README.md
CHANGED
@@ -185,7 +185,9 @@ require 'rails_helper'
|
|
185
185
|
|
186
186
|
RSpec.describe 'Post creating user', type: :feature do
|
187
187
|
describe 'POST /api/v1/user with model User' do
|
188
|
-
let(:attributes)
|
188
|
+
let(:attributes) do
|
189
|
+
kebab_case_converter attributes_for :user
|
190
|
+
end
|
189
191
|
|
190
192
|
it 'returns created status' do
|
191
193
|
post '/api/v1/user', params: { user: attributes }
|
@@ -284,6 +286,67 @@ Enabled methods:
|
|
284
286
|
* index
|
285
287
|
* destroy
|
286
288
|
|
289
|
+
### Index
|
290
|
+
|
291
|
+
Every model you've added in initializer will be able by URL `api/v1/records?model=#{model_class}`.
|
292
|
+
|
293
|
+
Just update your initializer:
|
294
|
+
|
295
|
+
```ruby
|
296
|
+
::Tramway::Api.set_available_models user: { open: %i[create], closed: %i[update index] } # we've added index method
|
297
|
+
```
|
298
|
+
|
299
|
+
Create serializer
|
300
|
+
|
301
|
+
*app/serializers/user_serializer.rb*
|
302
|
+
|
303
|
+
```ruby
|
304
|
+
class UserSerializer < Tramway::Core::ApplicationSerializer
|
305
|
+
attributes :username, :email
|
306
|
+
end
|
307
|
+
```
|
308
|
+
|
309
|
+
Then write test:
|
310
|
+
|
311
|
+
```ruby
|
312
|
+
it 'returns status' do
|
313
|
+
get '/api/v1/records', params: { model: 'User' }, headers: headers
|
314
|
+
|
315
|
+
expect(response.status).to eq 200
|
316
|
+
end
|
317
|
+
|
318
|
+
it 'returns needed count' do
|
319
|
+
get '/api/v1/records', params: { model: 'User' }, headers: headers
|
320
|
+
|
321
|
+
expect(json_response[:data].size).to eq User.active.count
|
322
|
+
end
|
323
|
+
```
|
324
|
+
|
325
|
+
You have your records in JSON API spec.
|
326
|
+
|
327
|
+
### Create
|
328
|
+
|
329
|
+
Production ready
|
330
|
+
|
331
|
+
Docs coming soon
|
332
|
+
|
333
|
+
### Update
|
334
|
+
|
335
|
+
Production ready
|
336
|
+
|
337
|
+
Docs coming soon
|
338
|
+
|
339
|
+
### Show
|
340
|
+
|
341
|
+
Production ready
|
342
|
+
|
343
|
+
Docs coming soon
|
344
|
+
|
345
|
+
### Destroy
|
346
|
+
|
347
|
+
Production ready
|
348
|
+
|
349
|
+
Docs coming soon
|
287
350
|
|
288
351
|
## Contributing
|
289
352
|
Contribution directions go here.
|
@@ -9,6 +9,14 @@ module Tramway
|
|
9
9
|
def render_error_with_text(text)
|
10
10
|
render json: { text: text }, status: :bad_request
|
11
11
|
end
|
12
|
+
|
13
|
+
def snake_case(params)
|
14
|
+
hash = {}
|
15
|
+
params.each do |attribute, value|
|
16
|
+
hash.merge! attribute.to_s.gsub('-', '_') => value
|
17
|
+
end
|
18
|
+
hash
|
19
|
+
end
|
12
20
|
end
|
13
21
|
end
|
14
22
|
end
|
@@ -15,7 +15,7 @@ module Tramway::Api::V1
|
|
15
15
|
|
16
16
|
def create
|
17
17
|
record_form = form_class.new model_class.new
|
18
|
-
if record_form.submit params[:data][:attributes]
|
18
|
+
if record_form.submit snake_case params[:data][:attributes]
|
19
19
|
render json: record_form.model,
|
20
20
|
serializer: serializer_class,
|
21
21
|
include: '*',
|
@@ -27,7 +27,7 @@ module Tramway::Api::V1
|
|
27
27
|
|
28
28
|
def update
|
29
29
|
record_form = form_class.new model_class.active.find params[:id]
|
30
|
-
if record_form.submit params[:data][:attributes]
|
30
|
+
if record_form.submit snake_case params[:data][:attributes]
|
31
31
|
render json: record_form.model,
|
32
32
|
serializer: serializer_class,
|
33
33
|
include: '*',
|
data/lib/tramway/api/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tramway-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: '1.5'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pavel Kalashnikov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-09-
|
11
|
+
date: 2019-09-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: knock
|
@@ -76,6 +76,7 @@ files:
|
|
76
76
|
- app/serializers/tramway/api/v1/error_serializer.rb
|
77
77
|
- app/views/layouts/tramway/api/application.html.erb
|
78
78
|
- config/initializers/active_model_serializers.rb
|
79
|
+
- config/initializers/json_param_key_transform.rb
|
79
80
|
- config/routes.rb
|
80
81
|
- lib/tasks/tramway/api_tasks.rake
|
81
82
|
- lib/tramway/api.rb
|