federal_register 0.0.1
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.
- data/.document +5 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +38 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +34 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/federal_register.gemspec +83 -0
- data/lib/federal_register.rb +11 -0
- data/lib/federal_register/agency.rb +30 -0
- data/lib/federal_register/article.rb +56 -0
- data/lib/federal_register/base.rb +36 -0
- data/lib/federal_register/client.rb +23 -0
- data/lib/federal_register/result_set.rb +27 -0
- data/spec/agency_spec.rb +55 -0
- data/spec/article_spec.rb +43 -0
- data/spec/result_set_spec.rb +10 -0
- data/spec/spec_helper.rb +17 -0
- data/test/helper.rb +18 -0
- data/test/test_federal_register.rb +7 -0
- metadata +172 -0
data/.document
ADDED
data/Gemfile
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
source "http://rubygems.org"
|
|
2
|
+
|
|
3
|
+
gem "httparty", ">= 0.7.0"
|
|
4
|
+
|
|
5
|
+
# Add dependencies to develop your gem here.
|
|
6
|
+
# Include everything needed to run rake, tests, features, etc.
|
|
7
|
+
group :development do
|
|
8
|
+
gem "shoulda", ">= 0"
|
|
9
|
+
gem "bundler", "~> 1.0.0"
|
|
10
|
+
gem "jeweler", "~> 1.6.0"
|
|
11
|
+
gem "rcov", ">= 0"
|
|
12
|
+
gem "rspec", "~> 2.6"
|
|
13
|
+
gem "rspec", "~> 2.6"
|
|
14
|
+
gem "activesupport", "~> 3"
|
|
15
|
+
gem "fakeweb", "~> 1.3.0"
|
|
16
|
+
end
|
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
GEM
|
|
2
|
+
remote: http://rubygems.org/
|
|
3
|
+
specs:
|
|
4
|
+
activesupport (3.0.7)
|
|
5
|
+
crack (0.1.8)
|
|
6
|
+
diff-lcs (1.1.2)
|
|
7
|
+
fakeweb (1.3.0)
|
|
8
|
+
git (1.2.5)
|
|
9
|
+
httparty (0.7.7)
|
|
10
|
+
crack (= 0.1.8)
|
|
11
|
+
jeweler (1.6.0)
|
|
12
|
+
bundler (~> 1.0.0)
|
|
13
|
+
git (>= 1.2.5)
|
|
14
|
+
rake
|
|
15
|
+
rake (0.8.7)
|
|
16
|
+
rcov (0.9.9)
|
|
17
|
+
rspec (2.6.0)
|
|
18
|
+
rspec-core (~> 2.6.0)
|
|
19
|
+
rspec-expectations (~> 2.6.0)
|
|
20
|
+
rspec-mocks (~> 2.6.0)
|
|
21
|
+
rspec-core (2.6.4)
|
|
22
|
+
rspec-expectations (2.6.0)
|
|
23
|
+
diff-lcs (~> 1.1.2)
|
|
24
|
+
rspec-mocks (2.6.0)
|
|
25
|
+
shoulda (2.11.3)
|
|
26
|
+
|
|
27
|
+
PLATFORMS
|
|
28
|
+
ruby
|
|
29
|
+
|
|
30
|
+
DEPENDENCIES
|
|
31
|
+
activesupport (~> 3)
|
|
32
|
+
bundler (~> 1.0.0)
|
|
33
|
+
fakeweb (~> 1.3.0)
|
|
34
|
+
httparty (>= 0.7.0)
|
|
35
|
+
jeweler (~> 1.6.0)
|
|
36
|
+
rcov
|
|
37
|
+
rspec (~> 2.6)
|
|
38
|
+
shoulda
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2011 Andrew Carpenter
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
= federal_register
|
|
2
|
+
|
|
3
|
+
Ruby API Client for FederalRegister.gov that handles searching articles and getting basic information about agencies.
|
|
4
|
+
|
|
5
|
+
For more information about the FederalRegister.gov API, see http://www.federalregister.gov/learn/developers
|
|
6
|
+
|
|
7
|
+
== Usage
|
|
8
|
+
|
|
9
|
+
FederalRegister::Article.find('2011-17721').title
|
|
10
|
+
result_set = FederalRegister::Article.search(:conditions => {:term => "Accessibility"})
|
|
11
|
+
result_set.count
|
|
12
|
+
result_set.results.each do |article|
|
|
13
|
+
puts "#{article.title} by #{article.agencies.map(&:name)}"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
FederalRegister::Agency.all.each do |agency|
|
|
17
|
+
puts agency.name
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
== Contributing to federal_register
|
|
21
|
+
|
|
22
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
|
23
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
|
24
|
+
* Fork the project
|
|
25
|
+
* Start a feature/bugfix branch
|
|
26
|
+
* Commit and push until you are happy with your contribution
|
|
27
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
|
28
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
|
29
|
+
|
|
30
|
+
== Copyright
|
|
31
|
+
|
|
32
|
+
Copyright (c) 2011 Critical Juncture. See LICENSE.txt for
|
|
33
|
+
further details.
|
|
34
|
+
|
data/Rakefile
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'rubygems'
|
|
4
|
+
require 'bundler'
|
|
5
|
+
begin
|
|
6
|
+
Bundler.setup(:default, :development)
|
|
7
|
+
rescue Bundler::BundlerError => e
|
|
8
|
+
$stderr.puts e.message
|
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
|
10
|
+
exit e.status_code
|
|
11
|
+
end
|
|
12
|
+
require 'rake'
|
|
13
|
+
|
|
14
|
+
require 'jeweler'
|
|
15
|
+
Jeweler::Tasks.new do |gem|
|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
|
17
|
+
gem.name = "federal_register"
|
|
18
|
+
gem.homepage = "http://github.com/criticaljuncture/federal_register"
|
|
19
|
+
gem.license = "MIT"
|
|
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}
|
|
22
|
+
gem.email = "andrew@criticaljuncture.org"
|
|
23
|
+
gem.authors = ["Andrew Carpenter"]
|
|
24
|
+
# dependencies defined in Gemfile
|
|
25
|
+
end
|
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
|
27
|
+
|
|
28
|
+
require 'rspec/core'
|
|
29
|
+
require 'rspec/core/rake_task'
|
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
|
36
|
+
spec.rcov = true
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
task :default => :spec
|
|
40
|
+
|
|
41
|
+
require 'rake/rdoctask'
|
|
42
|
+
Rake::RDocTask.new do |rdoc|
|
|
43
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
|
44
|
+
|
|
45
|
+
rdoc.rdoc_dir = 'rdoc'
|
|
46
|
+
rdoc.title = "federal_register #{version}"
|
|
47
|
+
rdoc.rdoc_files.include('README*')
|
|
48
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
49
|
+
end
|
data/VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.0.1
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# Generated by jeweler
|
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
|
4
|
+
# -*- encoding: utf-8 -*-
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |s|
|
|
7
|
+
s.name = %q{federal_register}
|
|
8
|
+
s.version = "0.0.1"
|
|
9
|
+
|
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
|
+
s.authors = ["Andrew Carpenter"]
|
|
12
|
+
s.date = %q{2011-08-01}
|
|
13
|
+
s.description = %q{Ruby API Client for FederalRegister.gov that handles searching articles and getting information about agencies}
|
|
14
|
+
s.email = %q{andrew@criticaljuncture.org}
|
|
15
|
+
s.extra_rdoc_files = [
|
|
16
|
+
"LICENSE.txt",
|
|
17
|
+
"README.rdoc"
|
|
18
|
+
]
|
|
19
|
+
s.files = [
|
|
20
|
+
".document",
|
|
21
|
+
"Gemfile",
|
|
22
|
+
"Gemfile.lock",
|
|
23
|
+
"LICENSE.txt",
|
|
24
|
+
"README.rdoc",
|
|
25
|
+
"Rakefile",
|
|
26
|
+
"VERSION",
|
|
27
|
+
"federal_register.gemspec",
|
|
28
|
+
"lib/federal_register.rb",
|
|
29
|
+
"lib/federal_register/agency.rb",
|
|
30
|
+
"lib/federal_register/article.rb",
|
|
31
|
+
"lib/federal_register/base.rb",
|
|
32
|
+
"lib/federal_register/client.rb",
|
|
33
|
+
"lib/federal_register/result_set.rb",
|
|
34
|
+
"spec/agency_spec.rb",
|
|
35
|
+
"spec/article_spec.rb",
|
|
36
|
+
"spec/result_set_spec.rb",
|
|
37
|
+
"spec/spec_helper.rb",
|
|
38
|
+
"test/helper.rb",
|
|
39
|
+
"test/test_federal_register.rb"
|
|
40
|
+
]
|
|
41
|
+
s.homepage = %q{http://github.com/criticaljuncture/federal_register}
|
|
42
|
+
s.licenses = ["MIT"]
|
|
43
|
+
s.require_paths = ["lib"]
|
|
44
|
+
s.rubygems_version = %q{1.6.2}
|
|
45
|
+
s.summary = %q{Ruby API Client for FederalRegister.gov}
|
|
46
|
+
|
|
47
|
+
if s.respond_to? :specification_version then
|
|
48
|
+
s.specification_version = 3
|
|
49
|
+
|
|
50
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
|
51
|
+
s.add_runtime_dependency(%q<httparty>, [">= 0.7.0"])
|
|
52
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
|
53
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
|
54
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.0"])
|
|
55
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
|
56
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.6"])
|
|
57
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.6"])
|
|
58
|
+
s.add_development_dependency(%q<activesupport>, ["~> 3"])
|
|
59
|
+
s.add_development_dependency(%q<fakeweb>, ["~> 1.3.0"])
|
|
60
|
+
else
|
|
61
|
+
s.add_dependency(%q<httparty>, [">= 0.7.0"])
|
|
62
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
|
63
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
|
64
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
|
|
65
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
|
66
|
+
s.add_dependency(%q<rspec>, ["~> 2.6"])
|
|
67
|
+
s.add_dependency(%q<rspec>, ["~> 2.6"])
|
|
68
|
+
s.add_dependency(%q<activesupport>, ["~> 3"])
|
|
69
|
+
s.add_dependency(%q<fakeweb>, ["~> 1.3.0"])
|
|
70
|
+
end
|
|
71
|
+
else
|
|
72
|
+
s.add_dependency(%q<httparty>, [">= 0.7.0"])
|
|
73
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
|
74
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
|
75
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
|
|
76
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
|
77
|
+
s.add_dependency(%q<rspec>, ["~> 2.6"])
|
|
78
|
+
s.add_dependency(%q<rspec>, ["~> 2.6"])
|
|
79
|
+
s.add_dependency(%q<activesupport>, ["~> 3"])
|
|
80
|
+
s.add_dependency(%q<fakeweb>, ["~> 1.3.0"])
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'httparty'
|
|
3
|
+
|
|
4
|
+
module FederalRegister
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
require "federal_register/client.rb"
|
|
8
|
+
require "federal_register/base.rb"
|
|
9
|
+
require "federal_register/result_set.rb"
|
|
10
|
+
require "federal_register/agency.rb"
|
|
11
|
+
require "federal_register/article.rb"
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
class FederalRegister::Agency < FederalRegister::Base
|
|
2
|
+
ATTRIBUTES = [
|
|
3
|
+
:id,
|
|
4
|
+
:name,
|
|
5
|
+
:short_name,
|
|
6
|
+
:url,
|
|
7
|
+
:description,
|
|
8
|
+
:url,
|
|
9
|
+
:recent_articles_url,
|
|
10
|
+
:logo,
|
|
11
|
+
:json_url
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
def self.all
|
|
15
|
+
response = get('/agencies.json')
|
|
16
|
+
if response.success?
|
|
17
|
+
response.map do |hsh|
|
|
18
|
+
new(hsh, :full => true)
|
|
19
|
+
end
|
|
20
|
+
else
|
|
21
|
+
raise response.inspect
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def logo_url(size)
|
|
26
|
+
if attributes.has_key?("logo")
|
|
27
|
+
attributes["logo"]["#{size}_url"] || raise("size '#{size}' not a valid image size")
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
class FederalRegister::Article < FederalRegister::Base
|
|
2
|
+
ATTRIBUTES = [
|
|
3
|
+
:title,
|
|
4
|
+
:type,
|
|
5
|
+
:abstract,
|
|
6
|
+
:document_number,
|
|
7
|
+
:html_url,
|
|
8
|
+
:pdf_url,
|
|
9
|
+
:publication_date,
|
|
10
|
+
:agencies,
|
|
11
|
+
:full_text_xml_url,
|
|
12
|
+
:abstract_html_url,
|
|
13
|
+
:body_html_url,
|
|
14
|
+
:mods_url,
|
|
15
|
+
:action,
|
|
16
|
+
:dates,
|
|
17
|
+
:effective_on,
|
|
18
|
+
:comments_close_on,
|
|
19
|
+
:start_page,
|
|
20
|
+
:end_page,
|
|
21
|
+
:volume,
|
|
22
|
+
:docket_id,
|
|
23
|
+
:regulation_id_numbers,
|
|
24
|
+
:cfr_refernces,
|
|
25
|
+
:json_url
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
def self.search(args)
|
|
29
|
+
FederalRegister::ResultSet.fetch("/articles.json", :query => args, :result_class => self)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def self.find(document_number)
|
|
33
|
+
attributes = get("/articles/#{document_number}.json")
|
|
34
|
+
new(attributes, :full => true)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def agencies
|
|
38
|
+
attributes["agencies"].map do |attr|
|
|
39
|
+
FederalRegister::Agency.new(attr)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
%w(full_text_xml abstract_html body_html mods).each do |file_type|
|
|
44
|
+
define_method file_type do
|
|
45
|
+
self.class.get(attributes["#{file_type}_url"]).body
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def full_text_xml
|
|
50
|
+
self.class.get(full_text_xml_url).body
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def full_text_xml
|
|
54
|
+
self.class.get(full_text_xml_url).body
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
class FederalRegister::Base < FederalRegister::Client
|
|
2
|
+
attr_reader :attributes
|
|
3
|
+
def initialize(attributes = {}, options = {})
|
|
4
|
+
@attributes = attributes
|
|
5
|
+
@full = options[:full] || false
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def full?
|
|
9
|
+
@full
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def fetch_full
|
|
13
|
+
@attributes = self.class.get(json_url)
|
|
14
|
+
@full = true
|
|
15
|
+
self
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
private
|
|
19
|
+
|
|
20
|
+
attr_reader :attributes
|
|
21
|
+
|
|
22
|
+
def method_missing(name, *args)
|
|
23
|
+
if attributes.has_key?(name.to_s)
|
|
24
|
+
attributes[name.to_s]
|
|
25
|
+
elsif self.class::ATTRIBUTES.include?(name.to_sym)
|
|
26
|
+
if ! full? && @attributes['json_url']
|
|
27
|
+
fetch_full
|
|
28
|
+
method_missing(name,*args)
|
|
29
|
+
else
|
|
30
|
+
nil
|
|
31
|
+
end
|
|
32
|
+
else
|
|
33
|
+
super
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
class FederalRegister::Client
|
|
2
|
+
include HTTParty
|
|
3
|
+
|
|
4
|
+
class RecordNotFound < HTTParty::ResponseError; end
|
|
5
|
+
class ServerError < HTTParty::ResponseError; end
|
|
6
|
+
|
|
7
|
+
base_uri 'http://www.federalregister.gov/api/v1'
|
|
8
|
+
|
|
9
|
+
def self.get(url, *options)
|
|
10
|
+
response = super
|
|
11
|
+
|
|
12
|
+
case response.code
|
|
13
|
+
when 200
|
|
14
|
+
response
|
|
15
|
+
when 404
|
|
16
|
+
raise RecordNotFound.new(response)
|
|
17
|
+
when 500
|
|
18
|
+
raise ServerError.new(response)
|
|
19
|
+
else
|
|
20
|
+
raise HTTParty::ResponseError.new(response)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
class FederalRegister::ResultSet < FederalRegister::Client
|
|
2
|
+
attr_reader :count, :total_pages, :results
|
|
3
|
+
|
|
4
|
+
def initialize(attributes, result_class)
|
|
5
|
+
@result_class = result_class
|
|
6
|
+
@count = attributes['count']
|
|
7
|
+
@total_pages = attributes['total_pages']
|
|
8
|
+
@results = (attributes['results'] || []).map{|result| @result_class.new(result) }
|
|
9
|
+
|
|
10
|
+
@prev_url = attributes['previous_page_url']
|
|
11
|
+
@next_url = attributes['next_page_url']
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def next
|
|
15
|
+
self.class.fetch(@next_url, :result_class => @result_class) if @next_url
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def previous
|
|
19
|
+
self.class.fetch(@prev_url, :result_class => @result_class) if @prev_url
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def self.fetch(url, options = {})
|
|
23
|
+
result_class = options.delete(:result_class)
|
|
24
|
+
response = get(url, options)
|
|
25
|
+
new(response, result_class)
|
|
26
|
+
end
|
|
27
|
+
end
|
data/spec/agency_spec.rb
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
|
2
|
+
|
|
3
|
+
describe FederalRegister::Agency do
|
|
4
|
+
describe ".all" do
|
|
5
|
+
before(:each) do
|
|
6
|
+
FakeWeb.register_uri(:get, "http://www.federalregister.gov/api/v1/agencies.json", :body => [{},{}].to_json, :content_type =>"text/json")
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it "returns Agency objects" do
|
|
10
|
+
agencies = FederalRegister::Agency.all
|
|
11
|
+
agencies.each do |agency|
|
|
12
|
+
agency.should be_an_instance_of(FederalRegister::Agency)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "returns multiple agencies" do
|
|
17
|
+
agencies = FederalRegister::Agency.all
|
|
18
|
+
agencies.count.should == 2
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
describe "attribute loading" do
|
|
23
|
+
before(:each) do
|
|
24
|
+
@agency = FederalRegister::Agency.new({'name' => "Commerce Department", 'json_url' => "http://www.federalregister.gov/api/v1/agencies/1.json"})
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
describe "existing attribute" do
|
|
28
|
+
it "reads the from the json hash if already there" do
|
|
29
|
+
@agency.name.should == 'Commerce Department'
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
describe "non-existent attributes" do
|
|
34
|
+
it "should trigger an error" do
|
|
35
|
+
lambda {@agency.non_existent_attribute}.should raise_error NoMethodError
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
describe "missing attribute" do
|
|
40
|
+
FakeWeb.register_uri(:get, "http://www.federalregister.gov/api/v1/agencies/1.json", :body => {:description => "Lorem ipsum"}.to_json, :content_type =>"text/json")
|
|
41
|
+
it "should lazy-load from the json_url" do
|
|
42
|
+
@agency.send(:attributes)['description'].should be_nil
|
|
43
|
+
@agency.description.should == "Lorem ipsum"
|
|
44
|
+
@agency.send(:attributes)['description'].should == "Lorem ipsum"
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
describe "missing attribute when no full json" do
|
|
49
|
+
it "should lazy-load from the json_url" do
|
|
50
|
+
@agency = FederalRegister::Agency.new({'name' => "Commerce Department"})
|
|
51
|
+
@agency.description.should be_nil
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
|
2
|
+
|
|
3
|
+
describe FederalRegister::Article do
|
|
4
|
+
describe ".find" do
|
|
5
|
+
it "should fetch the document by its document number" do
|
|
6
|
+
document_number = "2010-213"
|
|
7
|
+
FakeWeb.register_uri(
|
|
8
|
+
:get,
|
|
9
|
+
"http://www.federalregister.gov/api/v1/articles/#{document_number}.json",
|
|
10
|
+
:content_type =>"text/json",
|
|
11
|
+
:body => {:title => "Important Notice"}.to_json
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
FederalRegister::Article.find(document_number).title.should == 'Important Notice'
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "should throw an error when a document doesn't exist" do
|
|
18
|
+
document_number = "some-random-document"
|
|
19
|
+
FakeWeb.register_uri(
|
|
20
|
+
:get,
|
|
21
|
+
"http://www.federalregister.gov/api/v1/articles/#{document_number}.json",
|
|
22
|
+
:content_type =>"text/json",
|
|
23
|
+
:status => 404
|
|
24
|
+
)
|
|
25
|
+
lambda{ FederalRegister::Article.find(document_number) }.should raise_error FederalRegister::Client::RecordNotFound
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
describe ".search" do
|
|
30
|
+
before(:each) do
|
|
31
|
+
FakeWeb.register_uri(
|
|
32
|
+
:get,
|
|
33
|
+
"http://www.federalregister.gov/api/v1/articles.json?conditions[term]=Fish",
|
|
34
|
+
:content_type =>"text/json",
|
|
35
|
+
:body => {:count => 3}.to_json
|
|
36
|
+
)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it "should return a resultset object" do
|
|
40
|
+
FederalRegister::Article.search(:conditions => {:term => "Fish"}).should be_an_instance_of(FederalRegister::ResultSet)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
|
2
|
+
|
|
3
|
+
describe FederalRegister::ResultSet do
|
|
4
|
+
describe "#next" do
|
|
5
|
+
it "should load the next_page_url" do
|
|
6
|
+
FakeWeb.register_uri(:get, "http://www.federalregister.gov/api/v1/fishes?page=2", :body => {:count => 24}.to_json, :content_type =>"text/json")
|
|
7
|
+
FederalRegister::ResultSet.new({'next_page_url' => 'http://www.federalregister.gov/api/v1/fishes?page=2'}, FederalRegister::Article).next.count.should == 24
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
3
|
+
require 'rspec'
|
|
4
|
+
require 'fakeweb'
|
|
5
|
+
require 'active_support/ordered_hash'
|
|
6
|
+
require 'active_support/json'
|
|
7
|
+
require 'federal_register'
|
|
8
|
+
|
|
9
|
+
FakeWeb.allow_net_connect = false
|
|
10
|
+
|
|
11
|
+
# Requires supporting files with custom matchers and macros, etc,
|
|
12
|
+
# in ./support/ and its subdirectories.
|
|
13
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
|
14
|
+
|
|
15
|
+
# RSpec.configure do |config|
|
|
16
|
+
#
|
|
17
|
+
# end
|
data/test/helper.rb
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'bundler'
|
|
3
|
+
begin
|
|
4
|
+
Bundler.setup(:default, :development)
|
|
5
|
+
rescue Bundler::BundlerError => e
|
|
6
|
+
$stderr.puts e.message
|
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
|
8
|
+
exit e.status_code
|
|
9
|
+
end
|
|
10
|
+
require 'test/unit'
|
|
11
|
+
require 'shoulda'
|
|
12
|
+
|
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
15
|
+
require 'federal_register'
|
|
16
|
+
|
|
17
|
+
class Test::Unit::TestCase
|
|
18
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: federal_register
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Andrew Carpenter
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2011-08-01 00:00:00.000000000 %:z
|
|
13
|
+
default_executable:
|
|
14
|
+
dependencies:
|
|
15
|
+
- !ruby/object:Gem::Dependency
|
|
16
|
+
name: httparty
|
|
17
|
+
requirement: &2156251100 !ruby/object:Gem::Requirement
|
|
18
|
+
none: false
|
|
19
|
+
requirements:
|
|
20
|
+
- - ! '>='
|
|
21
|
+
- !ruby/object:Gem::Version
|
|
22
|
+
version: 0.7.0
|
|
23
|
+
type: :runtime
|
|
24
|
+
prerelease: false
|
|
25
|
+
version_requirements: *2156251100
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: shoulda
|
|
28
|
+
requirement: &2156250540 !ruby/object:Gem::Requirement
|
|
29
|
+
none: false
|
|
30
|
+
requirements:
|
|
31
|
+
- - ! '>='
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: *2156250540
|
|
37
|
+
- !ruby/object:Gem::Dependency
|
|
38
|
+
name: bundler
|
|
39
|
+
requirement: &2156250000 !ruby/object:Gem::Requirement
|
|
40
|
+
none: false
|
|
41
|
+
requirements:
|
|
42
|
+
- - ~>
|
|
43
|
+
- !ruby/object:Gem::Version
|
|
44
|
+
version: 1.0.0
|
|
45
|
+
type: :development
|
|
46
|
+
prerelease: false
|
|
47
|
+
version_requirements: *2156250000
|
|
48
|
+
- !ruby/object:Gem::Dependency
|
|
49
|
+
name: jeweler
|
|
50
|
+
requirement: &2156249380 !ruby/object:Gem::Requirement
|
|
51
|
+
none: false
|
|
52
|
+
requirements:
|
|
53
|
+
- - ~>
|
|
54
|
+
- !ruby/object:Gem::Version
|
|
55
|
+
version: 1.6.0
|
|
56
|
+
type: :development
|
|
57
|
+
prerelease: false
|
|
58
|
+
version_requirements: *2156249380
|
|
59
|
+
- !ruby/object:Gem::Dependency
|
|
60
|
+
name: rcov
|
|
61
|
+
requirement: &2156248820 !ruby/object:Gem::Requirement
|
|
62
|
+
none: false
|
|
63
|
+
requirements:
|
|
64
|
+
- - ! '>='
|
|
65
|
+
- !ruby/object:Gem::Version
|
|
66
|
+
version: '0'
|
|
67
|
+
type: :development
|
|
68
|
+
prerelease: false
|
|
69
|
+
version_requirements: *2156248820
|
|
70
|
+
- !ruby/object:Gem::Dependency
|
|
71
|
+
name: rspec
|
|
72
|
+
requirement: &2156246240 !ruby/object:Gem::Requirement
|
|
73
|
+
none: false
|
|
74
|
+
requirements:
|
|
75
|
+
- - ~>
|
|
76
|
+
- !ruby/object:Gem::Version
|
|
77
|
+
version: '2.6'
|
|
78
|
+
type: :development
|
|
79
|
+
prerelease: false
|
|
80
|
+
version_requirements: *2156246240
|
|
81
|
+
- !ruby/object:Gem::Dependency
|
|
82
|
+
name: rspec
|
|
83
|
+
requirement: &2156245560 !ruby/object:Gem::Requirement
|
|
84
|
+
none: false
|
|
85
|
+
requirements:
|
|
86
|
+
- - ~>
|
|
87
|
+
- !ruby/object:Gem::Version
|
|
88
|
+
version: '2.6'
|
|
89
|
+
type: :development
|
|
90
|
+
prerelease: false
|
|
91
|
+
version_requirements: *2156245560
|
|
92
|
+
- !ruby/object:Gem::Dependency
|
|
93
|
+
name: activesupport
|
|
94
|
+
requirement: &2156243940 !ruby/object:Gem::Requirement
|
|
95
|
+
none: false
|
|
96
|
+
requirements:
|
|
97
|
+
- - ~>
|
|
98
|
+
- !ruby/object:Gem::Version
|
|
99
|
+
version: '3'
|
|
100
|
+
type: :development
|
|
101
|
+
prerelease: false
|
|
102
|
+
version_requirements: *2156243940
|
|
103
|
+
- !ruby/object:Gem::Dependency
|
|
104
|
+
name: fakeweb
|
|
105
|
+
requirement: &2156243060 !ruby/object:Gem::Requirement
|
|
106
|
+
none: false
|
|
107
|
+
requirements:
|
|
108
|
+
- - ~>
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: 1.3.0
|
|
111
|
+
type: :development
|
|
112
|
+
prerelease: false
|
|
113
|
+
version_requirements: *2156243060
|
|
114
|
+
description: Ruby API Client for FederalRegister.gov that handles searching articles
|
|
115
|
+
and getting information about agencies
|
|
116
|
+
email: andrew@criticaljuncture.org
|
|
117
|
+
executables: []
|
|
118
|
+
extensions: []
|
|
119
|
+
extra_rdoc_files:
|
|
120
|
+
- LICENSE.txt
|
|
121
|
+
- README.rdoc
|
|
122
|
+
files:
|
|
123
|
+
- .document
|
|
124
|
+
- Gemfile
|
|
125
|
+
- Gemfile.lock
|
|
126
|
+
- LICENSE.txt
|
|
127
|
+
- README.rdoc
|
|
128
|
+
- Rakefile
|
|
129
|
+
- VERSION
|
|
130
|
+
- federal_register.gemspec
|
|
131
|
+
- lib/federal_register.rb
|
|
132
|
+
- lib/federal_register/agency.rb
|
|
133
|
+
- lib/federal_register/article.rb
|
|
134
|
+
- lib/federal_register/base.rb
|
|
135
|
+
- lib/federal_register/client.rb
|
|
136
|
+
- lib/federal_register/result_set.rb
|
|
137
|
+
- spec/agency_spec.rb
|
|
138
|
+
- spec/article_spec.rb
|
|
139
|
+
- spec/result_set_spec.rb
|
|
140
|
+
- spec/spec_helper.rb
|
|
141
|
+
- test/helper.rb
|
|
142
|
+
- test/test_federal_register.rb
|
|
143
|
+
has_rdoc: true
|
|
144
|
+
homepage: http://github.com/criticaljuncture/federal_register
|
|
145
|
+
licenses:
|
|
146
|
+
- MIT
|
|
147
|
+
post_install_message:
|
|
148
|
+
rdoc_options: []
|
|
149
|
+
require_paths:
|
|
150
|
+
- lib
|
|
151
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
152
|
+
none: false
|
|
153
|
+
requirements:
|
|
154
|
+
- - ! '>='
|
|
155
|
+
- !ruby/object:Gem::Version
|
|
156
|
+
version: '0'
|
|
157
|
+
segments:
|
|
158
|
+
- 0
|
|
159
|
+
hash: 4374774013964272713
|
|
160
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
161
|
+
none: false
|
|
162
|
+
requirements:
|
|
163
|
+
- - ! '>='
|
|
164
|
+
- !ruby/object:Gem::Version
|
|
165
|
+
version: '0'
|
|
166
|
+
requirements: []
|
|
167
|
+
rubyforge_project:
|
|
168
|
+
rubygems_version: 1.6.2
|
|
169
|
+
signing_key:
|
|
170
|
+
specification_version: 3
|
|
171
|
+
summary: Ruby API Client for FederalRegister.gov
|
|
172
|
+
test_files: []
|