ecfr 1.0.4 → 1.0.7
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/CHANGELOG.md +13 -0
- data/lib/ecfr/client.rb +8 -3
- data/lib/ecfr/prince_xml_service/pdf.rb +1 -1
- data/lib/ecfr/version.rb +1 -1
- data/lib/ecfr/versioner_service/ancestors.rb +32 -10
- data/lib/ecfr/versioner_service/structure.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: ad783e80fbc8dd7934378bb9b9afc6b98f3ba5a066c8ebe4408e037c4a247a4d
|
4
|
+
data.tar.gz: cff950a97ec12681c9228e42976d7d28d617f50c52fde48dd2aad835bc5cd564
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3033789d092b96abe406f93f73efe0f725a6dcd8b37cd3750035cf3e76463ff28bfdcec22e5448a38390cf1f771a7f2c0bf6e338e4875c7e029f519f220a9bc5
|
7
|
+
data.tar.gz: 79e512df9d7253e97e756a1d49f90a2fb3ea8983e3e4d643eb33ae569d6ab305053c29242412a9b9447a57286aa4d82036acff583e9efb67ba70882031c401d7
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,18 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [1.0.7] - 2023-05-04
|
4
|
+
### Bugfixes
|
5
|
+
- Remove change to .build method signature that was unnecessary and caused issues with the testing extensions we provide.
|
6
|
+
- Includes bugfix from 1.0.6
|
7
|
+
|
8
|
+
## [1.0.6] - 2023-05-04 (yanked)
|
9
|
+
### Bugfixes
|
10
|
+
- Properly cache ancestor base response (fbfdf1e6)
|
11
|
+
|
12
|
+
## [1.0.5] - 2023-04-24
|
13
|
+
### Bugfixes
|
14
|
+
- Remove blank response body check in PDF generation that doesn't play well with all encodings
|
15
|
+
|
3
16
|
## [1.0.4] - 2023-04-24
|
4
17
|
### Additions
|
5
18
|
- Add Ecfr::VarnishCacheService for clearing of cache
|
data/lib/ecfr/client.rb
CHANGED
@@ -135,9 +135,12 @@ module Ecfr
|
|
135
135
|
RequestStore.fetch(cache_key) do
|
136
136
|
puts "Request not in eCFR gem cache, fetching..."
|
137
137
|
|
138
|
-
response = fetch(method, path, params: params,
|
138
|
+
response = fetch(method, path, params: params,
|
139
|
+
client_options: client_options)
|
139
140
|
|
140
|
-
|
141
|
+
if respond_to?(:cache_base_response, true)
|
142
|
+
cache_base_response(response, method, path, params)
|
143
|
+
end
|
141
144
|
|
142
145
|
response
|
143
146
|
end
|
@@ -187,7 +190,9 @@ module Ecfr
|
|
187
190
|
#
|
188
191
|
# See the .perform/.fetch method for argument signatures
|
189
192
|
#
|
190
|
-
def self.build(response:,
|
193
|
+
def self.build(response:,
|
194
|
+
request_data: {}, build_options: {})
|
195
|
+
|
191
196
|
default_build_options = {parse_response: true}
|
192
197
|
build_options = default_build_options.merge(build_options)
|
193
198
|
|
@@ -13,7 +13,7 @@ module Ecfr
|
|
13
13
|
def self.html_to_pdf(string, output_path, sha)
|
14
14
|
response = post(PDF_PATH, {html: string})
|
15
15
|
|
16
|
-
if response.status != 200
|
16
|
+
if response.status != 200
|
17
17
|
raise PdfGenerationFailure.new(response.body)
|
18
18
|
else
|
19
19
|
directory = File.dirname(output_path)
|
data/lib/ecfr/version.rb
CHANGED
@@ -86,7 +86,7 @@ module Ecfr
|
|
86
86
|
perform(
|
87
87
|
:get,
|
88
88
|
ancestors_path(date, title_number),
|
89
|
-
params: options
|
89
|
+
params: options.compact
|
90
90
|
)
|
91
91
|
end
|
92
92
|
|
@@ -97,25 +97,47 @@ module Ecfr
|
|
97
97
|
|
98
98
|
# these parameters add items to the base response but do not affect our
|
99
99
|
# ability to cache that base response
|
100
|
-
PARAMETERS_NOT_AFFECTING_BASE_RESPONSE = %
|
100
|
+
PARAMETERS_NOT_AFFECTING_BASE_RESPONSE = %i[metadata]
|
101
|
+
SIDELOAD_PARAMETERS = %i[structure descendant_depth]
|
101
102
|
|
102
103
|
# if the request only includes optional parameters that don't affect the
|
103
|
-
# basic part of the response, then we can
|
104
|
+
# basic part of the response, then we can cache a base form of that
|
104
105
|
# response by removing those optional return items (this keeps the cache
|
105
106
|
# consistent across request by not including extra items).
|
106
|
-
def self.cache_base_response(response, path, params)
|
107
|
-
|
108
|
-
|
107
|
+
def self.cache_base_response(response, method, path, params)
|
108
|
+
non_hierarchy_params = params.except(
|
109
|
+
*Ecfr::Constants::Hierarchy::HIERARCHY_LEVELS.map(&:to_sym)
|
110
|
+
)
|
111
|
+
|
112
|
+
if only_safe_params?(non_hierarchy_params)
|
113
|
+
cache_key = cache_key(method, path, params.except(*SIDELOAD_PARAMETERS))
|
114
|
+
|
115
|
+
# in the case the the response is the base response the cache keys
|
116
|
+
# will match - fetch will just return that and this will essentially
|
117
|
+
# be a no op
|
109
118
|
RequestStore.fetch(cache_key) do
|
110
|
-
|
119
|
+
excluded_items = params.key?(:metadata) ?
|
120
|
+
[:structure] : [:metadata, :structure]
|
121
|
+
|
122
|
+
response_body = JSON.parse(response.body)
|
123
|
+
.except(*excluded_items.map(&:to_s))
|
124
|
+
|
125
|
+
# return a ducktyped object like the response object
|
126
|
+
OpenStruct.new(
|
127
|
+
body: response_body.to_json,
|
128
|
+
status: response.status
|
129
|
+
)
|
111
130
|
end
|
112
131
|
end
|
113
132
|
end
|
114
|
-
private_class_method :cache_base_response
|
133
|
+
# private_class_method :cache_base_response
|
115
134
|
|
116
135
|
def self.only_safe_params?(params)
|
117
|
-
# are all of the params keys included in the
|
118
|
-
params.keys.all?
|
136
|
+
# are all of the params keys included in the one of the lists?
|
137
|
+
params.keys.all? do |p|
|
138
|
+
(PARAMETERS_NOT_AFFECTING_BASE_RESPONSE +
|
139
|
+
SIDELOAD_PARAMETERS).include?(p)
|
140
|
+
end
|
119
141
|
end
|
120
142
|
|
121
143
|
# override enumerable setup because we don't have
|
@@ -22,7 +22,7 @@ module Ecfr
|
|
22
22
|
perform(
|
23
23
|
:get,
|
24
24
|
structure_path(date, title_number, format),
|
25
|
-
params: options.except(:section, :appendix),
|
25
|
+
params: options.except(:section, :appendix).compact,
|
26
26
|
perform_options: {
|
27
27
|
init_data: {format: format},
|
28
28
|
parse_response: false
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ecfr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peregrinator
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-04
|
11
|
+
date: 2023-05-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|