4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/federal_register/document_utilities.rb', line 4
def find_all(*args)
options, document_numbers_or_citations = (args)
document_numbers_or_citations.flatten!
fetch_options = {:result_class => self}
fetch_options.merge!(:query => {:fields => options[:fields]}) if options[:fields]
document_numbers_or_citations.uniq!
if document_numbers_or_citations.empty?
raise "No documents or citation numbers were provided"
end
if document_numbers_or_citations.size == 1
document_numbers_or_citations << " "
end
http_request_batches = calculate_request_batches(document_numbers_or_citations, fetch_options)
slice_size = (document_numbers_or_citations.count.to_f / http_request_batches).ceil
results = []
document_numbers_or_citations.each_slice(slice_size).each do |slice|
params = URI.encode(slice.join(',').strip)
url = "#{find_all_base_path}/#{params}.json"
response = get(url, fetch_options).parsed_response
results += response['results']
end
FederalRegister::ResultSet.new(
{
'count' => results.count,
'results' => results,
},
self
)
end
|