openstates 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 +17 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/Guardfile +9 -0
- data/LICENSE.txt +22 -0
- data/README.md +28 -0
- data/Rakefile +1 -0
- data/lib/openstates.rb +5 -0
- data/lib/openstates/api.rb +66 -0
- data/lib/openstates/configuration.rb +9 -0
- data/lib/openstates/connection.rb +29 -0
- data/lib/openstates/core.rb +20 -0
- data/lib/openstates/mashify.rb +13 -0
- data/lib/openstates/model.rb +64 -0
- data/lib/openstates/models/bill.rb +53 -0
- data/lib/openstates/models/committee.rb +25 -0
- data/lib/openstates/models/district.rb +36 -0
- data/lib/openstates/models/event.rb +28 -0
- data/lib/openstates/models/legislator.rb +45 -0
- data/lib/openstates/version.rb +3 -0
- data/openstates.gemspec +31 -0
- data/spec/openstates/api_spec.rb +184 -0
- data/spec/openstates/models/bill_spec.rb +33 -0
- data/spec/openstates/models/committee_spec.rb +15 -0
- data/spec/openstates/models/district_spec.rb +34 -0
- data/spec/openstates/models/event_spec.rb +15 -0
- data/spec/openstates/models/legislator_spec.rb +41 -0
- data/spec/openstates/version_spec.rb +9 -0
- data/spec/spec_helper.rb +13 -0
- metadata +249 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Chris Stephan
|
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,28 @@
|
|
1
|
+
# Ruby::Openstates
|
2
|
+
|
3
|
+
Ruby gem to interact with the OpenStates API.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'openstates'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install openstates
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
|
22
|
+
## Contributing
|
23
|
+
|
24
|
+
1. Fork it
|
25
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
26
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
27
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
28
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/openstates.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
module OpenStates
|
2
|
+
module Api
|
3
|
+
def metadata(state = nil)
|
4
|
+
url = "metadata/"
|
5
|
+
url << "#{state}/" if state
|
6
|
+
get(url)
|
7
|
+
end
|
8
|
+
|
9
|
+
def bills(options = {})
|
10
|
+
url = "bills/"
|
11
|
+
if options[:state] && options[:session] && options[:bill_id]
|
12
|
+
url << "#{options[:state]}/#{options[:session]}/#{options[:bill_id]}/"
|
13
|
+
[:state, :session, :bill_id].each do |key|
|
14
|
+
options.delete(key)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
get(url, options)
|
19
|
+
end
|
20
|
+
|
21
|
+
def legislators(options = {})
|
22
|
+
url = "legislators/"
|
23
|
+
url << "#{options[:leg_id]}/" if options[:leg_id]
|
24
|
+
|
25
|
+
get(url, options)
|
26
|
+
end
|
27
|
+
|
28
|
+
def geo_legislators(lat, lon)
|
29
|
+
url = "legislators/geo/"
|
30
|
+
|
31
|
+
get(url, {:lat => lat, :long => lon})
|
32
|
+
end
|
33
|
+
|
34
|
+
def committees(options = {})
|
35
|
+
url = "committees/"
|
36
|
+
url << "#{options[:committee_id]}/" if options[:committee_id]
|
37
|
+
|
38
|
+
get(url, options)
|
39
|
+
end
|
40
|
+
|
41
|
+
def events(options = {})
|
42
|
+
url = "events/"
|
43
|
+
url << "#{options[:event_id]}/" if options[:event_id]
|
44
|
+
|
45
|
+
get(url, options)
|
46
|
+
end
|
47
|
+
|
48
|
+
def districts(options = {})
|
49
|
+
return [] if !options[:state]
|
50
|
+
|
51
|
+
url = "districts/"
|
52
|
+
url << "#{options[:state]}/"
|
53
|
+
url << "#{options[:chamber]}/" if options[:chamber]
|
54
|
+
|
55
|
+
get(url, options)
|
56
|
+
end
|
57
|
+
|
58
|
+
def district_boundaries(boundary_id)
|
59
|
+
return if !boundary_id
|
60
|
+
|
61
|
+
url = "districts/boundary/#{boundary_id}/"
|
62
|
+
|
63
|
+
get(url)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module OpenStates
|
2
|
+
module Connection
|
3
|
+
BASE_URL = 'http://openstates.org/api/v1/'
|
4
|
+
def connection
|
5
|
+
@connection ||= begin
|
6
|
+
conn = Faraday.new(BASE_URL) do |b|
|
7
|
+
b.use Faraday::Response::Logger, logger
|
8
|
+
b.use FaradayMiddleware::Mashify
|
9
|
+
b.use FaradayMiddleware::ParseJson, content_type: 'application/json'
|
10
|
+
b.use FaradayMiddleware::Caching, cache, strip_params: %w[apikey] unless cache.nil?
|
11
|
+
b.response :raise_error
|
12
|
+
b.adapter Faraday.default_adapter
|
13
|
+
end
|
14
|
+
|
15
|
+
conn.params['apikey'] = api_key unless api_key.nil?
|
16
|
+
|
17
|
+
conn
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def get(path, params = nil)
|
22
|
+
response = connection.get(path) do |request|
|
23
|
+
request.params.merge!(params) if params
|
24
|
+
end
|
25
|
+
|
26
|
+
response.body
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'faraday_middleware'
|
2
|
+
require 'hashie/mash'
|
3
|
+
require 'logger'
|
4
|
+
require 'openstates/version'
|
5
|
+
require 'openstates/mashify'
|
6
|
+
require 'openstates/connection'
|
7
|
+
require 'openstates/configuration'
|
8
|
+
require 'openstates/api'
|
9
|
+
require 'openstates/model'
|
10
|
+
require 'openstates/models/legislator'
|
11
|
+
require 'openstates/models/bill'
|
12
|
+
require 'openstates/models/committee'
|
13
|
+
require 'openstates/models/district'
|
14
|
+
require 'openstates/models/event'
|
15
|
+
|
16
|
+
module OpenStates
|
17
|
+
extend OpenStates::Configuration
|
18
|
+
extend OpenStates::Connection
|
19
|
+
extend OpenStates::Api
|
20
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module OpenStates
|
2
|
+
module Model
|
3
|
+
def self.included(base)
|
4
|
+
base.extend ClassMethods
|
5
|
+
end
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def from_hash(hash)
|
9
|
+
instance = new
|
10
|
+
instance.populate_from_hash!(hash)
|
11
|
+
yield instance if block_given?
|
12
|
+
instance
|
13
|
+
end
|
14
|
+
|
15
|
+
def hash_attr_accessor(*symbols)
|
16
|
+
attr_writer(*symbols)
|
17
|
+
symbols.each do |symbol|
|
18
|
+
define_method(symbol) do
|
19
|
+
instance_variable_get("@#{symbol}")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def find(id)
|
25
|
+
return if !id
|
26
|
+
|
27
|
+
id_hash = Hash.new
|
28
|
+
id_hash[id_key] = id
|
29
|
+
response = OpenStates.send(api_method, id_hash)
|
30
|
+
|
31
|
+
from_hash(response)
|
32
|
+
end
|
33
|
+
|
34
|
+
def where(options = {})
|
35
|
+
return [] if options.empty?
|
36
|
+
|
37
|
+
OpenStates.send(api_method, options).map do |leg_hash|
|
38
|
+
from_hash(leg_hash)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def api_method
|
43
|
+
raise NotImplementedError
|
44
|
+
end
|
45
|
+
|
46
|
+
def id_key
|
47
|
+
raise NotImplementedError
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def populate_from_hash!(hash)
|
52
|
+
return unless hash
|
53
|
+
|
54
|
+
hash.each do |key, value|
|
55
|
+
set_attr_method = "#{key}="
|
56
|
+
unless value.nil?
|
57
|
+
if respond_to?(set_attr_method)
|
58
|
+
self.__send__(set_attr_method, value)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module OpenStates
|
2
|
+
class Bill
|
3
|
+
include Model
|
4
|
+
hash_attr_accessor :action_dates,
|
5
|
+
:actions,
|
6
|
+
:alternate_titles,
|
7
|
+
:bill_id,
|
8
|
+
:chamber,
|
9
|
+
:created_at,
|
10
|
+
:documents,
|
11
|
+
:id,
|
12
|
+
:level,
|
13
|
+
:scraped_subjects,
|
14
|
+
:session,
|
15
|
+
:session,
|
16
|
+
:sources,
|
17
|
+
:sponsors,
|
18
|
+
:state,
|
19
|
+
:subjects,
|
20
|
+
:subjects,
|
21
|
+
:title,
|
22
|
+
:title,
|
23
|
+
:type,
|
24
|
+
:type,
|
25
|
+
:updated_at,
|
26
|
+
:versions,
|
27
|
+
:votes
|
28
|
+
|
29
|
+
class << self
|
30
|
+
def api_method
|
31
|
+
:bills
|
32
|
+
end
|
33
|
+
|
34
|
+
def id_key
|
35
|
+
:bill_id
|
36
|
+
end
|
37
|
+
|
38
|
+
def bill_details(state, session, bill_id)
|
39
|
+
return if !state || !session || !bill_id
|
40
|
+
|
41
|
+
options = {
|
42
|
+
state: state,
|
43
|
+
session: session,
|
44
|
+
bill_id: bill_id
|
45
|
+
}
|
46
|
+
|
47
|
+
response = OpenStates.bills(options)
|
48
|
+
|
49
|
+
from_hash(response)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module OpenStates
|
2
|
+
class Committee
|
3
|
+
include Model
|
4
|
+
hash_attr_accessor :chamber,
|
5
|
+
:committee,
|
6
|
+
:created_at,
|
7
|
+
:id,
|
8
|
+
:members,
|
9
|
+
:parent_id,
|
10
|
+
:sources,
|
11
|
+
:state,
|
12
|
+
:subcommittee,
|
13
|
+
:updated_at
|
14
|
+
|
15
|
+
class << self
|
16
|
+
def api_method
|
17
|
+
:committees
|
18
|
+
end
|
19
|
+
|
20
|
+
def id_key
|
21
|
+
:committee_id
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module OpenStates
|
2
|
+
class District
|
3
|
+
include Model
|
4
|
+
hash_attr_accessor :abbr,
|
5
|
+
:bbox,
|
6
|
+
:boundary_id,
|
7
|
+
:center_lat,
|
8
|
+
:center_lon,
|
9
|
+
:chamber,
|
10
|
+
:id,
|
11
|
+
:lat_delta,
|
12
|
+
:lon_delta,
|
13
|
+
:name,
|
14
|
+
:num_seats,
|
15
|
+
:region,
|
16
|
+
:shape
|
17
|
+
|
18
|
+
class << self
|
19
|
+
def api_method
|
20
|
+
:districts
|
21
|
+
end
|
22
|
+
|
23
|
+
def id_key
|
24
|
+
:boundary_id
|
25
|
+
end
|
26
|
+
|
27
|
+
def find(boundary_id)
|
28
|
+
return if !boundary_id
|
29
|
+
|
30
|
+
response = OpenStates.district_boundaries(boundary_id)
|
31
|
+
|
32
|
+
from_hash(response)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module OpenStates
|
2
|
+
class Event
|
3
|
+
include Model
|
4
|
+
hash_attr_accessor :created_at,
|
5
|
+
:description,
|
6
|
+
:documents,
|
7
|
+
:end,
|
8
|
+
:id,
|
9
|
+
:location,
|
10
|
+
:participants,
|
11
|
+
:related_bills,
|
12
|
+
:sources,
|
13
|
+
:state,
|
14
|
+
:timezone,
|
15
|
+
:type,
|
16
|
+
:updated_at,
|
17
|
+
:when
|
18
|
+
class << self
|
19
|
+
def api_method
|
20
|
+
:events
|
21
|
+
end
|
22
|
+
|
23
|
+
def id_key
|
24
|
+
:event_id
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module OpenStates
|
2
|
+
class Legislator
|
3
|
+
include Model
|
4
|
+
hash_attr_accessor :active,
|
5
|
+
:chamber,
|
6
|
+
:created_at,
|
7
|
+
:district,
|
8
|
+
:email,
|
9
|
+
:first_name,
|
10
|
+
:full_name,
|
11
|
+
:last_name,
|
12
|
+
:leg_id,
|
13
|
+
:middle_name,
|
14
|
+
:offices,
|
15
|
+
:old_roles,
|
16
|
+
:party,
|
17
|
+
:photo_url,
|
18
|
+
:roles,
|
19
|
+
:state,
|
20
|
+
:suffixes,
|
21
|
+
:transparencydata_id,
|
22
|
+
:updated_at,
|
23
|
+
:url
|
24
|
+
|
25
|
+
class << self
|
26
|
+
def api_method
|
27
|
+
:legislators
|
28
|
+
end
|
29
|
+
|
30
|
+
def id_key
|
31
|
+
:leg_id
|
32
|
+
end
|
33
|
+
|
34
|
+
def by_location(lat, lon)
|
35
|
+
return if !lat || !lon
|
36
|
+
|
37
|
+
response = OpenStates.geo_legislators(lat, lon)
|
38
|
+
|
39
|
+
response.map do |leg_hash|
|
40
|
+
from_hash(leg_hash)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/openstates.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'openstates/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "openstates"
|
8
|
+
spec.version = OpenStates::VERSION
|
9
|
+
spec.authors = ["Chris"]
|
10
|
+
spec.email = ["chris@wideeyelabs.com"]
|
11
|
+
spec.summary = %q{Ruby gem to interact with the OpenStates API.}
|
12
|
+
spec.description = %q{Ruby gem to interact with the OpenStates API.}
|
13
|
+
spec.homepage = "https://github.com/WideEyeLabs"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "faraday_middleware"
|
22
|
+
spec.add_dependency "hashie"
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "rspec"
|
26
|
+
spec.add_development_dependency "guard"
|
27
|
+
spec.add_development_dependency "guard-rspec"
|
28
|
+
spec.add_development_dependency "pry"
|
29
|
+
spec.add_development_dependency "pry-remote"
|
30
|
+
spec.add_development_dependency "pry-debugger"
|
31
|
+
end
|
@@ -0,0 +1,184 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe OpenStates::Api do
|
4
|
+
before { OpenStates.stub(:get).and_return({}) }
|
5
|
+
|
6
|
+
describe ".metadata" do
|
7
|
+
it "should call .get on OpenStates" do
|
8
|
+
expect(OpenStates).to receive(:get)
|
9
|
+
OpenStates.metadata
|
10
|
+
end
|
11
|
+
|
12
|
+
context "without a state passed" do
|
13
|
+
it "should call .get with 'metadata/'" do
|
14
|
+
expect(OpenStates).to receive(:get).with("metadata/")
|
15
|
+
OpenStates.metadata
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "with a state passed in" do
|
20
|
+
it "should call .get with 'metadata/in/'" do
|
21
|
+
state = "in"
|
22
|
+
expect(OpenStates).to receive(:get).with("metadata/#{state}/")
|
23
|
+
OpenStates.metadata(state)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe ".bills" do
|
29
|
+
it "should call .get on OpenStates" do
|
30
|
+
expect(OpenStates).to receive(:get)
|
31
|
+
OpenStates.bills
|
32
|
+
end
|
33
|
+
|
34
|
+
context "without an options hash passed" do
|
35
|
+
it "should call .get with 'bills/' and an empty hash" do
|
36
|
+
expect(OpenStates).to receive(:get).with("bills/", {})
|
37
|
+
OpenStates.bills
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "with an options hash passed" do
|
42
|
+
it "should call .get with 'bills/in/summer/10' and an options hash" do
|
43
|
+
options = {:state => "in", :session => "summer", :bill_id => 10}
|
44
|
+
expect(OpenStates).to receive(:get).with("bills/#{options[:state]}/#{options[:session]}/#{options[:bill_id]}/", options)
|
45
|
+
OpenStates.bills(options)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe ".legislators" do
|
51
|
+
it "should call .get on OpenStates" do
|
52
|
+
expect(OpenStates).to receive(:get)
|
53
|
+
OpenStates.legislators
|
54
|
+
end
|
55
|
+
|
56
|
+
context "without an options hash passed" do
|
57
|
+
it "should call .get with 'legislators/' and an empty hash" do
|
58
|
+
expect(OpenStates).to receive(:get).with("legislators/", {})
|
59
|
+
OpenStates.legislators
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context "with an options hash passed" do
|
64
|
+
it "should call .get with 'legislators/' and an options hash" do
|
65
|
+
options = {:leg_id => 1}
|
66
|
+
expect(OpenStates).to receive(:get).with("legislators/#{options[:leg_id]}/", options)
|
67
|
+
OpenStates.legislators(options)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe ".geo_legislators" do
|
73
|
+
it "should call .get on OpenStates" do
|
74
|
+
expect(OpenStates).to receive(:get)
|
75
|
+
OpenStates.geo_legislators(nil, nil)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should call .get with 'legislators/geo/' and a hash with lat/lon" do
|
79
|
+
lat, lon = 10,10
|
80
|
+
expect(OpenStates).to receive(:get).with("legislators/geo/", {:lat => lat, :long => lon})
|
81
|
+
OpenStates.geo_legislators(lat, lon)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe ".committees" do
|
86
|
+
it "should call .get on OpenStates" do
|
87
|
+
expect(OpenStates).to receive(:get)
|
88
|
+
OpenStates.committees
|
89
|
+
end
|
90
|
+
|
91
|
+
context "without an options hash passed" do
|
92
|
+
it "should call .get with 'committees/' and an empty hash" do
|
93
|
+
expect(OpenStates).to receive(:get).with("committees/", {})
|
94
|
+
OpenStates.committees
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
context "with an options hash passed" do
|
99
|
+
it "should call .get with 'committees/' and an options hash" do
|
100
|
+
options = {:committee_id => 1}
|
101
|
+
expect(OpenStates).to receive(:get).with("committees/#{options[:committee_id]}/", options)
|
102
|
+
OpenStates.committees(options)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe ".events" do
|
108
|
+
it "should call .get on OpenStates" do
|
109
|
+
expect(OpenStates).to receive(:get)
|
110
|
+
OpenStates.events
|
111
|
+
end
|
112
|
+
|
113
|
+
context "without an options hash passed" do
|
114
|
+
it "should call .get with 'events/' and an empty hash" do
|
115
|
+
expect(OpenStates).to receive(:get).with("events/", {})
|
116
|
+
OpenStates.events
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
context "with an options hash passed" do
|
121
|
+
it "should call .get with 'events/' and an options hash" do
|
122
|
+
options = {:event_id => 1}
|
123
|
+
expect(OpenStates).to receive(:get).with("events/#{options[:event_id]}/", options)
|
124
|
+
OpenStates.events(options)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
describe ".districts" do
|
130
|
+
context "without an options hash passed" do
|
131
|
+
it "should return an Array" do
|
132
|
+
expect(OpenStates.districts).to be_an Array
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should return an empty Array" do
|
136
|
+
expect(OpenStates.districts).to be_empty
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
context "with an options hash passed" do
|
141
|
+
context "with a state key only" do
|
142
|
+
it "should call .get on OpenStates" do
|
143
|
+
expect(OpenStates).to receive(:get)
|
144
|
+
OpenStates.districts(state: 'fl')
|
145
|
+
end
|
146
|
+
|
147
|
+
it "should call .get with 'districts/' and an options hash" do
|
148
|
+
options = {:state => 'oh'}
|
149
|
+
expect(OpenStates).to receive(:get).with("districts/#{options[:state]}/", options)
|
150
|
+
OpenStates.districts(options)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
context "with a state and chamber key" do
|
155
|
+
it "should call .get with 'districts/' and an options hash" do
|
156
|
+
options = {:state => 'in', :chamber => "blah"}
|
157
|
+
expect(OpenStates).to receive(:get).with("districts/#{options[:state]}/#{options[:chamber]}/", options)
|
158
|
+
OpenStates.districts(options)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
describe ".district_boundaries" do
|
165
|
+
let(:boundary_id) { 1 }
|
166
|
+
it "should call .get on OpenStates" do
|
167
|
+
expect(OpenStates).to receive(:get)
|
168
|
+
OpenStates.district_boundaries(boundary_id)
|
169
|
+
end
|
170
|
+
|
171
|
+
context "with a boundary_id parameter" do
|
172
|
+
it "should call .get with 'districts/:boundary_id'" do
|
173
|
+
expect(OpenStates).to receive(:get).with("districts/boundary/#{boundary_id}/")
|
174
|
+
OpenStates.district_boundaries(boundary_id)
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
context "without a boundary_id parameter" do
|
179
|
+
it "should return nil" do
|
180
|
+
expect(OpenStates.district_boundaries(nil)).to be_nil
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OpenStates::Bill do
|
4
|
+
describe ".api_method" do
|
5
|
+
it "should not raise a NotImplementedError" do
|
6
|
+
expect{ OpenStates::Bill.api_method }.not_to raise_error
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe ".id_key" do
|
11
|
+
it "should not raise a NotImplementedError" do
|
12
|
+
expect{ OpenStates::Bill.id_key }.not_to raise_error
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe ".bill_details" do
|
17
|
+
context "when state, session, and bill_id are nil" do
|
18
|
+
it "should return nil" do
|
19
|
+
expect(OpenStates::Bill.bill_details(nil, nil, nil)).to be_nil
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "when state, session, and bill_id are not nil" do
|
24
|
+
it "should return an OpenState::Bill" do
|
25
|
+
state = 'fl'
|
26
|
+
session = '2013'
|
27
|
+
bill_id = '1234'
|
28
|
+
OpenStates.stub(:bills).and_return({:bill_id => bill_id, :state => state, :session => session})
|
29
|
+
OpenStates::Bill.bill_details(state, session, bill_id).should be_a OpenStates::Bill
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OpenStates::Committee do
|
4
|
+
describe ".api_method" do
|
5
|
+
it "should not raise a NotImplementedError" do
|
6
|
+
expect{ OpenStates::Committee.api_method }.not_to raise_error
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe ".id_key" do
|
11
|
+
it "should not raise a NotImplementedError" do
|
12
|
+
expect{ OpenStates::Committee.id_key }.not_to raise_error
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OpenStates::District do
|
4
|
+
describe ".api_method" do
|
5
|
+
it "should not raise a NotImplementedError" do
|
6
|
+
expect{ OpenStates::District.api_method }.not_to raise_error
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe ".id_key" do
|
11
|
+
it "should not raise a NotImplementedError" do
|
12
|
+
expect{ OpenStates::District.id_key }.not_to raise_error
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe ".find" do
|
17
|
+
before(:each) do
|
18
|
+
OpenStates.stub(:district_boundaries).and_return({ :state => 'il' })
|
19
|
+
end
|
20
|
+
|
21
|
+
context "without a boundary id" do
|
22
|
+
it "should return nil" do
|
23
|
+
expect(OpenStates::District.find(nil)).to be_nil
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "with a boundary id" do
|
28
|
+
it "should return an OpenState::District" do
|
29
|
+
options = { :state => 'il' }
|
30
|
+
expect(OpenStates::District.find(options)).to be_a OpenStates::District
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OpenStates::Event do
|
4
|
+
describe ".api_method" do
|
5
|
+
it "should not raise a NotImplementedError" do
|
6
|
+
expect{ OpenStates::Event.api_method }.not_to raise_error
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe ".id_key" do
|
11
|
+
it "should not raise a NotImplementedError" do
|
12
|
+
expect{ OpenStates::Event.id_key }.not_to raise_error
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OpenStates::Legislator do
|
4
|
+
describe ".api_method" do
|
5
|
+
it "should not raise a NotImplementedError" do
|
6
|
+
expect{ OpenStates::Legislator.api_method }.not_to raise_error
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe ".id_key" do
|
11
|
+
it "should not raise a NotImplementedError" do
|
12
|
+
expect{ OpenStates::Legislator.id_key }.not_to raise_error
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe ".by_location" do
|
17
|
+
context "when lat and lon are nil" do
|
18
|
+
it "should return nil" do
|
19
|
+
OpenStates::Legislator.by_location(nil,nil).should be_nil
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "when lat and lon are not nil" do
|
24
|
+
before(:each) do
|
25
|
+
legislator_hash = {leg_id: '1', first_name: 'bob'}
|
26
|
+
response = [legislator_hash, legislator_hash]
|
27
|
+
OpenStates.stub(:geo_legislators).and_return(response)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should return an array" do
|
31
|
+
OpenStates::Legislator.by_location(123.10, -85.20).should be_an Array
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should return an array of legislator objects" do
|
35
|
+
OpenStates::Legislator.by_location(123.10, -85.20).each do |obj|
|
36
|
+
obj.should be_a OpenStates::Legislator
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
require 'openstates'
|
4
|
+
require 'pry'
|
5
|
+
require 'pry-remote'
|
6
|
+
require 'pry-debugger'
|
7
|
+
|
8
|
+
RSpec.configure do |config|
|
9
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
10
|
+
config.run_all_when_everything_filtered = true
|
11
|
+
config.filter_run :focus
|
12
|
+
config.order = 'random'
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,249 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: openstates
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Chris
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-12-01 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: faraday_middleware
|
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: hashie
|
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: bundler
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '1.3'
|
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: '1.3'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rake
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '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: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: rspec
|
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
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: guard
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: guard-rspec
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: pry
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
type: :development
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
- !ruby/object:Gem::Dependency
|
143
|
+
name: pry-remote
|
144
|
+
requirement: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ! '>='
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
150
|
+
type: :development
|
151
|
+
prerelease: false
|
152
|
+
version_requirements: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ! '>='
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
- !ruby/object:Gem::Dependency
|
159
|
+
name: pry-debugger
|
160
|
+
requirement: !ruby/object:Gem::Requirement
|
161
|
+
none: false
|
162
|
+
requirements:
|
163
|
+
- - ! '>='
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0'
|
166
|
+
type: :development
|
167
|
+
prerelease: false
|
168
|
+
version_requirements: !ruby/object:Gem::Requirement
|
169
|
+
none: false
|
170
|
+
requirements:
|
171
|
+
- - ! '>='
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
description: Ruby gem to interact with the OpenStates API.
|
175
|
+
email:
|
176
|
+
- chris@wideeyelabs.com
|
177
|
+
executables: []
|
178
|
+
extensions: []
|
179
|
+
extra_rdoc_files: []
|
180
|
+
files:
|
181
|
+
- .gitignore
|
182
|
+
- .rspec
|
183
|
+
- Gemfile
|
184
|
+
- Guardfile
|
185
|
+
- LICENSE.txt
|
186
|
+
- README.md
|
187
|
+
- Rakefile
|
188
|
+
- lib/openstates.rb
|
189
|
+
- lib/openstates/api.rb
|
190
|
+
- lib/openstates/configuration.rb
|
191
|
+
- lib/openstates/connection.rb
|
192
|
+
- lib/openstates/core.rb
|
193
|
+
- lib/openstates/mashify.rb
|
194
|
+
- lib/openstates/model.rb
|
195
|
+
- lib/openstates/models/bill.rb
|
196
|
+
- lib/openstates/models/committee.rb
|
197
|
+
- lib/openstates/models/district.rb
|
198
|
+
- lib/openstates/models/event.rb
|
199
|
+
- lib/openstates/models/legislator.rb
|
200
|
+
- lib/openstates/version.rb
|
201
|
+
- openstates.gemspec
|
202
|
+
- spec/openstates/api_spec.rb
|
203
|
+
- spec/openstates/models/bill_spec.rb
|
204
|
+
- spec/openstates/models/committee_spec.rb
|
205
|
+
- spec/openstates/models/district_spec.rb
|
206
|
+
- spec/openstates/models/event_spec.rb
|
207
|
+
- spec/openstates/models/legislator_spec.rb
|
208
|
+
- spec/openstates/version_spec.rb
|
209
|
+
- spec/spec_helper.rb
|
210
|
+
homepage: https://github.com/WideEyeLabs
|
211
|
+
licenses:
|
212
|
+
- MIT
|
213
|
+
post_install_message:
|
214
|
+
rdoc_options: []
|
215
|
+
require_paths:
|
216
|
+
- lib
|
217
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
218
|
+
none: false
|
219
|
+
requirements:
|
220
|
+
- - ! '>='
|
221
|
+
- !ruby/object:Gem::Version
|
222
|
+
version: '0'
|
223
|
+
segments:
|
224
|
+
- 0
|
225
|
+
hash: -4304350490256027937
|
226
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
227
|
+
none: false
|
228
|
+
requirements:
|
229
|
+
- - ! '>='
|
230
|
+
- !ruby/object:Gem::Version
|
231
|
+
version: '0'
|
232
|
+
segments:
|
233
|
+
- 0
|
234
|
+
hash: -4304350490256027937
|
235
|
+
requirements: []
|
236
|
+
rubyforge_project:
|
237
|
+
rubygems_version: 1.8.25
|
238
|
+
signing_key:
|
239
|
+
specification_version: 3
|
240
|
+
summary: Ruby gem to interact with the OpenStates API.
|
241
|
+
test_files:
|
242
|
+
- spec/openstates/api_spec.rb
|
243
|
+
- spec/openstates/models/bill_spec.rb
|
244
|
+
- spec/openstates/models/committee_spec.rb
|
245
|
+
- spec/openstates/models/district_spec.rb
|
246
|
+
- spec/openstates/models/event_spec.rb
|
247
|
+
- spec/openstates/models/legislator_spec.rb
|
248
|
+
- spec/openstates/version_spec.rb
|
249
|
+
- spec/spec_helper.rb
|