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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9a461ee470f942857af590c19d394480c9fae9120f34d350177c2cfcdde01afa
4
- data.tar.gz: c5e33627c9a6de6cc626588dc5772c9e51276aab272293960f85672c7e2c30d4
3
+ metadata.gz: ad783e80fbc8dd7934378bb9b9afc6b98f3ba5a066c8ebe4408e037c4a247a4d
4
+ data.tar.gz: cff950a97ec12681c9228e42976d7d28d617f50c52fde48dd2aad835bc5cd564
5
5
  SHA512:
6
- metadata.gz: 5f1289d6881ae12c16bf38d3f6f19b4d62690f8fd651273b2146a08a2c8e6c1e715f279f71dee059ff7304c5f2e4b092cc95b003fbfacd84c6bd712616ba7ce8
7
- data.tar.gz: feb036c209435977e25198394deb3a814d76f821ee560d643bf5c4dcd1a0bf0f4abc649921d8fbd9dce11d467c07eb2660319149aa1343e8351d494348cbbf14
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, client_options: client_options)
138
+ response = fetch(method, path, params: params,
139
+ client_options: client_options)
139
140
 
140
- cache_base_response(response, path, params) if respond_to?(:cache_base_response)
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:, request_data: {}, build_options: {})
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 || response.body.blank?
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ecfr
4
- VERSION = "1.0.4"
4
+ VERSION = "1.0.7"
5
5
  end
@@ -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 = %w[metadata structure descendant_depth]
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 catch a base form of that
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
- if only_safe_params?(params)
108
- cache_key = cache_key(method, path, {})
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
- response.except(:metadata, :structure)
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 list?
118
- params.keys.all? { |p| PARAMETERS_NOT_AFFECTING_BASE_RESPONSE.include?(p) }
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
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-24 00:00:00.000000000 Z
11
+ date: 2023-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel