tramway-api 1.8.3 → 1.8.3.1
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 +96 -8
- data/app/controllers/tramway/api/v1/application_controller.rb +1 -1
- data/lib/tramway/api/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ea920d1d95b5d0879e4761b50d32a53ae9cd09425fd7ce6f3c35cc6173821cf
|
4
|
+
data.tar.gz: 248fc9efe23a6b44db5ce5065fc4e15500c3c387f5c39380b83e677cb750434c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 949028808784d424710d0a72e602eefe85144ef46ffd1cba3a1671ad787fb91c527ae2b52002a5c60ada7c4225c9b853c3ee0f944ccda9ac7d224d086d029402
|
7
|
+
data.tar.gz: 5ca4783d217ee96ab1aef6be3368dd1a8c0a71233a5b129b30147b34d77f74b868933986bddcb0a12229fc4f9d6454332c7a7a1351f4c883b2be8269223c0023
|
data/README.md
CHANGED
@@ -88,14 +88,28 @@ rails g model user email:text password_digest:text username:text state:text uuid
|
|
88
88
|
Enable extension in your database:
|
89
89
|
|
90
90
|
*db/migrate/enable_extension.rb*
|
91
|
-
```
|
92
|
-
|
93
|
-
|
91
|
+
```ruby
|
92
|
+
class EnableExtensionUUIDOSSP < ActiveRecord::Migration
|
93
|
+
def change
|
94
|
+
enable_extension 'uuid-ossp'
|
95
|
+
end
|
94
96
|
end
|
95
97
|
```
|
96
98
|
|
99
|
+
### You can choose a method, which will be using as public ID method
|
100
|
+
|
101
|
+
By default, it's a `uuid` method
|
102
|
+
|
103
|
+
To choose your own public ID method, just add this line to:
|
104
|
+
|
105
|
+
*config/initializers/tramway.rb*
|
106
|
+
|
107
|
+
```ruby
|
108
|
+
Tramway::Api.id_methods_of(User => :id)
|
109
|
+
```
|
110
|
+
If you want to use `uuid` by default, please, add it to your models
|
97
111
|
|
98
|
-
Add generating uuid by default to every model, that is accessible by API
|
112
|
+
#### Add generating uuid by default to every model, that is accessible by API
|
99
113
|
|
100
114
|
*db/migrate/add_uuid_to_some_model.rb*
|
101
115
|
|
@@ -371,15 +385,89 @@ You have your records in JSON API spec.
|
|
371
385
|
|
372
386
|
### Create
|
373
387
|
|
374
|
-
|
388
|
+
*config/initializers/tramway.rb*
|
375
389
|
|
376
|
-
|
390
|
+
```ruby
|
391
|
+
::Tramway::Api.set_available_models({ YourModel => [ :create ] }, project: :your_project_name })
|
392
|
+
```
|
393
|
+
|
394
|
+
*app/forms/your_model_form.rb*
|
395
|
+
|
396
|
+
```ruby
|
397
|
+
class YourModelForm < Tramway::Core::ApplicationForm
|
398
|
+
properties :attribute1, :attribute2, :name
|
399
|
+
|
400
|
+
association :another_association_model
|
401
|
+
|
402
|
+
def name=(value)
|
403
|
+
model.first_name = value.split(' ')[0]
|
404
|
+
model.first_name = value.split(' ')[1]
|
405
|
+
end
|
406
|
+
end
|
407
|
+
```
|
408
|
+
|
409
|
+
Now you can your request. It has such structure
|
410
|
+
|
411
|
+
**POST** `/api/v1/records?model=YourModel`
|
412
|
+
|
413
|
+
```
|
414
|
+
Params Structure
|
415
|
+
{
|
416
|
+
data: {
|
417
|
+
attributes: {
|
418
|
+
attribute1: 'some value',
|
419
|
+
attribute2: 'some value',
|
420
|
+
name: 'some full name',
|
421
|
+
another_association_model: {
|
422
|
+
# here a list of attributes, which you described in AnotherAssociationModelForm
|
423
|
+
}
|
424
|
+
}
|
425
|
+
}
|
426
|
+
}
|
427
|
+
```
|
377
428
|
|
378
429
|
### Update
|
379
430
|
|
380
|
-
|
431
|
+
*config/initializers/tramway.rb*
|
381
432
|
|
382
|
-
|
433
|
+
```ruby
|
434
|
+
::Tramway::Api.set_available_models({ YourModel => [ :update ] }, project: :your_project_name })
|
435
|
+
```
|
436
|
+
|
437
|
+
*app/forms/your_model_form.rb*
|
438
|
+
|
439
|
+
```ruby
|
440
|
+
class YourModelForm < Tramway::Core::ApplicationForm
|
441
|
+
properties :attribute1, :attribute2, :name
|
442
|
+
|
443
|
+
association :another_association_model
|
444
|
+
|
445
|
+
def name=(value)
|
446
|
+
model.first_name = value.split(' ')[0]
|
447
|
+
model.first_name = value.split(' ')[1]
|
448
|
+
end
|
449
|
+
end
|
450
|
+
```
|
451
|
+
|
452
|
+
Now you can your request. It has such structure
|
453
|
+
|
454
|
+
**PATCH** `/api/v1/records/#{object_id}?model=YourModel`
|
455
|
+
|
456
|
+
```
|
457
|
+
Params Structure
|
458
|
+
{
|
459
|
+
data: {
|
460
|
+
attributes: {
|
461
|
+
attribute1: 'some value',
|
462
|
+
attribute2: 'some value',
|
463
|
+
name: 'some full name',
|
464
|
+
another_association_model: {
|
465
|
+
# here a list of attributes, which you described in AnotherAssociationModelForm
|
466
|
+
}
|
467
|
+
}
|
468
|
+
}
|
469
|
+
}
|
470
|
+
```
|
383
471
|
|
384
472
|
### Show
|
385
473
|
|
@@ -15,7 +15,7 @@ module Tramway
|
|
15
15
|
def snake_case(params)
|
16
16
|
hash = {}
|
17
17
|
params.each do |attribute, value|
|
18
|
-
key = UUID.validate(attribute) ? attribute : attribute.to_s.gsub('-', '_')
|
18
|
+
key = ::UUID.validate(attribute) ? attribute : attribute.to_s.gsub('-', '_')
|
19
19
|
hash.merge! key => value
|
20
20
|
end
|
21
21
|
hash
|
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.8.3
|
4
|
+
version: 1.8.3.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-07-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_model_serializers
|