congress 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data/.gitignore +5 -35
- data/.rspec +1 -2
- data/.rubocop.yml +81 -0
- data/.travis.yml +22 -4
- data/CONTRIBUTING.md +49 -0
- data/Gemfile +20 -6
- data/LICENSE.md +1 -1
- data/README.md +3 -60
- data/Rakefile +23 -3
- data/congress.gemspec +3 -2
- data/lib/congress/client.rb +38 -35
- data/lib/congress/connection.rb +16 -6
- data/lib/congress/request.rb +3 -2
- data/lib/congress/version.rb +1 -1
- data/lib/congress.rb +20 -20
- data/spec/congress/client_spec.rb +100 -89
- data/spec/congress_spec.rb +26 -9
- data/spec/fixtures/google_geocoding.json +1 -0
- data/spec/helper.rb +13 -3
- data.tar.gz.sig +0 -0
- metadata +63 -71
- metadata.gz.sig +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: dc99e0d62cf703391f40a4ed7616465dec13ce5c
|
4
|
+
data.tar.gz: 20dac4fda3dc21e5e9cf1dc4689d22c9aee6e525
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 42cdb0f6d8350b143efb903cd6e499ce3641736d9df0ab5e068f37d077d3854e76bea8f728f86853fb9515162dfc6f311c974c638492870a0e9bae025befe67f
|
7
|
+
data.tar.gz: 5475793e4c807877e443a64fb719582f6c4e507009414276bde67e79a050fc3b8387a337d3ad8ea72f42eba3670faa0bf95399c515ecf1c1272ac61184752b63
|
checksums.yaml.gz.sig
ADDED
Binary file
|
data/.gitignore
CHANGED
@@ -1,41 +1,11 @@
|
|
1
|
-
!.gitignore
|
2
1
|
*.gem
|
3
|
-
*.rbc
|
4
|
-
*.sw[a-p]
|
5
|
-
*.tmproj
|
6
|
-
*.tmproject
|
7
|
-
*.un~
|
8
2
|
*~
|
9
|
-
.DS_Store
|
10
|
-
.Spotlight-V100
|
11
|
-
.Trashes
|
12
|
-
._*
|
13
3
|
.bundle
|
14
|
-
.
|
15
|
-
.directory
|
16
|
-
.elc
|
17
|
-
.redcar
|
4
|
+
.rvmrc
|
18
5
|
.yardoc
|
19
|
-
/.emacs.desktop
|
20
|
-
/.emacs.desktop.lock
|
21
|
-
Desktop.ini
|
22
6
|
Gemfile.lock
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
\#*\#
|
28
|
-
_yardoc
|
29
|
-
auto-save-list
|
30
|
-
coverage
|
31
|
-
doc/
|
32
|
-
lib/bundler/man
|
33
|
-
pkg
|
7
|
+
coverage/*
|
8
|
+
doc/*
|
9
|
+
log/*
|
10
|
+
measurement/*
|
34
11
|
pkg/*
|
35
|
-
rdoc
|
36
|
-
spec/reports
|
37
|
-
test/tmp
|
38
|
-
test/version_tmp
|
39
|
-
tmp
|
40
|
-
tmtags
|
41
|
-
tramp
|
data/.rspec
CHANGED
data/.rubocop.yml
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
AllCops:
|
2
|
+
Includes:
|
3
|
+
- 'Gemfile'
|
4
|
+
- 'Rakefile'
|
5
|
+
- 'congress.gemspec'
|
6
|
+
|
7
|
+
# Avoid long parameter lists
|
8
|
+
ParameterLists:
|
9
|
+
Max: 4
|
10
|
+
CountKeywordArgs: true
|
11
|
+
|
12
|
+
MethodLength:
|
13
|
+
CountComments: false
|
14
|
+
Max: 15
|
15
|
+
|
16
|
+
# Avoid more than `Max` levels of nesting.
|
17
|
+
BlockNesting:
|
18
|
+
Max: 3
|
19
|
+
|
20
|
+
# Align with the style guide.
|
21
|
+
CollectionMethods:
|
22
|
+
PreferredMethods:
|
23
|
+
collect: 'map'
|
24
|
+
inject: 'reduce'
|
25
|
+
find: 'detect'
|
26
|
+
find_all: 'select'
|
27
|
+
|
28
|
+
# Do not force public/protected/private keyword to be indented at the same
|
29
|
+
# level as the def keyword. My personal preference is to outdent these keywords
|
30
|
+
# because I think when scanning code it makes it easier to identify the
|
31
|
+
# sections of code and visually separate them. When the keyword is at the same
|
32
|
+
# level I think it sort of blends in with the def keywords and makes it harder
|
33
|
+
# to scan the code and see where the sections are.
|
34
|
+
AccessModifierIndentation:
|
35
|
+
Enabled: false
|
36
|
+
|
37
|
+
# Limit line length
|
38
|
+
LineLength:
|
39
|
+
Enabled: false
|
40
|
+
|
41
|
+
# Disable documentation checking until a class needs to be documented once
|
42
|
+
Documentation:
|
43
|
+
Enabled: false
|
44
|
+
|
45
|
+
# Enforce Ruby 1.8-compatible hash syntax
|
46
|
+
HashSyntax:
|
47
|
+
EnforcedStyle: hash_rockets
|
48
|
+
|
49
|
+
# No spaces inside hash literals
|
50
|
+
SpaceInsideHashLiteralBraces:
|
51
|
+
EnforcedStyle: no_space
|
52
|
+
|
53
|
+
# Allow dots at the end of lines
|
54
|
+
DotPosition:
|
55
|
+
Enabled: false
|
56
|
+
|
57
|
+
# Don't require magic comment at the top of every file
|
58
|
+
Encoding:
|
59
|
+
Enabled: false
|
60
|
+
|
61
|
+
# Enforce outdenting of access modifiers (i.e. public, private, protected)
|
62
|
+
AccessModifierIndentation:
|
63
|
+
EnforcedStyle: outdent
|
64
|
+
|
65
|
+
EmptyLinesAroundAccessModifier:
|
66
|
+
Enabled: true
|
67
|
+
|
68
|
+
# Align ends correctly
|
69
|
+
EndAlignment:
|
70
|
+
AlignWith: variable
|
71
|
+
|
72
|
+
# Indentation of when/else
|
73
|
+
CaseIndentation:
|
74
|
+
IndentWhenRelativeTo: end
|
75
|
+
IndentOneStep: false
|
76
|
+
|
77
|
+
Lambda:
|
78
|
+
Enabled: false
|
79
|
+
|
80
|
+
NumericLiterals:
|
81
|
+
Enabled: false
|
data/.travis.yml
CHANGED
@@ -1,10 +1,28 @@
|
|
1
|
+
before_install:
|
2
|
+
- gem update bundler
|
3
|
+
- bundle --version
|
4
|
+
- gem update --system 2.1.11
|
5
|
+
- gem --version
|
6
|
+
bundler_args: --without development
|
1
7
|
language: ruby
|
2
8
|
rvm:
|
3
|
-
- jruby-18mode
|
4
|
-
- jruby-19mode
|
5
|
-
- rbx-18mode
|
6
|
-
- rbx-19mode
|
7
9
|
- 1.8.7
|
8
10
|
- 1.9.2
|
9
11
|
- 1.9.3
|
10
12
|
- 2.0.0
|
13
|
+
- 2.1.0
|
14
|
+
- rbx
|
15
|
+
- ruby-head
|
16
|
+
matrix:
|
17
|
+
include:
|
18
|
+
- rvm: jruby-18mode
|
19
|
+
env: JRUBY_OPTS="$JRUBY_OPTS --debug"
|
20
|
+
- rvm: jruby-19mode
|
21
|
+
env: JRUBY_OPTS="$JRUBY_OPTS --debug"
|
22
|
+
- rvm: jruby-head
|
23
|
+
env: JRUBY_OPTS="$JRUBY_OPTS --debug"
|
24
|
+
allow_failures:
|
25
|
+
- rvm: jruby-head
|
26
|
+
- rvm: rbx
|
27
|
+
- rvm: ruby-head
|
28
|
+
fast_finish: true
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
## Contributing
|
2
|
+
In the spirit of [free software][free-sw], **everyone** is encouraged to help
|
3
|
+
improve this project. Here are some ways *you* can contribute:
|
4
|
+
|
5
|
+
[free-sw]: http://www.fsf.org/licensing/essays/free-sw.html
|
6
|
+
|
7
|
+
* Use alpha, beta, and pre-release versions.
|
8
|
+
* Report bugs.
|
9
|
+
* Suggest new features.
|
10
|
+
* Write or edit documentation.
|
11
|
+
* Write specifications.
|
12
|
+
* Write code (**no patch is too small**: fix typos, add comments, clean up
|
13
|
+
inconsistent whitespace).
|
14
|
+
* Refactor code.
|
15
|
+
* Fix [issues][].
|
16
|
+
* Review patches.
|
17
|
+
* Financially pledge using [gittip][].
|
18
|
+
|
19
|
+
[issues]: https://github.com/sferik/congress/issues
|
20
|
+
[gittip]: https://www.gittip.com/sferik/
|
21
|
+
|
22
|
+
## Submitting an Issue
|
23
|
+
We use the [GitHub issue tracker][issues] to track bugs and features. Before
|
24
|
+
submitting a bug report or feature request, check to make sure it hasn't
|
25
|
+
already been submitted. When submitting a bug report, please include a [Gist][]
|
26
|
+
that includes a stack trace and any details that may be necessary to reproduce
|
27
|
+
the bug, including your gem version, Ruby version, and operating system.
|
28
|
+
Ideally, a bug report should include a pull request with failing specs.
|
29
|
+
|
30
|
+
[gist]: https://gist.github.com/
|
31
|
+
|
32
|
+
## Submitting a Pull Request
|
33
|
+
1. [Fork the repository.][fork]
|
34
|
+
2. [Create a topic branch.][branch]
|
35
|
+
3. Add specs for your unimplemented feature or bug fix.
|
36
|
+
4. Run `bundle exec rake spec`. If your specs pass, return to step 3.
|
37
|
+
5. Implement your feature or bug fix.
|
38
|
+
6. Run `bundle exec rake`. If your specs fail, return to step 5.
|
39
|
+
7. Run `open coverage/index.html`. If your changes are not completely covered
|
40
|
+
by your tests, return to step 3.
|
41
|
+
8. Add documentation for your feature or bug fix.
|
42
|
+
9. Run `bundle exec rake verify_measurements`. If your changes are not 100%
|
43
|
+
documented, go back to step 8.
|
44
|
+
10. Commit and push your changes.
|
45
|
+
11. [Submit a pull request.][pr]
|
46
|
+
|
47
|
+
[fork]: http://help.github.com/fork-a-repo/
|
48
|
+
[branch]: http://learn.github.com/p/branching.html
|
49
|
+
[pr]: http://help.github.com/send-pull-requests/
|
data/Gemfile
CHANGED
@@ -1,21 +1,35 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
+
gem 'jruby-openssl', :platforms => :jruby
|
3
4
|
gem 'rake'
|
4
|
-
|
5
|
-
|
6
|
-
gem 'jruby-openssl', '~> 0.7'
|
7
|
-
end
|
5
|
+
gem 'yard'
|
6
|
+
gem 'geocoder'
|
8
7
|
|
9
8
|
group :development do
|
10
9
|
gem 'kramdown'
|
11
|
-
gem '
|
10
|
+
gem 'pry'
|
11
|
+
gem 'pry-rescue'
|
12
|
+
platforms :ruby_19, :ruby_20 do
|
13
|
+
gem 'pry-debugger'
|
14
|
+
gem 'pry-stack_explorer'
|
15
|
+
end
|
12
16
|
end
|
13
17
|
|
14
18
|
group :test do
|
19
|
+
gem 'backports'
|
15
20
|
gem 'coveralls', :require => false
|
16
|
-
gem '
|
21
|
+
gem 'mime-types', '~> 1.25', :platforms => [:jruby, :ruby_18]
|
22
|
+
gem 'rspec', '>= 2.14'
|
23
|
+
gem 'rubocop', '>= 0.16', :platforms => [:ruby_19, :ruby_20, :ruby_21]
|
17
24
|
gem 'simplecov', :require => false
|
18
25
|
gem 'webmock'
|
26
|
+
gem 'yardstick'
|
27
|
+
end
|
28
|
+
|
29
|
+
platforms :rbx do
|
30
|
+
gem 'racc'
|
31
|
+
gem 'rubinius-coverage', '~> 2.0'
|
32
|
+
gem 'rubysl', '~> 2.0'
|
19
33
|
end
|
20
34
|
|
21
35
|
gemspec
|
data/LICENSE.md
CHANGED
data/README.md
CHANGED
@@ -17,16 +17,6 @@ Congress, provided by the Sunlight Foundation.
|
|
17
17
|
## Installation
|
18
18
|
gem install congress
|
19
19
|
|
20
|
-
To ensure the code you're installing hasn't been tampered with, it's
|
21
|
-
recommended that you verify the signature. To do this, you need to add my
|
22
|
-
public key as a trusted certificate (you only need to do this once):
|
23
|
-
|
24
|
-
gem cert --add <(curl -Ls https://raw.github.com/codeforamerica/congress/master/certs/sferik.pem)
|
25
|
-
|
26
|
-
Then, install the gem with the high security trust policy:
|
27
|
-
|
28
|
-
gem install congress -P HighSecurity
|
29
|
-
|
30
20
|
## Documentation
|
31
21
|
[http://rdoc.info/gems/congress][documentation]
|
32
22
|
[documentation]: http://rdoc.info/gems/congress
|
@@ -98,55 +88,7 @@ Congress.hearings
|
|
98
88
|
Congress.upcoming_bills
|
99
89
|
```
|
100
90
|
|
101
|
-
##
|
102
|
-
In the spirit of [free software][free-sw], **everyone** is encouraged to help improve
|
103
|
-
this project.
|
104
|
-
|
105
|
-
[free-sw]: http://www.fsf.org/licensing/essays/free-sw.html
|
106
|
-
|
107
|
-
Here are some ways *you* can contribute:
|
108
|
-
|
109
|
-
* by using alpha, beta, and prerelease versions
|
110
|
-
* by reporting bugs
|
111
|
-
* by suggesting new features
|
112
|
-
* by writing or editing documentation
|
113
|
-
* by writing specifications
|
114
|
-
* by writing code (**no patch is too small**: fix typos, add comments, clean up
|
115
|
-
inconsistent whitespace)
|
116
|
-
* by refactoring code
|
117
|
-
* by fixing [issues][]
|
118
|
-
* by reviewing patches
|
119
|
-
|
120
|
-
[issues]: https://github.com/codeforamerica/congress/issues
|
121
|
-
|
122
|
-
## Submitting an Issue
|
123
|
-
We use the [GitHub issue tracker][issues] to track bugs and features. Before
|
124
|
-
submitting a bug report or feature request, check to make sure it hasn't
|
125
|
-
already been submitted. When submitting a bug report, please include a [Gist][]
|
126
|
-
that includes a stack trace and any details that may be necessary to reproduce
|
127
|
-
the bug, including your gem version, Ruby version, and operating system.
|
128
|
-
Ideally, a bug report should include a pull request with failing specs.
|
129
|
-
|
130
|
-
## Submitting a Pull Request
|
131
|
-
1. [Fork the repository.][fork]
|
132
|
-
2. [Create a topic branch.][branch]
|
133
|
-
3. Add specs for your unimplemented feature or bug fix.
|
134
|
-
4. Run `bundle exec rake spec`. If your specs pass, return to step 3.
|
135
|
-
5. Implement your feature or bug fix.
|
136
|
-
6. Run `bundle exec rake spec`. If your specs fail, return to step 5.
|
137
|
-
7. Run `open coverage/index.html`. If your changes are not completely covered
|
138
|
-
by your tests, return to step 3.
|
139
|
-
8. Add documentation for your feature or bug fix.
|
140
|
-
9. Run `bundle exec rake yard`. If your changes are not 100% documented, go
|
141
|
-
back to step 8.
|
142
|
-
10. Add, commit, and push your changes.
|
143
|
-
11. [Submit a pull request.][pr]
|
144
|
-
|
145
|
-
[fork]: http://help.github.com/fork-a-repo/
|
146
|
-
[branch]: http://learn.github.com/p/branching.html
|
147
|
-
[pr]: http://help.github.com/send-pull-requests/
|
148
|
-
|
149
|
-
## Supported Rubies
|
91
|
+
## Supported Ruby Versions
|
150
92
|
This library aims to support and is [tested against][travis] the following Ruby
|
151
93
|
implementations:
|
152
94
|
|
@@ -154,6 +96,7 @@ implementations:
|
|
154
96
|
* Ruby 1.9.2
|
155
97
|
* Ruby 1.9.3
|
156
98
|
* Ruby 2.0.0
|
99
|
+
* Ruby 2.1.0
|
157
100
|
* [JRuby][]
|
158
101
|
* [Rubinius][]
|
159
102
|
|
@@ -175,6 +118,6 @@ timely fashion. If critical issues for a particular implementation exist at the
|
|
175
118
|
time of a major release, support for that Ruby version may be dropped.
|
176
119
|
|
177
120
|
## Copyright
|
178
|
-
Copyright (c) 2011-
|
121
|
+
Copyright (c) 2011-2014, Code for America. See [LICENSE][] for details.
|
179
122
|
|
180
123
|
[license]: https://github.com/codeforamerica/congress/blob/master/LICENSE.md
|
data/Rakefile
CHANGED
@@ -4,13 +4,33 @@ Bundler::GemHelper.install_tasks
|
|
4
4
|
require 'rspec/core/rake_task'
|
5
5
|
RSpec::Core::RakeTask.new(:spec)
|
6
6
|
|
7
|
-
task :default => :spec
|
8
7
|
task :test => :spec
|
9
8
|
|
9
|
+
begin
|
10
|
+
require 'rubocop/rake_task'
|
11
|
+
Rubocop::RakeTask.new
|
12
|
+
rescue LoadError
|
13
|
+
task :rubocop do
|
14
|
+
$stderr.puts 'Rubocop is disabled'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
10
18
|
require 'yard'
|
11
19
|
namespace :doc do
|
12
20
|
YARD::Rake::YardocTask.new do |task|
|
13
|
-
task.files = [
|
14
|
-
task.options = [
|
21
|
+
task.files = %w[lib/**/*.rb]
|
22
|
+
task.options = %w[--markup markdown]
|
15
23
|
end
|
16
24
|
end
|
25
|
+
|
26
|
+
require 'yardstick/rake/measurement'
|
27
|
+
Yardstick::Rake::Measurement.new do |measurement|
|
28
|
+
measurement.output = 'measurement/report.txt'
|
29
|
+
end
|
30
|
+
|
31
|
+
require 'yardstick/rake/verify'
|
32
|
+
Yardstick::Rake::Verify.new do |verify|
|
33
|
+
verify.threshold = 60.0
|
34
|
+
end
|
35
|
+
|
36
|
+
task :default => [:spec, :rubocop, :verify_measurements]
|
data/congress.gemspec
CHANGED
@@ -7,8 +7,9 @@ Gem::Specification.new do |spec|
|
|
7
7
|
spec.add_dependency 'hashie', '~> 2.0'
|
8
8
|
spec.add_dependency 'json', '~> 1.8'
|
9
9
|
spec.add_dependency 'rash', '~> 0.4'
|
10
|
+
spec.add_dependency 'geocoder', '~> 1.1.9'
|
10
11
|
spec.add_development_dependency 'bundler', '~> 1.0'
|
11
|
-
spec.author =
|
12
|
+
spec.author = 'Erik Michaels-Ober'
|
12
13
|
spec.cert_chain = ['certs/sferik.pem']
|
13
14
|
spec.description = %q{Ruby wrapper for the Sunlight Congress API, a live JSON API for the people and work of Congress, provided by the Sunlight Foundation.}
|
14
15
|
spec.email = 'sferik@gmail.com'
|
@@ -17,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
17
18
|
spec.licenses = ['MIT']
|
18
19
|
spec.name = 'congress'
|
19
20
|
spec.require_paths = ['lib']
|
20
|
-
spec.signing_key = File.expand_path(
|
21
|
+
spec.signing_key = File.expand_path('~/.gem/private_key.pem') if $PROGRAM_NAME =~ /gem\z/
|
21
22
|
spec.summary = %q{Ruby wrapper for the Sunlight Congress API}
|
22
23
|
spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
23
24
|
spec.version = Congress::VERSION
|
data/lib/congress/client.rb
CHANGED
@@ -1,10 +1,17 @@
|
|
1
1
|
require 'congress/connection'
|
2
2
|
require 'congress/request'
|
3
|
+
require 'geocoder'
|
3
4
|
|
4
5
|
module Congress
|
5
6
|
class Client
|
6
7
|
include Connection
|
7
8
|
include Request
|
9
|
+
attr_reader :key
|
10
|
+
|
11
|
+
def initialize(key)
|
12
|
+
fail ArgumentError, 'API key required' if key.nil?
|
13
|
+
@key = key
|
14
|
+
end
|
8
15
|
|
9
16
|
# Current legislators' names, IDs, biography, and social media.
|
10
17
|
#
|
@@ -12,32 +19,32 @@ module Congress
|
|
12
19
|
# @example
|
13
20
|
# Congress.key = YOUR_SUNLIGHT_API_KEY
|
14
21
|
# Congress.legislators
|
15
|
-
def legislators(options={})
|
16
|
-
get('/legislators', options
|
22
|
+
def legislators(options = {})
|
23
|
+
get('/legislators', options)
|
17
24
|
end
|
18
25
|
|
19
|
-
# Find representatives and senators for a latitude/longitude or
|
26
|
+
# Find representatives and senators for a latitude/longitude, zip, or address.
|
20
27
|
#
|
21
28
|
# @return [Hashie::Rash]
|
22
29
|
# @example
|
23
30
|
# Congress.key = YOUR_SUNLIGHT_API_KEY
|
24
31
|
# Congress.legislators_locate(94107)
|
25
32
|
# Congress.legislators_locate(37.775, -122.418)
|
33
|
+
# Congress.legislators_locate('2169 Mission Street, San Francisco, CA 94110')
|
26
34
|
def legislators_locate(*args)
|
27
|
-
|
28
|
-
get('/legislators/locate', options.merge(api_key))
|
35
|
+
get('/legislators/locate', extract_location(args))
|
29
36
|
end
|
30
37
|
|
31
|
-
# Find congressional districts for a latitude/longitude or
|
38
|
+
# Find congressional districts for a latitude/longitude, zip, or address.
|
32
39
|
#
|
33
40
|
# @return [Hashie::Rash]
|
34
41
|
# @example
|
35
42
|
# Congress.key = YOUR_SUNLIGHT_API_KEY
|
36
43
|
# Congress.districts_locate(94107)
|
37
44
|
# Congress.districts_locate(37.775, -122.418)
|
45
|
+
# Congress.districts_locate('2169 Mission Street, San Francisco, CA 94110')
|
38
46
|
def districts_locate(*args)
|
39
|
-
|
40
|
-
get('/districts/locate', options.merge(api_key))
|
47
|
+
get('/districts/locate', extract_location(args))
|
41
48
|
end
|
42
49
|
|
43
50
|
# Current committees, subcommittees, and their membership.
|
@@ -46,8 +53,8 @@ module Congress
|
|
46
53
|
# @example
|
47
54
|
# Congress.key = YOUR_SUNLIGHT_API_KEY
|
48
55
|
# Congress.committees
|
49
|
-
def committees(options={})
|
50
|
-
get('/committees', options
|
56
|
+
def committees(options = {})
|
57
|
+
get('/committees', options)
|
51
58
|
end
|
52
59
|
|
53
60
|
# Legislation in the House and Senate, back to 2009. Updated daily.
|
@@ -56,8 +63,8 @@ module Congress
|
|
56
63
|
# @example
|
57
64
|
# Congress.key = YOUR_SUNLIGHT_API_KEY
|
58
65
|
# Congress.bills
|
59
|
-
def bills(options={})
|
60
|
-
get('/bills', options
|
66
|
+
def bills(options = {})
|
67
|
+
get('/bills', options)
|
61
68
|
end
|
62
69
|
|
63
70
|
# ull text search over legislation.
|
@@ -66,8 +73,8 @@ module Congress
|
|
66
73
|
# @example
|
67
74
|
# Congress.key = YOUR_SUNLIGHT_API_KEY
|
68
75
|
# Congress.bills_search
|
69
|
-
def bills_search(options={})
|
70
|
-
get('/bills/search', options
|
76
|
+
def bills_search(options = {})
|
77
|
+
get('/bills/search', options)
|
71
78
|
end
|
72
79
|
|
73
80
|
# Roll call votes in Congress, back to 2009. Updated within minutes of votes.
|
@@ -76,8 +83,8 @@ module Congress
|
|
76
83
|
# @example
|
77
84
|
# Congress.key = YOUR_SUNLIGHT_API_KEY
|
78
85
|
# Congress.votes
|
79
|
-
def votes(options={})
|
80
|
-
get('/votes', options
|
86
|
+
def votes(options = {})
|
87
|
+
get('/votes', options)
|
81
88
|
end
|
82
89
|
|
83
90
|
# To-the-minute updates from the floor of the House and Senate.
|
@@ -86,8 +93,8 @@ module Congress
|
|
86
93
|
# @example
|
87
94
|
# Congress.key = YOUR_SUNLIGHT_API_KEY
|
88
95
|
# Congress.floor_updates
|
89
|
-
def floor_updates(options={})
|
90
|
-
get('/floor_updates', options
|
96
|
+
def floor_updates(options = {})
|
97
|
+
get('/floor_updates', options)
|
91
98
|
end
|
92
99
|
|
93
100
|
# Committee hearings in Congress. Updated as hearings are announced.
|
@@ -96,8 +103,8 @@ module Congress
|
|
96
103
|
# @example
|
97
104
|
# Congress.key = YOUR_SUNLIGHT_API_KEY
|
98
105
|
# Congress.hearings
|
99
|
-
def hearings(options={})
|
100
|
-
get('/hearings', options
|
106
|
+
def hearings(options = {})
|
107
|
+
get('/hearings', options)
|
101
108
|
end
|
102
109
|
|
103
110
|
# Bills scheduled for debate in the future, as announced by party leadership.
|
@@ -106,29 +113,25 @@ module Congress
|
|
106
113
|
# @example
|
107
114
|
# Congress.key = YOUR_SUNLIGHT_API_KEY
|
108
115
|
# Congress.upcoming_bills
|
109
|
-
def upcoming_bills(options={})
|
110
|
-
get('/upcoming_bills', options
|
116
|
+
def upcoming_bills(options = {})
|
117
|
+
get('/upcoming_bills', options)
|
111
118
|
end
|
112
119
|
|
113
120
|
private
|
114
121
|
|
115
|
-
def api_key
|
116
|
-
{:apikey => Congress.key}
|
117
|
-
end
|
118
|
-
|
119
122
|
def extract_location(args)
|
120
123
|
options = args.last.is_a?(::Hash) ? args.pop : {}
|
121
|
-
case args.size
|
122
|
-
when 1
|
123
|
-
options
|
124
|
-
when
|
125
|
-
|
126
|
-
options
|
124
|
+
case [args.size, args.first.class]
|
125
|
+
when [1, Fixnum]
|
126
|
+
options.merge(:zip => args.pop)
|
127
|
+
when [1, String]
|
128
|
+
placemark = Geocoder.search(args.pop).first
|
129
|
+
options.merge(:longitude => placemark.longitude, :latitude => placemark.latitude)
|
130
|
+
when [2, Float]
|
131
|
+
options.merge(:longitude => args.pop, :latitude => args.pop)
|
127
132
|
else
|
128
|
-
|
133
|
+
fail ArgumentError, 'Must pass a latitude/longitude, zip or address'
|
129
134
|
end
|
130
|
-
options
|
131
135
|
end
|
132
|
-
|
133
136
|
end
|
134
137
|
end
|
data/lib/congress/connection.rb
CHANGED
@@ -2,16 +2,26 @@ require 'faraday_middleware'
|
|
2
2
|
|
3
3
|
module Congress
|
4
4
|
module Connection
|
5
|
-
|
5
|
+
ENDPOINT = 'https://congress.api.sunlightfoundation.com'.freeze
|
6
|
+
|
7
|
+
private
|
6
8
|
|
7
9
|
def connection
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
@connection ||= create_connection
|
11
|
+
end
|
12
|
+
|
13
|
+
def create_connection
|
14
|
+
Faraday.new(:url => ENDPOINT) do |connection|
|
15
|
+
middlewares.each { |middleware| connection.use(middleware) }
|
13
16
|
connection.adapter(Faraday.default_adapter)
|
14
17
|
end
|
15
18
|
end
|
19
|
+
|
20
|
+
def middlewares
|
21
|
+
[Faraday::Request::UrlEncoded,
|
22
|
+
Faraday::Response::RaiseError,
|
23
|
+
Faraday::Response::Rashify,
|
24
|
+
Faraday::Response::ParseJson]
|
25
|
+
end
|
16
26
|
end
|
17
27
|
end
|
data/lib/congress/request.rb
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
module Congress
|
2
2
|
module Request
|
3
|
-
def get(path, options={})
|
3
|
+
def get(path, options = {})
|
4
4
|
request(:get, path, options)
|
5
5
|
end
|
6
6
|
|
7
|
-
|
7
|
+
private
|
8
8
|
|
9
9
|
def request(method, path, options)
|
10
10
|
response = connection.send(method) do |request|
|
11
|
+
request.headers['X-APIKEY'] = key
|
11
12
|
request.url(path, options)
|
12
13
|
end
|
13
14
|
response.body
|
data/lib/congress/version.rb
CHANGED