lhs 21.3.0.pre.autoauth.1 → 22.1.1.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +205 -117
- data/lhs.gemspec +1 -1
- data/lib/lhs/concerns/record/chainable.rb +4 -4
- data/lib/lhs/concerns/record/configuration.rb +23 -14
- data/lib/lhs/concerns/record/request.rb +29 -32
- data/lib/lhs/concerns/record/update.rb +17 -0
- data/lib/lhs/interceptors/auto_oauth/interceptor.rb +16 -1
- data/lib/lhs/record.rb +6 -3
- data/lib/lhs/version.rb +1 -1
- data/spec/auto_oauth_spec.rb +141 -23
- data/spec/dummy/app/controllers/application_controller.rb +9 -1
- data/spec/dummy/app/controllers/automatic_authentication_controller.rb +18 -0
- data/spec/dummy/app/models/dummy_record_with_auto_oauth_provider.rb +6 -0
- data/spec/dummy/app/models/dummy_record_with_multiple_oauth_providers1.rb +7 -0
- data/spec/dummy/app/models/dummy_record_with_multiple_oauth_providers2.rb +7 -0
- data/spec/dummy/app/models/dummy_record_with_multiple_providers_per_endpoint.rb +6 -0
- data/spec/dummy/app/models/providers/internal_services.rb +7 -0
- data/spec/dummy/config/routes.rb +2 -0
- data/spec/item/destroy_spec.rb +1 -1
- data/spec/proxy/record_identification_spec.rb +1 -1
- data/spec/record/all_spec.rb +1 -1
- data/spec/record/endpoints_spec.rb +1 -1
- data/spec/record/handle_includes_errors_spec.rb +1 -1
- data/spec/record/has_many_spec.rb +1 -1
- data/spec/record/has_one_spec.rb +1 -1
- data/spec/record/includes_first_page_spec.rb +727 -0
- data/spec/record/includes_spec.rb +545 -579
- data/spec/record/includes_warning_spec.rb +1 -1
- data/spec/record/mapping_spec.rb +2 -2
- data/spec/record/references_spec.rb +1 -1
- data/spec/record/relation_caching_spec.rb +3 -3
- data/spec/record/update_spec.rb +62 -0
- metadata +21 -10
- data/spec/dummy/config/initializers/lhs.rb +0 -3
- data/spec/record/includes_all_spec.rb +0 -693
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16eb1258e85aa5df4d0e727f4c0d76d2d9dfb7c90431d0bfe3fb6d91fa017c01
|
4
|
+
data.tar.gz: 9ba046b707ca2ada6faec0723b11567beab63a071bebb246314a00329ba56244
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce04f36ec3df38081737a718f81ff3714e41aadb429392bc881cd206d602686aab0d80d47ebe931a8d900b18535c01fde05c5e788592df12f635c7e26ff81efa
|
7
|
+
data.tar.gz: 1962f862a8699cf5f9c39f2076092eabe8d76e759f2f0b458b71db3713a65092a846cbf4ffbdabfbe745d57c33449259df987a61addaba1315828fc1bd4a310d
|
data/README.md
CHANGED
@@ -39,113 +39,118 @@ record.review # "Lunch was great
|
|
39
39
|
|
40
40
|
## Table of contents
|
41
41
|
* [LHS](#lhs)
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
42
|
+
* [Quickstart](#quickstart)
|
43
|
+
* [Installation/Startup checklist](#installationstartup-checklist)
|
44
|
+
* [Record](#record)
|
45
|
+
* [Endpoints](#endpoints)
|
46
|
+
* [Configure endpoint hosts](#configure-endpoint-hosts)
|
47
|
+
* [Endpoint Priorities](#endpoint-priorities)
|
48
|
+
* [Provider](#provider)
|
49
|
+
* [Record inheritance](#record-inheritance)
|
50
|
+
* [Find multiple records](#find-multiple-records)
|
51
|
+
* [fetch](#fetch)
|
52
|
+
* [where](#where)
|
53
|
+
* [Reuse/Dry where statements: Use scopes](#reusedry-where-statements-use-scopes)
|
54
|
+
* [all](#all)
|
55
|
+
* [all with unpaginated endpoints](#all-with-unpaginated-endpoints)
|
56
|
+
* [Retrieve the amount of a collection of items: count vs. length](#retrieve-the-amount-of-a-collection-of-items-count-vs-length)
|
57
|
+
* [Find single records](#find-single-records)
|
58
|
+
* [find](#find)
|
59
|
+
* [find_by](#find_by)
|
60
|
+
* [first](#first)
|
61
|
+
* [last](#last)
|
62
|
+
* [Work with retrieved data](#work-with-retrieved-data)
|
63
|
+
* [Automatic detection/conversion of collections](#automatic-detectionconversion-of-collections)
|
64
|
+
* [Map complex data for easy access](#map-complex-data-for-easy-access)
|
65
|
+
* [Access and identify nested records](#access-and-identify-nested-records)
|
66
|
+
* [Relations / Associations](#relations--associations)
|
67
|
+
* [has_many](#has_many)
|
68
|
+
* [has_one](#has_one)
|
69
|
+
* [Unwrap nested items from the response body](#unwrap-nested-items-from-the-response-body)
|
70
|
+
* [Determine collections from the response body](#determine-collections-from-the-response-body)
|
71
|
+
* [Load additional data based on retrieved data](#load-additional-data-based-on-retrieved-data)
|
72
|
+
* [Chain complex queries](#chain-complex-queries)
|
73
|
+
* [Chain where queries](#chain-where-queries)
|
74
|
+
* [Expand plain collections of links: expanded](#expand-plain-collections-of-links-expanded)
|
75
|
+
* [Error handling with chains](#error-handling-with-chains)
|
76
|
+
* [Resolve chains: fetch](#resolve-chains-fetch)
|
77
|
+
* [Add request options to a query chain: options](#add-request-options-to-a-query-chain-options)
|
78
|
+
* [Control pagination within a query chain](#control-pagination-within-a-query-chain)
|
79
|
+
* [Record pagination](#record-pagination)
|
80
|
+
* [Pagination strategy](#pagination-strategy)
|
81
|
+
* [Pagination strategy: offset (default)](#pagination-strategy-offset-default)
|
82
|
+
* [Pagination strategy: page](#pagination-strategy-page)
|
83
|
+
* [Pagination strategy: start](#pagination-strategy-start)
|
84
|
+
* [Pagination strategy: link](#pagination-strategy-link)
|
85
|
+
* [Pagination keys](#pagination-keys)
|
86
|
+
* [limit_key](#limit_key)
|
87
|
+
* [pagination_key](#pagination_key)
|
88
|
+
* [total_key](#total_key)
|
89
|
+
* [Pagination links](#pagination-links)
|
90
|
+
* [next?](#next)
|
91
|
+
* [previous?](#previous)
|
92
|
+
* [Kaminari support (limited)](#kaminari-support-limited)
|
93
|
+
* [Build, create and update records](#build-create-and-update-records)
|
94
|
+
* [Create new records](#create-new-records)
|
95
|
+
* [create](#create)
|
96
|
+
* [Unwrap nested data when creation response nests created record data](#unwrap-nested-data-when-creation-response-nests-created-record-data)
|
97
|
+
* [Create records through associations: Nested sub resources](#create-records-through-associations-nested-sub-resources)
|
98
|
+
* [Start building new records](#start-building-new-records)
|
99
|
+
* [Change/Update existing records](#changeupdate-existing-records)
|
100
|
+
* [save](#save)
|
101
|
+
* [update](#update)
|
102
|
+
* [partial_update](#partial_update)
|
103
|
+
* [Endpoint url parameter injection during record creation/change](#endpoint-url-parameter-injection-during-record-creationchange)
|
104
|
+
* [Record validation](#record-validation)
|
105
|
+
* [Configure record validations](#configure-record-validations)
|
106
|
+
* [HTTP Status Codes for validation errors](#http-status-codes-for-validation-errors)
|
107
|
+
* [Reset validation errors](#reset-validation-errors)
|
108
|
+
* [Add validation errors](#add-validation-errors)
|
109
|
+
* [Validation errors for nested data](#validation-errors-for-nested-data)
|
110
|
+
* [Translation of validation errors](#translation-of-validation-errors)
|
111
|
+
* [Validation error types: errors vs. warnings](#validation-error-types-errors-vs-warnings)
|
112
|
+
* [Persistance failed: errors](#persistance-failed-errors)
|
113
|
+
* [Persistance succeeded: warnings](#persistance-succeeded-warnings)
|
114
|
+
* [Using ActiveModel::Validations none the less](#using-activemodelvalidations-none-the-less)
|
115
|
+
* [Use form_helper to create and update records](#use-form_helper-to-create-and-update-records)
|
116
|
+
* [Destroy records](#destroy-records)
|
117
|
+
* [Record getters and setters](#record-getters-and-setters)
|
118
|
+
* [Record setters](#record-setters)
|
119
|
+
* [Record getters](#record-getters)
|
120
|
+
* [Include linked resources (hyperlinks and hypermedia)](#include-linked-resources-hyperlinks-and-hypermedia)
|
121
|
+
* [Generate links from parameters](#generate-links-from-parameters)
|
122
|
+
* [Ensure the whole linked collection is included: includes_all](#ensure-the-whole-linked-collection-is-included-includes_all)
|
123
|
+
* [Include the first linked page or single item is included: include](#include-the-first-linked-page-or-single-item-is-included-include)
|
124
|
+
* [Include various levels of linked data](#include-various-levels-of-linked-data)
|
125
|
+
* [Identify and cast known records when including records](#identify-and-cast-known-records-when-including-records)
|
126
|
+
* [Apply options for requests performed to fetch included records](#apply-options-for-requests-performed-to-fetch-included-records)
|
127
|
+
* [Record batch processing](#record-batch-processing)
|
128
|
+
* [all](#all-1)
|
129
|
+
* [Using all, when endpoint does not implement response pagination meta data](#using-all-when-endpoint-does-not-implement-response-pagination-meta-data)
|
130
|
+
* [find_each](#find_each)
|
131
|
+
* [find_in_batches](#find_in_batches)
|
132
|
+
* [Convert/Cast specific record types: becomes](#convertcast-specific-record-types-becomes)
|
133
|
+
* [Assign attributes](#assign-attributes)
|
134
|
+
* [Request Cycle Cache](#request-cycle-cache)
|
135
|
+
* [Change store for LHS' request cycle cache](#change-store-for-lhs-request-cycle-cache)
|
136
|
+
* [Disable request cycle cache](#disable-request-cycle-cache)
|
137
|
+
* [Automatic Authentication (OAuth)](#automatic-authentication-oauth)
|
138
|
+
* [Configure multiple auth providers (even per endpoint)](#configure-multiple-auth-providers-even-per-endpoint)
|
139
|
+
* [Configure providers](#configure-providers)
|
140
|
+
* [Option Blocks](#option-blocks)
|
141
|
+
* [Request tracing](#request-tracing)
|
142
|
+
* [Extended Rollbar Logging](#extended-rollbar-logging)
|
143
|
+
* [Testing with LHS](#testing-with-lhs)
|
144
|
+
* [Test helper](#test-helper)
|
145
|
+
* [Stub](#stub)
|
146
|
+
* [stub_all](#stub_all)
|
147
|
+
* [Test query chains](#test-query-chains)
|
148
|
+
* [By explicitly resolving the chain: fetch](#by-explicitly-resolving-the-chain-fetch)
|
149
|
+
* [Without resolving the chain: where_values_hash](#without-resolving-the-chain-where_values_hash)
|
150
|
+
* [License](#license)
|
151
|
+
|
152
|
+
|
153
|
+
|
149
154
|
|
150
155
|
## Installation/Startup checklist
|
151
156
|
|
@@ -1602,6 +1607,21 @@ POST https://service.example.com/records/1z-5r1fkaj { body: "{ 'name': 'Starbuck
|
|
1602
1607
|
|
1603
1608
|
##### update
|
1604
1609
|
|
1610
|
+
###### Directly via Record
|
1611
|
+
|
1612
|
+
```ruby
|
1613
|
+
# app/controllers/some_controller.rb
|
1614
|
+
|
1615
|
+
Record.update(id: '1z-5r1fkaj', name: 'Steve')
|
1616
|
+
|
1617
|
+
```
|
1618
|
+
```
|
1619
|
+
GET https://service.example.com/records/1z-5r1fkaj
|
1620
|
+
{ name: 'Steve' }
|
1621
|
+
```
|
1622
|
+
|
1623
|
+
###### per Instance
|
1624
|
+
|
1605
1625
|
`update` persists the whole object after new parameters are applied through arguments.
|
1606
1626
|
|
1607
1627
|
`update` will return false if persisting fails. `update!` instead will raise an exception.
|
@@ -2088,7 +2108,7 @@ In a service-oriented architecture using [hyperlinks](https://en.wikipedia.org/w
|
|
2088
2108
|
|
2089
2109
|
When fetching records with LHS, you can specify in advance all the linked resources that you want to include in the results.
|
2090
2110
|
|
2091
|
-
With `includes`
|
2111
|
+
With `includes` LHS ensures that all matching and explicitly linked resources are loaded and merged (even if the linked resources are paginated).
|
2092
2112
|
|
2093
2113
|
Including linked resources/records is heavily influenced by [https://guides.rubyonrails.org/active_record_querying.html](https://guides.rubyonrails.org/active_record_querying.html#eager-loading-associations) and you should read it to understand this feature in all it's glory.
|
2094
2114
|
|
@@ -2107,16 +2127,16 @@ Presence.create(place: { href: Place.href_for(123) })
|
|
2107
2127
|
POST '/presences' { place: { href: "http://datastore/places/123" } }
|
2108
2128
|
```
|
2109
2129
|
|
2110
|
-
#### Ensure the whole linked collection is included
|
2130
|
+
#### Ensure the whole linked collection is included with includes
|
2111
2131
|
|
2112
|
-
In case endpoints are paginated and you are certain that you'll need all objects of a set and not only the first page/batch, use `
|
2132
|
+
In case endpoints are paginated and you are certain that you'll need all objects of a set and not only the first page/batch, use `includes`.
|
2113
2133
|
|
2114
2134
|
LHS will ensure that all linked resources are around by loading all pages (parallelized/performance optimized).
|
2115
2135
|
|
2116
2136
|
```ruby
|
2117
2137
|
# app/controllers/some_controller.rb
|
2118
2138
|
|
2119
|
-
customer = Customer.
|
2139
|
+
customer = Customer.includes(contracts: :products).find(1)
|
2120
2140
|
```
|
2121
2141
|
```
|
2122
2142
|
> GET https://service.example.com/customers/1
|
@@ -2143,14 +2163,14 @@ customer.contracts.first.products.first.name # Local Business Card
|
|
2143
2163
|
|
2144
2164
|
```
|
2145
2165
|
|
2146
|
-
#### Include the first linked page
|
2166
|
+
#### Include only the first linked page of a linked collection: includes_first_page
|
2147
2167
|
|
2148
|
-
`
|
2168
|
+
`includes_first_page` includes the first page/response when loading the linked resource. **If the endpoint is paginated, only the first page will be included.**
|
2149
2169
|
|
2150
2170
|
```ruby
|
2151
2171
|
# app/controllers/some_controller.rb
|
2152
2172
|
|
2153
|
-
customer = Customer.
|
2173
|
+
customer = Customer.includes_first_page(contracts: :products).find(1)
|
2154
2174
|
```
|
2155
2175
|
```
|
2156
2176
|
> GET https://service.example.com/customers/1
|
@@ -2174,7 +2194,7 @@ customer.contracts.first.products.first.name # Local Business Card
|
|
2174
2194
|
|
2175
2195
|
#### Include various levels of linked data
|
2176
2196
|
|
2177
|
-
The method syntax of `includes`
|
2197
|
+
The method syntax of `includes` allows you include hyperlinks stored in deep nested data strutures:
|
2178
2198
|
|
2179
2199
|
Some examples:
|
2180
2200
|
|
@@ -2194,7 +2214,7 @@ Record.includes(campaign: [:entry, :user])
|
|
2194
2214
|
|
2195
2215
|
#### Identify and cast known records when including records
|
2196
2216
|
|
2197
|
-
When including linked resources with `includes
|
2217
|
+
When including linked resources with `includes`, already defined records and their endpoints and configurations are used to make the requests to fetch the additional data.
|
2198
2218
|
|
2199
2219
|
That also means that options for endpoints of linked resources are applied when requesting those in addition.
|
2200
2220
|
|
@@ -2450,7 +2470,7 @@ LHS provides a way to have records automatically fetch and use OAuth authenticat
|
|
2450
2470
|
|
2451
2471
|
In order to enable automatic oauth authentication, perform the following steps:
|
2452
2472
|
|
2453
|
-
1. Make sure LHS is configured to perform `auto_oauth`. Provide a block that when executed in the controller context returns a valid access_token/bearer_token.
|
2473
|
+
1. Make sure LHS is configured to perform `auto_oauth`. Provide a block that, when executed in the controller context, returns a valid access_token/bearer_token.
|
2454
2474
|
```ruby
|
2455
2475
|
# config/initializers/lhs.rb
|
2456
2476
|
|
@@ -2504,6 +2524,74 @@ https://records/1
|
|
2504
2524
|
Authentication: 'Bearer token-12345'
|
2505
2525
|
```
|
2506
2526
|
|
2527
|
+
### Configure multiple auth providers (even per endpoint)
|
2528
|
+
|
2529
|
+
In case you need to configure multiple auth provider access_tokens within your application,
|
2530
|
+
make sure you provide a proc returning a hash when configuring `auto_oauth`,
|
2531
|
+
naming every single provider and the responsive method to retrieve the access_tokens in the controller context:
|
2532
|
+
|
2533
|
+
```ruby
|
2534
|
+
# config/initializers/lhs.rb
|
2535
|
+
LHS.configure do |config|
|
2536
|
+
config.auto_oauth = proc do
|
2537
|
+
{
|
2538
|
+
provider1: access_token_provider_1,
|
2539
|
+
provider2: access_token_provider_2
|
2540
|
+
}
|
2541
|
+
end
|
2542
|
+
end
|
2543
|
+
```
|
2544
|
+
|
2545
|
+
Then make sure you either define which provider to use on a record level:
|
2546
|
+
|
2547
|
+
```ruby
|
2548
|
+
# model/record.rb
|
2549
|
+
class Record < LHS::Record
|
2550
|
+
oauth(:provider1)
|
2551
|
+
#...
|
2552
|
+
end
|
2553
|
+
```
|
2554
|
+
|
2555
|
+
or on an endpoint level:
|
2556
|
+
|
2557
|
+
```ruby
|
2558
|
+
# model/record.rb
|
2559
|
+
class Record < LHS::Record
|
2560
|
+
endpoint 'https://service/records', oauth: :provider1
|
2561
|
+
#...
|
2562
|
+
end
|
2563
|
+
```
|
2564
|
+
|
2565
|
+
### Configure providers
|
2566
|
+
|
2567
|
+
If you're using LHS service providers, you can also configure auto auth on a provider level:
|
2568
|
+
|
2569
|
+
```ruby
|
2570
|
+
# app/models/providers/localsearch.rb
|
2571
|
+
module Providers
|
2572
|
+
class Localsearch < LHS::Record
|
2573
|
+
|
2574
|
+
provider(
|
2575
|
+
oauth: true
|
2576
|
+
)
|
2577
|
+
end
|
2578
|
+
end
|
2579
|
+
```
|
2580
|
+
|
2581
|
+
or with multiple auth providers:
|
2582
|
+
|
2583
|
+
```ruby
|
2584
|
+
# app/models/providers/localsearch.rb
|
2585
|
+
module Providers
|
2586
|
+
class Localsearch < LHS::Record
|
2587
|
+
|
2588
|
+
provider(
|
2589
|
+
oauth: :provider_1
|
2590
|
+
)
|
2591
|
+
end
|
2592
|
+
end
|
2593
|
+
```
|
2594
|
+
|
2507
2595
|
## Option Blocks
|
2508
2596
|
|
2509
2597
|
In order to apply options to all requests performed in a give block, LHS provides option blocks.
|
data/lhs.gemspec
CHANGED
@@ -32,7 +32,7 @@ Gem::Specification.new do |s|
|
|
32
32
|
s.add_development_dependency 'pry'
|
33
33
|
s.add_development_dependency 'pry-byebug'
|
34
34
|
s.add_development_dependency 'rails', '>= 4.2.11'
|
35
|
-
s.add_development_dependency 'rollbar'
|
35
|
+
s.add_development_dependency 'rollbar', '<= 2.24.0'
|
36
36
|
s.add_development_dependency 'rspec-rails', '>= 3.7.0'
|
37
37
|
s.add_development_dependency 'rubocop', '~> 0.57.1'
|
38
38
|
s.add_development_dependency 'rubocop-rspec', '~> 1.26.0'
|
@@ -64,11 +64,11 @@ class LHS::Record
|
|
64
64
|
chain
|
65
65
|
end
|
66
66
|
|
67
|
-
def
|
67
|
+
def includes_first_page(*args)
|
68
68
|
Chain.new(self, Include.new(Chain.unfold(args)))
|
69
69
|
end
|
70
70
|
|
71
|
-
def
|
71
|
+
def includes(*args)
|
72
72
|
chain = Chain.new(self, Include.new(Chain.unfold(args)))
|
73
73
|
chain.include_all!(args)
|
74
74
|
chain
|
@@ -259,11 +259,11 @@ class LHS::Record
|
|
259
259
|
push(ErrorHandling.new(error_class => handler))
|
260
260
|
end
|
261
261
|
|
262
|
-
def
|
262
|
+
def includes_first_page(*args)
|
263
263
|
push(Include.new(Chain.unfold(args)))
|
264
264
|
end
|
265
265
|
|
266
|
-
def
|
266
|
+
def includes(*args)
|
267
267
|
chain = push(Include.new(Chain.unfold(args)))
|
268
268
|
chain.include_all!(args)
|
269
269
|
chain
|
@@ -12,53 +12,62 @@ class LHS::Record
|
|
12
12
|
mattr_accessor :configuration
|
13
13
|
|
14
14
|
module ClassMethods
|
15
|
-
def configuration(args)
|
16
|
-
|
15
|
+
def configuration(args = nil)
|
16
|
+
if !args.nil?
|
17
|
+
@configuration = args
|
18
|
+
else
|
19
|
+
@configuration || {}
|
20
|
+
end
|
17
21
|
end
|
18
22
|
|
19
23
|
def auto_oauth?
|
20
|
-
LHS.config.auto_oauth &&
|
24
|
+
LHS.config.auto_oauth && configuration && auto_oauth
|
21
25
|
end
|
22
26
|
|
23
|
-
def
|
24
|
-
|
27
|
+
def auto_oauth
|
28
|
+
configuration.fetch(:auto_oauth, false)
|
29
|
+
end
|
30
|
+
|
31
|
+
def oauth(provider = nil)
|
32
|
+
value = provider || true
|
33
|
+
configuration.present? ? configuration.merge!(auto_oauth: value) : configuration(auto_oauth: value)
|
25
34
|
end
|
26
35
|
|
27
36
|
def item_key
|
28
37
|
symbolize_unless_complex(
|
29
|
-
|
38
|
+
configuration.dig(:item_key) || :item
|
30
39
|
)
|
31
40
|
end
|
32
41
|
|
33
42
|
def items_key
|
34
43
|
symbolize_unless_complex(
|
35
|
-
|
44
|
+
configuration.dig(:items_key) || :items
|
36
45
|
)
|
37
46
|
end
|
38
47
|
|
39
48
|
def item_created_key
|
40
49
|
symbolize_unless_complex(
|
41
|
-
|
50
|
+
configuration.dig(:item_created_key)
|
42
51
|
)
|
43
52
|
end
|
44
53
|
|
45
54
|
def limit_key(type = nil)
|
46
55
|
symbolize_unless_complex(
|
47
|
-
pagination_parameter(
|
56
|
+
pagination_parameter(configuration.dig(:limit_key), type) ||
|
48
57
|
:limit
|
49
58
|
)
|
50
59
|
end
|
51
60
|
|
52
61
|
def total_key
|
53
62
|
symbolize_unless_complex(
|
54
|
-
|
63
|
+
configuration.dig(:total_key) || :total
|
55
64
|
)
|
56
65
|
end
|
57
66
|
|
58
67
|
# Key used for determine current page
|
59
68
|
def pagination_key(type = nil)
|
60
69
|
symbolize_unless_complex(
|
61
|
-
pagination_parameter(
|
70
|
+
pagination_parameter(configuration.dig(:pagination_key), type) ||
|
62
71
|
:offset
|
63
72
|
)
|
64
73
|
end
|
@@ -66,15 +75,15 @@ class LHS::Record
|
|
66
75
|
# Strategy used for calculationg next pages and navigate pages
|
67
76
|
def pagination_strategy
|
68
77
|
symbolize_unless_complex(
|
69
|
-
|
78
|
+
configuration.dig(:pagination_strategy) || :offset
|
70
79
|
)
|
71
80
|
end
|
72
81
|
|
73
82
|
# Allows record to be configured as not paginated,
|
74
83
|
# as by default it's considered paginated
|
75
84
|
def paginated
|
76
|
-
return true if
|
77
|
-
|
85
|
+
return true if configuration.blank?
|
86
|
+
configuration.fetch(:paginated, true)
|
78
87
|
end
|
79
88
|
|
80
89
|
private
|