ecfr 1.0.5 → 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ac4f799a4cc68b3a71f156bf577a550203c72dd40b10a3f9ed5e51e670059a08
4
- data.tar.gz: b5632a1b02852a341edd594d6a6e7aa999e24affe1a8e0b6f1aa2c77085f78b8
3
+ metadata.gz: 3982b2145a3ab849c7fbbe13699265d5d3c75ca19be019e8b3e57bad78f6c2ee
4
+ data.tar.gz: 2d4b94aa527179914dce1d89f6f781bde99af455abddccb8d1c409d199a811be
5
5
  SHA512:
6
- metadata.gz: 0d39ecb6d87038d7a7675fb2b8b0a64949301a68a0dbe467dfb9292a55d6738748611afe274664fb610b4c4e68c1dfa98dd772e78e331f559e1ac82d77fe8cce
7
- data.tar.gz: 2c91c3086b5f911a49dcd585290ac4f968d942731cd56c7787492b5d18856963a50c602b53889ba8baefe8aad75eea8d33a885cf5af77d8547529d5549a2f70d
6
+ metadata.gz: 964a37efcba4b38cbca2c9108f59ef9f972ab23f1b6904149b59bc3105370c351781f166397a9bb97fd9564e91cbc21f89ded0defcb64d678e57636b42db309b
7
+ data.tar.gz: 55fefed80cbf964968660b8c625cf35189d21c55611bbfa0143ce3394e3408d5d5253817f73c115f7f53d0844b8afaf04d5e828c6d563ee1b947325799157f00
data/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.0.8] - 2023-05-05
4
+ ### Updates
5
+ - Update Ecfr::RenderService::Diff to rescue expected error types and raise more specific diff errors
6
+
7
+ ## [1.0.7] - 2023-05-04
8
+ ### Bugfixes
9
+ - Remove change to .build method signature that was unnecessary and caused issues with the testing extensions we provide.
10
+ - Includes bugfix from 1.0.6
11
+
12
+ ## [1.0.6] - 2023-05-04 (yanked)
13
+ ### Bugfixes
14
+ - Properly cache ancestor base response (fbfdf1e6)
15
+
3
16
  ## [1.0.5] - 2023-04-24
4
17
  ### Bugfixes
5
18
  - Remove blank response body check in PDF generation that doesn't play well with all encodings
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
 
@@ -17,14 +17,21 @@ module Ecfr
17
17
  view_mode = options.delete(:view_mode) || :enhanced
18
18
  params = hierarchy.merge(options).merge(compare: old_date)
19
19
 
20
- new(
21
- {
22
- html: get(
23
- content_path(new_date, title, view_mode: view_mode),
24
- params
25
- ).body
26
- }.stringify_keys
27
- )
20
+ begin
21
+ new(
22
+ {
23
+ html: get(
24
+ content_path(new_date, title, view_mode: view_mode),
25
+ params
26
+ ).body
27
+ }.stringify_keys
28
+ )
29
+ rescue Ecfr::Client::ResponseError, Ecfr::Client::ServerError
30
+ # diff too large - diff service generated broken pipe error or 500 code
31
+ raise DiffTooLarge
32
+ rescue Ecfr::Client::UnknownStatusCode
33
+ raise Undiffable
34
+ end
28
35
  end
29
36
  end
30
37
  end
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.5"
4
+ VERSION = "1.0.8"
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.5
4
+ version: 1.0.8
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-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel