federal_register 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/.rubocop.yml +286 -0
  2. data/Gemfile +3 -4
  3. data/Gemfile.lock +82 -22
  4. data/README.md +6 -6
  5. data/Rakefile +5 -5
  6. data/VERSION +1 -1
  7. data/federal_register.gemspec +49 -19
  8. data/lib/federal_register.rb +41 -0
  9. data/lib/federal_register/agency.rb +45 -9
  10. data/lib/federal_register/article.rb +2 -106
  11. data/lib/federal_register/base.rb +52 -3
  12. data/lib/federal_register/client.rb +3 -3
  13. data/lib/federal_register/document.rb +113 -0
  14. data/lib/federal_register/document_image.rb +17 -0
  15. data/lib/federal_register/facet.rb +21 -0
  16. data/lib/federal_register/facet/agency.rb +5 -0
  17. data/lib/federal_register/facet/document.rb +2 -0
  18. data/lib/federal_register/facet/document/agency.rb +5 -0
  19. data/lib/federal_register/facet/document/daily.rb +5 -0
  20. data/lib/federal_register/facet/document/frequency.rb +12 -0
  21. data/lib/federal_register/facet/document/monthly.rb +5 -0
  22. data/lib/federal_register/facet/document/quarterly.rb +5 -0
  23. data/lib/federal_register/facet/document/section.rb +5 -0
  24. data/lib/federal_register/facet/document/topic.rb +5 -0
  25. data/lib/federal_register/facet/document/type.rb +5 -0
  26. data/lib/federal_register/facet/document/weekly.rb +5 -0
  27. data/lib/federal_register/facet/document/yearly.rb +5 -0
  28. data/lib/federal_register/facet/presidential_document_type.rb +6 -0
  29. data/lib/federal_register/facet/public_inspection_document.rb +2 -0
  30. data/lib/federal_register/facet/public_inspection_document/agencies.rb +5 -0
  31. data/lib/federal_register/facet/public_inspection_document/agency.rb +5 -0
  32. data/lib/federal_register/facet/public_inspection_document/type.rb +5 -0
  33. data/lib/federal_register/facet/public_inspection_issue.rb +36 -0
  34. data/lib/federal_register/facet/public_inspection_issue/daily.rb +11 -0
  35. data/lib/federal_register/facet/public_inspection_issue/daily_filing.rb +6 -0
  36. data/lib/federal_register/facet/public_inspection_issue/type.rb +11 -0
  37. data/lib/federal_register/facet/public_inspection_issue/type_filing.rb +22 -0
  38. data/lib/federal_register/facet/topic.rb +5 -0
  39. data/lib/federal_register/facet_result_set.rb +25 -0
  40. data/lib/federal_register/highlighted_document.rb +42 -0
  41. data/lib/federal_register/public_inspection_document.rb +21 -7
  42. data/lib/federal_register/public_inspection_issue_result_set.rb +10 -0
  43. data/lib/federal_register/result_set.rb +5 -5
  44. data/lib/federal_register/section.rb +26 -0
  45. data/lib/federal_register/suggested_search.rb +26 -0
  46. data/lib/federal_register/topic.rb +13 -0
  47. data/spec/{article_spec.rb → document_spec.rb} +20 -28
  48. data/spec/public_inspection_document_spec.rb +5 -6
  49. data/spec/result_set_spec.rb +4 -4
  50. metadata +99 -39
data/Rakefile CHANGED
@@ -15,12 +15,12 @@ require 'jeweler'
15
15
  Jeweler::Tasks.new do |gem|
16
16
  # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
17
  gem.name = "federal_register"
18
- gem.homepage = "http://github.com/criticaljuncture/federal_register"
18
+ gem.homepage = "http://github.com/usnationalarchives/federal_register"
19
19
  gem.license = "MIT"
20
20
  gem.summary = %Q{Ruby API Client for FederalRegister.gov}
21
- gem.description = %Q{Ruby API Client for FederalRegister.gov that handles searching articles and getting information about agencies}
21
+ gem.description = %Q{Ruby API Client for FederalRegister.gov that handles searching documents and getting information about agencies}
22
22
  gem.email = "andrew@criticaljuncture.org"
23
- gem.authors = ["Andrew Carpenter"]
23
+ gem.authors = ["Andrew Carpenter", "Bob Burbach"]
24
24
  # dependencies defined in Gemfile
25
25
  end
26
26
  Jeweler::RubygemsDotOrgTasks.new
@@ -38,8 +38,8 @@ end
38
38
 
39
39
  task :default => :spec
40
40
 
