congress_v3 0.1.0
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.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +67 -0
- data/Rakefile +6 -0
- data/bin/console +11 -0
- data/bin/setup +6 -0
- data/congress_v3.gemspec +32 -0
- data/lib/CongressV3.rb +9 -0
- data/lib/congress_v3/bill.rb +24 -0
- data/lib/congress_v3/config.rb +13 -0
- data/lib/congress_v3/legislator.rb +24 -0
- data/lib/congress_v3/request.rb +61 -0
- data/lib/congress_v3/response.rb +8 -0
- data/lib/congress_v3/version.rb +3 -0
- metadata +187 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ea1036d76da797bc76f1a93b295110d8660dc070
|
4
|
+
data.tar.gz: 514a31e67eab943baddac93e090166341582c60d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 132d9c765f98b21230074266e4b19fcb3a47e971d42438441e6cf8bc067f127f933a79ec86805e5cc214f100cd06ff634b954fb6360a0f9afa901b2340494f7e
|
7
|
+
data.tar.gz: 9e2b42d5ab61dbd93dd1b3dcac94b2ae829fb1dd7f682551f1305042e99b4345b2cf6c719eec25bc9142ced9d049f3db9bc263832a3735fa7b1d2970ba62ad1a
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 charlesmassry
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
# CongressV3
|
2
|
+
|
3
|
+
[](https://coveralls.io/github/CharlesMassry/CongressV3?branch=master)
|
4
|
+
[](https://travis-ci.org/CharlesMassry/CongressV3)
|
5
|
+
|
6
|
+
Easily access the CongressV3 API through Ruby
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'congress_v3'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle install
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install congress_v3
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
First configure with your API KEY from [Sunlight Foundation](http://sunlightfoundation.com/api/accounts/register/)
|
27
|
+
|
28
|
+
Once you have your API KEY:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
CongressV3::Config.api_key = "MY_API_KEY"
|
32
|
+
```
|
33
|
+
|
34
|
+
Using the API is simple:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
CongressV3::Legislators.all
|
38
|
+
# => #<CongressV3::Response:0x007fd26a0ef2b0
|
39
|
+
@count=100,
|
40
|
+
@page={"count"=>20, "per_page"=>20, "page"=>1},
|
41
|
+
@results=[ #<CongressV3::Legislator:0x007fa3343989b8 @chamber="house" @in_office=true> ]>
|
42
|
+
```
|
43
|
+
|
44
|
+
For the Bill API you can even get the text of the bill if it is available
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
CongressV3::Bill.all(bill_id: "hconres128-114").results.first.text
|
48
|
+
# => "\n[Congressional Bills 114th Congress]\n[From the U.S. Government Publishing Office]\n[H. Con. Res. 128 Introduced in House..."
|
49
|
+
```
|
50
|
+
|
51
|
+
One limitation of the Sunlight API is it has a per page limit default to 20. You can take it to the max of 50 easily though `CongressV3::Legislators.all(per_page: 50)`. You can also add query parameters to further refine your criteria `CongressV3::Legislators.all(chamber: 'house')`
|
52
|
+
|
53
|
+
## Development
|
54
|
+
|
55
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
56
|
+
|
57
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
58
|
+
|
59
|
+
## Contributing
|
60
|
+
|
61
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/CharlesMassry/CongressV3.
|
62
|
+
|
63
|
+
|
64
|
+
## License
|
65
|
+
|
66
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
67
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/bin/setup
ADDED
data/congress_v3.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'congress_v3/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "congress_v3"
|
8
|
+
spec.version = CongressV3::VERSION
|
9
|
+
spec.authors = ["charlesmassry"]
|
10
|
+
spec.email = ["me@charliemassry.com"]
|
11
|
+
spec.platform = Gem::Platform::RUBY
|
12
|
+
spec.summary = "Ruby wrapper for accessing the Congress V3 API"
|
13
|
+
spec.description = "The Congress V3 API requires an API key which you can get at http://sunlightfoundation.com/api/accounts/register/"
|
14
|
+
spec.homepage = "https://github.com/CharlesMassry/CongressV3"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency "nokogiri", "~> 1.6.7"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.11.2"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
27
|
+
spec.add_development_dependency "pry", "~> 0.10.0"
|
28
|
+
spec.add_development_dependency "vcr", "~> 3.0.0"
|
29
|
+
spec.add_development_dependency "dotenv", "~> 2.1.0"
|
30
|
+
spec.add_development_dependency "webmock", "~> 1.24.0"
|
31
|
+
spec.add_development_dependency "coveralls", "0.8.0"
|
32
|
+
end
|
data/lib/CongressV3.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
class CongressV3::Bill
|
2
|
+
def self.all(params={})
|
3
|
+
CongressV3::Request.bills(params)
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.search(params={})
|
7
|
+
CongressV3::Request.bill_search(params)
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize(params)
|
11
|
+
params.each do |key, value|
|
12
|
+
instance_variable_set("@#{key}", value)
|
13
|
+
self.class.send(:attr_reader, key)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def text
|
18
|
+
@text ||= if @last_version && @last_version['urls'] && @last_version['urls']['html']
|
19
|
+
CongressV3::Request.bill_text(@last_version['urls']['html'])
|
20
|
+
else
|
21
|
+
"No text for this bill"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class CongressV3::Legislator
|
2
|
+
def self.all(params={})
|
3
|
+
CongressV3::Request.legislators(params)
|
4
|
+
end
|
5
|
+
|
6
|
+
def initialize(params)
|
7
|
+
params.each do |key, value|
|
8
|
+
instance_variable_set("@#{key}", value)
|
9
|
+
self.class.send(:attr_reader, key)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def full_name
|
14
|
+
if middle_name
|
15
|
+
"#{first_name} #{middle_name} #{last_name}"
|
16
|
+
else
|
17
|
+
"#{first_name} #{last_name}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def term
|
22
|
+
Time.parse(term_start)...Time.parse(term_end)
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
|
+
require 'nokogiri'
|
4
|
+
require 'open-uri'
|
5
|
+
|
6
|
+
class CongressV3::Request
|
7
|
+
BASE_URI = 'https://congress.api.sunlightfoundation.com'
|
8
|
+
attr_accessor :route, :params
|
9
|
+
|
10
|
+
def initialize(route, params)
|
11
|
+
if !CongressV3::Config.api_key || CongressV3::Config.api_key.empty?
|
12
|
+
raise Exception.new("API Key MUST be set!")
|
13
|
+
end
|
14
|
+
|
15
|
+
defaults = { page: 1, apikey: CongressV3::Config.api_key }
|
16
|
+
@route = route
|
17
|
+
@params = defaults.merge(params)
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.legislators(params={})
|
21
|
+
response = new("/legislators", params).request
|
22
|
+
|
23
|
+
response.results.map! do |legislator|
|
24
|
+
CongressV3::Legislator.new(legislator)
|
25
|
+
end
|
26
|
+
|
27
|
+
response
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.bills(params)
|
31
|
+
response = new("/bills", params).request
|
32
|
+
|
33
|
+
response.results.map! do |bill|
|
34
|
+
CongressV3::Bill.new(bill)
|
35
|
+
end
|
36
|
+
|
37
|
+
response
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.bill_search(params)
|
41
|
+
response = new("/bills/search", params).request
|
42
|
+
|
43
|
+
response.results.map! do |bill|
|
44
|
+
CongressV3::Bill.new(bill)
|
45
|
+
end
|
46
|
+
|
47
|
+
response
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.bill_text(uri)
|
51
|
+
html = Nokogiri::HTML(open(uri))
|
52
|
+
html.css('body pre').text
|
53
|
+
end
|
54
|
+
|
55
|
+
def request
|
56
|
+
uri = URI(BASE_URI + route)
|
57
|
+
uri.query = URI.encode_www_form(params)
|
58
|
+
response = Net::HTTP.get(uri)
|
59
|
+
CongressV3::Response.new(JSON.parse(response))
|
60
|
+
end
|
61
|
+
end
|
metadata
ADDED
@@ -0,0 +1,187 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: congress_v3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- charlesmassry
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nokogiri
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.6.7
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.6.7
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.11.2
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.11.2
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.10.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.10.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: vcr
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 3.0.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 3.0.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: dotenv
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 2.1.0
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 2.1.0
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: webmock
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 1.24.0
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 1.24.0
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: coveralls
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 0.8.0
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 0.8.0
|
139
|
+
description: The Congress V3 API requires an API key which you can get at http://sunlightfoundation.com/api/accounts/register/
|
140
|
+
email:
|
141
|
+
- me@charliemassry.com
|
142
|
+
executables: []
|
143
|
+
extensions: []
|
144
|
+
extra_rdoc_files: []
|
145
|
+
files:
|
146
|
+
- ".gitignore"
|
147
|
+
- ".rspec"
|
148
|
+
- ".travis.yml"
|
149
|
+
- Gemfile
|
150
|
+
- LICENSE.txt
|
151
|
+
- README.md
|
152
|
+
- Rakefile
|
153
|
+
- bin/console
|
154
|
+
- bin/setup
|
155
|
+
- congress_v3.gemspec
|
156
|
+
- lib/CongressV3.rb
|
157
|
+
- lib/congress_v3/bill.rb
|
158
|
+
- lib/congress_v3/config.rb
|
159
|
+
- lib/congress_v3/legislator.rb
|
160
|
+
- lib/congress_v3/request.rb
|
161
|
+
- lib/congress_v3/response.rb
|
162
|
+
- lib/congress_v3/version.rb
|
163
|
+
homepage: https://github.com/CharlesMassry/CongressV3
|
164
|
+
licenses:
|
165
|
+
- MIT
|
166
|
+
metadata: {}
|
167
|
+
post_install_message:
|
168
|
+
rdoc_options: []
|
169
|
+
require_paths:
|
170
|
+
- lib
|
171
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
172
|
+
requirements:
|
173
|
+
- - ">="
|
174
|
+
- !ruby/object:Gem::Version
|
175
|
+
version: '0'
|
176
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
requirements: []
|
182
|
+
rubyforge_project:
|
183
|
+
rubygems_version: 2.6.3
|
184
|
+
signing_key:
|
185
|
+
specification_version: 4
|
186
|
+
summary: Ruby wrapper for accessing the Congress V3 API
|
187
|
+
test_files: []
|