federal_register 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/.watchr ADDED
@@ -0,0 +1,63 @@
1
+ ENV["WATCHR"] = "1"
2
+ system 'clear'
3
+
4
+ def growl(title, message)
5
+ growlnotify = `which growlnotify`.chomp
6
+ puts message
7
+ image = message.match(/\s0\s(errors|failures)/) ? "~/.watchr_images/passed.png" : "~/.watchr_images/failed.png"
8
+ options = "-w -n Watchr --image '#{File.expand_path(image)}' -m '#{message}' '#{title}'"
9
+ system %(#{growlnotify} #{options} &)
10
+ end
11
+
12
+ def run(cmd)
13
+ puts(cmd)
14
+ `#{cmd}`
15
+ end
16
+
17
+ def run_spec_file(file)
18
+ system('clear')
19
+ result = run(%Q(rspec #{file}))
20
+ growl( "Watchr results for '#{file}'", result.split("\n").last ) rescue nil
21
+ puts result
22
+ end
23
+
24
+ def run_all_specs
25
+ system('clear')
26
+ result = run "rspec spec"
27
+ growl( "Watchr results for all specs", result.split("\n").last ) rescue nil
28
+ puts result
29
+ end
30
+
31
+ def related_spec_files(path)
32
+ Dir['spec/**/*.rb'].select { |file| file =~ /#{File.basename(path).split(".").first}_spec.rb/ }
33
+ end
34
+
35
+ def run_suite
36
+ run_all_specs
37
+ end
38
+
39
+ watch('spec/spec_helper\.rb') { run_all_specs }
40
+ watch('spec/.*_spec\.rb') { |m| run_spec_file(m[0]) }
41
+ watch('lib/.*/.*\.rb') { |m| related_spec_files(m[0]).map {|tf| run_spec_file(tf) } }
42
+
43
+ # Ctrl-\
44
+ Signal.trap 'QUIT' do
45
+ puts " --- Running all specs ---\n\n"
46
+ run_all_specs
47
+ end
48
+
49
+ @interrupted = false
50
+
51
+ # Ctrl-C
52
+ Signal.trap 'INT' do
53
+ if @interrupted then
54
+ @wants_to_quit = true
55
+ abort("\n")
56
+ else
57
+ puts "Interrupt a second time to quit"
58
+ @interrupted = true
59
+ Kernel.sleep 1.5
60
+ # raise Interrupt, nil # let the run loop catch it
61
+ run_suite
62
+ end
63
+ end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{federal_register}
8
- s.version = "0.2.0"
8
+ s.version = "0.3.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"]
12
- s.date = %q{2011-08-17}
12
+ s.date = %q{2011-08-22}
13
13
  s.description = %q{Ruby API Client for FederalRegister.gov that handles searching articles and getting information about agencies}
14
14
  s.email = %q{andrew@criticaljuncture.org}
15
15
  s.extra_rdoc_files = [
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
18
18
  ]
19
19
  s.files = [
20
20
  ".document",
21
+ ".watchr",
21
22
  "Gemfile",
22
23
  "Gemfile.lock",
23
24
  "LICENSE.txt",
@@ -33,15 +34,14 @@ Gem::Specification.new do |s|
33
34
  "lib/federal_register/result_set.rb",
34
35
  "spec/agency_spec.rb",
35
36
  "spec/article_spec.rb",
37
+ "spec/base_spec.rb",
36
38
  "spec/result_set_spec.rb",
37
- "spec/spec_helper.rb",
38
- "test/helper.rb",
39
- "test/test_federal_register.rb"
39
+ "spec/spec_helper.rb"
40
40
  ]
41
41
  s.homepage = %q{http://github.com/criticaljuncture/federal_register}
42
42
  s.licenses = ["MIT"]
43
43
  s.require_paths = ["lib"]
44
- s.rubygems_version = %q{1.5.2}
44
+ s.rubygems_version = %q{1.7.2}
45
45
  s.summary = %q{Ruby API Client for FederalRegister.gov}
46
46
 
47
47
  if s.respond_to? :specification_version then
@@ -1,15 +1,12 @@
1
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
- ]
2
+ add_attribute :description,
3
+ :id,
4
+ :json_url,
5
+ :logo,
6
+ :name,
7
+ :recent_articles_url,
8
+ :short_name,
9
+ :url
13
10
 
14
11
  def self.all
15
12
  response = get('/agencies.json')
@@ -27,4 +24,4 @@ class FederalRegister::Agency < FederalRegister::Base
27
24
  attributes["logo"]["#{size}_url"] || raise("size '#{size}' not a valid image size")
28
25
  end
29
26
  end
30
- end
27
+ end
@@ -1,30 +1,30 @@
1
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_references,
25
- :json_url
26
- ]
27
-
2
+ add_attribute :abstract,
3
+ :abstract_html_url,
4
+ :action,
5
+ :agencies,
6
+ :body_html_url,
7
+ :cfr_references,
8
+ :dates,
9
+ :docket_id,
10
+ :document_number,
11
+ :end_page,
12
+ :full_text_xml_url,
13
+ :html_url,
14
+ :json_url,
15
+ :mods_url,
16
+ :pdf_url,
17
+ :regulation_id_numbers,
18
+ :start_page,
19
+ :title,
20
+ :type,
21
+ :volume
22
+
23
+ add_attribute :comments_close_on,
24
+ :effective_on,
25
+ :publication_date,
26
+ :type => :date
27
+
28
28
  def self.search(args)
29
29
  FederalRegister::ResultSet.fetch("/articles.json", :query => args, :result_class => self)
30
30
  end
@@ -46,7 +46,7 @@ class FederalRegister::Article < FederalRegister::Base
46
46
 
47
47
  %w(full_text_xml abstract_html body_html mods).each do |file_type|
48
48
  define_method file_type do
49
- self.class.get(attributes["#{file_type}_url"]).body
49
+ self.class.get(send("#{file_type}_url")).body
50
50
  end
51
51
  end
52
52
  end
@@ -1,5 +1,29 @@
1
1
  class FederalRegister::Base < FederalRegister::Client
2
2
  attr_reader :attributes
3
+
4
+ def self.add_attribute(*attributes)
5
+ options = {}
6
+
7
+ if attributes.last.is_a?(Hash)
8
+ options = attributes.pop
9
+ end
10
+
11
+ attributes.each do |attr|
12
+ define_method attr do
13
+ val = @attributes[attr.to_s]
14
+ if val && options[:type] == :date
15
+ val = Date.strptime(val.to_s)
16
+ end
17
+
18
+ if ! val && ! full? && respond_to?(:json_url) && @attributes['json_url']
19
+ fetch_full
20
+ val = send(attr)
21
+ end
22
+ val
23
+ end
24
+ end
25
+ end
26
+
3
27
  def initialize(attributes = {}, options = {})
4
28
  @attributes = attributes
5
29
  @full = options[:full] || false
@@ -14,23 +38,14 @@ class FederalRegister::Base < FederalRegister::Client
14
38
  @full = true
15
39
  self
16
40
  end
17
-
41
+
42
+ def self.override_base_uri(uri)
43
+ [FederalRegister::Agency, FederalRegister::Article, FederalRegister::Base, FederalRegister::Client, FederalRegister:: ResultSet].each do |klass|
44
+ klass.base_uri(uri)
45
+ end
46
+ end
47
+
18
48
  private
19
49
 
20
50
  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
51
+ end
@@ -4,7 +4,7 @@ class FederalRegister::Client
4
4
  class RecordNotFound < HTTParty::ResponseError; end
5
5
  class ServerError < HTTParty::ResponseError; end
6
6
 
7
- base_uri 'http://www.federalregister.gov/api/v1'
7
+ base_uri 'http://api.federalregister.gov/v1'
8
8
 
9
9
  def self.get(url, *options)
10
10
  response = super
@@ -20,4 +20,4 @@ class FederalRegister::Client
20
20
  raise HTTParty::ResponseError.new(response)
21
21
  end
22
22
  end
23
- end
23
+ end
data/spec/article_spec.rb CHANGED
@@ -53,4 +53,25 @@ describe FederalRegister::Article do
53
53
  FederalRegister::Article.search(:conditions => {:term => "Fish"}).should be_an_instance_of(FederalRegister::ResultSet)
54
54
  end
55
55
  end
56
+
57
+ describe "#full_text_xml" do
58
+ it "fetches the full_text_xml from the full_text_xml_url" do
59
+ url = "http://example.com/full_text"
60
+ article = FederalRegister::Article.new("full_text_xml_url" => url)
61
+ FakeWeb.register_uri(
62
+ :get,
63
+ url,
64
+ :content_type =>"text/xml",
65
+ :body => "hello, world!"
66
+ )
67
+ article.full_text_xml.should == 'hello, world!'
68
+ end
69
+ end
70
+
71
+ describe "#publication_date" do
72
+ it "returns a Date object" do
73
+ article = FederalRegister::Article.new("publication_date" => "2011-07-22")
74
+ article.publication_date.should == Date.strptime("2011-07-22")
75
+ end
76
+ end
56
77
  end
data/spec/base_spec.rb ADDED
@@ -0,0 +1,37 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe FederalRegister::Base do
4
+ describe '.add_attribute' do
5
+ it 'creates a getter method of the same name' do
6
+ klass = Class.new(FederalRegister::Base)
7
+ klass.add_attribute(:foo)
8
+ instance = klass.new("foo" => "bar")
9
+ instance.foo.should == "bar"
10
+ end
11
+
12
+ it 'creates a getter method that lazy loads the full data' do
13
+ klass = Class.new(FederalRegister::Base)
14
+ klass.add_attribute(:foo, :json_url)
15
+ instance = klass.new('json_url' => 'http://example.com/details')
16
+ FakeWeb.register_uri(
17
+ :get,
18
+ "http://example.com/details",
19
+ :content_type =>"text/json",
20
+ :body => {:foo => "bar"}.to_json
21
+ )
22
+ instance.foo.should == 'bar'
23
+ end
24
+ end
25
+
26
+ describe '.override_base_uri' do
27
+ before(:each) do
28
+ FederalRegister::Base.override_base_uri('http://fr2.local/api/v1')
29
+ end
30
+
31
+ [FederalRegister::Agency, FederalRegister::Article, FederalRegister::Base, FederalRegister::Client, FederalRegister::ResultSet].each do |klass|
32
+ it "should set default_options[:base_uri] for #{klass}" do
33
+ klass.default_options[:base_uri].should == 'http://fr2.local/api/v1'
34
+ end
35
+ end
36
+ end
37
+ end
metadata CHANGED
@@ -1,170 +1,126 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: federal_register
3
- version: !ruby/object:Gem::Version
4
- hash: 23
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 2
9
- - 0
10
- version: 0.2.0
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Andrew Carpenter
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-08-17 00:00:00 -07:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
22
- type: :runtime
23
- requirement: &id001 !ruby/object:Gem::Requirement
12
+ date: 2011-08-22 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: &70199854862940 !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 3
29
- segments:
30
- - 0
31
- - 7
32
- - 0
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
33
21
  version: 0.7.0
34
- name: httparty
35
- version_requirements: *id001
22
+ type: :runtime
36
23
  prerelease: false
37
- - !ruby/object:Gem::Dependency
38
- type: :development
39
- requirement: &id002 !ruby/object:Gem::Requirement
40
- none: false
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- hash: 3
45
- segments:
46
- - 0
47
- version: "0"
24
+ version_requirements: *70199854862940
25
+ - !ruby/object:Gem::Dependency
48
26
  name: shoulda
49
- version_requirements: *id002
50
- prerelease: false
51
- - !ruby/object:Gem::Dependency
27
+ requirement: &70199854862460 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
52
33
  type: :development
53
- requirement: &id003 !ruby/object:Gem::Requirement
34
+ prerelease: false
35
+ version_requirements: *70199854862460
36
+ - !ruby/object:Gem::Dependency
37
+ name: bundler
38
+ requirement: &70199854861960 !ruby/object:Gem::Requirement
54
39
  none: false
55
- requirements:
40
+ requirements:
56
41
  - - ~>
57
- - !ruby/object:Gem::Version
58
- hash: 23
59
- segments:
60
- - 1
61
- - 0
62
- - 0
42
+ - !ruby/object:Gem::Version
63
43
  version: 1.0.0
64
- name: bundler
65
- version_requirements: *id003
66
- prerelease: false
67
- - !ruby/object:Gem::Dependency
68
44
  type: :development
69
- requirement: &id004 !ruby/object:Gem::Requirement
45
+ prerelease: false
46
+ version_requirements: *70199854861960
47
+ - !ruby/object:Gem::Dependency
48
+ name: jeweler
49
+ requirement: &70199854861480 !ruby/object:Gem::Requirement
70
50
  none: false
71
- requirements:
51
+ requirements:
72
52
  - - ~>
73
- - !ruby/object:Gem::Version
74
- hash: 15
75
- segments:
76
- - 1
77
- - 6
78
- - 0
53
+ - !ruby/object:Gem::Version
79
54
  version: 1.6.0
80
- name: jeweler
81
- version_requirements: *id004
82
- prerelease: false
83
- - !ruby/object:Gem::Dependency
84
55
  type: :development
85
- requirement: &id005 !ruby/object:Gem::Requirement
86
- none: false
87
- requirements:
88
- - - ">="
89
- - !ruby/object:Gem::Version
90
- hash: 3
91
- segments:
92
- - 0
93
- version: "0"
94
- name: rcov
95
- version_requirements: *id005
96
56
  prerelease: false
97
- - !ruby/object:Gem::Dependency
57
+ version_requirements: *70199854861480
58
+ - !ruby/object:Gem::Dependency
59
+ name: rcov
60
+ requirement: &70199854861000 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
98
66
  type: :development
99
- requirement: &id006 !ruby/object:Gem::Requirement
67
+ prerelease: false
68
+ version_requirements: *70199854861000
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: &70199854860520 !ruby/object:Gem::Requirement
100
72
  none: false
101
- requirements:
73
+ requirements:
102
74
  - - ~>
103
- - !ruby/object:Gem::Version
104
- hash: 15
105
- segments:
106
- - 2
107
- - 6
108
- version: "2.6"
109
- name: rspec
110
- version_requirements: *id006
111
- prerelease: false
112
- - !ruby/object:Gem::Dependency
75
+ - !ruby/object:Gem::Version
76
+ version: '2.6'
113
77
  type: :development
114
- requirement: &id007 !ruby/object:Gem::Requirement
78
+ prerelease: false
79
+ version_requirements: *70199854860520
80
+ - !ruby/object:Gem::Dependency
81
+ name: rspec
82
+ requirement: &70199854860040 !ruby/object:Gem::Requirement
115
83
  none: false
116
- requirements:
84
+ requirements:
117
85
  - - ~>
118
- - !ruby/object:Gem::Version
119
- hash: 15
120
- segments:
121
- - 2
122
- - 6
123
- version: "2.6"
124
- name: rspec
125
- version_requirements: *id007
126
- prerelease: false
127
- - !ruby/object:Gem::Dependency
86
+ - !ruby/object:Gem::Version
87
+ version: '2.6'
128
88
  type: :development
129
- requirement: &id008 !ruby/object:Gem::Requirement
89
+ prerelease: false
90
+ version_requirements: *70199854860040
91
+ - !ruby/object:Gem::Dependency
92
+ name: activesupport
93
+ requirement: &70199854859540 !ruby/object:Gem::Requirement
130
94
  none: false
131
- requirements:
95
+ requirements:
132
96
  - - ~>
133
- - !ruby/object:Gem::Version
134
- hash: 5
135
- segments:
136
- - 3
137
- version: "3"
138
- name: activesupport
139
- version_requirements: *id008
140
- prerelease: false
141
- - !ruby/object:Gem::Dependency
97
+ - !ruby/object:Gem::Version
98
+ version: '3'
142
99
  type: :development
143
- requirement: &id009 !ruby/object:Gem::Requirement
100
+ prerelease: false
101
+ version_requirements: *70199854859540
102
+ - !ruby/object:Gem::Dependency
103
+ name: fakeweb
104
+ requirement: &70199854859020 !ruby/object:Gem::Requirement
144
105
  none: false
145
- requirements:
106
+ requirements:
146
107
  - - ~>
147
- - !ruby/object:Gem::Version
148
- hash: 27
149
- segments:
150
- - 1
151
- - 3
152
- - 0
108
+ - !ruby/object:Gem::Version
153
109
  version: 1.3.0
154
- name: fakeweb
155
- version_requirements: *id009
110
+ type: :development
156
111
  prerelease: false
157
- description: Ruby API Client for FederalRegister.gov that handles searching articles and getting information about agencies
112
+ version_requirements: *70199854859020
113
+ description: Ruby API Client for FederalRegister.gov that handles searching articles
114
+ and getting information about agencies
158
115
  email: andrew@criticaljuncture.org
159
116
  executables: []
160
-
161
117
  extensions: []
162
-
163
- extra_rdoc_files:
118
+ extra_rdoc_files:
164
119
  - LICENSE.txt
165
120
  - README.rdoc
166
- files:
121
+ files:
167
122
  - .document
123
+ - .watchr
168
124
  - Gemfile
169
125
  - Gemfile.lock
170
126
  - LICENSE.txt
@@ -180,43 +136,35 @@ files:
180
136
  - lib/federal_register/result_set.rb
181
137
  - spec/agency_spec.rb
182
138
  - spec/article_spec.rb
139
+ - spec/base_spec.rb
183
140
  - spec/result_set_spec.rb
184
141
  - spec/spec_helper.rb
185
- - test/helper.rb
186
- - test/test_federal_register.rb
187
- has_rdoc: true
188
142
  homepage: http://github.com/criticaljuncture/federal_register
189
- licenses:
143
+ licenses:
190
144
  - MIT
191
145
  post_install_message:
192
146
  rdoc_options: []
193
-
194
- require_paths:
147
+ require_paths:
195
148
  - lib
196
- required_ruby_version: !ruby/object:Gem::Requirement
149
+ required_ruby_version: !ruby/object:Gem::Requirement
197
150
  none: false
198
- requirements:
199
- - - ">="
200
- - !ruby/object:Gem::Version
201
- hash: 3
202
- segments:
151
+ requirements:
152
+ - - ! '>='
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ segments:
203
156
  - 0
204
- version: "0"
205
- required_rubygems_version: !ruby/object:Gem::Requirement
157
+ hash: 4415661570330803763
158
+ required_rubygems_version: !ruby/object:Gem::Requirement
206
159
  none: false
207
- requirements:
208
- - - ">="
209
- - !ruby/object:Gem::Version
210
- hash: 3
211
- segments:
212
- - 0
213
- version: "0"
160
+ requirements:
161
+ - - ! '>='
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
214
164
  requirements: []
215
-
216
165
  rubyforge_project:
217
- rubygems_version: 1.5.2
166
+ rubygems_version: 1.7.2
218
167
  signing_key:
219
168
  specification_version: 3
220
169
  summary: Ruby API Client for FederalRegister.gov
221
170
  test_files: []
222
-
data/test/helper.rb DELETED
@@ -1,18 +0,0 @@
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
@@ -1,7 +0,0 @@
1
- require 'helper'
2
-
3
- class TestFederalRegister < Test::Unit::TestCase
4
- should "probably rename this file and start testing for real" do
5
- flunk "hey buddy, you should probably rename this file and start testing for real"
6
- end
7
- end