41
- require 'rake/rdoctask'
42
- Rake::RDocTask.new do |rdoc|
41
+ require 'rdoc/task'
42
+ RDoc::Task.new do |rdoc|
43
43
  version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
44
 
45
45
  rdoc.rdoc_dir = 'rdoc'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.1
1
+ 0.6.0
@@ -5,12 +5,12 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "federal_register"
8
- s.version = "0.5.1"
8
+ s.version = "0.6.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Andrew Carpenter"]
12
- s.date = "2015-02-06"
13
- s.description = "Ruby API Client for FederalRegister.gov that handles searching articles and getting information about agencies"
11
+ s.authors = ["Andrew Carpenter", "Bob Burbach"]
12
+ s.date = "2016-11-03"
13
+ s.description = "Ruby API Client for FederalRegister.gov that handles searching documents and getting information about agencies"
14
14
  s.email = "andrew@criticaljuncture.org"
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE.md",
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
18
18
  ]
19
19
  s.files = [
20
20
  ".document",
21
+ ".rubocop.yml",
21
22
  ".watchr",
22
23
  "Gemfile",
23
24
  "Gemfile.lock",
@@ -31,20 +32,52 @@ Gem::Specification.new do |s|
31
32
  "lib/federal_register/article.rb",
32
33
  "lib/federal_register/base.rb",
33
34
  "lib/federal_register/client.rb",
35
+ "lib/federal_register/document.rb",
36
+ "lib/federal_register/document_image.rb",
37
+ "lib/federal_register/facet.rb",
38
+ "lib/federal_register/facet/agency.rb",
39
+ "lib/federal_register/facet/document.rb",
40
+ "lib/federal_register/facet/document/agency.rb",
41
+ "lib/federal_register/facet/document/daily.rb",
42
+ "lib/federal_register/facet/document/frequency.rb",
43
+ "lib/federal_register/facet/document/monthly.rb",
44
+ "lib/federal_register/facet/document/quarterly.rb",
45
+ "lib/federal_register/facet/document/section.rb",
46
+ "lib/federal_register/facet/document/topic.rb",
47
+ "lib/federal_register/facet/document/type.rb",
48
+ "lib/federal_register/facet/document/weekly.rb",
49
+ "lib/federal_register/facet/document/yearly.rb",
50
+ "lib/federal_register/facet/presidential_document_type.rb",
51
+ "lib/federal_register/facet/public_inspection_document.rb",
52
+ "lib/federal_register/facet/public_inspection_document/agencies.rb",
53
+ "lib/federal_register/facet/public_inspection_document/agency.rb",
54
+ "lib/federal_register/facet/public_inspection_document/type.rb",
55
+ "lib/federal_register/facet/public_inspection_issue.rb",
56
+ "lib/federal_register/facet/public_inspection_issue/daily.rb",
57
+ "lib/federal_register/facet/public_inspection_issue/daily_filing.rb",
58
+ "lib/federal_register/facet/public_inspection_issue/type.rb",
59
+ "lib/federal_register/facet/public_inspection_issue/type_filing.rb",
60
+ "lib/federal_register/facet/topic.rb",
61
+ "lib/federal_register/facet_result_set.rb",
62
+ "lib/federal_register/highlighted_document.rb",
34
63
  "lib/federal_register/public_inspection_document.rb",
64
+ "lib/federal_register/public_inspection_issue_result_set.rb",
35
65
  "lib/federal_register/result_set.rb",
66
+ "lib/federal_register/section.rb",
67
+ "lib/federal_register/suggested_search.rb",
68
+ "lib/federal_register/topic.rb",
36
69
  "lib/federal_register/utilities.rb",
37
70
  "spec/agency_spec.rb",
38
- "spec/article_spec.rb",
39
71
  "spec/base_spec.rb",
72
+ "spec/document_spec.rb",
40
73
  "spec/public_inspection_document_spec.rb",
41
74
  "spec/result_set_spec.rb",
42
75
  "spec/spec_helper.rb"
43
76
  ]
44
- s.homepage = "http://github.com/criticaljuncture/federal_register"
77
+ s.homepage = "http://github.com/usnationalarchives/federal_register"
45
78
  s.licenses = ["MIT"]
46
79
  s.require_paths = ["lib"]
47
- s.rubygems_version = "1.8.11"
80
+ s.rubygems_version = "1.8.29"
48
81
  s.summary = "Ruby API Client for FederalRegister.gov"
49
82
 
50
83
  if s.respond_to? :specification_version then
@@ -53,34 +86,31 @@ Gem::Specification.new do |s|
53
86
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
54
87
  s.add_runtime_dependency(%q<httparty>, [">= 0.7.0"])
