govtrack 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.
@@ -0,0 +1,3 @@
1
+ 0.0.1
2
+ -----
3
+ * Initial release
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Noah Litvin
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,77 @@
1
+ # GovTrack Gem
2
+ An unofficial Ruby wrapper for the [GovTrack API](http://www.govtrack.us/developers/api). You must agree to the surprisingly brief and readable [license terms](http://www.govtrack.us/developers/license) before using.
3
+
4
+ ## Installation
5
+
6
+ gem install govtrack
7
+
8
+ Then ```require 'govtrack'``` and you're good to go.
9
+
10
+ ## Usage
11
+
12
+ GovTrack data is supplied through various find methods:
13
+
14
+ ```ruby
15
+ sopa = GovTrack::Bill.find_by_id(71392) #Find SOPA with a GovTrack ID...
16
+ al = GovTrack::Person.find(firstname: 'Al', lastname: 'Franken') #...Al Franken with a hash of parameters...
17
+ john = GovTrack::Person.find_by_firstname_and_lastname('John','McCain') #...or John McCain with an ActiveRecord-style dynamic finder!
18
+
19
+ #Let's see if SOPA's sponsor is older than Al Franken.
20
+ sopa.sponsor.birthday < al.birthday
21
+ => true
22
+
23
+ #Is he older than John McCain?
24
+ sopa.sponsor.birthday < john.birthday
25
+ => false
26
+ ```
27
+
28
+ **Not all fields can be used in a query.** Some fields support [Django-style filters](https://docs.djangoproject.com/en/dev/ref/models/querysets/#field-lookups) and some can span relationships. Refer to the [GovTrack Data API Documentation](http://www.govtrack.us/developers/api) for details.
29
+
30
+ ### Pagination
31
+ By default, the API returns data in arrays of 20. You can adjust this amount and move through the results by setting ```:limit``` and ```:offset``` in your query. Alternatively, call ```.find``` with a block to iterate through all of the results.
32
+
33
+ ```ruby
34
+ #Returns the titles of every bill currently introduced to the 112th Congress.
35
+ GovTrack::Bill.find(current_status: 'introduced', congress: 112) { |bill| bill.title }
36
+ ```
37
+
38
+ ## Examples
39
+
40
+ **See how Ron Paul and Dennis Kucinich voted on 'H.R. 3590: Patient Protection and Affordable Care Act':**
41
+
42
+ ```ruby
43
+ obamacare = GovTrack::Bill.find_by_congress_and_bill_type_and_number(111,:house_bill,3590)
44
+ recent_obamacare_vote = GovTrack::Vote.find(related_bill: obamacare, order_by: "-created").first
45
+
46
+ ron = GovTrack::Person.find_by_nickname_and_lastname('Ron','Paul')
47
+ ron_vote = GovTrack::VoteVoter.find(vote: recent_obamacare_vote, person: ron)
48
+ "#{ron.name_no_details} voted '#{ron_vote.option.to_display_text}' on '#{obamacare.title}'."
49
+ => "Ronald Paul voted 'No' on 'H.R. 3590 (111th): Patient Protection and Afforble Care Act'."
50
+
51
+ dennis = GovTrack::Person.find_by_firstname_and_lastname('Dennis','Kucinich')
52
+ dennis_vote = GovTrack::VoteVoter.find(vote: recent_obamacare_vote, person: dennis)
53
+ "#{dennis.name_no_details} voted '#{dennis_vote.option.to_display_text}' on '#{obamacare.title}'."
54
+ => "Dennis Kucinich voted 'Aye' on 'H.R. 3590 (111th): Patient Protection and Affordble Care Act'."
55
+ ```
56
+
57
+ **List the female members of congress who abstained from voting on 'H.R. 3: No Taxpayer Funding for Abortion Act':**
58
+
59
+ ```ruby
60
+ hr3 = GovTrack::Bill.find_by_congress_and_bill_type_and_number(112,:house_bill,3)
61
+ recent_hr3_vote = GovTrack::Vote.find(related_bill: hr3, order_by: "-created").first
62
+ GovTrack::VoteVoter.find(vote: recent_hr3_vote) { |vote_voter|
63
+ vote_voter.person.name if vote_voter.option == '0' && vote_voter.person.gender == 'female'
64
+ }
65
+ => "Rep. Gabrielle Giffords [D-AZ8, 2007-2012]"
66
+ => "Rep. Jo Ann Emerson [R-MO8]"
67
+ ```
68
+
69
+ ## Tips
70
+
71
+ * If you're searching for a particular bill by its number, include a ```congress``` and ```bill_type``` in your query as well.
72
+ * There will often be more than one vote related to a bill.
73
+ * Depending on your application, consider using GovTrack's [Bulk Raw Data](http://www.govtrack.us/developers/data) instead.
74
+
75
+ ## Copyright
76
+
77
+ Copyright (c) 2012 Noah Litvin. See [LICENSE](https://github.com/noahlitvin/govtrack/blob/master/LICENSE.md) for details.
data/TODO.md ADDED
@@ -0,0 +1,2 @@
1
+ * Clean up and add more tests.
2
+ * Add documentation.
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/govtrack/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = "govtrack"
6
+ gem.version = GovTrack::Gem::VERSION
7
+ gem.authors = ["Noah Litvin"]
8
+ gem.email = ["noah.litvin@gmail.com"]
9
+ gem.homepage = "https://github.com/noahlitvin/govtrack"
10
+ gem.summary = %q{A Ruby wrapper for the GovTrack API.}
11
+ gem.description = %q{A Ruby wrapper for the GovTrack API.}
12
+
13
+ gem.files = %w(CHANGELOG.md LICENSE.md README.md TODO.md govtrack.gemspec)
14
+ gem.files += Dir.glob("lib/**/*.rb")
15
+ gem.files += Dir.glob("spec/**/*")
16
+
17
+ gem.test_files = Dir.glob("spec/**/*")
18
+
19
+ gem.add_dependency 'httparty', ">= 0.6.1"
20
+
21
+ gem.add_development_dependency 'rspec'
22
+ gem.add_development_dependency 'fakeweb', "~> 1.3"
23
+ end
@@ -0,0 +1,9 @@
1
+ require 'httparty'
2
+ require 'govtrack/base'
3
+ require 'govtrack/bill'
4
+ require 'govtrack/person'
5
+ require 'govtrack/role'
6
+ require 'govtrack/vote'
7
+ require 'govtrack/vote_voter'
8
+ require 'govtrack/paginated_list'
9
+ require 'govtrack/helper'
@@ -0,0 +1,73 @@
1
+ module GovTrack
2
+ class Base
3
+ include HTTParty
4
+
5
+ base_uri 'http://www.govtrack.us/api/v1'
6
+
7
+ def initialize(attributes=nil)
8
+ attributes ||= {}
9
+ attributes.each do |(attr, val)|
10
+ instance_variable_set("@#{attr}", val)
11
+ instance_eval "def #{attr}() @#{attr} end" unless self.respond_to?(attr)
12
+ end
13
+ end
14
+
15
+ def self.find(args)
16
+ args[:limit] ||= 500 if block_given? #default to queries of 500 when a block is given
17
+
18
+ response = get("/#{self.demodulized_name}/?#{URI.escape(URI.encode_www_form(args))}")
19
+ paginated_list = GovTrack::PaginatedList.new(self,response["meta"],response["objects"])
20
+
21
+ if block_given?
22
+ page = paginated_list.offset
23
+ for page in paginated_list.offset..(paginated_list.total/paginated_list.limit)
24
+ args[:offset] = page
25
+ if page == (paginated_list.total/paginated_list.limit).to_i #don't supply the end of the last page
26
+ self.find(args).first(paginated_list.total%paginated_list.limit).each { |item| yield item }
27
+ else
28
+ self.find(args).each { |item| yield item }
29
+ end
30
+ end
31
+ else
32
+ paginated_list
33
+ end
34
+ end
35
+
36
+ def self.find_by_id(id)
37
+ new(get("/#{self.demodulized_name}/#{id}"))
38
+ end
39
+
40
+ def self.find_by_uri(uri)
41
+ new(get("http://www.govtrack.us#{uri}"))
42
+ end
43
+
44
+ def ==(other)
45
+ other.equal?(self) || (other.instance_of?(self.class) && other.id == id)
46
+ end
47
+
48
+ def eql?(other)
49
+ self == other
50
+ end
51
+
52
+ def self.method_missing(method_id, *arguments)
53
+ #generates dynamic find_by methods, ActiveRecord style.
54
+ if method_id.to_s =~ /^find_by_([_a-zA-Z]\w*)$/
55
+ attribute_names = $1.split '_and_'
56
+ conditions = {}
57
+ attribute_names.each_with_index do |name,index|
58
+ conditions[name.to_sym] = arguments[index]
59
+ end
60
+ self.find(conditions)
61
+ else
62
+ super
63
+ end
64
+ end
65
+
66
+ protected
67
+
68
+ def self.demodulized_name
69
+ self.name.split('::').last.downcase == "votevoter" ? "vote_voter" : self.name.split('::').last.downcase
70
+ end
71
+
72
+ end
73
+ end
@@ -0,0 +1,31 @@
1
+ module GovTrack
2
+ class Bill < Base
3
+
4
+ def initialize(attributes={})
5
+ super
6
+ @introduced_date = Date.parse(@introduced_date) if @introduced_date
7
+ @current_status_date = Date.parse(@current_status_date) if @current_status_date
8
+ end
9
+
10
+ def self.find(args)
11
+ args[:bill_type] = args[:bill_type].to_bill_type_number if args[:bill_type]
12
+ args[:current_status] = args[:current_status].to_current_status_number if args[:current_status]
13
+ super
14
+ end
15
+
16
+ def sponsor
17
+ @sponsor.class == GovTrack::Person ? @sponsor : @sponsor = GovTrack::Person.find_by_id(@sponsor['id'])
18
+ end
19
+
20
+ def cosponsors
21
+ if @cosponsors[0].class == GovTrack::Person
22
+ @cosponsors
23
+ else
24
+ @cosponsors.map! { |cosponsor_uri|
25
+ GovTrack::Person.find_by_uri(cosponsor_uri)
26
+ }
27
+ end
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,60 @@
1
+ class Object
2
+ def to_bill_type_number
3
+ #Fix for API not accepting bill_type as a string
4
+ case self.to_s
5
+ when 'house_resolution'
6
+ 1
7
+ when 'senate_bill'
8
+ 2
9
+ when 'house_bill'
10
+ 3
11
+ when 'senate_resolution'
12
+ 4
13
+ when 'house_concurrent_resolution'
14
+ 5
15
+ when 'senate_concurrent_resolution'
16
+ 6
17
+ when 'house_joint_resolution'
18
+ 7
19
+ when 'senate_joint_resolution'
20
+ 8
21
+ else
22
+ self
23
+ end
24
+ end
25
+
26
+ def to_current_status_number
27
+ #Fix for API not accepting current_status as a string
28
+ case self.to_s
29
+ when 'introduced'
30
+ 1
31
+ when 'referred'
32
+ 2
33
+ when 'reported'
34
+ 3
35
+ when 'pass_over_house'
36
+ 4
37
+ when 'pass_over_senate'
38
+ 5
39
+ when 'passed_simpleres'
40
+ 6
41
+ else
42
+ self
43
+ end
44
+ end
45
+
46
+ def to_display_text
47
+ case self
48
+ when "+"
49
+ "Aye"
50
+ when "-"
51
+ "No"
52
+ when "0"
53
+ "Not Voting"
54
+ when "P"
55
+ "Present"
56
+ else
57
+ self
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,26 @@
1
+ module GovTrack
2
+ class PaginatedList < ::Array
3
+
4
+ attr_reader :limit, :offset, :total
5
+
6
+ def initialize(object_class,meta,objects)
7
+ if meta
8
+ @limit = meta['limit']
9
+ @offset = meta['offset']
10
+ @total = meta['total_count']
11
+ end
12
+
13
+ super((objects || []).map { |object| object_class.new(object) })
14
+ end
15
+
16
+ def method_missing(method_id, *arguments)
17
+ #passes methods through to item when list contains only one
18
+ if self.length == 1
19
+ self.first.send(method_id, *arguments)
20
+ else
21
+ super
22
+ end
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,24 @@
1
+ module GovTrack
2
+ class Person < Base
3
+
4
+ def initialize(attributes={})
5
+ super
6
+ @birthday = Date.parse(@birthday) if @birthday
7
+ end
8
+
9
+ def current_role
10
+ @current_role.class == GovTrack::Role ? @current_role : @current_role = GovTrack::Role.find_by_id(@current_role['id'])
11
+ end
12
+
13
+ def roles
14
+ if @roles[0].class == GovTrack::Role
15
+ @roles
16
+ else
17
+ @roles.map! { |role_uri|
18
+ GovTrack::Role.find_by_uri(role_uri)
19
+ }
20
+ end
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,11 @@
1
+ module GovTrack
2
+ class Role < Base
3
+
4
+ def initialize(attributes={})
5
+ super
6
+ @startdate = Date.parse(@startdate) if @startdate
7
+ @enddate = Date.parse(@enddate) if @enddate
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ module GovTrack
2
+ module Gem
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,26 @@
1
+ module GovTrack
2
+ class Vote < Base
3
+
4
+ def initialize(attributes={})
5
+ super
6
+ @created = DateTime.parse(@created) if @created
7
+ end
8
+
9
+ def self.find(args)
10
+ #API doesn't allow searching for bill by ID, so query with congress, bill_type, and number.
11
+ if args[:related_bill]
12
+ args[:related_bill__congress] = args[:related_bill].congress
13
+ args[:related_bill__bill_type] = args[:related_bill].bill_type.to_bill_type_number
14
+ args[:related_bill__number] = args[:related_bill].number
15
+ args.delete(:related_bill)
16
+ end
17
+
18
+ super
19
+ end
20
+
21
+ def related_bill
22
+ @related_bill.class == GovTrack::Bill ? @related_bill : @related_bill = GovTrack::Bill.find_by_id(@related_bill['id'])
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ module GovTrack
2
+ class VoteVoter < Base
3
+
4
+ def initialize(attributes={})
5
+ super
6
+ @created = DateTime.parse(@created) if @created
7
+ end
8
+
9
+ def self.find(args)
10
+ #allows searching with Person and Vote objects
11
+ args.each { |k,v|
12
+ args[k] = v.id if v.class == GovTrack::Person || v.class == GovTrack::Vote || v.class == GovTrack::PaginatedList
13
+ }
14
+ super
15
+ end
16
+
17
+ def person
18
+ @person.class == GovTrack::Person ? @person : @person = GovTrack::Person.find_by_uri(@person)
19
+ end
20
+
21
+ def vote
22
+ @vote.class == GovTrack::Vote ? @vote : @vote = GovTrack::Vote.find_by_uri(@vote)
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,63 @@
1
+ require 'helper'
2
+
3
+ describe GovTrack::Bill do
4
+
5
+ it "should find an array of bills based on parameters" do
6
+ bills = GovTrack::Bill.find(congress:112, is_current: "true")
7
+ bills.should be_an Array
8
+ bills[0].should be_a GovTrack::Bill
9
+ end
10
+
11
+ it "should iterate through an array of bills based on parameters when supplied with a block" do
12
+ count = 0
13
+ GovTrack::Bill.find(congress:95, bill_type: 'house_concurrent_resolution', limit: 70) { |bill| count += 1 }
14
+ count.should eq GovTrack::Bill.find(congress:95, bill_type: 'house_concurrent_resolution').total
15
+ end
16
+
17
+ it "should find an array of bills based on parameters with a dynamic finder" do
18
+ bills = GovTrack::Bill.find_by_congress_and_is_current(112, "true")
19
+ bills.should be_an Array
20
+ bills[0].should be_a GovTrack::Bill
21
+ end
22
+
23
+ it "should find a bill by id" do
24
+ bill = GovTrack::Bill.find_by_id(74369)
25
+ bill.id.should eq "74369"
26
+ end
27
+
28
+ it "should retreive sponsor as a Person and cache it" do
29
+ bill = GovTrack::Bill.find_by_id(74369)
30
+ bill.sponsor.should be_a GovTrack::Person
31
+
32
+ FakeWeb.allow_net_connect = false
33
+ bill.sponsor.should be_a GovTrack::Person
34
+ FakeWeb.allow_net_connect = true
35
+ end
36
+
37
+ it "should retreive cosponsors as a Person array and cache it" do
38
+ bill = GovTrack::Bill.find_by_id(2343)
39
+ bill.cosponsors.should be_an Array
40
+ bill.cosponsors[0].should be_a GovTrack::Person
41
+
42
+ FakeWeb.allow_net_connect = false
43
+ bill.cosponsors.should be_an Array
44
+ bill.cosponsors[0].should be_a GovTrack::Person
45
+ FakeWeb.allow_net_connect = true
46
+ end
47
+
48
+ it "should return an empty array if there are no cosponsors" do
49
+ bill = GovTrack::Bill.find_by_id(74369)
50
+ bill.cosponsors.should be_empty
51
+ end
52
+
53
+ it "should retreive introduced_date as a Date object" do
54
+ bill = GovTrack::Bill.find_by_id(2343)
55
+ bill.introduced_date.should be_a Date
56
+ end
57
+
58
+ it "should retreive current_status_date as a Date object" do
59
+ bill = GovTrack::Bill.find_by_id(2343)
60
+ bill.current_status_date.should be_a Date
61
+ end
62
+
63
+ end
@@ -0,0 +1,5 @@
1
+ require 'helper'
2
+
3
+ describe GovTrack::PaginatedList do
4
+
5
+ end
@@ -0,0 +1,54 @@
1
+ require 'helper'
2
+
3
+ describe GovTrack::Person do
4
+
5
+ it "should find an array of people based on parameters" do
6
+ people = GovTrack::Person.find(roles__party:"Republican", roles__current: "true")
7
+ people.should be_an Array
8
+ people[0].should be_a GovTrack::Person
9
+ end
10
+
11
+ it "should find an array of people based on parameters with a dynamic finder" do
12
+ people = GovTrack::Person.find_by_roles__party_and_roles__current("Republican", "true")
13
+ people.should be_an Array
14
+ people[0].should be_a GovTrack::Person
15
+ end
16
+
17
+ it "should find a person by id" do
18
+ person = GovTrack::Person.find_by_id(400326)
19
+ person.id.should eq "400326"
20
+ person.firstname.should eq "David"
21
+ person.lastname.should eq "Price"
22
+ end
23
+
24
+ it "should find a person by uri" do
25
+ person = GovTrack::Person.find_by_uri('/api/v1/person/300038/')
26
+ person.id.should eq "300038"
27
+ end
28
+
29
+ it "should retreive current_role as a Role and cache it" do
30
+ person = GovTrack::Person.find_by_id(400326)
31
+ person.current_role.should be_a GovTrack::Role
32
+
33
+ FakeWeb.allow_net_connect = false
34
+ person.current_role.should be_a GovTrack::Role
35
+ FakeWeb.allow_net_connect = true
36
+ end
37
+
38
+ it "should retreive roles as a Role array and cache it" do
39
+ person = GovTrack::Person.find_by_id(400326)
40
+ person.roles.should be_an Array
41
+ person.roles[0].should be_a GovTrack::Role
42
+
43
+ FakeWeb.allow_net_connect = false
44
+ person.roles.should be_an Array
45
+ person.roles[0].should be_a GovTrack::Role
46
+ FakeWeb.allow_net_connect = true
47
+ end
48
+
49
+ it "should retreive birthday as a Date object" do
50
+ person = GovTrack::Person.find_by_id(400326)
51
+ person.birthday.should be_a Date
52
+ end
53
+
54
+ end
@@ -0,0 +1,32 @@
1
+ require 'helper'
2
+
3
+ describe GovTrack::Role do
4
+
5
+ it "should find an array of roles based on parameters" do
6
+ roles = GovTrack::Role.find(state:"MD", current: true)
7
+ roles.should be_an Array
8
+ roles[0].should be_a GovTrack::Role
9
+ end
10
+
11
+ it "should find an array of roles based on parameters with a dynamic finder" do
12
+ roles = GovTrack::Role.find_by_state_and_current("MD", true)
13
+ roles.should be_an Array
14
+ roles[0].should be_a GovTrack::Role
15
+ end
16
+
17
+ it "should find a role by id" do
18
+ role = GovTrack::Role.find_by_id(387)
19
+ role.id.should eq "387"
20
+ end
21
+
22
+ it "should retreive startdate as a Date object" do
23
+ role = GovTrack::Role.find_by_id(387)
24
+ role.startdate.should be_a Date
25
+ end
26
+
27
+ it "should retreive enddate as a Date object" do
28
+ role = GovTrack::Role.find_by_id(387)
29
+ role.enddate.should be_a Date
30
+ end
31
+
32
+ end
@@ -0,0 +1,36 @@
1
+ require 'helper'
2
+
3
+ describe GovTrack::Vote do
4
+
5
+ it "should find an array of votes based on parameters" do
6
+ votes = GovTrack::Vote.find(is_alive:true, session: 1)
7
+ votes.should be_an Array
8
+ votes[0].should be_a GovTrack::Vote
9
+ end
10
+
11
+ it "should find an array of votes based on parameters with a dynamic finder" do
12
+ votes = GovTrack::Vote.find_by_is_alive_and_session(true, 1)
13
+ votes.should be_an Array
14
+ votes[0].should be_a GovTrack::Vote
15
+ end
16
+
17
+ it "should find a vote" do
18
+ vote = GovTrack::Vote.find_by_id(1)
19
+ vote.id.should eq "1"
20
+ end
21
+
22
+ it "should retreive related_bill as a Bill and cache it" do
23
+ vote = GovTrack::Vote.find_by_id(34577)
24
+ vote.related_bill.should be_a GovTrack::Bill
25
+
26
+ FakeWeb.allow_net_connect = false
27
+ vote.related_bill.should be_a GovTrack::Bill
28
+ FakeWeb.allow_net_connect = true
29
+ end
30
+
31
+ it "should retreive created as a DateTime object" do
32
+ vote = GovTrack::Vote.find_by_id(34577)
33
+ vote.created.should be_a DateTime
34
+ end
35
+
36
+ end
@@ -0,0 +1,53 @@
1
+ require 'helper'
2
+
3
+ describe GovTrack::VoteVoter do
4
+
5
+ it "should find an array of VoteVoters based on parameters" do
6
+ vote_voters = GovTrack::VoteVoter.find(vote:1, person: 400639)
7
+ vote_voters.should be_an Array
8
+ vote_voters[0].should be_a GovTrack::VoteVoter
9
+ end
10
+
11
+ it "should find an array of VoteVoters based on parameters with a dynamic finder" do
12
+ vote_voters = GovTrack::VoteVoter.find_by_vote_and_person(1, 400639)
13
+ vote_voters.should be_an Array
14
+ vote_voters[0].should be_a GovTrack::VoteVoter
15
+ end
16
+
17
+ it "should find a vote voter with votes and people objects" do
18
+ manny = GovTrack::Person.find_by_firstname_and_lastname("Emanuel","Cleaver").first
19
+ vote = GovTrack::Vote.find_by_number_and_congress(183,112).first
20
+ vote_voters = GovTrack::VoteVoter.find_by_person_and_vote(manny, vote)
21
+ vote_voters.should be_an Array
22
+ vote_voters[0].should be_a GovTrack::VoteVoter
23
+ end
24
+
25
+ it "should find a vote voter" do
26
+ vote_voter = GovTrack::VoteVoter.find_by_id(8248471)
27
+ vote_voter.id.should eq "8248471"
28
+ end
29
+
30
+ it "should retreive person as a Person and cache it" do
31
+ vote_voter = GovTrack::VoteVoter.find_by_id(8248471)
32
+ vote_voter.person.should be_a GovTrack::Person
33
+
34
+ FakeWeb.allow_net_connect = false
35
+ vote_voter.person.should be_a GovTrack::Person
36
+ FakeWeb.allow_net_connect = true
37
+ end
38
+
39
+ it "should retreive vote as a Vote and cache it" do
40
+ vote_voter = GovTrack::VoteVoter.find_by_id(8248471)
41
+ vote_voter.vote.should be_a GovTrack::Vote
42
+
43
+ FakeWeb.allow_net_connect = false
44
+ vote_voter.vote.should be_a GovTrack::Vote
45
+ FakeWeb.allow_net_connect = true
46
+ end
47
+
48
+ it "should retreive created as a DateTime object" do
49
+ vote_voter = GovTrack::VoteVoter.find_by_id(8248471)
50
+ vote_voter.created.should be_a DateTime
51
+ end
52
+
53
+ end
@@ -0,0 +1,3 @@
1
+ require 'govtrack'
2
+ require 'rspec'
3
+ require 'fakeweb'
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: govtrack
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Noah Litvin
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.6.1
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.6.1
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
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: fakeweb
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
+ description: A Ruby wrapper for the GovTrack API.
63
+ email:
64
+ - noah.litvin@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - CHANGELOG.md
70
+ - LICENSE.md
71
+ - README.md
72
+ - TODO.md
73
+ - govtrack.gemspec
74
+ - lib/govtrack/base.rb
75
+ - lib/govtrack/bill.rb
76
+ - lib/govtrack/helper.rb
77
+ - lib/govtrack/paginated_list.rb
78
+ - lib/govtrack/person.rb
79
+ - lib/govtrack/role.rb
80
+ - lib/govtrack/version.rb
81
+ - lib/govtrack/vote.rb
82
+ - lib/govtrack/vote_voter.rb
83
+ - lib/govtrack.rb
84
+ - spec/govtrack/bill_spec.rb
85
+ - spec/govtrack/paginated_list_spec.rb
86
+ - spec/govtrack/person_spec.rb
87
+ - spec/govtrack/role_spec.rb
88
+ - spec/govtrack/vote_spec.rb
89
+ - spec/govtrack/vote_voter_spec.rb
90
+ - spec/helper.rb
91
+ homepage: https://github.com/noahlitvin/govtrack
92
+ licenses: []
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ! '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 1.8.24
112
+ signing_key:
113
+ specification_version: 3
114
+ summary: A Ruby wrapper for the GovTrack API.
115
+ test_files:
116
+ - spec/govtrack/bill_spec.rb
117
+ - spec/govtrack/paginated_list_spec.rb
118
+ - spec/govtrack/person_spec.rb
119
+ - spec/govtrack/role_spec.rb
120
+ - spec/govtrack/vote_spec.rb
121
+ - spec/govtrack/vote_voter_spec.rb
122
+ - spec/helper.rb