lhs 14.6.5 → 15.0.0
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/.ruby-version +1 -1
- data/README.md +68 -68
- data/lhs.gemspec +1 -1
- data/lib/lhs/concerns/record/endpoints.rb +1 -1
- data/lib/lhs/concerns/record/request.rb +1 -1
- data/lib/lhs/version.rb +1 -1
- data/spec/autoloading_spec.rb +2 -2
- data/spec/collection/collection_items_spec.rb +1 -1
- data/spec/collection/configurable_spec.rb +1 -1
- data/spec/collection/meta_data_spec.rb +4 -4
- data/spec/collection/without_object_items_spec.rb +1 -1
- data/spec/data/collection_spec.rb +1 -1
- data/spec/data/inspect_spec.rb +1 -1
- data/spec/data/item_spec.rb +2 -2
- data/spec/data/merge_spec.rb +2 -2
- data/spec/data/raw_spec.rb +3 -3
- data/spec/data/root_spec.rb +3 -3
- data/spec/data/select_spec.rb +1 -1
- data/spec/data/to_json_spec.rb +2 -2
- data/spec/dummy/app/models/user.rb +1 -1
- data/spec/endpoint/for_url_spec.rb +6 -6
- data/spec/item/becomes_spec.rb +2 -2
- data/spec/item/delegate_spec.rb +2 -2
- data/spec/item/destroy_spec.rb +3 -3
- data/spec/item/dig_spec.rb +1 -1
- data/spec/item/errors_spec.rb +2 -2
- data/spec/item/fetch_spec.rb +1 -1
- data/spec/item/getter_spec.rb +2 -2
- data/spec/item/internal_data_structure_spec.rb +2 -2
- data/spec/item/map_spec.rb +1 -1
- data/spec/item/partial_update_spec.rb +4 -4
- data/spec/item/save_spec.rb +2 -2
- data/spec/item/setter_spec.rb +2 -2
- data/spec/item/update_spec.rb +2 -2
- data/spec/item/validation_spec.rb +2 -2
- data/spec/pagination/pages_left_spec.rb +1 -1
- data/spec/proxy/create_sub_resource_spec.rb +2 -2
- data/spec/proxy/load_spec.rb +2 -2
- data/spec/proxy/record_identification_spec.rb +1 -1
- data/spec/record/build_spec.rb +2 -2
- data/spec/record/cast_nested_data_spec.rb +6 -6
- data/spec/record/create_spec.rb +2 -2
- data/spec/record/creation_failed_spec.rb +2 -2
- data/spec/record/definitions_spec.rb +2 -2
- data/spec/record/destroy_spec.rb +1 -1
- data/spec/record/endpoint_inheritance_spec.rb +3 -3
- data/spec/record/endpoint_misconfiguration_spec.rb +4 -4
- data/spec/record/endpoint_options_spec.rb +1 -1
- data/spec/record/endpoints_spec.rb +19 -19
- data/spec/record/find_by_spec.rb +4 -4
- data/spec/record/find_each_spec.rb +2 -2
- data/spec/record/find_in_batches_spec.rb +4 -4
- data/spec/record/find_in_parallel_spec.rb +1 -1
- data/spec/record/find_spec.rb +4 -4
- data/spec/record/first_spec.rb +2 -2
- data/spec/record/has_many_spec.rb +1 -1
- data/spec/record/ignore_errors_spec.rb +1 -1
- data/spec/record/includes_all_spec.rb +7 -7
- data/spec/record/includes_spec.rb +28 -28
- data/spec/record/includes_warning_spec.rb +1 -1
- data/spec/record/item_key_spec.rb +1 -1
- data/spec/record/loading_twice_spec.rb +2 -2
- data/spec/record/mapping_spec.rb +5 -5
- data/spec/record/model_name_spec.rb +1 -1
- data/spec/record/new_spec.rb +3 -3
- data/spec/record/options_spec.rb +2 -2
- data/spec/record/paginatable_collection_spec.rb +4 -4
- data/spec/record/pagination_chain_spec.rb +3 -3
- data/spec/record/pagination_spec.rb +1 -1
- data/spec/record/persisted_spec.rb +1 -1
- data/spec/record/references_spec.rb +1 -1
- data/spec/record/reload_by_id_spec.rb +2 -2
- data/spec/record/reload_spec.rb +2 -2
- data/spec/record/request_spec.rb +6 -6
- data/spec/record/save_spec.rb +1 -1
- data/spec/record/scope_chains_spec.rb +1 -1
- data/spec/record/to_json_spec.rb +1 -1
- data/spec/record/where_chains_spec.rb +1 -1
- data/spec/record/where_spec.rb +2 -2
- data/spec/record/where_values_hash_spec.rb +1 -1
- data/spec/request_cycle_cache/main_spec.rb +1 -1
- data/spec/views/form_for_spec.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0bd4227239bcdbb798aa8a247eafdde0d26281b1
|
4
|
+
data.tar.gz: 0dcbf3830c7adf536d74b815ba3ceb4ce9c3e0a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 55eb024313e5824288d2ec1741c6e3ec926200449e515d888be415552b9a39a86523d3e1b5e3edadd78ac48c9d881143e14e6f332ae26ee5957497c839b6a6a1
|
7
|
+
data.tar.gz: 4e975157294c34983a4c2e438f5f0fde7b0eade11768c894f8af72cd5f7dc98365c1429b2ce0b512986f3ced4e3da821fc14e3deb3190cd533800cdfa94e6cab
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ruby-2.3
|
1
|
+
ruby-2.4.3
|
data/README.md
CHANGED
@@ -20,13 +20,13 @@ end
|
|
20
20
|
|
21
21
|
## Very Short Introduction
|
22
22
|
|
23
|
-
Access data that is provided by an http
|
23
|
+
Access data that is provided by an http JSON service with ease using a LHS::Record.
|
24
24
|
|
25
25
|
```ruby
|
26
26
|
class Record < LHS::Record
|
27
27
|
|
28
|
-
endpoint '
|
29
|
-
endpoint '
|
28
|
+
endpoint '{+service}/v2/records'
|
29
|
+
endpoint '{+service}/v2/association/{association_id}/records'
|
30
30
|
|
31
31
|
end
|
32
32
|
|
@@ -36,7 +36,7 @@ record.review # "Lunch was great"
|
|
36
36
|
|
37
37
|
## Where to store LHS::Records
|
38
38
|
|
39
|
-
Please store all defined LHS::Records in `app/models` as they are not
|
39
|
+
Please store all defined LHS::Records in `app/models` as they are not auto loaded by rails otherwise.
|
40
40
|
|
41
41
|
## Endpoints
|
42
42
|
|
@@ -45,10 +45,10 @@ You setup a LHS::Record by configuring one or multiple endpoints. You can also a
|
|
45
45
|
```ruby
|
46
46
|
class Record < LHS::Record
|
47
47
|
|
48
|
-
endpoint '
|
49
|
-
endpoint '
|
50
|
-
endpoint '
|
51
|
-
endpoint '
|
48
|
+
endpoint '{+service}/v2/association/{association_id}/records'
|
49
|
+
endpoint '{+service}/v2/association/{association_id}/records/{id}'
|
50
|
+
endpoint '{+service}/v2/records', auth: { basic: 'PASSWORD' }
|
51
|
+
endpoint '{+service}/v2/records/{id}', auth: { basic: 'PASSWORD' }
|
52
52
|
|
53
53
|
end
|
54
54
|
```
|
@@ -61,8 +61,8 @@ If you try to setup a LHS::Record with clashing endpoints it will immediately ra
|
|
61
61
|
```ruby
|
62
62
|
class Record < LHS::Record
|
63
63
|
|
64
|
-
endpoint '
|
65
|
-
endpoint '
|
64
|
+
endpoint '{+service}/v2/records'
|
65
|
+
endpoint '{+service}/v2/something_else'
|
66
66
|
|
67
67
|
end
|
68
68
|
# raises: Clashing endpoints.
|
@@ -76,13 +76,13 @@ You can query a service for records by using `where`.
|
|
76
76
|
Record.where(color: 'blue')
|
77
77
|
```
|
78
78
|
|
79
|
-
This uses the
|
79
|
+
This uses the `{+service}/v2/records` endpoint, cause `{association_id}` was not provided. In addition it would add `?color=blue` to the get parameters.
|
80
80
|
|
81
81
|
```ruby
|
82
82
|
Record.where(association_id: 'fq-a81ngsl1d')
|
83
83
|
```
|
84
84
|
|
85
|
-
Uses the
|
85
|
+
Uses the `{+service}/v2/association/{association_id}/records` endpoint.
|
86
86
|
|
87
87
|
### Expand plain collection of links
|
88
88
|
|
@@ -118,7 +118,7 @@ That allows you to chain multiple where-queries:
|
|
118
118
|
```ruby
|
119
119
|
class Record < LHS::Record
|
120
120
|
endpoint 'records/'
|
121
|
-
endpoint 'records
|
121
|
+
endpoint 'records/{id}'
|
122
122
|
end
|
123
123
|
|
124
124
|
records = Record.where(color: 'blue')
|
@@ -151,12 +151,12 @@ expect(
|
|
151
151
|
|
152
152
|
## Scopes: Reuse where statements
|
153
153
|
|
154
|
-
In order to make common where statements reusable you can
|
154
|
+
In order to make common where statements reusable you can organize them in scopes:
|
155
155
|
|
156
156
|
```ruby
|
157
157
|
class Record < LHS::Record
|
158
158
|
endpoint 'records/'
|
159
|
-
endpoint 'records
|
159
|
+
endpoint 'records/{id}'
|
160
160
|
scope :blue, -> { where(color: 'blue') }
|
161
161
|
scope :available, ->(state) { where(available: state) }
|
162
162
|
end
|
@@ -171,7 +171,7 @@ One benefit of chains is lazy evaluation. This means they get resolved when data
|
|
171
171
|
|
172
172
|
To simplify error handling with chains, you can also chain error handlers to be resolved, as part of the chain.
|
173
173
|
|
174
|
-
In case no
|
174
|
+
In case no matching error handler is found the error gets re-raised.
|
175
175
|
|
176
176
|
```ruby
|
177
177
|
record = Record.where(color: 'blue')
|
@@ -193,7 +193,7 @@ record # nil
|
|
193
193
|
|
194
194
|
## Resolve chains
|
195
195
|
|
196
|
-
LHS Chains can be resolved with `fetch`,
|
196
|
+
LHS Chains can be resolved with `fetch`, similar to ActiveRecord:
|
197
197
|
|
198
198
|
```ruby
|
199
199
|
records = Record.where(color: 'blue').fetch
|
@@ -201,7 +201,7 @@ records = Record.where(color: 'blue').fetch
|
|
201
201
|
|
202
202
|
## Find single records
|
203
203
|
|
204
|
-
`find` finds a unique record by unique identifier (
|
204
|
+
`find` finds a unique record by unique identifier (usually id or href).
|
205
205
|
|
206
206
|
```ruby
|
207
207
|
Record.find(123)
|
@@ -268,7 +268,7 @@ After fetching [single](#find-single-records) or [multiple](#find-multiple-recor
|
|
268
268
|
|
269
269
|
## Relations
|
270
270
|
|
271
|
-
Even though, nested data is automatically casted when accessed, see: [Nested records](#nested-records), sometimes api's don't provide dedicated endpoints to
|
271
|
+
Even though, nested data is automatically casted when accessed, see: [Nested records](#nested-records), sometimes api's don't provide dedicated endpoints to retrieve these records.
|
272
272
|
|
273
273
|
As those records also don't have an href, nested records can not be casted automatically, when accessed.
|
274
274
|
|
@@ -277,15 +277,15 @@ Those kind of relations, you can still configure manually:
|
|
277
277
|
```ruby
|
278
278
|
|
279
279
|
class Location < LHS::Record
|
280
|
-
|
281
|
-
endpoint 'http://uberall/locations
|
280
|
+
|
281
|
+
endpoint 'http://uberall/locations/{id}'
|
282
282
|
|
283
283
|
has_many :listings
|
284
284
|
|
285
285
|
end
|
286
286
|
|
287
287
|
class Listing < LHS::Record
|
288
|
-
|
288
|
+
|
289
289
|
def supported?
|
290
290
|
type == 'SUPPORTED'
|
291
291
|
end
|
@@ -329,7 +329,7 @@ By default, LHS does not perform the same http request during one request cycle
|
|
329
329
|
|
330
330
|
It uses the [LHC Caching Interceptor](https://github.com/local-ch/lhc/blob/master/docs/interceptors/caching.md) as caching mechanism base and sets a unique request id for every request cycle with Railties to ensure data is just cached within one request cycle and not shared with other requests.
|
331
331
|
|
332
|
-
Only GET requests are considered for caching by using LHC Caching Interceptor's `cache_methods` option
|
332
|
+
Only GET requests are considered for caching by using LHC Caching Interceptor's `cache_methods` option internally and considers request headers when caching requests, so requests with different headers are not served from cache.
|
333
333
|
|
334
334
|
The LHS Request Cycle Cache is opt-out, so it's enabled by default and will require you to enable the [LHC Caching Interceptor](https://github.com/local-ch/lhc/blob/master/docs/interceptors/caching.md) in your project.
|
335
335
|
|
@@ -374,7 +374,7 @@ In case an API does not provide pagination information (limit, offset and total)
|
|
374
374
|
|
375
375
|
```ruby
|
376
376
|
Record.find_each(start: 50, batch_size: 20, params: { has_reviews: true }) do |record|
|
377
|
-
# Iterates over each record. Starts with record
|
377
|
+
# Iterates over each record. Starts with record no. 50 and fetches 20 records each batch.
|
378
378
|
record
|
379
379
|
break if record.some_attribute == some_value
|
380
380
|
end
|
@@ -383,7 +383,7 @@ end
|
|
383
383
|
`find_in_batches` is used by `find_each` and processes batches.
|
384
384
|
```ruby
|
385
385
|
Record.find_in_batches(start: 50, batch_size: 20, params: { has_reviews: true }) do |records|
|
386
|
-
# Iterates over multiple records (batch size is 20). Starts with record
|
386
|
+
# Iterates over multiple records (batch size is 20). Starts with record no. 50 and fetches 20 records each batch.
|
387
387
|
records
|
388
388
|
break if records.first.name == some_value
|
389
389
|
end
|
@@ -405,11 +405,11 @@ See [Validation](#Validation) for handling validation errors when creating recor
|
|
405
405
|
|
406
406
|
```ruby
|
407
407
|
class Review < LHS::Record
|
408
|
-
endpoint '
|
408
|
+
endpoint '{+service}/reviews'
|
409
409
|
end
|
410
410
|
|
411
411
|
class Comment < LHS::Record
|
412
|
-
endpoint '
|
412
|
+
endpoint '{+service}/reviews/{review_id/}comments'
|
413
413
|
end
|
414
414
|
```
|
415
415
|
|
@@ -417,20 +417,20 @@ See [Validation](#Validation) for handling validation errors when creating recor
|
|
417
417
|
```ruby
|
418
418
|
review = Review.find(1)
|
419
419
|
# Review#1
|
420
|
-
# :href => '
|
420
|
+
# :href => '{+service}/reviews/1
|
421
421
|
# :text => 'Simply awesome'
|
422
|
-
# :comment => { :href => '
|
422
|
+
# :comment => { :href => '{+service}/reviews/1/comments }
|
423
423
|
|
424
424
|
review.comment.create(text: 'Thank you!')
|
425
425
|
# Comment#1
|
426
|
-
# :href => '
|
426
|
+
# :href => '{+service}/reviews/1/comments
|
427
427
|
# :text => 'Thank you!'
|
428
428
|
|
429
429
|
review
|
430
430
|
# Review#1
|
431
|
-
# :href => '
|
431
|
+
# :href => '{+service}/reviews/1
|
432
432
|
# :text => 'Simply awesome'
|
433
|
-
# :comment => { :href => '
|
433
|
+
# :comment => { :href => '{+service}/reviews/1/comments, :text => 'Thank you!' }
|
434
434
|
```
|
435
435
|
|
436
436
|
If the item already exists `ArgumentError` is raised.
|
@@ -439,40 +439,40 @@ If the item already exists `ArgumentError` is raised.
|
|
439
439
|
```ruby
|
440
440
|
review = Review.includes(:comments).find(1)
|
441
441
|
# Review#1
|
442
|
-
# :href => '
|
442
|
+
# :href => '{+service}/reviews/1'
|
443
443
|
# :text => 'Simply awesome'
|
444
|
-
# :comments => { :href => '
|
444
|
+
# :comments => { :href => '{+service}/reviews/1/comments, :items => [] }
|
445
445
|
|
446
446
|
review.comments.create(text: 'Thank you!')
|
447
447
|
# Comment#1
|
448
|
-
# :href => '
|
448
|
+
# :href => '{+service}/reviews/1/comments/1'
|
449
449
|
# :text => 'Thank you!'
|
450
450
|
|
451
451
|
review
|
452
452
|
# Review#1
|
453
|
-
# :href => '
|
453
|
+
# :href => '{+service}/reviews/1'
|
454
454
|
# :text => 'Simply awesome'
|
455
|
-
# :comments => { :href => '
|
455
|
+
# :comments => { :href => '{+service}/reviews/1/comments, :items => [{ :href => '{+service}/reviews/1/comments/1', :text => 'Thank you!' }] }
|
456
456
|
```
|
457
457
|
|
458
458
|
### Not expanded collection
|
459
459
|
```ruby
|
460
460
|
review = Review.find(1)
|
461
461
|
# Review#1
|
462
|
-
# :href => '
|
462
|
+
# :href => '{+service}/reviews/1'
|
463
463
|
# :text => 'Simply awesome'
|
464
|
-
# :comments => { :href => '
|
464
|
+
# :comments => { :href => '{+service}/reviews/1/comments' }
|
465
465
|
|
466
466
|
review.comments.create(text: 'Thank you!')
|
467
467
|
# Comment#1
|
468
|
-
# :href => '
|
468
|
+
# :href => '{+service}/reviews/1/comments/1'
|
469
469
|
# :text => 'Thank you!'
|
470
470
|
|
471
471
|
review
|
472
472
|
# Review#1
|
473
|
-
# :href => '
|
473
|
+
# :href => '{+service}/reviews/1
|
474
474
|
# :text => 'Simply awesome'
|
475
|
-
# :comments => { :href => '
|
475
|
+
# :comments => { :href => '{+service}/reviews/1/comments', :items => [{ :href => '{+service}/reviews/1/comments/1', :text => 'Thank you!' }] }
|
476
476
|
```
|
477
477
|
|
478
478
|
## Build new records
|
@@ -632,15 +632,15 @@ The [Auth Inteceptor](https://github.com/local-ch/lhc-core-interceptors#auth-int
|
|
632
632
|
```ruby
|
633
633
|
class Favorite < LHS::Record
|
634
634
|
|
635
|
-
endpoint '
|
636
|
-
endpoint '
|
635
|
+
endpoint '{+service}/{user_id}/favorites', auth: { basic: { username: 'steve', password: 'can' } }
|
636
|
+
endpoint '{+service}/{user_id}/favorites/:id', auth: { basic: { username: 'steve', password: 'can' } }
|
637
637
|
|
638
638
|
end
|
639
639
|
|
640
640
|
class Place < LHS::Record
|
641
641
|
|
642
|
-
endpoint '
|
643
|
-
endpoint '
|
642
|
+
endpoint '{+service}/v2/places', auth: { basic: { username: 'steve', password: 'can' } }
|
643
|
+
endpoint '{+service}/v2/places/{id}', auth: { basic: { username: 'steve', password: 'can' } }
|
644
644
|
|
645
645
|
end
|
646
646
|
|
@@ -660,7 +660,7 @@ Provide options to the requests made to include referenced resources:
|
|
660
660
|
|
661
661
|
## Map data
|
662
662
|
|
663
|
-
To influence how data is accessed/
|
663
|
+
To influence how data is accessed/provided, you can use mappings to either map deep nested data or to manipulate data when its accessed. Simply create methods inside the LHS::Record. They can access underlying data:
|
664
664
|
|
665
665
|
```ruby
|
666
666
|
class LocalEntry < LHS::Record
|
@@ -675,11 +675,11 @@ end
|
|
675
675
|
|
676
676
|
## Nested records
|
677
677
|
|
678
|
-
Nested records (in nested data) are
|
678
|
+
Nested records (in nested data) are automatically casted when the href matches any defined endpoint of any LHS::Record.
|
679
679
|
|
680
680
|
```ruby
|
681
681
|
class Place < LHS::Record
|
682
|
-
endpoint '
|
682
|
+
endpoint '{+service}/v2/places'
|
683
683
|
|
684
684
|
def name
|
685
685
|
addresses.first.business.identities.first.name
|
@@ -687,7 +687,7 @@ class Place < LHS::Record
|
|
687
687
|
end
|
688
688
|
|
689
689
|
class Favorite < LHS::Record
|
690
|
-
endpoint '
|
690
|
+
endpoint '{+service}/v2/favorites'
|
691
691
|
end
|
692
692
|
|
693
693
|
favorite = Favorite.includes(:place).find(1)
|
@@ -753,11 +753,11 @@ _NOTE: RPC-style actions, that are discouraged in REST anyway, are utilizable wi
|
|
753
753
|
```ruby
|
754
754
|
class Location < LHS::Record
|
755
755
|
endpoint 'http://sync/locations'
|
756
|
-
endpoint 'http://sync/locations
|
756
|
+
endpoint 'http://sync/locations/{id}'
|
757
757
|
end
|
758
758
|
|
759
759
|
class Synchronization < LHS::Record
|
760
|
-
endpoint 'http://sync/locations
|
760
|
+
endpoint 'http://sync/locations/{id}/sync'
|
761
761
|
end
|
762
762
|
|
763
763
|
location = Location.find(1)
|
@@ -790,14 +790,14 @@ or with parameters:
|
|
790
790
|
|
791
791
|
In order to validate LHS::Records before persisting them, you can use the `valid?` (`validate` alias) method.
|
792
792
|
|
793
|
-
The specific endpoint has to support validations without
|
793
|
+
The specific endpoint has to support validations without persistence. An endpoint has to be enabled (opt-in) for validations in the service configuration.
|
794
794
|
|
795
795
|
```ruby
|
796
796
|
class User < LHS::Record
|
797
|
-
endpoint '
|
797
|
+
endpoint '{+service}/v2/users', validates: { params: { persist: false } }
|
798
798
|
end
|
799
799
|
|
800
|
-
user = User.build(email: '
|
800
|
+
user = User.build(email: 'i\'m not an email address')
|
801
801
|
unless user.valid?
|
802
802
|
fail(user.errors[:email])
|
803
803
|
end
|
@@ -813,10 +813,10 @@ user.errors.message # email must be set when user is created."
|
|
813
813
|
The parameters passed to the `validates` endpoint option are used to perform the validation:
|
814
814
|
|
815
815
|
```ruby
|
816
|
-
endpoint '
|
817
|
-
endpoint '
|
818
|
-
endpoint '
|
819
|
-
endpoint '
|
816
|
+
endpoint '{+service}/v2/users', validates: { params: { persist: false } } # will add ?persist=false to the request
|
817
|
+
endpoint '{+service}/v2/users', validates: { params: { publish: false } } # will add ?publish=false to the request
|
818
|
+
endpoint '{+service}/v2/users', validates: { params: { validates: true } } # will add ?validates=true to the request
|
819
|
+
endpoint '{+service}/v2/users', validates: { path: 'validate' } # will perform a validation via :service/v2/users/validate
|
820
820
|
```
|
821
821
|
|
822
822
|
### HTTP Status Codes for validation errors
|
@@ -953,7 +953,7 @@ Warnings behave like [Validation Errors](#Validation) and implements the same in
|
|
953
953
|
|
954
954
|
LHS supports paginated APIs and it also supports various pagination strategies and by providing configuration possibilities.
|
955
955
|
|
956
|
-
LHS
|
956
|
+
LHS differentiates between the *pagination strategy* (how items/pages are navigated) itself and *pagination keys* (how stuff is named).
|
957
957
|
|
958
958
|
*Example 1 "offset"-strategy (default configuration)*
|
959
959
|
```ruby
|
@@ -1019,7 +1019,7 @@ class Search < LHS::Record
|
|
1019
1019
|
end
|
1020
1020
|
```
|
1021
1021
|
|
1022
|
-
`item_key` key used to unwrap the
|
1022
|
+
`item_key` key used to unwrap the actual object from within the response body.
|
1023
1023
|
|
1024
1024
|
`items_key` key used to determine items of the current page (e.g. `docs`, `items`, etc.).
|
1025
1025
|
|
@@ -1027,7 +1027,7 @@ end
|
|
1027
1027
|
|
1028
1028
|
`limit_key` key used to work with page limits (e.g. `size`, `limit`, etc.)
|
1029
1029
|
|
1030
|
-
In case the `limit_key` parameter differs for where it's located in the body and how it's provided as get parameter, when retreiving pages, provide a hash with `body` and `
|
1030
|
+
In case the `limit_key` parameter differs for where it's located in the body and how it's provided as get parameter, when retreiving pages, provide a hash with `body` and `parameter` key, to keep those two use cases separated:
|
1031
1031
|
|
1032
1032
|
```ruby
|
1033
1033
|
configuration limit_key: { body: [:response, :max], parameter: :max }
|
@@ -1035,7 +1035,7 @@ In case the `limit_key` parameter differs for where it's located in the body and
|
|
1035
1035
|
|
1036
1036
|
`pagination_key` key used to paginate multiple pages (e.g. `offset`, `page`, `startAt` etc.).
|
1037
1037
|
|
1038
|
-
In case the `pagination_key` parameter differs for where it's located in the body and how it's provided as get parameter, when retreiving pages, provide a hash with `body` and `
|
1038
|
+
In case the `pagination_key` parameter differs for where it's located in the body and how it's provided as get parameter, when retreiving pages, provide a hash with `body` and `parameter` key, to keep those two use cases separated:
|
1039
1039
|
|
1040
1040
|
```ruby
|
1041
1041
|
configuration pagination_key: { body: [:response, :page], parameter: :page }
|
@@ -1125,7 +1125,7 @@ The applied pagination strategy depends on the actual configured pagination, so
|
|
1125
1125
|
|
1126
1126
|
```ruby
|
1127
1127
|
class Record < LHS::Record
|
1128
|
-
endpoint '
|
1128
|
+
endpoint '{+service}/records'
|
1129
1129
|
configuration pagination_strategy: 'page'
|
1130
1130
|
end
|
1131
1131
|
Record.page(3).per(20).where(color: 'blue')
|
@@ -1134,7 +1134,7 @@ The applied pagination strategy depends on the actual configured pagination, so
|
|
1134
1134
|
|
1135
1135
|
```ruby
|
1136
1136
|
class Record < LHS::Record
|
1137
|
-
endpoint '
|
1137
|
+
endpoint '{+service}/records'
|
1138
1138
|
configuration pagination_strategy: 'start'
|
1139
1139
|
end
|
1140
1140
|
Record.page(3).per(20).where(color: 'blue')
|
@@ -1172,7 +1172,7 @@ When endpoints provide indicators for current page position with links (like `ne
|
|
1172
1172
|
|
1173
1173
|
How to configure endpoints for automatic collection detection?
|
1174
1174
|
|
1175
|
-
LHS detects
|
1175
|
+
LHS detects automatically if the responded data is a single business object or a set of business objects (collection).
|
1176
1176
|
|
1177
1177
|
Conventionally, when the responds contains an `items` key `{ items: [] }` it's treated as a collection, but also if the responds contains a plain raw array: `[{ href: '' }]` it's also treated as a collection.
|
1178
1178
|
|
@@ -1196,7 +1196,7 @@ Rails `form_for` view-helper can be used in combination with instances of LHS::R
|
|
1196
1196
|
|
1197
1197
|
## Count vs. Length
|
1198
1198
|
|
1199
|
-
The
|
1199
|
+
The behavior of `count` and `length` is based on ActiveRecord's behavior.
|
1200
1200
|
|
1201
1201
|
`count` Determine the number of elements by taking the number of total elements that is provided by the endpoint/api.
|
1202
1202
|
|
@@ -1208,7 +1208,7 @@ You can inherit from previously defined records and also inherit endpoints that
|
|
1208
1208
|
|
1209
1209
|
```
|
1210
1210
|
class Base < LHS::Record
|
1211
|
-
endpoint 'records
|
1211
|
+
endpoint 'records/{id}'
|
1212
1212
|
end
|
1213
1213
|
|
1214
1214
|
class Example < Base
|
data/lhs.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.requirements << 'Ruby >= 2.3.0'
|
21
21
|
s.required_ruby_version = '>= 2.3.0'
|
22
22
|
|
23
|
-
s.add_dependency 'lhc', '>=
|
23
|
+
s.add_dependency 'lhc', '>= 7.0.0'
|
24
24
|
s.add_dependency 'activesupport', '> 4.2'
|
25
25
|
s.add_dependency 'activemodel'
|
26
26
|
|