55
88
  s.add_development_dependency(%q<shoulda>, [">= 0"])
56
- s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
57
- s.add_development_dependency(%q<jeweler>, ["~> 1.6.0"])
58
- s.add_development_dependency(%q<rcov>, [">= 0"])
59
- s.add_development_dependency(%q<rspec>, ["~> 2.6"])
89
+ s.add_development_dependency(%q<bundler>, [">= 0"])
90
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
60
91
  s.add_development_dependency(%q<rspec>, ["~> 2.6"])
61
92
  s.add_development_dependency(%q<activesupport>, ["~> 3"])
62
93
  s.add_development_dependency(%q<fakeweb>, ["~> 1.3.0"])
94
+ s.add_development_dependency(%q<rubocop>, [">= 0"])
63
95
  else
64
96
  s.add_dependency(%q<httparty>, [">= 0.7.0"])
65
97
  s.add_dependency(%q<shoulda>, [">= 0"])
66
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
67
- s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
68
- s.add_dependency(%q<rcov>, [">= 0"])
69
- s.add_dependency(%q<rspec>, ["~> 2.6"])
98
+ s.add_dependency(%q<bundler>, [">= 0"])
99
+ s.add_dependency(%q<jeweler>, [">= 0"])
70
100
  s.add_dependency(%q<rspec>, ["~> 2.6"])
71
101
  s.add_dependency(%q<activesupport>, ["~> 3"])
72
102
  s.add_dependency(%q<fakeweb>, ["~> 1.3.0"])
103
+ s.add_dependency(%q<rubocop>, [">= 0"])
73
104
  end
74
105
  else
75
106
  s.add_dependency(%q<httparty>, [">= 0.7.0"])
76
107
  s.add_dependency(%q<shoulda>, [">= 0"])
77
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
78
- s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
79
- s.add_dependency(%q<rcov>, [">= 0"])
80
- s.add_dependency(%q<rspec>, ["~> 2.6"])
108
+ s.add_dependency(%q<bundler>, [">= 0"])
109
+ s.add_dependency(%q<jeweler>, [">= 0"])
81
110
  s.add_dependency(%q<rspec>, ["~> 2.6"])
82
111
  s.add_dependency(%q<activesupport>, ["~> 3"])
83
112
  s.add_dependency(%q<fakeweb>, ["~> 1.3.0"])
113
+ s.add_dependency(%q<rubocop>, [">= 0"])
84
114
  end
85
115
  end
86
116
 
@@ -7,7 +7,48 @@ end
7
7
  require "federal_register/utilities.rb"
8
8
  require "federal_register/client.rb"
9
9
  require "federal_register/base.rb"
10
+
10
11
  require "federal_register/result_set.rb"
12
+ require "federal_register/public_inspection_issue_result_set.rb"
13
+ require "federal_register/facet_result_set.rb"
14
+
11
15
  require "federal_register/agency.rb"
16
+ require "federal_register/document.rb"
12
17
  require "federal_register/article.rb"
18
+ require "federal_register/document_image.rb"
19
+
20
+
21
+ require "federal_register/facet.rb"
22
+ require "federal_register/facet/agency.rb"
23
+ require "federal_register/facet/presidential_document_type.rb"
24
+ require "federal_register/facet/topic.rb"
25
+ require "federal_register/facet/document.rb"
26
+
27
+ require "federal_register/facet/document/frequency.rb"
28
+ require "federal_register/facet/document/daily.rb"
29
+ require "federal_register/facet/document/weekly.rb"
30
+ require "federal_register/facet/document/monthly.rb"
31
+ require "federal_register/facet/document/quarterly.rb"
32
+ require "federal_register/facet/document/yearly.rb"
33
+
34
+ require "federal_register/facet/document/agency.rb"
35
+ require "federal_register/facet/document/section.rb"
36
+ require "federal_register/facet/document/topic.rb"
37
+ require "federal_register/facet/document/type.rb"
38
+
39
+ require "federal_register/facet/public_inspection_document.rb"
40
+ require "federal_register/facet/public_inspection_document/agencies.rb"
41
+ require "federal_register/facet/public_inspection_document/agency.rb"
42
+ require "federal_register/facet/public_inspection_document/type.rb"
43
+
44
+ require "federal_register/facet/public_inspection_issue.rb"
45
+ require "federal_register/facet/public_inspection_issue/daily.rb"
46
+ require "federal_register/facet/public_inspection_issue/daily_filing.rb"
47
+ require "federal_register/facet/public_inspection_issue/type.rb"
48
+ require "federal_register/facet/public_inspection_issue/type_filing.rb"
49
+
50
+ require "federal_register/highlighted_document.rb"
13
51
  require "federal_register/public_inspection_document.rb"
