lhs 21.2.3 → 22.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +249 -116
  3. data/lhs.gemspec +1 -1
  4. data/lib/lhs.rb +8 -0
  5. data/lib/lhs/concerns/o_auth.rb +25 -0
  6. data/lib/lhs/concerns/record/chainable.rb +4 -4
  7. data/lib/lhs/concerns/record/configuration.rb +28 -11
  8. data/lib/lhs/concerns/record/request.rb +29 -8
  9. data/lib/lhs/config.rb +1 -1
  10. data/lib/lhs/interceptors/auto_oauth/interceptor.rb +33 -0
  11. data/lib/lhs/interceptors/auto_oauth/thread_registry.rb +18 -0
  12. data/lib/lhs/version.rb +1 -1
  13. data/spec/auto_oauth_spec.rb +169 -0
  14. data/spec/dummy/app/controllers/application_controller.rb +15 -0
  15. data/spec/dummy/app/controllers/automatic_authentication_controller.rb +29 -0
  16. data/spec/dummy/app/models/dummy_record_with_auto_oauth_provider.rb +6 -0
  17. data/spec/dummy/app/models/dummy_record_with_multiple_oauth_providers1.rb +7 -0
  18. data/spec/dummy/app/models/dummy_record_with_multiple_oauth_providers2.rb +7 -0
  19. data/spec/dummy/app/models/dummy_record_with_multiple_providers_per_endpoint.rb +6 -0
  20. data/spec/dummy/app/models/dummy_record_with_oauth.rb +7 -0
  21. data/spec/dummy/app/models/providers/internal_services.rb +7 -0
  22. data/spec/dummy/config/routes.rb +5 -0
  23. data/spec/item/destroy_spec.rb +1 -1
  24. data/spec/proxy/record_identification_spec.rb +1 -1
  25. data/spec/record/all_spec.rb +1 -1
  26. data/spec/record/endpoints_spec.rb +1 -1
  27. data/spec/record/error_handling_integration_spec.rb +1 -1
  28. data/spec/record/handle_includes_errors_spec.rb +1 -1
  29. data/spec/record/has_many_spec.rb +1 -1
  30. data/spec/record/has_one_spec.rb +1 -1
  31. data/spec/record/includes_first_page_spec.rb +727 -0
  32. data/spec/record/includes_spec.rb +546 -561
  33. data/spec/record/includes_warning_spec.rb +1 -1
  34. data/spec/record/mapping_spec.rb +2 -2
  35. data/spec/record/references_spec.rb +1 -1
  36. data/spec/record/relation_caching_spec.rb +3 -3
  37. data/spec/request_cycle_cache_spec.rb +3 -3
  38. metadata +27 -8
  39. data/spec/record/includes_all_spec.rb +0 -693
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 90588d8b49ea001a59c76710d97dc5b2b55ba77917ded5012c35e6924b9f2208
4
- data.tar.gz: 880b24d7a80d32eeccde0e7818fd36a31b59cfb8699cb880746a28c60e7ec983
3
+ metadata.gz: a749e7862bb20791a4a25fa5fdce92461ebfceaf6e30602c7e600f7342a69806
4
+ data.tar.gz: eceb2d57d258630583394079f495474320354db45e15c205f66005b570abc448
5
5
  SHA512:
