tramway-api 1.7.0.1 → 1.7.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -5
- data/app/controllers/tramway/api/application_controller.rb +1 -1
- data/app/controllers/tramway/api/v1/records_controller.rb +3 -3
- data/app/controllers/tramway/api/v1/user_tokens_controller.rb +1 -2
- data/app/controllers/tramway/api/v1/users_controller.rb +2 -3
- data/lib/tramway/api.rb +2 -0
- data/lib/tramway/api/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 882cf139a619aab77c7030d6c3864e9cfa51a6abbfe5e516891acbd192221a89
|
4
|
+
data.tar.gz: 24077c4462a3d65b4dc1bcdca0761ea20b4e53c68a4af11b4ef190924128d655
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a6fcfe6c3f09ae9cbabaa91e3c4005c5abfb8aa88e5a28a792dcb6e26d1f09988b44b330865e70216239fef7ec2812f858e9179c9a0345bd7ec01f50d1f73ff
|
7
|
+
data.tar.gz: 687f34614962c0a8702dd671c93aca3cfa743e3b2ef1ee0fe6f42482416090cbd5848ec035131936ffd75e33d0d204be9f84036f264001800b1a41054ab50e4d
|
data/README.md
CHANGED
@@ -70,12 +70,22 @@ Then generate User (you use another name, it's just an example) model
|
|
70
70
|
rails g model user email:text password_digest:text username:text state:text uid:text
|
71
71
|
```
|
72
72
|
|
73
|
-
|
73
|
+
Enable extension in your database:
|
74
74
|
|
75
|
-
*db/migrate/
|
75
|
+
*db/migrate/enable_extension.rb*
|
76
|
+
```
|
77
|
+
def change
|
78
|
+
enable_extension 'uuid-ossp'
|
79
|
+
end
|
80
|
+
```
|
81
|
+
|
82
|
+
|
83
|
+
Add generating uuid by default to every model, that is accessible by API
|
84
|
+
|
85
|
+
*db/migrate/add_uuid_to_some_model.rb*
|
76
86
|
|
77
87
|
```ruby
|
78
|
-
t.uuid :
|
88
|
+
t.uuid :uuid, default: 'uuid_generate_v4()'
|
79
89
|
```
|
80
90
|
|
81
91
|
*app/models/user.rb*
|
@@ -85,7 +95,7 @@ class User < Tramway::Core::ApplicationRecord
|
|
85
95
|
has_secure_password
|
86
96
|
|
87
97
|
def self.from_token_payload(payload)
|
88
|
-
find_by
|
98
|
+
find_by uuid: payload['sub']
|
89
99
|
end
|
90
100
|
end
|
91
101
|
```
|
@@ -227,7 +237,7 @@ RSpec.describe 'Post generate token', type: :feature do
|
|
227
237
|
post '/api/v1/user_token', params: { auth: { login: user.email, password: '123456789' } }
|
228
238
|
|
229
239
|
expect(json_response[:auth_token].present?).to be_truthy
|
230
|
-
expect(json_response[:user]).to include_json({ email: user.email,
|
240
|
+
expect(json_response[:user]).to include_json({ email: user.email, uuid: user.uuid })
|
231
241
|
end
|
232
242
|
|
233
243
|
end
|
@@ -29,7 +29,7 @@ module Tramway::Api::V1
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def update
|
32
|
-
record_form = form_class.new model_class.active.find_by uuid: params[:id]
|
32
|
+
record_form = form_class.new model_class.active.find_by! uuid: params[:id]
|
33
33
|
if record_form.submit snake_case params[:data][:attributes]
|
34
34
|
render json: record_form.model,
|
35
35
|
serializer: serializer_class,
|
@@ -41,7 +41,7 @@ module Tramway::Api::V1
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def show
|
44
|
-
record = model_class.active.find_by uuid: params[:id]
|
44
|
+
record = model_class.active.find_by! uuid: params[:id]
|
45
45
|
render json: record,
|
46
46
|
serializer: serializer_class,
|
47
47
|
include: '*',
|
@@ -49,7 +49,7 @@ module Tramway::Api::V1
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def destroy
|
52
|
-
record = model_class.active.find_by uuid: params[:id]
|
52
|
+
record = model_class.active.find_by! uuid: params[:id]
|
53
53
|
record.remove
|
54
54
|
render json: record,
|
55
55
|
serializer: serializer_class,
|
@@ -10,13 +10,12 @@ class Tramway::Api::V1::UsersController < ::Tramway::Api::V1::ApplicationControl
|
|
10
10
|
user_form = sign_up_form_class_name(user_based_model).new user_based_model.new
|
11
11
|
# Implement JSON API spec here
|
12
12
|
if user_form.submit snake_case params[:data][:attributes]
|
13
|
-
token = ::Knock::AuthToken.new(payload: { sub: user_form.model.
|
13
|
+
token = ::Knock::AuthToken.new(payload: { sub: user_form.model.uuid }).token
|
14
14
|
# FIXME: refactor this bullshit
|
15
15
|
serialized_user = OpenStruct.new(
|
16
16
|
user_form.model.attributes.merge(
|
17
17
|
authentication_token: token,
|
18
|
-
|
19
|
-
id: user_form.model.id
|
18
|
+
id: user_form.model.uuid
|
20
19
|
)
|
21
20
|
)
|
22
21
|
render json: serialized_user, status: :created
|
data/lib/tramway/api.rb
CHANGED
@@ -18,12 +18,14 @@ module Tramway
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def user_based_models
|
21
|
+
@@auth_config ||= []
|
21
22
|
@@auth_config.map do |conf|
|
22
23
|
conf[:user_model]
|
23
24
|
end
|
24
25
|
end
|
25
26
|
|
26
27
|
def auth_attributes
|
28
|
+
@@auth_config ||= []
|
27
29
|
@@auth_config.reduce({}) do |hash, conf|
|
28
30
|
hash.merge! conf[:user_model] => conf[:auth_attributes]
|
29
31
|
end
|
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.7.
|
4
|
+
version: 1.7.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pavel Kalashnikov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_model_serializers
|
@@ -100,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
100
|
- !ruby/object:Gem::Version
|
101
101
|
version: '0'
|
102
102
|
requirements: []
|
103
|
-
rubygems_version: 3.
|
103
|
+
rubygems_version: 3.1.2
|
104
104
|
signing_key:
|
105
105
|
specification_version: 4
|
106
106
|
summary: Engine for api
|