52
+ require "federal_register/section.rb"
53
+ require "federal_register/suggested_search.rb"
54
+ require "federal_register/topic.rb"
@@ -1,26 +1,62 @@
1
1
  class FederalRegister::Agency < FederalRegister::Base
2
- add_attribute :description,
2
+ add_attribute :agency_url,
3
+ :child_ids,
4
+ :description,
3
5
  :json_url,
4
6
  :logo,
5
7
  :name,
8
+ :raw_name,
6
9
  :recent_articles_url,
7
10
  :short_name,
11
+ :slug,
8
12
  :url
9
13
  add_attribute :id,
10
14
  :parent_id,
11
15
  :type => :integer
12
-
13
- def self.all
14
- response = get('/agencies.json')
15
- if response.success?
16
- response.map do |hsh|
17
- new(hsh, :full => true)
16
+
17
+ def self.all(options={})
18
+ get_options = {}
19
+ get_options.merge!(:query => {:fields => options[:fields]}) if options[:fields]
20
+
21
+ response = get('/agencies.json', get_options)
22
+
23
+ response.map do |hsh|
24
+ new(hsh, :full => true)
25
+ end
26
+ end
27
+
28
+ def self.find(id_or_slug, options={})
29
+ if options[:fields].present?
30
+ response = get("/agencies/#{id_or_slug}.json", :query => {:fields => options[:fields]})
31
+
32
+ if response.is_a?(Hash)
33
+ new(response)
34
+ else
35
+ response.map do |hsh|
36
+ new(hsh)
37
+ end
18
38
  end
19
39
  else
20
- raise response.inspect
40
+ response = get("/agencies/#{id_or_slug}.json")
41
+
42
+ if response.is_a?(Hash)
43
+ new(response, :full => true)
44
+ else
45
+ response.map do |hsh|
46
+ new(hsh, :full => true)
47
+ end
48
+ end
49
+ end
50
+ end
51
+
52
+ def self.suggestions(args={})
53
+ response = get("/agencies/suggestions", query: args)
54
+
55
+ response.map do |hsh|
56
+ new(hsh, :full => true)
21
57
  end
22
58
  end
23
-
59
+
24
60
  def logo_url(size)
25
61
  if attributes.has_key?("logo")
26
62
  attributes["logo"]["#{size}_url"] || raise("size '#{size}' not a valid image size")
@@ -1,106 +1,2 @@
1
- class FederalRegister::Article < FederalRegister::Base
2
- extend FederalRegister::Utilities
3
- class InvalidDocumentNumber < ArgumentError; end
4
-
5
- add_attribute :abstract,
6
- :abstract_html_url,
7
- :action,
8
- :agencies,
9
- :agency_names,
10
- :body_html_url,
11
- :cfr_references,
12
- :citation,
13
- :comment_url,
14
- :corrections,
15
- :correction_of,
16
- :dates,
17
- :docket_id,
18
- :docket_ids,
19
- :document_number,
20
- :end_page,
21
- :excerpts,
22
- :executive_order_notes,
23
- :executive_order_number,
24
- :full_text_xml_url,
25
- :html_url,
26
- :json_url,
27
- :mods_url,
28
- :pdf_url,
29
- :president,
30
- :public_inspection_pdf_url,
31
- :regulation_id_number_info,
32
- :regulation_id_numbers,
33
- :regulations_dot_gov_info,
34
- :regulations_dot_gov_url,
35
- :start_page,
36
- :subtype,
37
- :raw_text_url,
38
- :title,
39
- :toc_subject,
40
- :toc_doc,
41
- :type,
42
- :volume
43
-
44
- add_attribute :comments_close_on,
45
- :effective_on,
46
- :publication_date,
47
- :signing_date,
48
- :type => :date
49
-
50
- def self.search(args)
51
- FederalRegister::ResultSet.fetch("/articles.json", :query => args, :result_class => self)
52
- end
53
-
54
- def self.search_metadata(args)
55
- FederalRegister::ResultSet.fetch("/articles.json", :query => args.merge(:metadata_only => '1'), :result_class => self)
56
- end
57
-
58
- def self.find(document_number, options={})
59
- validate_document_number!(document_number)
60
- if options[:fields].present?
61
- attributes = get("/articles/#{document_number}.json", :query => {:fields => options[:fields]})
62
- new(attributes)
63
- else
64
- attributes = get("/articles/#{document_number}.json")
65
- new(attributes, :full => true)
66
- end
67
- end
68
-
69
- def self.find_all(*args)
70
- options, document_numbers = extract_options(args)
71
-
72
- fetch_options = {:result_class => self}
73
- fetch_options.merge!(:query => {:fields => options[:fields]}) if options[:fields]
74
-
75
- document_numbers = document_numbers.flatten
76
- document_numbers.each {|doc_num| validate_document_number!(doc_num)}
77
-
78
- result_set = FederalRegister::ResultSet.fetch("/articles/#{document_numbers.join(',')}.json", fetch_options)
79
- end
80
-
81
- def agencies
82
- attributes["agencies"].map do |attr|
83
- FederalRegister::Agency.new(attr)
84
- end
85
- end
86
-
87
- %w(full_text_xml abstract_html body_html raw_text mods).each do |file_type|
88
- define_method file_type do
89
- begin
90
- self.class.get(send("#{file_type}_url")).body
91
- rescue FederalRegister::Client::RecordNotFound
92
- nil
93
- rescue
94
- raise send("#{file_type}_url").inspect
95
- end
96
- end
97
- end
98
-
99
- private
100
-
101
- def self.validate_document_number!(document_number)
102
- if document_number.blank? || document_number !~ /^[a-zA-Z0-9-]+$/
103
- raise InvalidDocumentNumber.new("'#{document_number}' is not a valid FR Document Number")
104
- end
105
- end
106
- end
1
+ # support old references
2
+ FederalRegister::Article = FederalRegister::Document
@@ -37,19 +37,68 @@ class FederalRegister::Base < FederalRegister::Client
37
37
  @attributes = attributes