6
- metadata.gz: 9294294bb7c1c21881bccea2a70e756da27a54edc59385361f2179d3d2069b2a00469a74957bd145b3d54c94eff18d08813db054a87ffa6526388de2473f8649
7
- data.tar.gz: 6bdbfaab6df958c88cb791b7202b9ed713c460e2297bbb3fc9da160bb55c9fc97b6051978f451d074da08e073d647d3653cd94090f2235c4b00fee707d861824
6
+ metadata.gz: 9432edd5f7d4c2d76f873d21bb3e79c2bc54965e64d3a2df7aa8c06f64dbea479274adde5ea4d1f1acf3e128d4cc7af1fa8fb41bc801b6b3629e6ddbf1156667
7
+ data.tar.gz: 719d291ec00314bf8061cbe72a6abab98e1466a7162dcd174588ffc57823b8509951eb2ed28a4be3d6b6e938bd0791ff26cab9f6d478dd49f50cf28139b3cdbf
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
- * [Quickstart](#quickstart)
43
- * [Table of contents](#table-of-contents)
44
- * [Installation/Startup checklist](#installationstartup-checklist)
45
- * [Record](#record)
46
- * [Endpoints](#endpoints)
47
- * [Configure endpoint hosts](#configure-endpoint-hosts)
48
- * [Endpoint Priorities](#endpoint-priorities)
49
- * [Provider](#provider)
50
- * [Record inheritance](#record-inheritance)
51
- * [Find multiple records](#find-multiple-records)
52
- * [fetch](#fetch)
53
- * [where](#where)
54
- * [Reuse/Dry where statements: Use scopes](#reusedry-where-statements-use-scopes)
55
- * [all](#all)
56
- * [all with unpaginated endpoints](#all-with-unpaginated-endpoints)
57
- * [Retrieve the amount of a collection of items: count vs. length](#retrieve-the-amount-of-a-collection-of-items-count-vs-length)
58
- * [Find single records](#find-single-records)
59
- * [find](#find)
60
- * [find_by](#find_by)
61
- * [first](#first)
62
- * [last](#last)
63
- * [Work with retrieved data](#work-with-retrieved-data)
64
- * [Automatic detection/conversion of collections](#automatic-detectionconversion-of-collections)
65
- * [Map complex data for easy access](#map-complex-data-for-easy-access)
66
- * [Access and identify nested records](#access-and-identify-nested-records)
67
- * [Relations / Associations](#relations--associations)
68
- * [has_many](#has_many)
69
- * [has_one](#has_one)
70
- * [Unwrap nested items from the response body](#unwrap-nested-items-from-the-response-body)
71
- * [Determine collections from the response body](#determine-collections-from-the-response-body)
72
- * [Load additional data based on retrieved data](#load-additional-data-based-on-retrieved-data)
73
- * [Chain complex queries](#chain-complex-queries)
74
- * [Chain where queries](#chain-where-queries)
75
- * [Expand plain collections of links: expanded](#expand-plain-collections-of-links-expanded)
76
- * [Error handling with chains](#error-handling-with-chains)
77
- * [Resolve chains: fetch](#resolve-chains-fetch)
78
- * [Add request options to a query chain: options](#add-request-options-to-a-query-chain-options)
79
- * [Control pagination within a query chain](#control-pagination-within-a-query-chain)
80
- * [Record pagination](#record-pagination)
81
- * [Pagination strategy](#pagination-strategy)
82
- * [Pagination strategy: offset (default)](#pagination-strategy-offset-default)
83
- * [Pagination strategy: page](#pagination-strategy-page)
84
- * [Pagination strategy: start](#pagination-strategy-start)
85
- * [Pagination strategy: link](#pagination-strategy-link)
86
- * [Pagination keys](#pagination-keys)
87
- * [limit_key](#limit_key)
88
- * [pagination_key](#pagination_key)
89
- * [total_key](#total_key)
90
- * [Pagination links](#pagination-links)
91
- * [next?](#next)
92
- * [previous?](#previous)
93
- * [Kaminari support (limited)](#kaminari-support-limited)
94
- * [Build, create and update records](#build-create-and-update-records)
95
- * [Create new records](#create-new-records)
96
- * [create](#create)
97
- * [Unwrap nested data when creation response nests created record data](#unwrap-nested-data-when-creation-response-nests-created-record-data)
98
- * [Create records through associations: Nested sub resources](#create-records-through-associations-nested-sub-resources)
99
- * [Start building new records](#start-building-new-records)
100
- * [Change/Update existing records](#changeupdate-existing-records)
101
- * [save](#save)
102
- * [update](#update)
103
- * [partial_update](#partial_update)
104
- * [Endpoint url parameter injection during record creation/change](#endpoint-url-parameter-injection-during-record-creationchange)
105
- * [Record validation](#record-validation)
106
- * [Configure record validations](#configure-record-validations)
107
- * [HTTP Status Codes for validation errors](#http-status-codes-for-validation-errors)
108
- * [Reset validation errors](#reset-validation-errors)
109
- * [Add validation errors](#add-validation-errors)
110
- * [Validation errors for nested data](#validation-errors-for-nested-data)
111
- * [Translation of validation errors](#translation-of-validation-errors)
112
- * [Validation error types: errors vs. warnings](#validation-error-types-errors-vs-warnings)
113
- * [Persistance failed: errors](#persistance-failed-errors)
114
- * [Persistance succeeded: warnings](#persistance-succeeded-warnings)
115
- * [Using ActiveModel::Validations none the less](#using-activemodelvalidations-none-the-less)
116
- * [Use form_helper to create and update records](#use-form_helper-to-create-and-update-records)
117
- * [Destroy records](#destroy-records)
118
- * [Record getters and setters](#record-getters-and-setters)
119
- * [Record setters](#record-setters)
120
- * [Record getters](#record-getters)
121
- * [Include linked resources (hyperlinks and hypermedia)](#include-linked-resources-hyperlinks-and-hypermedia)
122
- * [Generate links from parameters](#generate-links-from-parameters)
123
- * [Ensure the whole linked collection is included: includes_all](#ensure-the-whole-linked-collection-is-included-includes_all)
124
- * [Include the first linked page or single item is included: include](#include-the-first-linked-page-or-single-item-is-included-include)
125
- * [Include various levels of linked data](#include-various-levels-of-linked-data)
126
- * [Identify and cast known records when including records](#identify-and-cast-known-records-when-including-records)
127
- * [Apply options for requests performed to fetch included records](#apply-options-for-requests-performed-to-fetch-included-records)
128
- * [Record batch processing](#record-batch-processing)
129
- * [all](#all-1)
130
- * [Using all, when endpoint does not implement response pagination meta data](#using-all-when-endpoint-does-not-implement-response-pagination-meta-data)
131
- * [find_each](#find_each)
132
- * [find_in_batches](#find_in_batches)
133
- * [Convert/Cast specific record types: becomes](#convertcast-specific-record-types-becomes)
134
- * [Assign attributes](#assign-attributes)
135
- * [Request Cycle Cache](#request-cycle-cache)
136
- * [Change store for LHS' request cycle cache](#change-store-for-lhs-request-cycle-cache)
137
- * [Disable request cycle cache](#disable-request-cycle-cache)
138
- * [Option Blocks](#option-blocks)
139
- * [Request tracing](#request-tracing)
140
- * [Extended Rollbar Logging](#extended-rollbar-logging)
141
- * [Testing with LHS](#testing-with-lhs)
142
- * [Test helper](#test-helper)
143
- * [Stub](#stub)
144
- * [Stub All](#stub-all)
145
- * [Test query chains](#test-query-chains)
146
- * [By explicitly resolving the chain: fetch](#by-explicitly-resolving-the-chain-fetch)
147
- * [Without resolving the chain: where_values_hash](#without-resolving-the-chain-where_values_hash)
148
- * [License](#license)
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
 
@@ -2088,7 +2093,7 @@ In a service-oriented architecture using [hyperlinks](https://en.wikipedia.org/w
2088
2093
 
2089
2094
  When fetching records with LHS, you can specify in advance all the linked resources that you want to include in the results.
2090
2095
 
2091
- With `includes` or `includes_all` (to enforce fetching all remote objects for paginated endpoints), LHS ensures that all matching and explicitly linked resources are loaded and merged.
2096
+ With `includes` LHS ensures that all matching and explicitly linked resources are loaded and merged (even if the linked resources are paginated).
2092
2097
 
2093
2098
  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
2099
 
@@ -2107,16 +2112,16 @@ Presence.create(place: { href: Place.href_for(123) })
2107
2112
  POST '/presences' { place: { href: "http://datastore/places/123" } }
2108
2113
  ```
2109
2114
 
2110
- #### Ensure the whole linked collection is included: includes_all
2115
+ #### Ensure the whole linked collection is included with includes
2111
2116
 
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 `includes_all`.
2117
+ 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
2118
 
2114
2119
  LHS will ensure that all linked resources are around by loading all pages (parallelized/performance optimized).
2115
2120
 
2116
2121
  ```ruby
2117
2122
  # app/controllers/some_controller.rb
2118
2123
 
2119
- customer = Customer.includes_all(contracts: :products).find(1)
2124
+ customer = Customer.includes(contracts: :products).find(1)
2120
2125
  ```
2121
2126
  ```
2122
2127
  > GET https://service.example.com/customers/1
@@ -2143,14 +2148,14 @@ customer.contracts.first.products.first.name # Local Business Card
2143
2148
 
2144
2149
  ```
2145
2150
 
2146
- #### Include the first linked page or single item is included: include
2151
+ #### Include only the first linked page of a linked collection: includes_first_page
2147
2152
 
2148
- `includes` includes the first page/response when loading the linked resource. **If the endpoint is paginated, only the first page will be included.**
2153
+ `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
2154
 
2150
2155
  ```ruby
2151
2156
  # app/controllers/some_controller.rb
2152
2157
 
2153
- customer = Customer.includes(contracts: :products).find(1)
2158
+ customer = Customer.includes_first_page(contracts: :products).find(1)
2154
2159
  ```
2155
2160
  ```
2156
2161
  > GET https://service.example.com/customers/1
@@ -2174,7 +2179,7 @@ customer.contracts.first.products.first.name # Local Business Card
2174
2179
 
2175
2180
  #### Include various levels of linked data
2176
2181
 
2177
- The method syntax of `includes` and `includes_all`, allows you include hyperlinks stored in deep nested data strutures:
2182
+ The method syntax of `includes` allows you include hyperlinks stored in deep nested data strutures:
2178
2183
 
2179
2184
  Some examples:
2180
2185
 
@@ -2194,7 +2199,7 @@ Record.includes(campaign: [:entry, :user])
2194
2199
 
2195
2200
  #### Identify and cast known records when including records
2196
2201
 
2197
- When including linked resources with `includes` or `includes_all`, already defined records and their endpoints and configurations are used to make the requests to fetch the additional data.
2202
+ 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
2203
 
2199
2204
  That also means that options for endpoints of linked resources are applied when requesting those in addition.
2200
2205
 
@@ -2444,6 +2449,134 @@ LHS.configure do |config|
2444
2449
  end
2445
2450
  ```
2446
2451
 
2452
+ ## Automatic Authentication (OAuth)
2453
+
2454
+ LHS provides a way to have records automatically fetch and use OAuth authentication when performing requests within Rails.
2455
+
2456
+ In order to enable automatic oauth authentication, perform the following steps:
2457
+
2458
+ 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.
2459
+ ```ruby
2460
+ # config/initializers/lhs.rb
2461
+
2462
+ LHS.configure do |config|
2463
+ config.auto_oauth = -> { access_token }
2464
+ end
2465
+ ```
2466
+
2467
+ 2. Opt-in records requiring oauth authentication:
2468
+
2469
+ ```ruby
2470
+ # app/models/record.rb
2471
+
2472
+ class Record < LHS::Record
2473
+ oauth
2474
+ # ...
2475
+ end
2476
+ ```
2477
+
2478
+ 3. Include the `LHS::OAuth` context into your application controller:
2479
+
2480
+ ```ruby
2481
+ # app/controllers/application_controller.rb
2482
+
2483
+ class ApplicationController < ActionController::Base
2484
+ include LHS::OAuth
2485
+
2486
+ # ...
2487
+ end
2488
+ ```
2489
+
2490
+ 4. Make sure you have the `LHC::Auth` interceptor enabled:
2491
+
2492
+ ```ruby
2493
+ # config/initializers/lhc.rb
2494
+
2495
+ LHC.configure do |config|
2496
+ config.interceptors = [LHC::Auth]
2497
+ end
2498
+ ```
2499
+
2500
+ Now you can perform requests based on the record that will be auto authenticated from now on:
2501
+
2502
+ ```ruby
2503
+ # app/controllers/some_controller.rb
2504
+
2505
+ Record.find(1)
2506
+ ```
2507
+ ```
2508
+ https://records/1
2509
+ Authentication: 'Bearer token-12345'
2510
+ ```
2511
+
2512
+ ### Configure multiple auth providers (even per endpoint)
2513
+
2514
+ In case you need to configure multiple auth provider access_tokens within your application,
2515
+ make sure you provide a proc returning a hash when configuring `auto_oauth`,
2516
+ naming every single provider and the responsive method to retrieve the access_tokens in the controller context:
2517
+
2518
+ ```ruby
2519
+ # config/initializers/lhs.rb
2520
+ LHS.configure do |config|
2521
+ config.auto_oauth = proc do
2522
+ {
2523
+ provider1: access_token_provider_1,
2524
+ provider2: access_token_provider_2
2525
+ }
2526
+ end
2527
+ end
2528
+ ```
2529
+
2530
+ Then make sure you either define which provider to use on a record level:
2531
+
2532
+ ```ruby
2533
+ # model/record.rb
2534
+ class Record < LHS::Record
2535
+ oauth(:provider1)
2536
+ #...
2537
+ end
2538
+ ```
2539
+
2540
+ or on an endpoint level:
2541
+
2542
+ ```ruby
2543
+ # model/record.rb
2544
+ class Record < LHS::Record
2545
+ endpoint 'https://service/records', oauth: :provider1
2546
+ #...
2547
+ end
2548
+ ```
2549
+
2550
+ ### Configure providers
2551
+
2552
+ If you're using LHS service providers, you can also configure auto auth on a provider level:
2553
+
2554
+ ```ruby
2555
+ # app/models/providers/localsearch.rb
2556
+ module Providers
2557
+ class Localsearch < LHS::Record
2558
+
2559
+ provider(
2560
+ oauth: true
2561
+ )
2562
+ end
2563
+ end
2564
+ ```
2565
+
2566
+ or with multiple auth providers:
2567
+
2568
+ ```ruby
2569
+ # app/models/providers/localsearch.rb
2570
+ module Providers
2571
+ class Localsearch < LHS::Record
2572
+
2573
+ provider(
2574
+ oauth: :provider_1
2575
+ )
2576
+ end
2577
+ end
2578
+ ```
2579
+
2447
2580
  ## Option Blocks
2448
2581
 
2449
2582
  In order to apply options to all requests performed in a give block, LHS provides option blocks.
@@ -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'
data/lib/lhs.rb CHANGED
@@ -22,6 +22,12 @@ module LHS
22
22
  autoload :Inspect,
23
23
  'lhs/concerns/inspect'
24
24
  module Interceptors
25
+ module AutoOauth
26
+ autoload :ThreadRegistry,
27
+ 'lhs/interceptors/auto_oauth/thread_registry'
28
+ autoload :Interceptor,
29
+ 'lhs/interceptors/auto_oauth/interceptor'
30
+ end
25
31
  module RequestCycleCache
26
32
  autoload :ThreadRegistry,
27
33
  'lhs/interceptors/request_cycle_cache/thread_registry'
@@ -41,6 +47,8 @@ module LHS
41
47
  'lhs/concerns/is_href'
42
48
  autoload :Item,
43
49
  'lhs/item'
50
+ autoload :OAuth,
51
+ 'lhs/concerns/o_auth.rb'
44
52
  autoload :OptionBlocks,
45
53
  'lhs/concerns/option_blocks'
46
54
  autoload :Pagination,