presdocs 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/.gitignore +5 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +23 -0
- data/LICENSE.txt +22 -0
- data/README.md +42 -0
- data/Rakefile +6 -0
- data/lib/presdocs/category.rb +29 -0
- data/lib/presdocs/document.rb +72 -0
- data/lib/presdocs/version.rb +3 -0
- data/lib/presdocs.rb +6 -0
- data/presdocs.gemspec +30 -0
- data/test/test_document.rb +36 -0
- metadata +141 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
presdocs (0.0.1)
|
5
|
+
json
|
6
|
+
oj
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
json (1.7.7)
|
12
|
+
minitest (4.6.1)
|
13
|
+
oj (2.0.7)
|
14
|
+
rake (0.8.7)
|
15
|
+
|
16
|
+
PLATFORMS
|
17
|
+
ruby
|
18
|
+
|
19
|
+
DEPENDENCIES
|
20
|
+
bundler (>= 1.1.0)
|
21
|
+
minitest
|
22
|
+
presdocs!
|
23
|
+
rake (= 0.8.7)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Derek Willis
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# Presdocs: A Ruby wrapper for the Compilation of Presidential Documents
|
2
|
+
|
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
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'presdocs'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install presdocs
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
require 'rubygems'
|
22
|
+
require 'presdocs'
|
23
|
+
include Presdocs
|
24
|
+
|
25
|
+
@latest_docs = Document.latest
|
26
|
+
|
27
|
+
More documentation coming soon. Check the tests, too.
|
28
|
+
|
29
|
+
## Test
|
30
|
+
|
31
|
+
Presdocs uses minitest; to run the tests:
|
32
|
+
|
33
|
+
rake test
|
34
|
+
|
35
|
+
## Contributing
|
36
|
+
|
37
|
+
1. Fork it
|
38
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
39
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
40
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
41
|
+
5. Create new Pull Request
|
42
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
module Presdocs
|
2
|
+
class Category
|
3
|
+
|
4
|
+
attr_reader :name, :count, :children
|
5
|
+
|
6
|
+
def initialize(params={})
|
7
|
+
params.each_pair do |k,v|
|
8
|
+
instance_variable_set("@#{k}", v)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.all
|
13
|
+
url = "http://m.gpo.gov/wscpd/mobilecpd/category.json"
|
14
|
+
results = Oj.load(open(url).read)
|
15
|
+
create_categories(results['navigatorResults']['Category'])
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.create_categories(results)
|
19
|
+
cats = []
|
20
|
+
results.each do |result|
|
21
|
+
cats << self.new(:name => result['name'],
|
22
|
+
:count => result['count'],
|
23
|
+
:children => result['children'])
|
24
|
+
end
|
25
|
+
cats
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module Presdocs
|
2
|
+
class Document
|
3
|
+
|
4
|
+
attr_reader :location, :title, :source, :president, :date, :package_id, :lat, :lng, :subjects, :category, :notes, :fdsys_url, :html, :city, :state
|
5
|
+
|
6
|
+
def initialize(params={})
|
7
|
+
params.each_pair do |k,v|
|
8
|
+
instance_variable_set("@#{k}", v)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def add_attributes(params)
|
13
|
+
params.each_pair do |k,v|
|
14
|
+
instance_variable_set("@#{k}", v)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.detail(package_id)
|
19
|
+
url = "http://m.gpo.gov/wscpd/mobilecpd/detailwgc/#{package_id}.json"
|
20
|
+
result = Oj.load(open(url).read)
|
21
|
+
create_document(result, nil, full=true)
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.latest
|
25
|
+
url = "http://m.gpo.gov/wscpd/mobilecpd/home.json"
|
26
|
+
results = Oj.load(open(url).read)
|
27
|
+
create_from_search_results(results['searchResults'], nil)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.with_locations
|
31
|
+
url = "http://m.gpo.gov/wscpd/mobilecpd/location.json"
|
32
|
+
results = Oj.load(open(url).read)
|
33
|
+
create_from_search_results(results['searchResults'], results['coordinates'])
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.create_from_search_results(results, coordinates)
|
37
|
+
docs = []
|
38
|
+
results.each do |result|
|
39
|
+
docs << create_document(result, coordinates)
|
40
|
+
end
|
41
|
+
docs
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.create_document(result, coordinates, full=false)
|
45
|
+
if full
|
46
|
+
detail = result
|
47
|
+
result = result['searchResult']
|
48
|
+
end
|
49
|
+
city, state = result['location'].split(', ')
|
50
|
+
if coordinates
|
51
|
+
locations = coordinates.map{|l| {"state" => l['state'], "city" => l['city'], "lat" => l["lat"], "lng" => l["lang"]}}.uniq
|
52
|
+
lat = locations.detect{|l| l['city'] == city && l['state'] == state}['lat']
|
53
|
+
lng = locations.detect{|l| l['city'] == city && l['state'] == state}['lng']
|
54
|
+
end
|
55
|
+
doc = self.new(:id => result['packageId'],
|
56
|
+
:city => city,
|
57
|
+
:state => state,
|
58
|
+
:lat => lat,
|
59
|
+
:lng => lng,
|
60
|
+
:title => result['line1'],
|
61
|
+
:source => result['line2'],
|
62
|
+
:president => result['president'],
|
63
|
+
:date => Date.parse(result['eventDate']))
|
64
|
+
|
65
|
+
if full
|
66
|
+
h = {:category => detail['category'], :notes => detail['notes'], :subjects => detail['subject'].map{|s| s.strip}.reject!(&:empty?), :fdsys_url => detail['fdsysUrl'], :html => detail['fullText']}
|
67
|
+
doc.add_attributes(h)
|
68
|
+
end
|
69
|
+
doc
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
data/lib/presdocs.rb
ADDED
data/presdocs.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'presdocs/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "presdocs"
|
8
|
+
gem.version = Presdocs::VERSION
|
9
|
+
gem.authors = ["Derek Willis"]
|
10
|
+
gem.email = ["dwillis@gmail.com"]
|
11
|
+
gem.description = %q{Thin Ruby wrapper for the Compilation of Presidential Documents}
|
12
|
+
gem.summary = %q{Official publications of materials released by the White House Press Secretary}
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.required_rubygems_version = ">= 1.3.6"
|
21
|
+
gem.rubyforge_project = "presdocs"
|
22
|
+
gem.add_runtime_dependency "json"
|
23
|
+
|
24
|
+
gem.add_dependency "oj"
|
25
|
+
|
26
|
+
gem.add_development_dependency "rake", "0.8.7"
|
27
|
+
gem.add_development_dependency "bundler", ">= 1.1.0"
|
28
|
+
gem.add_development_dependency "minitest"
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'presdocs'
|
3
|
+
include Presdocs
|
4
|
+
require 'minitest/autorun'
|
5
|
+
|
6
|
+
class TestDocument < MiniTest::Unit::TestCase
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@latest = Document.latest
|
10
|
+
@categories = Category.all
|
11
|
+
@locations = Document.with_locations
|
12
|
+
@doc = Document.detail('DCPD-201300104')
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_that_there_are_five_latest_docs
|
16
|
+
assert_equal 5, @latest.size
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_that_latest_docs_dont_have_coords
|
20
|
+
assert_nil @latest.first.lat
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_that_categories_have_a_positive_count
|
24
|
+
assert_operator @categories.count, :>=, 0
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_that_location_docs_have_lat_and_lng
|
28
|
+
assert @locations.last.lat
|
29
|
+
assert @locations.first.lng
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_that_document_detail_has_an_fdsys_url
|
33
|
+
assert_equal "http://www.gpo.gov/fdsys/pkg/DCPD-201300104/html/DCPD-201300104.htm", @doc.fdsys_url
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: presdocs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Derek Willis
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-24 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: json
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: oj
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - '='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.8.7
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.8.7
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: bundler
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.1.0
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.1.0
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: minitest
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
description: Thin Ruby wrapper for the Compilation of Presidential Documents
|
95
|
+
email:
|
96
|
+
- dwillis@gmail.com
|
97
|
+
executables: []
|
98
|
+
extensions: []
|
99
|
+
extra_rdoc_files: []
|
100
|
+
files:
|
101
|
+
- .gitignore
|
102
|
+
- Gemfile
|
103
|
+
- Gemfile.lock
|
104
|
+
- LICENSE.txt
|
105
|
+
- README.md
|
106
|
+
- Rakefile
|
107
|
+
- lib/presdocs.rb
|
108
|
+
- lib/presdocs/category.rb
|
109
|
+
- lib/presdocs/document.rb
|
110
|
+
- lib/presdocs/version.rb
|
111
|
+
- presdocs.gemspec
|
112
|
+
- test/test_document.rb
|
113
|
+
homepage: ''
|
114
|
+
licenses: []
|
115
|
+
post_install_message:
|
116
|
+
rdoc_options: []
|
117
|
+
require_paths:
|
118
|
+
- lib
|
119
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
+
none: false
|
121
|
+
requirements:
|
122
|
+
- - ! '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
segments:
|
126
|
+
- 0
|
127
|
+
hash: 3717820495547087070
|
128
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: 1.3.6
|
134
|
+
requirements: []
|
135
|
+
rubyforge_project: presdocs
|
136
|
+
rubygems_version: 1.8.24
|
137
|
+
signing_key:
|
138
|
+
specification_version: 3
|
139
|
+
summary: Official publications of materials released by the White House Press Secretary
|
140
|
+
test_files:
|
141
|
+
- test/test_document.rb
|