38
38
  @full = options[:full] || false
39
39
  end
40
-
40
+
41
41
  def full?
42
42
  @full
43
43
  end
44
-
44
+
45
45
  def fetch_full
46
46
  @attributes = self.class.get(json_url)
47
47
  @full = true
48
48
  self
49
49
  end
50
50
 
51
+ # this has to be done because HTTParty uses a custom attr_inheritable
52
+ # which copies the setting for base uri into each class at inheritance
53
+ # time - which is before we can modify it in something like a Rails
54
+ # initializer
51
55
  def self.override_base_uri(uri)
52
- [FederalRegister::Agency, FederalRegister::Article, FederalRegister::Base, FederalRegister::Client, FederalRegister:: ResultSet].each do |klass|
56
+ [
57
+ FederalRegister::Agency,
58
+ FederalRegister::Article,
59
+ FederalRegister::Base,
60
+ FederalRegister::Client,
61
+ FederalRegister::Document,
62
+ FederalRegister::DocumentImage,
63
+
64
+ FederalRegister::Facet,
65
+ FederalRegister::Facet::Agency,
66
+ FederalRegister::Facet::PresidentialDocumentType,
67
+ FederalRegister::Facet::Topic,
68
+
69
+ FederalRegister::Facet::Document::Frequency,
70
+ FederalRegister::Facet::Document::Daily,
71
+ FederalRegister::Facet::Document::Weekly,
72
+ FederalRegister::Facet::Document::Monthly,
73
+ FederalRegister::Facet::Document::Quarterly,
74
+ FederalRegister::Facet::Document::Yearly,
75
+
76
+ FederalRegister::Facet::Document::Agency,
77
+ FederalRegister::Facet::Document::Section,
78
+ FederalRegister::Facet::Document::Topic,
79
+ FederalRegister::Facet::Document::Type,
80
+
81
+ FederalRegister::Facet::PublicInspectionDocument,
82
+ FederalRegister::Facet::PublicInspectionDocument::Agencies,
83
+ FederalRegister::Facet::PublicInspectionDocument::Agency,
84
+ FederalRegister::Facet::PublicInspectionDocument::Type,
85
+
86
+ FederalRegister::Facet::PublicInspectionIssue,
87
+ FederalRegister::Facet::PublicInspectionIssue::Daily,
88
+ FederalRegister::Facet::PublicInspectionIssue::DailyFiling,
89
+ FederalRegister::Facet::PublicInspectionIssue::Type,
90
+ FederalRegister::Facet::PublicInspectionIssue::TypeFiling,
91
+
92
+ FederalRegister::HighlightedDocument,
93
+ FederalRegister::PublicInspectionDocument,
94
+ FederalRegister::Section,
95
+ FederalRegister::SuggestedSearch,
96
+ FederalRegister::Topic,
97
+
98
+ FederalRegister::ResultSet,
99
+ FederalRegister::PublicInspectionIssueResultSet,
100
+ FederalRegister::FacetResultSet,
101
+ ].each do |klass|
53
102
  klass.base_uri(uri)
54
103
  end
55
104
  end