federal_register 0.7.7 → 0.8.0
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/Gemfile.lock +29 -9
- data/VERSION +1 -1
- data/federal_register.gemspec +4 -2
- data/lib/federal_register/agency.rb +4 -4
- data/lib/federal_register/base.rb +7 -1
- data/lib/federal_register/client.rb +39 -8
- data/lib/federal_register/document.rb +11 -10
- data/lib/federal_register/document_search_details.rb +1 -1
- data/lib/federal_register/facet/agency.rb +1 -1
- data/lib/federal_register/facet/document/agency.rb +1 -1
- data/lib/federal_register/facet/document/daily.rb +1 -1
- data/lib/federal_register/facet/document/monthly.rb +1 -1
- data/lib/federal_register/facet/document/quarterly.rb +1 -1
- data/lib/federal_register/facet/document/section.rb +1 -1
- data/lib/federal_register/facet/document/topic.rb +1 -1
- data/lib/federal_register/facet/document/type.rb +1 -1
- data/lib/federal_register/facet/document/weekly.rb +1 -1
- data/lib/federal_register/facet/document/yearly.rb +1 -1
- data/lib/federal_register/facet/presidential_document_type.rb +1 -1
- data/lib/federal_register/facet/public_inspection_document/agencies.rb +1 -1
- data/lib/federal_register/facet/public_inspection_document/agency.rb +1 -1
- data/lib/federal_register/facet/public_inspection_document/type.rb +1 -1
- data/lib/federal_register/facet/public_inspection_issue/daily.rb +1 -1
- data/lib/federal_register/facet/public_inspection_issue/type.rb +1 -1
- data/lib/federal_register/facet/topic.rb +1 -1
- data/lib/federal_register/public_inspection_document.rb +6 -6
- data/lib/federal_register/public_inspection_document_search_details.rb +2 -2
- data/lib/federal_register/result_set.rb +2 -1
- data/lib/federal_register/section.rb +1 -1
- data/lib/federal_register/suggested_search.rb +2 -2
- data/lib/federal_register/topic.rb +1 -1
- data/lib/federal_register.rb +1 -1
- data/spec/agency_spec.rb +10 -1
- data/spec/base_spec.rb +2 -2
- data/spec/document_spec.rb +85 -50
- data/spec/public_inspection_document_spec.rb +33 -20
- data/spec/result_set_spec.rb +10 -1
- data/spec/spec_helper.rb +2 -4
- metadata +33 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9fa85057a2a29eaca05e6e24cbab933a2cb5da88eaae7e9e2a2bb99d94aea521
|
|
4
|
+
data.tar.gz: aba8ed95d1962cd872556da2f51b2a9024f8c9b430223a2d46779690dd943269
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 216eeb36c4e2f5e55ba14e83bc019d30b12e65551aad4b5b8a6064e7d3cc10ff06b481f403296cbdf9e1c0849edc56c98352f96af22b0b67b098e754a4438fc4
|
|
7
|
+
data.tar.gz: 01bc4a1455537a710ceb0572cda84b57c834574b3e1cc62e7b70785fa042729ac9b7a69b06801fdb7f4709ba43965ab7d01b01d84d5724124c5974ce2f137455
|
data/Gemfile.lock
CHANGED
|
@@ -2,7 +2,7 @@ PATH
|
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
4
|
federal_register (0.7.7)
|
|
5
|
-
|
|
5
|
+
faraday (>= 1.8)
|
|
6
6
|
|
|
7
7
|
GEM
|
|
8
8
|
remote: https://rubygems.org/
|
|
@@ -10,27 +10,40 @@ GEM
|
|
|
10
10
|
activesupport (3.2.22.5)
|
|
11
11
|
i18n (~> 0.6, >= 0.6.4)
|
|
12
12
|
multi_json (~> 1.0)
|
|
13
|
+
addressable (2.8.7)
|
|
14
|
+
public_suffix (>= 2.0.2, < 7.0)
|
|
13
15
|
ast (2.3.0)
|
|
16
|
+
base64 (0.2.0)
|
|
17
|
+
bigdecimal (3.1.8)
|
|
18
|
+
coderay (1.1.3)
|
|
14
19
|
concurrent-ruby (1.0.5)
|
|
20
|
+
crack (1.0.0)
|
|
21
|
+
bigdecimal
|
|
22
|
+
rexml
|
|
15
23
|
diff-lcs (1.2.5)
|
|
16
24
|
fakeweb (1.3.0)
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
25
|
+
faraday (2.8.1)
|
|
26
|
+
base64
|
|
27
|
+
faraday-net_http (>= 2.0, < 3.1)
|
|
28
|
+
ruby2_keywords (>= 0.0.4)
|
|
29
|
+
faraday-net_http (3.0.2)
|
|
30
|
+
hashdiff (1.1.1)
|
|
20
31
|
i18n (0.9.1)
|
|
21
32
|
concurrent-ruby (~> 1.0)
|
|
22
|
-
|
|
23
|
-
mime-types-data (~> 3.2015)
|
|
24
|
-
mime-types-data (3.2020.1104)
|
|
33
|
+
method_source (1.1.0)
|
|
25
34
|
multi_json (1.12.2)
|
|
26
|
-
multi_xml (0.6.0)
|
|
27
35
|
parallel (1.12.0)
|
|
28
36
|
parser (2.4.0.2)
|
|
29
37
|
ast (~> 2.3)
|
|
30
38
|
powerpack (0.1.1)
|
|
39
|
+
pry (0.14.2)
|
|
40
|
+
coderay (~> 1.1)
|
|
41
|
+
method_source (~> 1.0)
|
|
42
|
+
public_suffix (5.1.1)
|
|
31
43
|
rainbow (2.2.2)
|
|
32
44
|
rake
|
|
33
45
|
rake (12.3.0)
|
|
46
|
+
rexml (3.3.8)
|
|
34
47
|
rspec (2.99.0)
|
|
35
48
|
rspec-core (~> 2.99.0)
|
|
36
49
|
rspec-expectations (~> 2.99.0)
|
|
@@ -49,6 +62,7 @@ GEM
|
|
|
49
62
|
ruby-progressbar (~> 1.7)
|
|
50
63
|
unicode-display_width (~> 1.0, >= 1.0.1)
|
|
51
64
|
ruby-progressbar (1.9.0)
|
|
65
|
+
ruby2_keywords (0.0.5)
|
|
52
66
|
shoulda (3.5.0)
|
|
53
67
|
shoulda-context (~> 1.0, >= 1.0.1)
|
|
54
68
|
shoulda-matchers (>= 1.4.1, < 3.0)
|
|
@@ -56,6 +70,10 @@ GEM
|
|
|
56
70
|
shoulda-matchers (2.7.0)
|
|
57
71
|
activesupport (>= 3.0.0)
|
|
58
72
|
unicode-display_width (1.3.0)
|
|
73
|
+
webmock (3.24.0)
|
|
74
|
+
addressable (>= 2.8.0)
|
|
75
|
+
crack (>= 0.3.2)
|
|
76
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
|
59
77
|
|
|
60
78
|
PLATFORMS
|
|
61
79
|
ruby
|
|
@@ -65,10 +83,12 @@ DEPENDENCIES
|
|
|
65
83
|
bundler
|
|
66
84
|
fakeweb (~> 1.3.0)
|
|
67
85
|
federal_register!
|
|
86
|
+
pry
|
|
68
87
|
rspec (~> 2.6)
|
|
69
88
|
rspec_junit_formatter
|
|
70
89
|
rubocop
|
|
71
90
|
shoulda
|
|
91
|
+
webmock
|
|
72
92
|
|
|
73
93
|
BUNDLED WITH
|
|
74
|
-
2.
|
|
94
|
+
2.3.6
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.
|
|
1
|
+
0.8.0
|
data/federal_register.gemspec
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
Gem::Specification.new do |s|
|
|
7
7
|
s.name = "federal_register"
|
|
8
|
-
s.version = "0.
|
|
8
|
+
s.version = "0.8.0"
|
|
9
9
|
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
11
|
s.authors = ["Andrew Carpenter", "Bob Burbach"]
|
|
@@ -87,15 +87,17 @@ Gem::Specification.new do |s|
|
|
|
87
87
|
s.specification_version = 3
|
|
88
88
|
|
|
89
89
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
|
90
|
-
s.add_runtime_dependency(%q<
|
|
90
|
+
s.add_runtime_dependency(%q<faraday>, [">= 1.8"])
|
|
91
91
|
|
|
92
92
|
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
|
93
93
|
s.add_development_dependency(%q<bundler>, [">= 0"])
|
|
94
94
|
s.add_development_dependency(%q<rspec>, ["~> 2.6"])
|
|
95
95
|
s.add_development_dependency(%q<activesupport>, ["~> 3"])
|
|
96
96
|
s.add_development_dependency(%q<fakeweb>, ["~> 1.3.0"])
|
|
97
|
+
s.add_development_dependency(%q<webmock>, [">= 0"])
|
|
97
98
|
s.add_development_dependency(%q<rubocop>, [">= 0"])
|
|
98
99
|
s.add_development_dependency(%q<rspec_junit_formatter>, [">= 0"])
|
|
100
|
+
s.add_development_dependency(%q<pry>, [">= 0"])
|
|
99
101
|
else
|
|
100
102
|
s.add_dependency(%q<httparty>, [">= 0.7.0"])
|
|
101
103
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
|
@@ -18,7 +18,7 @@ class FederalRegister::Agency < FederalRegister::Base
|
|
|
18
18
|
get_options = {}
|
|
19
19
|
get_options.merge!(:query => {:fields => options[:fields]}) if options[:fields]
|
|
20
20
|
|
|
21
|
-
response = get('
|
|
21
|
+
response = get('agencies.json', get_options).parsed_response
|
|
22
22
|
|
|
23
23
|
response.map do |hsh|
|
|
24
24
|
new(hsh, :full => true)
|
|
@@ -29,7 +29,7 @@ class FederalRegister::Agency < FederalRegister::Base
|
|
|
29
29
|
slug = URI.encode(id_or_slug.to_s)
|
|
30
30
|
|
|
31
31
|
if options[:fields].present?
|
|
32
|
-
response = get("
|
|
32
|
+
response = get("agencies/#{slug}.json", :query => {:fields => options[:fields]}).parsed_response
|
|
33
33
|
|
|
34
34
|
if response.is_a?(Hash)
|
|
35
35
|
new(response)
|
|
@@ -39,7 +39,7 @@ class FederalRegister::Agency < FederalRegister::Base
|
|
|
39
39
|
end
|
|
40
40
|
end
|
|
41
41
|
else
|
|
42
|
-
response = get("
|
|
42
|
+
response = get("agencies/#{slug}.json").parsed_response
|
|
43
43
|
|
|
44
44
|
if response.is_a?(Hash)
|
|
45
45
|
new(response, :full => true)
|
|
@@ -52,7 +52,7 @@ class FederalRegister::Agency < FederalRegister::Base
|
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
def self.suggestions(args={})
|
|
55
|
-
response = get("
|
|
55
|
+
response = get("agencies/suggestions", query: args).parsed_response
|
|
56
56
|
|
|
57
57
|
response.map do |hsh|
|
|
58
58
|
new(hsh, :full => true)
|
|
@@ -103,7 +103,13 @@ class FederalRegister::Base < FederalRegister::Client
|
|
|
103
103
|
FederalRegister::PublicInspectionIssueResultSet,
|
|
104
104
|
FederalRegister::FacetResultSet,
|
|
105
105
|
].each do |klass|
|
|
106
|
-
|
|
106
|
+
|
|
107
|
+
klass.class_eval do
|
|
108
|
+
define_singleton_method(:base_uri) do
|
|
109
|
+
uri
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
107
113
|
end
|
|
108
114
|
end
|
|
109
115
|
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
class FederalRegister::Client
|
|
2
|
-
include HTTParty
|
|
3
2
|
|
|
4
|
-
class ResponseError <
|
|
3
|
+
class ResponseError < Faraday::Error
|
|
4
|
+
|
|
5
|
+
attr_reader :response
|
|
6
|
+
|
|
7
|
+
def initialize(response)
|
|
8
|
+
@response = response
|
|
9
|
+
super(message)
|
|
10
|
+
end
|
|
11
|
+
|
|
5
12
|
def message
|
|
6
13
|
response.body
|
|
7
14
|
end
|
|
@@ -17,14 +24,26 @@ class FederalRegister::Client
|
|
|
17
24
|
class ServerError < ResponseError; end
|
|
18
25
|
class ServiceUnavailable < ResponseError; end
|
|
19
26
|
|
|
20
|
-
|
|
27
|
+
FaradayResponseWrapper = Struct.new(:parsed_response)
|
|
28
|
+
|
|
29
|
+
def self.base_uri
|
|
30
|
+
'https://www.federalregister.gov/api/v1'
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def self.get(path, options={})
|
|
34
|
+
@connection = Faraday.new(url: base_uri) do |conn|
|
|
35
|
+
conn.request :url_encoded
|
|
36
|
+
conn.response :logger if ENV['DEBUG'] # Optional: Enable logging in debug mode
|
|
37
|
+
conn.adapter Faraday.default_adapter
|
|
38
|
+
conn.options.open_timeout = ENV['FARADAY_OPEN_TIMEOUT'].try(:to_i) || 2
|
|
39
|
+
conn.options.timeout = 10
|
|
40
|
+
end
|
|
21
41
|
|
|
22
|
-
|
|
23
|
-
response = super
|
|
42
|
+
response = @connection.get(strip_protocol_and_host(path), options[:query] || {})
|
|
24
43
|
|
|
25
|
-
case response.
|
|
44
|
+
case response.status
|
|
26
45
|
when 200
|
|
27
|
-
response
|
|
46
|
+
FaradayResponseWrapper.new(JSON.parse(response.body))
|
|
28
47
|
when 400
|
|
29
48
|
raise BadRequest.new(response)
|
|
30
49
|
when 404
|
|
@@ -36,7 +55,19 @@ class FederalRegister::Client
|
|
|
36
55
|
when 504
|
|
37
56
|
raise GatewayTimeout.new(response)
|
|
38
57
|
else
|
|
39
|
-
raise
|
|
58
|
+
raise Faraday::Error.new(nil, response)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def self.strip_protocol_and_host(path)
|
|
63
|
+
uri = URI.parse(path)
|
|
64
|
+
|
|
65
|
+
path_without_protocol_and_host = uri.path
|
|
66
|
+
if uri.query
|
|
67
|
+
path_without_protocol_and_host << "?#{uri.query}"
|
|
40
68
|
end
|
|
69
|
+
|
|
70
|
+
path_without_protocol_and_host
|
|
41
71
|
end
|
|
72
|
+
private_class_method :strip_protocol_and_host
|
|
42
73
|
end
|
|
@@ -53,11 +53,11 @@ class FederalRegister::Document < FederalRegister::Base
|
|
|
53
53
|
:type => :date
|
|
54
54
|
|
|
55
55
|
def self.search(args)
|
|
56
|
-
FederalRegister::ResultSet.fetch("
|
|
56
|
+
FederalRegister::ResultSet.fetch("documents.json", :query => args, :result_class => self)
|
|
57
57
|
end
|
|
58
58
|
|
|
59
59
|
def self.search_metadata(args)
|
|
60
|
-
FederalRegister::ResultSet.fetch("
|
|
60
|
+
FederalRegister::ResultSet.fetch("documents.json", :query => args.merge(:metadata_only => '1'), :result_class => self)
|
|
61
61
|
end
|
|
62
62
|
|
|
63
63
|
def self.find(document_number, options={})
|
|
@@ -65,7 +65,7 @@ class FederalRegister::Document < FederalRegister::Base
|
|
|
65
65
|
|
|
66
66
|
if options[:publication_date].present?
|
|
67
67
|
publication_date = options[:publication_date]
|
|
68
|
-
publication_date = publication_date.is_a?(Date) ? publication_date.
|
|
68
|
+
publication_date = publication_date.is_a?(Date) ? publication_date.strftime("%Y-%m-%d") : publication_date
|
|
69
69
|
|
|
70
70
|
query.merge!(:publication_date => publication_date)
|
|
71
71
|
end
|
|
@@ -74,12 +74,12 @@ class FederalRegister::Document < FederalRegister::Base
|
|
|
74
74
|
query.merge!(:fields => options[:fields])
|
|
75
75
|
end
|
|
76
76
|
|
|
77
|
-
attributes = get("
|
|
77
|
+
attributes = get("documents/#{document_number}.json", :query => query).parsed_response
|
|
78
78
|
new(attributes, :full => true)
|
|
79
79
|
end
|
|
80
80
|
|
|
81
81
|
def self.find_all_base_path
|
|
82
|
-
'
|
|
82
|
+
'documents'
|
|
83
83
|
end
|
|
84
84
|
|
|
85
85
|
def agencies
|
|
@@ -90,13 +90,14 @@ class FederalRegister::Document < FederalRegister::Base
|
|
|
90
90
|
|
|
91
91
|
%w(full_text_xml abstract_html body_html raw_text mods).each do |file_type|
|
|
92
92
|
define_method file_type do
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
93
|
+
response = Faraday.get(send("#{file_type}_url"))
|
|
94
|
+
if response.success?
|
|
95
|
+
response.body
|
|
96
|
+
elsif response.status == 404
|
|
96
97
|
nil
|
|
97
|
-
|
|
98
|
+
else
|
|
98
99
|
raise send("#{file_type}_url").inspect
|
|
99
|
-
|
|
100
|
+
end
|
|
100
101
|
end
|
|
101
102
|
end
|
|
102
103
|
|
|
@@ -5,7 +5,7 @@ class FederalRegister::DocumentSearchDetails < FederalRegister::Base
|
|
|
5
5
|
:suggestions
|
|
6
6
|
|
|
7
7
|
def self.search(args)
|
|
8
|
-
response = get('
|
|
8
|
+
response = get('documents/search-details', query: args).parsed_response
|
|
9
9
|
new(response)
|
|
10
10
|
end
|
|
11
11
|
end
|
|
@@ -24,28 +24,28 @@ class FederalRegister::PublicInspectionDocument < FederalRegister::Base
|
|
|
24
24
|
:type => :datetime
|
|
25
25
|
|
|
26
26
|
def self.search(args)
|
|
27
|
-
FederalRegister::ResultSet.fetch("
|
|
27
|
+
FederalRegister::ResultSet.fetch("public-inspection-documents.json", :query => args, :result_class => self)
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
def self.search_metadata(args)
|
|
31
|
-
FederalRegister::ResultSet.fetch("
|
|
31
|
+
FederalRegister::ResultSet.fetch("public-inspection-documents.json", :query => args.merge(:metadata_only => '1'), :result_class => self)
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
def self.find(document_number)
|
|
35
|
-
attributes = get("
|
|
35
|
+
attributes = get("public-inspection-documents/#{document_number}.json").parsed_response
|
|
36
36
|
new(attributes, :full => true)
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
def self.available_on(date)
|
|
40
|
-
FederalRegister::PublicInspectionIssueResultSet.fetch("
|
|
40
|
+
FederalRegister::PublicInspectionIssueResultSet.fetch("public-inspection-documents.json", :query => {:conditions => {:available_on => date}}, :result_class => self)
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
def self.current
|
|
44
|
-
FederalRegister::PublicInspectionIssueResultSet.fetch("
|
|
44
|
+
FederalRegister::PublicInspectionIssueResultSet.fetch("public-inspection-documents/current.json", :result_class => self)
|
|
45
45
|
end
|
|
46
46
|
|
|
47
47
|
def self.find_all_base_path
|
|
48
|
-
'
|
|
48
|
+
'public-inspection-documents'
|
|
49
49
|
end
|
|
50
50
|
|
|
51
51
|
def agencies
|
|
@@ -5,7 +5,7 @@ class FederalRegister::PublicInspectionDocumentSearchDetails < FederalRegister::
|
|
|
5
5
|
:suggestions
|
|
6
6
|
|
|
7
7
|
def self.search(args)
|
|
8
|
-
response = get('
|
|
8
|
+
response = get('public-inspection-documents/search-details', query: args).parsed_response
|
|
9
9
|
new(response)
|
|
10
10
|
end
|
|
11
|
-
end
|
|
11
|
+
end
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
class FederalRegister::ResultSet < FederalRegister::Client
|
|
2
2
|
include Enumerable
|
|
3
3
|
|
|
4
|
-
attr_reader :count, :total_pages, :results, :errors, :description
|
|
4
|
+
attr_reader :count, :total_pages, :results, :errors, :description, :is_neural
|
|
5
5
|
|
|
6
6
|
def initialize(attributes, result_class)
|
|
7
7
|
@result_class = result_class
|
|
8
8
|
@count = attributes['count']
|
|
9
|
+
@is_neural = attributes['is_neural']
|
|
9
10
|
@total_pages = attributes['total_pages']
|
|
10
11
|
@results = (attributes['results'] || []).map{|result| @result_class.new(result) }
|
|
11
12
|
|
|
@@ -2,7 +2,7 @@ class FederalRegister::Section < FederalRegister::Base
|
|
|
2
2
|
add_attribute :name
|
|
3
3
|
|
|
4
4
|
def self.search(args={})
|
|
5
|
-
response = get('
|
|
5
|
+
response = get('sections', query: args).parsed_response
|
|
6
6
|
|
|
7
7
|
responses = {}
|
|
8
8
|
response.map do |section, attributes|
|
|
@@ -9,7 +9,7 @@ class FederalRegister::SuggestedSearch < FederalRegister::Base
|
|
|
9
9
|
:title
|
|
10
10
|
|
|
11
11
|
def self.search(args={})
|
|
12
|
-
response = get('
|
|
12
|
+
response = get('suggested_searches', query: args).parsed_response
|
|
13
13
|
|
|
14
14
|
responses = {}
|
|
15
15
|
response.map do |section, searches|
|
|
@@ -20,7 +20,7 @@ class FederalRegister::SuggestedSearch < FederalRegister::Base
|
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
def self.find(slug)
|
|
23
|
-
response = get("
|
|
23
|
+
response = get("suggested_searches/#{URI.encode(slug.to_s)}").parsed_response
|
|
24
24
|
new(response)
|
|
25
25
|
end
|
|
26
26
|
end
|
|
@@ -4,7 +4,7 @@ class FederalRegister::Topic < FederalRegister::Base
|
|
|
4
4
|
:url
|
|
5
5
|
|
|
6
6
|
def self.suggestions(args={})
|
|
7
|
-
response = get("
|
|
7
|
+
response = get("topics/suggestions", query: args).parsed_response
|
|
8
8
|
|
|
9
9
|
response.map do |hsh|
|
|
10
10
|
new(hsh, :full => true)
|
data/lib/federal_register.rb
CHANGED
data/spec/agency_spec.rb
CHANGED
|
@@ -3,7 +3,16 @@ require File.dirname(__FILE__) + '/spec_helper'
|
|
|
3
3
|
describe FederalRegister::Agency do
|
|
4
4
|
describe ".all" do
|
|
5
5
|
before(:each) do
|
|
6
|
-
|
|
6
|
+
stub_request(
|
|
7
|
+
:get,
|
|
8
|
+
"https://www.federalregister.gov/api/v1/agencies.json"
|
|
9
|
+
)
|
|
10
|
+
.to_return(
|
|
11
|
+
body: [{},{}].to_json,
|
|
12
|
+
headers: { 'Content-Type' => 'application/json' },
|
|
13
|
+
status: 200
|
|
14
|
+
)
|
|
15
|
+
|
|
7
16
|
end
|
|
8
17
|
|
|
9
18
|
it "returns Agency objects" do
|
data/spec/base_spec.rb
CHANGED
|
@@ -101,8 +101,8 @@ describe FederalRegister::Base do
|
|
|
101
101
|
end
|
|
102
102
|
|
|
103
103
|
[FederalRegister::Agency, FederalRegister::Article, FederalRegister::Base, FederalRegister::Client, FederalRegister::ResultSet].each do |klass|
|
|
104
|
-
it "should set
|
|
105
|
-
klass.
|
|
104
|
+
it "should set base uri for #{klass}" do
|
|
105
|
+
klass.base_uri.should == 'http://fr2.local/api/v1'
|
|
106
106
|
end
|
|
107
107
|
end
|
|
108
108
|
|
data/spec/document_spec.rb
CHANGED
|
@@ -4,12 +4,15 @@ describe FederalRegister::Document do
|
|
|
4
4
|
describe ".find" do
|
|
5
5
|
it "fetches the document by its document number" do
|
|
6
6
|
document_number = "2010-213"
|
|
7
|
-
|
|
7
|
+
stub_request(
|
|
8
8
|
:get,
|
|
9
9
|
"https://www.federalregister.gov/api/v1/documents/#{document_number}.json",
|
|
10
|
-
:content_type =>"text/json",
|
|
11
|
-
:body => {:title => "Important Notice"}.to_json
|
|
12
10
|
)
|
|
11
|
+
.to_return(
|
|
12
|
+
body: {:title => "Important Notice"}.to_json,
|
|
13
|
+
headers: { 'Content-Type' => 'text/json' },
|
|
14
|
+
)
|
|
15
|
+
|
|
13
16
|
|
|
14
17
|
FederalRegister::Document.find(document_number).title.should == 'Important Notice'
|
|
15
18
|
end
|
|
@@ -18,11 +21,13 @@ describe FederalRegister::Document do
|
|
|
18
21
|
document_number = "2010-213"
|
|
19
22
|
params = URI.encode_www_form([["fields[]","title"],["fields[]", "start_page"]])
|
|
20
23
|
|
|
21
|
-
|
|
24
|
+
stub_request(
|
|
22
25
|
:get,
|
|
23
26
|
"https://www.federalregister.gov/api/v1/documents/#{document_number}.json?#{params}",
|
|
24
|
-
|
|
25
|
-
|
|
27
|
+
)
|
|
28
|
+
.to_return(
|
|
29
|
+
body: {:title => "Important Notice", :start_page => 12345}.to_json,
|
|
30
|
+
headers: { 'Content-Type' => 'text/json' },
|
|
26
31
|
)
|
|
27
32
|
|
|
28
33
|
result = FederalRegister::Document.find(document_number, :fields => ["title", "start_page"])
|
|
@@ -35,13 +40,16 @@ describe FederalRegister::Document do
|
|
|
35
40
|
document_number = "2010-213"
|
|
36
41
|
publication_date = "2010-02-02"
|
|
37
42
|
params = URI.encode_www_form([["publication_date", "#{publication_date}"]])
|
|
38
|
-
|
|
39
|
-
|
|
43
|
+
|
|
44
|
+
stub_request(
|
|
40
45
|
:get,
|
|
41
|
-
"https://www.federalregister.gov/api/v1/documents/#{document_number}.json?#{params}"
|
|
42
|
-
|
|
43
|
-
|
|
46
|
+
"https://www.federalregister.gov/api/v1/documents/#{document_number}.json?#{params}"
|
|
47
|
+
)
|
|
48
|
+
.to_return(
|
|
49
|
+
body: {:title => "Important Notice", :publication_date => publication_date}.to_json,
|
|
50
|
+
headers: { 'Content-Type' => 'text/json' }
|
|
44
51
|
)
|
|
52
|
+
|
|
45
53
|
|
|
46
54
|
result = FederalRegister::Document.find(document_number, :publication_date => publication_date)
|
|
47
55
|
result.title.should eql("Important Notice")
|
|
@@ -50,38 +58,46 @@ describe FederalRegister::Document do
|
|
|
50
58
|
|
|
51
59
|
it "throws an error when a document doesn't exist" do
|
|
52
60
|
document_number = "some-random-document"
|
|
53
|
-
|
|
61
|
+
stub_request(
|
|
54
62
|
:get,
|
|
55
63
|
"https://www.federalregister.gov/api/v1/documents/#{document_number}.json",
|
|
56
|
-
:content_type =>"text/json",
|
|
57
|
-
:status => 404
|
|
58
64
|
)
|
|
65
|
+
.to_return(
|
|
66
|
+
headers: { 'Content-Type' => 'text/json' },
|
|
67
|
+
status: 404
|
|
68
|
+
)
|
|
69
|
+
|
|
59
70
|
lambda{ FederalRegister::Document.find(document_number) }.should raise_error FederalRegister::Client::RecordNotFound
|
|
60
71
|
end
|
|
61
72
|
end
|
|
62
73
|
|
|
63
74
|
describe ".find_all" do
|
|
64
75
|
it "fetches multiple matching documents" do
|
|
65
|
-
|
|
76
|
+
stub_request(
|
|
66
77
|
:get,
|
|
67
78
|
"https://www.federalregister.gov/api/v1/documents/abc,def.json",
|
|
68
|
-
:content_type =>"text/json",
|
|
69
|
-
:body => {:results => [{:document_number => "abc"}, {:document_number => "def"}]}.to_json
|
|
70
79
|
)
|
|
80
|
+
.to_return(
|
|
81
|
+
body: {:results => [{:document_number => "abc"}, {:document_number => "def"}]}.to_json,
|
|
82
|
+
headers: { 'Content-Type' => 'text/json' },
|
|
83
|
+
)
|
|
84
|
+
|
|
71
85
|
result_set = FederalRegister::Document.find_all('abc','def')
|
|
72
86
|
result_set.results.map(&:document_number).sort.should === ['abc','def']
|
|
73
87
|
end
|
|
74
88
|
|
|
75
89
|
it "fetches multiple matching documents with only requested fields (when present)" do
|
|
76
90
|
params = URI.encode_www_form([["fields[]","document_number"],["fields[]", "title"]])
|
|
77
|
-
|
|
78
|
-
FakeWeb.register_uri(
|
|
91
|
+
stub_request(
|
|
79
92
|
:get,
|
|
80
93
|
"https://www.federalregister.gov/api/v1/documents/abc,def.json?#{params}",
|
|
81
|
-
:content_type =>"text/json",
|
|
82
|
-
:body => {:results => [{:document_number => "abc", :title => "Important Notice"},
|
|
83
|
-
{:document_number => "def", :title => "Important Rule"}]}.to_json
|
|
84
94
|
)
|
|
95
|
+
.to_return(
|
|
96
|
+
body: {:results => [{:document_number => "abc", :title => "Important Notice"},
|
|
97
|
+
{:document_number => "def", :title => "Important Rule"}]}.to_json,
|
|
98
|
+
headers: { 'Content-Type' => 'text/json' },
|
|
99
|
+
)
|
|
100
|
+
|
|
85
101
|
result_set = FederalRegister::Document.find_all('abc','def', :fields => ["document_number", "title"])
|
|
86
102
|
result_set.results.map(&:document_number).sort.should === ['abc','def']
|
|
87
103
|
result_set.results.map(&:title).sort.should === ['Important Notice','Important Rule']
|
|
@@ -90,11 +106,13 @@ describe FederalRegister::Document do
|
|
|
90
106
|
|
|
91
107
|
it "handles results when no documents are returned" do
|
|
92
108
|
params = URI.encode_www_form([["fields[]","document_number"],["fields[]", "title"]])
|
|
93
|
-
|
|
109
|
+
stub_request(
|
|
94
110
|
:get,
|
|
95
111
|
"https://www.federalregister.gov/api/v1/documents/bad_document_number,.json?#{params}",
|
|
96
|
-
|
|
97
|
-
|
|
112
|
+
)
|
|
113
|
+
.to_return(
|
|
114
|
+
body: {"count":0,"results":[],"errors":{"not_found":["bad_docuemnt_number"]}}.to_json,
|
|
115
|
+
headers: { 'Content-Type' => 'text/json' },
|
|
98
116
|
)
|
|
99
117
|
|
|
100
118
|
result_set = FederalRegister::Document.find_all('bad_document_number', :fields => ["document_number", "title"])
|
|
@@ -103,12 +121,14 @@ describe FederalRegister::Document do
|
|
|
103
121
|
|
|
104
122
|
it "appends a trailing comma when a single document is provided to ensure API interface doesn't return a single document" do
|
|
105
123
|
params = URI.encode_www_form([["fields[]","document_number"],["fields[]", "title"]])
|
|
106
|
-
|
|
124
|
+
stub_request(
|
|
107
125
|
:get,
|
|
108
126
|
"https://www.federalregister.gov/api/v1/documents/2016-26522,.json?#{params}",
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
127
|
+
)
|
|
128
|
+
.to_return(
|
|
129
|
+
body: {:results => [{:document_number => "2016-26522", :title => "Important Notice"}],
|
|
130
|
+
}.to_json,
|
|
131
|
+
headers: { 'Content-Type' => 'text/json' },
|
|
112
132
|
)
|
|
113
133
|
|
|
114
134
|
FederalRegister::Document.find_all('2016-26522', :fields => ["document_number", "title"])
|
|
@@ -117,36 +137,44 @@ describe FederalRegister::Document do
|
|
|
117
137
|
it "ensures document or citation numbers provided are unique before making requests to API Core." do
|
|
118
138
|
# Without calling unique, duplicate results could be returned since we're now batching up larger requests.
|
|
119
139
|
params = URI.encode_www_form([["fields[]","document_number"],["fields[]", "title"]])
|
|
120
|
-
|
|
140
|
+
stub_request(
|
|
121
141
|
:get,
|
|
122
|
-
"https://www.federalregister.gov/api/v1/documents/2016-26522,.json
|
|
123
|
-
|
|
142
|
+
"https://www.federalregister.gov/api/v1/documents/2016-26522,.json?#{params}",
|
|
143
|
+
)
|
|
144
|
+
.to_return(
|
|
124
145
|
:body => {:results => [{:document_number => "2016-26522", :title => "Important Notice"}],
|
|
125
|
-
}.to_json
|
|
146
|
+
}.to_json,
|
|
147
|
+
headers: { 'Content-Type' => 'text/json' },
|
|
126
148
|
)
|
|
149
|
+
|
|
127
150
|
FederalRegister::Document.find_all('2016-26522', '2016-26522', :fields => ["document_number", "title"])
|
|
128
151
|
end
|
|
129
152
|
|
|
130
153
|
#TODO: Add specs aroudn API response
|
|
131
154
|
it "batches up large requests when CGI parameters exceed the URL limit and returns the correct" do
|
|
132
155
|
params = URI.encode_www_form([["fields[]","document_number"],["fields[]", "title"]])
|
|
133
|
-
|
|
156
|
+
stub_request(
|
|
134
157
|
:get,
|
|
135
|
-
"https://www.federalregister.gov/api/v1/documents/2016-26000,2016-26001,2016-26002,2016-26003,2016-26004,2016-26005,2016-26006,2016-26007,2016-26008,2016-26009,2016-26010,2016-26011,2016-26012,2016-26013,2016-26014,2016-26015,2016-26016,2016-26017,2016-26018,2016-26019,2016-26020,2016-26021,2016-26022,2016-26023,2016-26024,2016-26025,2016-26026,2016-26027,2016-26028,2016-26029,2016-26030,2016-26031,2016-26032,2016-26033,2016-26034,2016-26035,2016-26036,2016-26037,2016-26038,2016-26039,2016-26040,2016-26041,2016-26042,2016-26043,2016-26044,2016-26045,2016-26046,2016-26047,2016-26048,2016-26049,2016-26050,2016-26051,2016-26052,2016-26053,2016-26054,2016-26055,2016-26056,2016-26057,2016-26058,2016-26059,2016-26060,2016-26061,2016-26062,2016-26063,2016-26064,2016-26065,2016-26066,2016-26067,2016-26068,2016-26069,2016-26070,2016-26071,2016-26072,2016-26073,2016-26074,2016-26075,2016-26076,2016-26077,2016-26078,2016-26079,2016-26080,2016-26081,2016-26082,2016-26083,2016-26084,2016-26085,2016-26086,2016-26087,2016-26088,2016-26089,2016-26090,2016-26091,2016-26092,2016-26093,2016-26094,2016-26095,2016-26096,2016-26097,2016-26098,2016-26099,2016-26100.json?#{params}"
|
|
136
|
-
|
|
158
|
+
"https://www.federalregister.gov/api/v1/documents/2016-26000,2016-26001,2016-26002,2016-26003,2016-26004,2016-26005,2016-26006,2016-26007,2016-26008,2016-26009,2016-26010,2016-26011,2016-26012,2016-26013,2016-26014,2016-26015,2016-26016,2016-26017,2016-26018,2016-26019,2016-26020,2016-26021,2016-26022,2016-26023,2016-26024,2016-26025,2016-26026,2016-26027,2016-26028,2016-26029,2016-26030,2016-26031,2016-26032,2016-26033,2016-26034,2016-26035,2016-26036,2016-26037,2016-26038,2016-26039,2016-26040,2016-26041,2016-26042,2016-26043,2016-26044,2016-26045,2016-26046,2016-26047,2016-26048,2016-26049,2016-26050,2016-26051,2016-26052,2016-26053,2016-26054,2016-26055,2016-26056,2016-26057,2016-26058,2016-26059,2016-26060,2016-26061,2016-26062,2016-26063,2016-26064,2016-26065,2016-26066,2016-26067,2016-26068,2016-26069,2016-26070,2016-26071,2016-26072,2016-26073,2016-26074,2016-26075,2016-26076,2016-26077,2016-26078,2016-26079,2016-26080,2016-26081,2016-26082,2016-26083,2016-26084,2016-26085,2016-26086,2016-26087,2016-26088,2016-26089,2016-26090,2016-26091,2016-26092,2016-26093,2016-26094,2016-26095,2016-26096,2016-26097,2016-26098,2016-26099,2016-26100.json?#{params}"
|
|
159
|
+
)
|
|
160
|
+
.to_return(
|
|
137
161
|
:body => {:results => [
|
|
138
162
|
{:document_number => "2016-26000", :title => "Important Notice"},
|
|
139
163
|
#...
|
|
140
|
-
]}.to_json
|
|
164
|
+
]}.to_json,
|
|
165
|
+
headers: { 'Content-Type' => 'text/json' }
|
|
141
166
|
)
|
|
142
|
-
|
|
167
|
+
|
|
168
|
+
stub_request(
|
|
143
169
|
:get,
|
|
144
|
-
"https://www.federalregister.gov/api/v1/documents/2016-26101,2016-26102,2016-26103,2016-26104,2016-26105,2016-26106,2016-26107,2016-26108,2016-26109,2016-26110,2016-26111,2016-26112,2016-26113,2016-26114,2016-26115,2016-26116,2016-26117,2016-26118,2016-26119,2016-26120,2016-26121,2016-26122,2016-26123,2016-26124,2016-26125,2016-26126,2016-26127,2016-26128,2016-26129,2016-26130,2016-26131,2016-26132,2016-26133,2016-26134,2016-26135,2016-26136,2016-26137,2016-26138,2016-26139,2016-26140,2016-26141,2016-26142,2016-26143,2016-26144,2016-26145,2016-26146,2016-26147,2016-26148,2016-26149,2016-26150,2016-26151,2016-26152,2016-26153,2016-26154,2016-26155,2016-26156,2016-26157,2016-26158,2016-26159,2016-26160,2016-26161,2016-26162,2016-26163,2016-26164,2016-26165,2016-26166,2016-26167,2016-26168,2016-26169,2016-26170,2016-26171,2016-26172,2016-26173,2016-26174,2016-26175,2016-26176,2016-26177,2016-26178,2016-26179,2016-26180,2016-26181,2016-26182,2016-26183,2016-26184,2016-26185,2016-26186,2016-26187,2016-26188,2016-26189,2016-26190,2016-26191,2016-26192,2016-26193,2016-26194,2016-26195,2016-26196,2016-26197,2016-26198,2016-26199,2016-26200.json?#{params}"
|
|
145
|
-
|
|
170
|
+
"https://www.federalregister.gov/api/v1/documents/2016-26101,2016-26102,2016-26103,2016-26104,2016-26105,2016-26106,2016-26107,2016-26108,2016-26109,2016-26110,2016-26111,2016-26112,2016-26113,2016-26114,2016-26115,2016-26116,2016-26117,2016-26118,2016-26119,2016-26120,2016-26121,2016-26122,2016-26123,2016-26124,2016-26125,2016-26126,2016-26127,2016-26128,2016-26129,2016-26130,2016-26131,2016-26132,2016-26133,2016-26134,2016-26135,2016-26136,2016-26137,2016-26138,2016-26139,2016-26140,2016-26141,2016-26142,2016-26143,2016-26144,2016-26145,2016-26146,2016-26147,2016-26148,2016-26149,2016-26150,2016-26151,2016-26152,2016-26153,2016-26154,2016-26155,2016-26156,2016-26157,2016-26158,2016-26159,2016-26160,2016-26161,2016-26162,2016-26163,2016-26164,2016-26165,2016-26166,2016-26167,2016-26168,2016-26169,2016-26170,2016-26171,2016-26172,2016-26173,2016-26174,2016-26175,2016-26176,2016-26177,2016-26178,2016-26179,2016-26180,2016-26181,2016-26182,2016-26183,2016-26184,2016-26185,2016-26186,2016-26187,2016-26188,2016-26189,2016-26190,2016-26191,2016-26192,2016-26193,2016-26194,2016-26195,2016-26196,2016-26197,2016-26198,2016-26199,2016-26200.json?#{params}"
|
|
171
|
+
)
|
|
172
|
+
.to_return(
|
|
146
173
|
:body => {:results => [
|
|
147
174
|
{:document_number => "2016-26000", :title => "Important Notice"},
|
|
148
175
|
#...
|
|
149
|
-
]}.to_json
|
|
176
|
+
]}.to_json,
|
|
177
|
+
headers: { 'Content-Type' => 'text/json' }
|
|
150
178
|
)
|
|
151
179
|
|
|
152
180
|
document_numbers = []
|
|
@@ -165,11 +193,13 @@ describe FederalRegister::Document do
|
|
|
165
193
|
describe ".search" do
|
|
166
194
|
before(:each) do
|
|
167
195
|
params = URI.encode_www_form([["conditions[term]","Fish"]])
|
|
168
|
-
|
|
196
|
+
stub_request(
|
|
169
197
|
:get,
|
|
170
198
|
"https://www.federalregister.gov/api/v1/documents.json?#{params}",
|
|
171
|
-
|
|
172
|
-
|
|
199
|
+
)
|
|
200
|
+
.to_return(
|
|
201
|
+
:body => {:count => 3}.to_json,
|
|
202
|
+
headers: { 'Content-Type' => 'text/json' },
|
|
173
203
|
)
|
|
174
204
|
end
|
|
175
205
|
|
|
@@ -182,12 +212,15 @@ describe FederalRegister::Document do
|
|
|
182
212
|
it "fetches the full_text_xml from the full_text_xml_url" do
|
|
183
213
|
url = "http://example.com/full_text"
|
|
184
214
|
document = FederalRegister::Document.new("full_text_xml_url" => url)
|
|
185
|
-
|
|
215
|
+
stub_request(
|
|
186
216
|
:get,
|
|
187
217
|
url,
|
|
188
|
-
:content_type =>"text/xml",
|
|
189
|
-
:body => "hello, world!"
|
|
190
218
|
)
|
|
219
|
+
.to_return(
|
|
220
|
+
:body => "hello, world!",
|
|
221
|
+
headers: { 'Content-Type' => 'text/xml' },
|
|
222
|
+
)
|
|
223
|
+
|
|
191
224
|
document.full_text_xml.should == 'hello, world!'
|
|
192
225
|
end
|
|
193
226
|
end
|
|
@@ -202,11 +235,13 @@ describe FederalRegister::Document do
|
|
|
202
235
|
describe "#docket_ids" do
|
|
203
236
|
it "returns an array" do
|
|
204
237
|
document_number = "2010-213"
|
|
205
|
-
|
|
238
|
+
stub_request(
|
|
206
239
|
:get,
|
|
207
240
|
"https://www.federalregister.gov/api/v1/documents/#{document_number}.json",
|
|
208
|
-
|
|
209
|
-
|
|
241
|
+
)
|
|
242
|
+
.to_return(
|
|
243
|
+
body: {:title => "Important Notice", :docket_ids => ['ABC','123']}.to_json,
|
|
244
|
+
headers: { 'Content-Type' => 'text/json' },
|
|
210
245
|
)
|
|
211
246
|
|
|
212
247
|
FederalRegister::Document.find(document_number).docket_ids.should == ['ABC','123']
|
|
@@ -4,36 +4,40 @@ describe FederalRegister::PublicInspectionDocument do
|
|
|
4
4
|
describe ".find" do
|
|
5
5
|
it "fetches the document by its document number" do
|
|
6
6
|
document_number = "2010-213"
|
|
7
|
-
|
|
7
|
+
stub_request(
|
|
8
8
|
:get,
|
|
9
|
-
"https://www.federalregister.gov/api/v1/public-inspection-documents/#{document_number}.json"
|
|
10
|
-
:content_type =>"text/json",
|
|
11
|
-
:body => {:title => "Important Notice"}.to_json
|
|
9
|
+
"https://www.federalregister.gov/api/v1/public-inspection-documents/#{document_number}.json"
|
|
12
10
|
)
|
|
11
|
+
.to_return(
|
|
12
|
+
body: {:title => "Important Notice"}.to_json,
|
|
13
|
+
headers: { 'Content-Type' => 'application/json' },
|
|
14
|
+
status: 200
|
|
15
|
+
)
|
|
16
|
+
|
|
13
17
|
|
|
14
18
|
FederalRegister::PublicInspectionDocument.find(document_number).title.should == 'Important Notice'
|
|
15
19
|
end
|
|
16
20
|
|
|
17
21
|
it "throws an error when a document doesn't exist" do
|
|
18
22
|
document_number = "some-random-document"
|
|
19
|
-
|
|
23
|
+
stub_request(
|
|
20
24
|
:get,
|
|
21
|
-
"https://www.federalregister.gov/api/v1/public-inspection-documents/#{document_number}.json"
|
|
22
|
-
|
|
23
|
-
|
|
25
|
+
"https://www.federalregister.gov/api/v1/public-inspection-documents/#{document_number}.json"
|
|
26
|
+
)
|
|
27
|
+
.to_return(
|
|
28
|
+
headers: { 'Content-Type' => 'text/json' },
|
|
29
|
+
status: 404
|
|
24
30
|
)
|
|
31
|
+
|
|
25
32
|
lambda{ FederalRegister::PublicInspectionDocument.find(document_number) }.should raise_error FederalRegister::Client::RecordNotFound
|
|
26
33
|
end
|
|
27
34
|
end
|
|
28
35
|
|
|
29
36
|
describe ".find_all" do
|
|
30
37
|
it "fetches multiple matching documents" do
|
|
31
|
-
|
|
32
|
-
:
|
|
33
|
-
|
|
34
|
-
:content_type =>"text/json",
|
|
35
|
-
:body => {:results => [{:document_number => "abc"}, {:document_number => "def"}]}.to_json
|
|
36
|
-
)
|
|
38
|
+
stub_request(:get, "https://www.federalregister.gov/api/v1/public-inspection-documents/abc,def.json").
|
|
39
|
+
to_return(status: 200, body: {:results => [{:document_number => "abc"}, {:document_number => "def"}]}.to_json, headers: { 'Content-Type' => 'text/json' })
|
|
40
|
+
|
|
37
41
|
result_set = FederalRegister::PublicInspectionDocument.find_all('abc','def')
|
|
38
42
|
result_set.results.map(&:document_number).sort.should === ['abc','def']
|
|
39
43
|
end
|
|
@@ -42,12 +46,17 @@ describe FederalRegister::PublicInspectionDocument do
|
|
|
42
46
|
describe ".available_on" do
|
|
43
47
|
it "fetches the document on PI on a given date" do
|
|
44
48
|
params = URI.encode_www_form([["conditions[available_on]", "2011-10-15"]])
|
|
45
|
-
|
|
49
|
+
|
|
50
|
+
stub_request(
|
|
46
51
|
:get,
|
|
47
52
|
"https://www.federalregister.gov/api/v1/public-inspection-documents.json?#{params}",
|
|
48
|
-
:content_type =>"text/json",
|
|
49
|
-
:body => {:results => [{:document_number => "abc"}, {:document_number => "def"}]}.to_json
|
|
50
53
|
)
|
|
54
|
+
.to_return(
|
|
55
|
+
body: {:results => [{:document_number => "abc"}, {:document_number => "def"}]}.to_json,
|
|
56
|
+
headers: { 'Content-Type' => 'text/json' },
|
|
57
|
+
# status: 200
|
|
58
|
+
)
|
|
59
|
+
|
|
51
60
|
result_set = FederalRegister::PublicInspectionDocument.available_on(Date.parse('2011-10-15'))
|
|
52
61
|
result_set.results.map(&:document_number).sort.should === ['abc','def']
|
|
53
62
|
end
|
|
@@ -55,12 +64,16 @@ describe FederalRegister::PublicInspectionDocument do
|
|
|
55
64
|
|
|
56
65
|
describe ".current" do
|
|
57
66
|
it "fetches the PI documents from the current issue" do
|
|
58
|
-
|
|
67
|
+
stub_request(
|
|
59
68
|
:get,
|
|
60
69
|
"https://www.federalregister.gov/api/v1/public-inspection-documents/current.json",
|
|
61
|
-
:content_type =>"text/json",
|
|
62
|
-
:body => {:results => [{:document_number => "abc"}, {:document_number => "def"}]}.to_json
|
|
63
70
|
)
|
|
71
|
+
.to_return(
|
|
72
|
+
body: {:results => [{:document_number => "abc"}, {:document_number => "def"}]}.to_json,
|
|
73
|
+
headers: { 'Content-Type' => 'text/json' },
|
|
74
|
+
# status: 200
|
|
75
|
+
)
|
|
76
|
+
|
|
64
77
|
result_set = FederalRegister::PublicInspectionDocument.current
|
|
65
78
|
result_set.results.map(&:document_number).sort.should === ['abc','def']
|
|
66
79
|
end
|
data/spec/result_set_spec.rb
CHANGED
|
@@ -3,7 +3,16 @@ require File.dirname(__FILE__) + '/spec_helper'
|
|
|
3
3
|
describe FederalRegister::ResultSet do
|
|
4
4
|
describe "#next" do
|
|
5
5
|
it "loads the next_page_url" do
|
|
6
|
-
|
|
6
|
+
stub_request(
|
|
7
|
+
:get,
|
|
8
|
+
"https://www.federalregister.gov/api/v1/fishes?page=2"
|
|
9
|
+
)
|
|
10
|
+
.to_return(
|
|
11
|
+
body: {:count => 24}.to_json,
|
|
12
|
+
headers: { 'Content-Type' => 'application/json' },
|
|
13
|
+
status: 200
|
|
14
|
+
)
|
|
15
|
+
|
|
7
16
|
FederalRegister::ResultSet.new({'next_page_url' => 'https://www.federalregister.gov/api/v1/fishes?page=2'}, FederalRegister::Document).next.count.should == 24
|
|
8
17
|
end
|
|
9
18
|
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
2
2
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
3
3
|
require 'rspec'
|
|
4
|
-
require '
|
|
4
|
+
require 'webmock/rspec'
|
|
5
5
|
require 'active_support/ordered_hash'
|
|
6
6
|
require 'active_support/json'
|
|
7
7
|
require 'active_support/time'
|
|
8
8
|
require 'federal_register'
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
WebMock.disable_net_connect!(allow_localhost: true) # Prevents real HTTP requests except to localhost
|
|
11
11
|
|
|
12
12
|
# Requires supporting files with custom matchers and macros, etc,
|
|
13
13
|
# in ./support/ and its subdirectories.
|
|
@@ -16,5 +16,3 @@ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
|
|
16
16
|
RSpec.configure do |config|
|
|
17
17
|
config.expect_with(:rspec) { |c| c.syntax = :should }
|
|
18
18
|
end
|
|
19
|
-
|
|
20
|
-
|
metadata
CHANGED
|
@@ -1,30 +1,29 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: federal_register
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.8.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andrew Carpenter
|
|
8
8
|
- Bob Burbach
|
|
9
|
-
autorequire:
|
|
10
9
|
bindir: bin
|
|
11
10
|
cert_chain: []
|
|
12
11
|
date: 2019-12-03 00:00:00.000000000 Z
|
|
13
12
|
dependencies:
|
|
14
13
|
- !ruby/object:Gem::Dependency
|
|
15
|
-
name:
|
|
14
|
+
name: faraday
|
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
|
17
16
|
requirements:
|
|
18
17
|
- - ">="
|
|
19
18
|
- !ruby/object:Gem::Version
|
|
20
|
-
version:
|
|
19
|
+
version: '1.8'
|
|
21
20
|
type: :runtime
|
|
22
21
|
prerelease: false
|
|
23
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
24
23
|
requirements:
|
|
25
24
|
- - ">="
|
|
26
25
|
- !ruby/object:Gem::Version
|
|
27
|
-
version:
|
|
26
|
+
version: '1.8'
|
|
28
27
|
- !ruby/object:Gem::Dependency
|
|
29
28
|
name: shoulda
|
|
30
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -95,6 +94,20 @@ dependencies:
|
|
|
95
94
|
- - "~>"
|
|
96
95
|
- !ruby/object:Gem::Version
|
|
97
96
|
version: 1.3.0
|
|
97
|
+
- !ruby/object:Gem::Dependency
|
|
98
|
+
name: webmock
|
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - ">="
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: '0'
|
|
104
|
+
type: :development
|
|
105
|
+
prerelease: false
|
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
+
requirements:
|
|
108
|
+
- - ">="
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: '0'
|
|
98
111
|
- !ruby/object:Gem::Dependency
|
|
99
112
|
name: rubocop
|
|
100
113
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -123,6 +136,20 @@ dependencies:
|
|
|
123
136
|
- - ">="
|
|
124
137
|
- !ruby/object:Gem::Version
|
|
125
138
|
version: '0'
|
|
139
|
+
- !ruby/object:Gem::Dependency
|
|
140
|
+
name: pry
|
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
|
142
|
+
requirements:
|
|
143
|
+
- - ">="
|
|
144
|
+
- !ruby/object:Gem::Version
|
|
145
|
+
version: '0'
|
|
146
|
+
type: :development
|
|
147
|
+
prerelease: false
|
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
149
|
+
requirements:
|
|
150
|
+
- - ">="
|
|
151
|
+
- !ruby/object:Gem::Version
|
|
152
|
+
version: '0'
|
|
126
153
|
description: Ruby API Client for FederalRegister.gov that handles searching documents
|
|
127
154
|
and getting information about agencies
|
|
128
155
|
email: andrew@criticaljuncture.org
|
|
@@ -195,7 +222,6 @@ homepage: http://github.com/usnationalarchives/federal_register
|
|
|
195
222
|
licenses:
|
|
196
223
|
- MIT
|
|
197
224
|
metadata: {}
|
|
198
|
-
post_install_message:
|
|
199
225
|
rdoc_options: []
|
|
200
226
|
require_paths:
|
|
201
227
|
- lib
|
|
@@ -210,8 +236,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
210
236
|
- !ruby/object:Gem::Version
|
|
211
237
|
version: '0'
|
|
212
238
|
requirements: []
|
|
213
|
-
rubygems_version: 3.
|
|
214
|
-
signing_key:
|
|
239
|
+
rubygems_version: 3.6.2
|
|
215
240
|
specification_version: 3
|
|
216
241
|
summary: Ruby API Client for FederalRegister.gov
|
|
217
242
|
test_files: []
|