presdocs 0.0.1 → 0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/README.md +11 -4
- data/lib/presdocs/category.rb +1 -1
- data/lib/presdocs/document.rb +51 -0
- data/lib/presdocs/version.rb +1 -1
- data/test/test_document.rb +12 -1
- metadata +3 -3
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
The White House releases a lot of stuff, and some of it is included in what's known as the [Compilation of Presidential Documents](http://www.gpo.gov/fdsys/browse/collection.action?collectionCode=CPD). This is a Ruby library for accessing details about those documents, including subjects, dates, locations and more.
|
4
4
|
|
5
|
+
Nearly every day, the White House releases one or more official publications, which may include presidential statements, announcements of nominations, press releases and schedule information. These are published by the Government Printing Office. Presdocs wraps JSON endpoints exposed by GPO, which has created a [mobile application](http://m.gpo.gov/dcpd) for browsing and searching these documents. I owe a debt of gratitude to the government employees who made these endpoints available; your commitment to making public information more easily accessible is truly a public service.
|
6
|
+
|
7
|
+
The current version is 0.5.
|
8
|
+
|
5
9
|
## Installation
|
6
10
|
|
7
11
|
Add this line to your application's Gemfile:
|
@@ -24,14 +28,18 @@ Or install it yourself as:
|
|
24
28
|
|
25
29
|
@latest_docs = Document.latest
|
26
30
|
|
27
|
-
|
31
|
+
Please see [the documentation](http://dwillis.github.com/presdocs/) for a more complete description of the library.
|
28
32
|
|
29
|
-
##
|
33
|
+
## Tests
|
30
34
|
|
31
|
-
Presdocs uses minitest; to run the tests:
|
35
|
+
Presdocs uses minitest and is tested under Ruby 1.9.3; to run the tests:
|
32
36
|
|
33
37
|
rake test
|
34
38
|
|
39
|
+
## License
|
40
|
+
|
41
|
+
Presdocs is licensed under the MIT License. See LICENSE.txt for more details.
|
42
|
+
|
35
43
|
## Contributing
|
36
44
|
|
37
45
|
1. Fork it
|
@@ -39,4 +47,3 @@ Presdocs uses minitest; to run the tests:
|
|
39
47
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
40
48
|
4. Push to the branch (`git push origin my-new-feature`)
|
41
49
|
5. Create new Pull Request
|
42
|
-
|
data/lib/presdocs/category.rb
CHANGED
data/lib/presdocs/document.rb
CHANGED
@@ -32,6 +32,57 @@ module Presdocs
|
|
32
32
|
results = Oj.load(open(url).read)
|
33
33
|
create_from_search_results(results['searchResults'], results['coordinates'])
|
34
34
|
end
|
35
|
+
|
36
|
+
def self.city(city, state)
|
37
|
+
url = "http://m.gpo.gov/wscpd/mobilecpd/location/#{city}/#{state}.json"
|
38
|
+
results = Oj.load(open(url).read)
|
39
|
+
create_from_search_results(results['searchResults'], results['coordinates'])
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.state(state)
|
43
|
+
url = "http://m.gpo.gov/wscpd/mobilecpd/location/#{state}.json"
|
44
|
+
results = Oj.load(open(url).read)
|
45
|
+
create_from_search_results(results['searchResults'], results['coordinates'])
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.location_with_distance(lat, lng, distance)
|
49
|
+
url = "http://m.gpo.gov/wscpd/mobilecpd/location/#{lat}/#{lng}/#{distance}.json"
|
50
|
+
results = Oj.load(open(url).read)
|
51
|
+
create_from_search_results(results['searchResults'], results['coordinates'])
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.date(date)
|
55
|
+
d = process_date(date)
|
56
|
+
url = "http://m.gpo.gov/wscpd/mobilecpd/date/#{d}.json"
|
57
|
+
results = Oj.load(open(url).read)
|
58
|
+
create_from_search_results(results['searchResults'], nil)
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.date_range(start_date, end_date)
|
62
|
+
s = process_date(start_date)
|
63
|
+
e = process_date(end_date)
|
64
|
+
url = "http://m.gpo.gov/wscpd/mobilecpd/date/#{s}/#{e}.json"
|
65
|
+
results = Oj.load(open(url).read)
|
66
|
+
create_from_search_results(results['searchResults'], nil)
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.category(category)
|
70
|
+
url = "http://m.gpo.gov/wscpd/mobilecpd/category/#{category}.json"
|
71
|
+
results = Oj.load(open(url).read)
|
72
|
+
create_from_search_results(results['searchResults'], nil)
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.process_date(date)
|
76
|
+
begin
|
77
|
+
if date.is_a?(Date)
|
78
|
+
d = date.strftime("%-m-%-d-%Y")
|
79
|
+
else
|
80
|
+
d = Date.strptime(date, '%m/%d/%Y').strftime("%-m-%-d-%Y")
|
81
|
+
end
|
82
|
+
rescue
|
83
|
+
raise "Dates must be Ruby Date objects or a Date string such as '2/14/2013'"
|
84
|
+
end
|
85
|
+
end
|
35
86
|
|
36
87
|
def self.create_from_search_results(results, coordinates)
|
37
88
|
docs = []
|
data/lib/presdocs/version.rb
CHANGED
data/test/test_document.rb
CHANGED
@@ -10,6 +10,7 @@ class TestDocument < MiniTest::Unit::TestCase
|
|
10
10
|
@categories = Category.all
|
11
11
|
@locations = Document.with_locations
|
12
12
|
@doc = Document.detail('DCPD-201300104')
|
13
|
+
@date = Document.date('2/14/2013')
|
13
14
|
end
|
14
15
|
|
15
16
|
def test_that_there_are_five_latest_docs
|
@@ -32,5 +33,15 @@ class TestDocument < MiniTest::Unit::TestCase
|
|
32
33
|
def test_that_document_detail_has_an_fdsys_url
|
33
34
|
assert_equal "http://www.gpo.gov/fdsys/pkg/DCPD-201300104/html/DCPD-201300104.htm", @doc.fdsys_url
|
34
35
|
end
|
35
|
-
|
36
|
+
|
37
|
+
def test_that_document_date_results_are_from_same_date
|
38
|
+
assert_equal Date.strptime('2/14/2013', '%m/%d/%Y'), @date.map{|d| d.date}.uniq.first
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_that_date_range_raises_error_for_bad_dates
|
42
|
+
assert_raises RuntimeError do
|
43
|
+
@range = Document.date_range('2/14/2013', '235')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
36
47
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: presdocs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.5'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-02-
|
12
|
+
date: 2013-02-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
@@ -124,7 +124,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
124
124
|
version: '0'
|
125
125
|
segments:
|
126
126
|
- 0
|
127
|
-
hash:
|
127
|
+
hash: -1267846798555734002
|
128
128
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
129
|
none: false
|
130
130
|
requirements:
|