From a1bd55362d0870ae5a003583b6b57ab9ce5b47a7 Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Sat, 21 Nov 2009 12:41:55 -0500 Subject: [PATCH 01/55] Rename the project to just votesmart, and add my details to the jeweler spec --- Rakefile | 38 +++++++++++++++++------- lib/{ruby-votesmart.rb => vote_smart.rb} | 0 lib/votesmart.rb | 1 + spec/spec_helper.rb | 2 +- 4 files changed, 30 insertions(+), 11 deletions(-) rename lib/{ruby-votesmart.rb => vote_smart.rb} (100%) create mode 100644 lib/votesmart.rb diff --git a/Rakefile b/Rakefile index 58f8b0b..737b8bf 100644 --- a/Rakefile +++ b/Rakefile @@ -1,26 +1,44 @@ %w[rubygems rake rake/clean fileutils].each { |f| require f } -require 'spec' -require 'spec/rake/spectask' -require File.dirname(__FILE__) + '/lib/ruby-votesmart' begin require 'jeweler' Jeweler::Tasks.new do |s| - s.name = "ruby-votesmart" + s.name = "votesmart" s.summary = "A wrapper for the Project Vote Smart API" - s.email = "dancunning@gmail.com" - s.homepage = "http://github.com/netroots/ruby-votesmart" + s.email = "ben.woosley@gmail.com" + s.homepage = "http://github.com/Empact/votesmart" s.description = "A wrapper for the Project Vote Smart API" - s.authors = ["Dan Cunning"] + s.authors = ["Dan Cunning", "Ben Woosley"] end + Jeweler::GemcutterTasks.new rescue LoadError puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com" end Dir['tasks/**/*.rake'].each { |t| load t } -Spec::Rake::SpecTask.new +require 'spec/rake/spectask' +Spec::Rake::SpecTask.new(:spec) do |spec| + spec.libs << 'lib' << 'spec' + spec.spec_files = FileList['spec/**/*_spec.rb'] +end + +Spec::Rake::SpecTask.new(:rcov) do |spec| + spec.libs << 'lib' << 'spec' + spec.pattern = 'spec/**/*_spec.rb' + spec.rcov = true +end + +task :spec => :check_dependencies -#Cucumber::Rake::Task.new +task :default => :spec -#task :default => [:features] \ No newline at end of file +require 'rake/rdoctask' +Rake::RDocTask.new do |rdoc| + version = File.exist?('VERSION') ? File.read('VERSION') : "" + + rdoc.rdoc_dir = 'rdoc' + rdoc.title = "votesmart #{version}" + rdoc.rdoc_files.include('README*') + rdoc.rdoc_files.include('lib/**/*.rb') +end diff --git a/lib/ruby-votesmart.rb b/lib/vote_smart.rb similarity index 100% rename from lib/ruby-votesmart.rb rename to lib/vote_smart.rb diff --git a/lib/votesmart.rb b/lib/votesmart.rb new file mode 100644 index 0000000..2b897f3 --- /dev/null +++ b/lib/votesmart.rb @@ -0,0 +1 @@ +require 'vote_smart' \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4c3fa16..839cab3 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,7 +1,7 @@ require 'rubygems' require 'stringio' require 'spec' -require "#{File.dirname(__FILE__)}/../lib/ruby-votesmart.rb" +require "votesmart" class Spec::Example::ExampleGroup From 5ec8e4d1e311f6ba757542d8cdac88d61cfb68e0 Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Sat, 21 Nov 2009 13:05:44 -0500 Subject: [PATCH 02/55] Update json spec cache --- spec/responses/Official.get_by_office_state.12.CO.js | 2 +- tasks/spec_json.rake | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/responses/Official.get_by_office_state.12.CO.js b/spec/responses/Official.get_by_office_state.12.CO.js index 055fe27..06e729e 100644 --- a/spec/responses/Official.get_by_office_state.12.CO.js +++ b/spec/responses/Official.get_by_office_state.12.CO.js @@ -1 +1 @@ -{"candidateList":{"generalInfo":{"title":"Project Vote Smart - Search Candidates","linkBack":"http:\/\/votesmart.org\/"},"candidate":{"electionDistrictName":"","lastName":"Suthers","candidateId":"29799","title":"Attorney General","officeDistrictName":"","nickName":"","electionYear":"","electionStatus":"","electionParties":"","middleName":"W.","firstName":"John","electionDistrictId":"","officeParties":"Republican","electionStateId":"","officeStateId":"CO","officeDistrictId":"","suffix":""}}} \ No newline at end of file +{"candidateList":{"generalInfo":{"title":"Project Vote Smart - Search Candidates","linkBack":"http://votesmart.org/"},"candidate":{"electionOfficeTypeId":"","electionOffice":"","lastName":"Suthers","candidateId":"29799","electionParties":"","title":"Attorney General","officeDistrictName":"","nickName":"","electionYear":"","electionStatus":"","middleName":"W.","officeId":"12","electionDistrictId":"","officeDistrictId":"","electionOfficeId":"","firstName":"John","officeTypeId":"S","suffix":"","officeName":"Attorney General","officeStateId":"CO","electionDistrictName":"","officeParties":"Republican","electionStateId":""}}} \ No newline at end of file diff --git a/tasks/spec_json.rake b/tasks/spec_json.rake index a342263..c44c276 100644 --- a/tasks/spec_json.rake +++ b/tasks/spec_json.rake @@ -17,6 +17,7 @@ namespace :spec do end task :json do + require "#{File.dirname(__FILE__)}/../lib/vote_smart" # response = VoteSmart::State.get_state("GA") # save_json_response "authorization_failed", response From 0d8d71de526fe96a68619bdf96efb46528b196d8 Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Sat, 21 Nov 2009 13:05:51 -0500 Subject: [PATCH 03/55] Specs pass --- spec/vote_smart/official_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/vote_smart/official_spec.rb b/spec/vote_smart/official_spec.rb index b400365..18b89cb 100644 --- a/spec/vote_smart/official_spec.rb +++ b/spec/vote_smart/official_spec.rb @@ -52,7 +52,7 @@ def do_find end def do_find - Official.find_all_by_address "123 fake st", "atlanta", "ga", "30303" + Official.find_all_by_address "123 fake st", "atlanta", "GA", "30303" end it_should_find :count => 5, :first => {:last_name => "Handel", :title => "Secretary"}, From 8c6a66a3ba8494f0ad1e119558f0fdba646d2976 Mon Sep 17 00:00:00 2001 From: Jeff Latz Date: Thu, 30 Jul 2009 16:50:07 -0400 Subject: [PATCH 04/55] access officeParties for Official objects. electionParties seems to be blank from the API now --- lib/vote_smart/official.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vote_smart/official.rb b/lib/vote_smart/official.rb index 3081f56..65a52ce 100644 --- a/lib/vote_smart/official.rb +++ b/lib/vote_smart/official.rb @@ -10,7 +10,7 @@ class Official < Common set_attribute_map "candidateId" => :id, "firstName" => :first_name, "nickName" => :nick_name, "middleName" => :middle_name, "lastName" => :last_name, "suffix" => :suffix, "title" => :title, "electionParties" => :election_parties, "officeDistrictId" => :district_id, - "officeDistrictName" => :district_name, "officeStateId" => :state_id + "officeDistrictName" => :district_name, "officeParties" => :officeParties, "officeStateId" => :state_id def offices Official.response_child_array(Address.get_office(self.id), "address", "office").collect {|office| CandidateOffice.new(office) } From d3f9ce389e659b09db5f2f0c4b8c760ab028ff5f Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Sun, 21 Mar 2010 14:12:48 -0400 Subject: [PATCH 05/55] Fix & spec Official#party brought in via db7bd12dd7d; it's not blank in the spec data --- lib/vote_smart/official.rb | 4 ++-- spec/vote_smart/official_spec.rb | 12 ++---------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/lib/vote_smart/official.rb b/lib/vote_smart/official.rb index 65a52ce..75e4cff 100644 --- a/lib/vote_smart/official.rb +++ b/lib/vote_smart/official.rb @@ -5,12 +5,12 @@ class Official < Common attr_accessor :id, :first_name, :nick_name, :middle_name, :last_name, :suffix, :title, :election_parties, :office_parties, :district_id, :district_name, :state_id - attr_accessor :district, :office, :office_id + attr_accessor :district, :office, :office_id, :party set_attribute_map "candidateId" => :id, "firstName" => :first_name, "nickName" => :nick_name, "middleName" => :middle_name, "lastName" => :last_name, "suffix" => :suffix, "title" => :title, "electionParties" => :election_parties, "officeDistrictId" => :district_id, - "officeDistrictName" => :district_name, "officeParties" => :officeParties, "officeStateId" => :state_id + "officeDistrictName" => :district_name, "officeParties" => :party, "officeStateId" => :state_id def offices Official.response_child_array(Address.get_office(self.id), "address", "office").collect {|office| CandidateOffice.new(office) } diff --git a/spec/vote_smart/official_spec.rb b/spec/vote_smart/official_spec.rb index 18b89cb..6332a95 100644 --- a/spec/vote_smart/official_spec.rb +++ b/spec/vote_smart/official_spec.rb @@ -4,16 +4,14 @@ module VoteSmart describe Official do describe "find_by_district_id" do - def do_find Official.find_by_district_id("20451") end - it_should_find :item => {:last_name => "Isakson", :id => "1721", :district_id => "20451"} + it_should_find :item => {:last_name => "Isakson", :id => "1721", :district_id => "20451", :party => 'Republican'} end describe "multiple offices" do - def do_find @official = Official.find_by_district_id("20451") @official.offices @@ -24,7 +22,6 @@ def do_find end describe "one office" do - def do_find @official = Official.find_by_district_id("21397") @official.offices @@ -34,17 +31,14 @@ def do_find end describe "find_by_office_id_and_state_id" do - def do_find Official.find_by_office_id_and_state_id("12", "CO") end it_should_find :item => {:last_name => "Suthers", :id => "29799", :office_id => "12", :state_id => "CO"} - end describe "find by address" do - before :each do mcll4r = {"response" => {"state_lower" => {"district" => "1"}, "state_upper" => {"district" => "2"}}} Geocoding.should_receive(:get).once.and_return([mock("placemark", :latitude => 2, :longitude => 10)]) @@ -57,8 +51,6 @@ def do_find it_should_find :count => 5, :first => {:last_name => "Handel", :title => "Secretary"}, :last => {:last_name => "Jackson", :title => "Senator"} - end end - -end \ No newline at end of file +end From bf8dfcff227901bcfb2a1a756aff07cf3ae6771b Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Sun, 21 Mar 2010 20:51:17 -0400 Subject: [PATCH 06/55] Fix Rating.get_sig_list categoryId parameter --- lib/vote_smart/rating.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vote_smart/rating.rb b/lib/vote_smart/rating.rb index 4763093..589d3d0 100644 --- a/lib/vote_smart/rating.rb +++ b/lib/vote_smart/rating.rb @@ -9,7 +9,7 @@ def self.get_categories state_id = nil # Returns a list of SIGs with ratings in category and state def self.get_sig_list category_id, state_id = 'NA' - request("Rating.getSigList", "category_id" => category_id, "stateId" => state_id) + request("Rating.getSigList", "categoryId" => category_id, "stateId" => state_id) end # Returns detailed SIG information From bcf4dbb3b83bb96526474d9627f5138a0d4bb66f Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Sun, 21 Mar 2010 20:52:25 -0400 Subject: [PATCH 07/55] Switch gemspect to just votesmart --- ruby-votesmart.gemspec | 29 ----------- votesmart.gemspec | 109 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+), 29 deletions(-) delete mode 100644 ruby-votesmart.gemspec create mode 100644 votesmart.gemspec diff --git a/ruby-votesmart.gemspec b/ruby-votesmart.gemspec deleted file mode 100644 index 8968fde..0000000 --- a/ruby-votesmart.gemspec +++ /dev/null @@ -1,29 +0,0 @@ -# -*- encoding: utf-8 -*- - -Gem::Specification.new do |s| - s.name = %q{ruby-votesmart} - s.version = "0.2.4" - - s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= - s.authors = ["Dan Cunning"] - s.date = %q{2009-02-17} - s.description = %q{A wrapper for the Project Vote Smart API} - s.email = %q{dancunning@gmail.com} - s.files = ["History.txt", "README.rdoc", "VERSION.yml", "lib/mcll4r", "lib/mcll4r/mcll4r.rb", "lib/mcll4r/mcll4r_test.rb", "lib/mcll4r/MIT-LICENSE", "lib/mcll4r/README", "lib/ruby-votesmart.rb", "lib/vote_smart", "lib/vote_smart/address.rb", "lib/vote_smart/candidate.rb", "lib/vote_smart/candidate_bio.rb", "lib/vote_smart/candidate_office.rb", "lib/vote_smart/committee.rb", "lib/vote_smart/common.rb", "lib/vote_smart/district.rb", "lib/vote_smart/election.rb", "lib/vote_smart/leadership.rb", "lib/vote_smart/local.rb", "lib/vote_smart/measure.rb", "lib/vote_smart/notes.rb", "lib/vote_smart/npat.rb", "lib/vote_smart/office.rb", "lib/vote_smart/official.rb", "lib/vote_smart/phone.rb", "lib/vote_smart/rating.rb", "lib/vote_smart/state.rb", "lib/vote_smart/vote.rb", "spec/responses", "spec/responses/Address.get_office.106446.js", "spec/responses/Address.get_office.1721.js", "spec/responses/authorization_failed.js", "spec/responses/District.get_by_office_state.7.GA.js", "spec/responses/District.get_by_office_state.8.GA.js", "spec/responses/District.get_by_office_state.9.GA.js", "spec/responses/Office.get_offices_by_type.C.js", "spec/responses/Office.get_offices_by_type.L.js", "spec/responses/Office.get_offices_by_type.P.js", "spec/responses/Office.get_offices_by_type.S.js", "spec/responses/Office.get_types.js", "spec/responses/Official.get_by_district.20451.js", "spec/responses/Official.get_by_district.20689.js", "spec/responses/Official.get_by_district.21397.js", "spec/responses/Official.get_by_district.21946.js", "spec/responses/Official.get_by_office_state.12.CO.js", "spec/responses/Official.get_by_office_state.12.GA.js", "spec/responses/Official.get_by_office_state.13.GA.js", "spec/responses/Official.get_by_office_state.33.GA.js", "spec/responses/Official.get_by_office_state.42.GA.js", "spec/responses/Official.get_by_office_state.44.GA.js", "spec/responses/Official.get_by_office_state.45.GA.js", "spec/responses/Official.get_by_office_state.53.GA.js", "spec/responses/State.get_state.GA.js", "spec/responses/State.get_state_ids.js", "spec/spec_helper.rb", "spec/vote_smart", "spec/vote_smart/district_spec.rb", "spec/vote_smart/office_spec.rb", "spec/vote_smart/official_spec.rb", "spec/vote_smart/state_spec.rb"] - s.has_rdoc = true - s.homepage = %q{http://github.com/netroots/ruby-votesmart} - s.rdoc_options = ["--inline-source", "--charset=UTF-8"] - s.require_paths = ["lib"] - s.rubygems_version = %q{1.3.1} - s.summary = %q{A wrapper for the Project Vote Smart API} - - if s.respond_to? :specification_version then - current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION - s.specification_version = 2 - - if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then - else - end - else - end -end diff --git a/votesmart.gemspec b/votesmart.gemspec new file mode 100644 index 0000000..864de91 --- /dev/null +++ b/votesmart.gemspec @@ -0,0 +1,109 @@ +# Generated by jeweler +# DO NOT EDIT THIS FILE DIRECTLY +# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command +# -*- encoding: utf-8 -*- + +Gem::Specification.new do |s| + s.name = %q{votesmart} + s.version = "0.2.4" + + s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= + s.authors = ["Dan Cunning", "Ben Woosley"] + s.date = %q{2010-03-21} + s.description = %q{A wrapper for the Project Vote Smart API} + s.email = %q{ben.woosley@gmail.com} + s.extra_rdoc_files = [ + "README.rdoc" + ] + s.files = [ + "History.txt", + "README.rdoc", + "Rakefile", + "VERSION.yml", + "lib/mcll4r/MIT-LICENSE", + "lib/mcll4r/README", + "lib/mcll4r/mcll4r.rb", + "lib/mcll4r/mcll4r_test.rb", + "lib/vote_smart.rb", + "lib/vote_smart/address.rb", + "lib/vote_smart/candidate.rb", + "lib/vote_smart/candidate_bio.rb", + "lib/vote_smart/candidate_office.rb", + "lib/vote_smart/committee.rb", + "lib/vote_smart/common.rb", + "lib/vote_smart/district.rb", + "lib/vote_smart/election.rb", + "lib/vote_smart/leadership.rb", + "lib/vote_smart/local.rb", + "lib/vote_smart/measure.rb", + "lib/vote_smart/notes.rb", + "lib/vote_smart/npat.rb", + "lib/vote_smart/office.rb", + "lib/vote_smart/official.rb", + "lib/vote_smart/phone.rb", + "lib/vote_smart/rating.rb", + "lib/vote_smart/state.rb", + "lib/vote_smart/vote.rb", + "lib/votesmart.rb", + "ruby-votesmart.gemspec", + "script/autospec", + "script/console", + "script/destroy", + "script/generate", + "script/is_gem_built", + "spec/responses/Address.get_office.106446.js", + "spec/responses/Address.get_office.1721.js", + "spec/responses/District.get_by_office_state.7.GA.js", + "spec/responses/District.get_by_office_state.8.GA.js", + "spec/responses/District.get_by_office_state.9.GA.js", + "spec/responses/Office.get_offices_by_type.C.js", + "spec/responses/Office.get_offices_by_type.L.js", + "spec/responses/Office.get_offices_by_type.P.js", + "spec/responses/Office.get_offices_by_type.S.js", + "spec/responses/Office.get_types.js", + "spec/responses/Official.get_by_district.20451.js", + "spec/responses/Official.get_by_district.20689.js", + "spec/responses/Official.get_by_district.21397.js", + "spec/responses/Official.get_by_district.21946.js", + "spec/responses/Official.get_by_office_state.12.CO.js", + "spec/responses/Official.get_by_office_state.12.GA.js", + "spec/responses/Official.get_by_office_state.13.GA.js", + "spec/responses/Official.get_by_office_state.33.GA.js", + "spec/responses/Official.get_by_office_state.42.GA.js", + "spec/responses/Official.get_by_office_state.44.GA.js", + "spec/responses/Official.get_by_office_state.45.GA.js", + "spec/responses/Official.get_by_office_state.53.GA.js", + "spec/responses/State.get_state.GA.js", + "spec/responses/State.get_state_ids.js", + "spec/responses/authorization_failed.js", + "spec/spec_helper.rb", + "spec/vote_smart/district_spec.rb", + "spec/vote_smart/office_spec.rb", + "spec/vote_smart/official_spec.rb", + "spec/vote_smart/state_spec.rb", + "tasks/spec_json.rake" + ] + s.homepage = %q{http://github.com/Empact/votesmart} + s.rdoc_options = ["--charset=UTF-8"] + s.require_paths = ["lib"] + s.rubygems_version = %q{1.3.6} + s.summary = %q{A wrapper for the Project Vote Smart API} + s.test_files = [ + "spec/spec_helper.rb", + "spec/vote_smart/district_spec.rb", + "spec/vote_smart/office_spec.rb", + "spec/vote_smart/official_spec.rb", + "spec/vote_smart/state_spec.rb" + ] + + if s.respond_to? :specification_version then + current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION + s.specification_version = 3 + + if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then + else + end + else + end +end + From fd5b06d9558e39ec3d47cb40576c26fe59e84d8f Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Sun, 21 Mar 2010 20:52:46 -0400 Subject: [PATCH 08/55] Ignore built gems --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..01d0a08 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +pkg/ From ae603eef33005a25063ad501f570edfc54bc35f8 Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Sun, 21 Mar 2010 21:06:53 -0400 Subject: [PATCH 09/55] Terse it up --- lib/vote_smart/common.rb | 32 +++++++++----------------------- lib/vote_smart/official.rb | 5 ++++- votesmart.gemspec | 7 ++++--- 3 files changed, 17 insertions(+), 27 deletions(-) diff --git a/lib/vote_smart/common.rb b/lib/vote_smart/common.rb index c172c39..f8e48f2 100644 --- a/lib/vote_smart/common.rb +++ b/lib/vote_smart/common.rb @@ -40,12 +40,7 @@ def self.response_child response, *children response || {} end - - def self.response_child_array response, *children - child = response_child response, *children - child.kind_of?(Array) ? child : [child] - end - + def self.request(api_method, params = {}) url = construct_url api_method, params @@ -65,31 +60,22 @@ def self.construct_url(api_method, params = {}) # Converts a hash to a GET string def self.hash2get(h) - - get_string = "" - - h.each_pair do |key, value| - get_string += "&#{key.to_s}=#{CGI::escape(value.to_s)}" unless value.nil? - end - - get_string - - end # def hash2get - - + h.map do |(key, value)| + "&#{key.to_s}=#{CGI::escape(value.to_s)}" if value + end.compact.join + end + # Use the Net::HTTP and JSON libraries to make the API call # # Usage: # District.get_json_data("http://someurl.com") # returns Hash of data or nil def self.get_json_data(url) response = Net::HTTP.get_response(URI.parse(url)) - if response.class == Net::HTTPOK - result = JSON.parse(response.body) - else + if response.class != Net::HTTPOK raise RequestFailed.new("Request was not OK: #{response.class}: #{url} #{response.body}") end - - end # self.get_json_data + JSON.parse(response.body) + end end diff --git a/lib/vote_smart/official.rb b/lib/vote_smart/official.rb index 75e4cff..41fc1f4 100644 --- a/lib/vote_smart/official.rb +++ b/lib/vote_smart/official.rb @@ -13,7 +13,10 @@ class Official < Common "officeDistrictName" => :district_name, "officeParties" => :party, "officeStateId" => :state_id def offices - Official.response_child_array(Address.get_office(self.id), "address", "office").collect {|office| CandidateOffice.new(office) } + offices = Official.response_child(Address.get_office(self.id), "address", "office") + (offices.is_a?(Array) ? offices : [offices]).collect {|office| + CandidateOffice.new(office) + } end def inspect diff --git a/votesmart.gemspec b/votesmart.gemspec index 864de91..d5c91d5 100644 --- a/votesmart.gemspec +++ b/votesmart.gemspec @@ -16,7 +16,8 @@ Gem::Specification.new do |s| "README.rdoc" ] s.files = [ - "History.txt", + ".gitignore", + "History.txt", "README.rdoc", "Rakefile", "VERSION.yml", @@ -45,7 +46,6 @@ Gem::Specification.new do |s| "lib/vote_smart/state.rb", "lib/vote_smart/vote.rb", "lib/votesmart.rb", - "ruby-votesmart.gemspec", "script/autospec", "script/console", "script/destroy", @@ -81,7 +81,8 @@ Gem::Specification.new do |s| "spec/vote_smart/office_spec.rb", "spec/vote_smart/official_spec.rb", "spec/vote_smart/state_spec.rb", - "tasks/spec_json.rake" + "tasks/spec_json.rake", + "votesmart.gemspec" ] s.homepage = %q{http://github.com/Empact/votesmart} s.rdoc_options = ["--charset=UTF-8"] From f529ae613ff7d49a34ec45cc35cb26280aadc067 Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Mon, 22 Mar 2010 02:30:37 -0400 Subject: [PATCH 10/55] Use patron for http --- Rakefile | 1 + lib/vote_smart/common.rb | 10 +++++++--- votesmart.gemspec | 5 ++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Rakefile b/Rakefile index 737b8bf..f087588 100644 --- a/Rakefile +++ b/Rakefile @@ -9,6 +9,7 @@ begin s.homepage = "http://github.com/Empact/votesmart" s.description = "A wrapper for the Project Vote Smart API" s.authors = ["Dan Cunning", "Ben Woosley"] + s.add_dependency 'patron', '>=0.4.6' end Jeweler::GemcutterTasks.new rescue LoadError diff --git a/lib/vote_smart/common.rb b/lib/vote_smart/common.rb index f8e48f2..e0f4b46 100644 --- a/lib/vote_smart/common.rb +++ b/lib/vote_smart/common.rb @@ -1,6 +1,6 @@ require 'json' require 'cgi' -require 'net/http' +require 'patron' require 'ym4r/google_maps/geocoding' module VoteSmart @@ -65,13 +65,17 @@ def self.hash2get(h) end.compact.join end + def self.session + @session ||= Patron::Session.new + end + # Use the Net::HTTP and JSON libraries to make the API call # # Usage: # District.get_json_data("http://someurl.com") # returns Hash of data or nil def self.get_json_data(url) - response = Net::HTTP.get_response(URI.parse(url)) - if response.class != Net::HTTPOK + response = session.get(url) + if response.status != 200 raise RequestFailed.new("Request was not OK: #{response.class}: #{url} #{response.body}") end JSON.parse(response.body) diff --git a/votesmart.gemspec b/votesmart.gemspec index d5c91d5..af42155 100644 --- a/votesmart.gemspec +++ b/votesmart.gemspec @@ -9,7 +9,7 @@ Gem::Specification.new do |s| s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Dan Cunning", "Ben Woosley"] - s.date = %q{2010-03-21} + s.date = %q{2010-03-22} s.description = %q{A wrapper for the Project Vote Smart API} s.email = %q{ben.woosley@gmail.com} s.extra_rdoc_files = [ @@ -102,9 +102,12 @@ Gem::Specification.new do |s| s.specification_version = 3 if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then + s.add_runtime_dependency(%q, [">= 0.4.6"]) else + s.add_dependency(%q, [">= 0.4.6"]) end else + s.add_dependency(%q, [">= 0.4.6"]) end end From 82ee46103325827aa27f7fe9d267499a371c65a3 Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Tue, 23 Mar 2010 09:33:56 -0400 Subject: [PATCH 11/55] First attempt at retry logic --- lib/vote_smart/common.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/vote_smart/common.rb b/lib/vote_smart/common.rb index e0f4b46..ec68c7d 100644 --- a/lib/vote_smart/common.rb +++ b/lib/vote_smart/common.rb @@ -78,7 +78,17 @@ def self.get_json_data(url) if response.status != 200 raise RequestFailed.new("Request was not OK: #{response.class}: #{url} #{response.body}") end + @json_retries = 0 JSON.parse(response.body) + rescue + @json_retries ||= 0 + if @json_retries < 3 + puts "Retrying #{url}" + @json_retries += 1 + retry + end + @json_retries = 0 + raise end end From 3361fa61f2096242c4740d3e109450b9e56ac33e Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Tue, 23 Mar 2010 19:19:13 -0400 Subject: [PATCH 12/55] Add some back-off logic to the retries --- lib/vote_smart/common.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/vote_smart/common.rb b/lib/vote_smart/common.rb index ec68c7d..af81015 100644 --- a/lib/vote_smart/common.rb +++ b/lib/vote_smart/common.rb @@ -82,8 +82,9 @@ def self.get_json_data(url) JSON.parse(response.body) rescue @json_retries ||= 0 - if @json_retries < 3 + if @json_retries < 5 puts "Retrying #{url}" + sleep(2 ** @json_retries) @json_retries += 1 retry end From f85b079e04346594dabb7a1e68d4c9953b3cf4df Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Thu, 25 Mar 2010 00:53:21 -0400 Subject: [PATCH 13/55] Use ensure to reset json retry count --- lib/vote_smart/common.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/vote_smart/common.rb b/lib/vote_smart/common.rb index af81015..8fcd8bc 100644 --- a/lib/vote_smart/common.rb +++ b/lib/vote_smart/common.rb @@ -78,7 +78,6 @@ def self.get_json_data(url) if response.status != 200 raise RequestFailed.new("Request was not OK: #{response.class}: #{url} #{response.body}") end - @json_retries = 0 JSON.parse(response.body) rescue @json_retries ||= 0 @@ -88,8 +87,9 @@ def self.get_json_data(url) @json_retries += 1 retry end - @json_retries = 0 raise + ensure + @json_retries = 0 end end From 128ea7244d60417880633898219a102376bb1a45 Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Thu, 25 Mar 2010 00:54:56 -0400 Subject: [PATCH 14/55] VoteSmart seems to be translating punctuation into unicode control characters at some point, for the sig descriptions at least. Translate the few I noticed into ascii-land --- lib/vote_smart/rating.rb | 16 +++++++++++++++- spec/responses/Rating.get_sig.1863.js | 1 + spec/vote_smart/rating_spec.rb | 9 +++++++++ tasks/spec_json.rake | 4 ++-- 4 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 spec/responses/Rating.get_sig.1863.js create mode 100644 spec/vote_smart/rating_spec.rb diff --git a/lib/vote_smart/rating.rb b/lib/vote_smart/rating.rb index 589d3d0..5da3136 100644 --- a/lib/vote_smart/rating.rb +++ b/lib/vote_smart/rating.rb @@ -14,7 +14,21 @@ def self.get_sig_list category_id, state_id = 'NA' # Returns detailed SIG information def self.get_sig sig_id - request("Rating.getSig", "sigId" => sig_id) + result = request("Rating.getSig", "sigId" => sig_id) + # PVS return utf control codes for punction in descriptions + result['sig']['description'] = result['sig']['description'].unpack("U*").map do |char| + case char + when 146 # 0092 + 39 + when 148, 147 # 0093,4 + 34 + when 150, 151 # 0096,7 + 45 + else + char + end + end.pack("U*") + result end # Returns an SIG's rating on a specific candidate diff --git a/spec/responses/Rating.get_sig.1863.js b/spec/responses/Rating.get_sig.1863.js new file mode 100644 index 0000000..353fa2a --- /dev/null +++ b/spec/responses/Rating.get_sig.1863.js @@ -0,0 +1 @@ +{"sig":{"contactName":"","city":"Washington","address":"601 E Street Northwest","name":"AARP","generalInfo":{"title":"Project Vote Smart - Interest Group Ratings","linkBack":"http://votesmart.org/issue_rating.php"},"zip":"20049","stateId":"NA","url":"http://www.aarp.org","phone1":"888-687-2277","sigId":"1863","phone2":"202-434-3525","fax":"","parentId":"-1","description":"\"Founded in 1958, AARP is a nonprofit, nonpartisan membership organization that helps people 50 and over improve the quality of their lives. AARP works tirelessly to fulfill its vision: a society in which everyone ages with dignity and purpose, and in which AARP helps people fulfill their goals and dreams. AARP speaks with one voice - united by a common motto: \"To serve, not be served.\" \"","email":"","state":"DC"}} \ No newline at end of file diff --git a/spec/vote_smart/rating_spec.rb b/spec/vote_smart/rating_spec.rb new file mode 100644 index 0000000..f41ef2b --- /dev/null +++ b/spec/vote_smart/rating_spec.rb @@ -0,0 +1,9 @@ +require File.dirname(__FILE__) + '/../spec_helper' + +describe VoteSmart::Rating do + describe ".get_sig" do + it "should properly handle UTF characters" do + VoteSmart::Rating.get_sig('1863')['sig']['description'].unpack("U*").should_not include(148) + end + end +end diff --git a/tasks/spec_json.rake b/tasks/spec_json.rake index c44c276..08cf9d7 100644 --- a/tasks/spec_json.rake +++ b/tasks/spec_json.rake @@ -58,7 +58,7 @@ namespace :spec do # save_json VoteSmart::Address, :get_office, "106446" - save_json VoteSmart::Official, :get_by_office_state, "12", "CO" + # save_json VoteSmart::Official, :get_by_office_state, "12", "CO" + save_json VoteSmart::Rating, :get_sig, "1863" end - end \ No newline at end of file From fbfd07d839ad9ca169ecac7025f0ca48c049283e Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Thu, 25 Mar 2010 01:05:08 -0400 Subject: [PATCH 15/55] Don't allow leading and trailing quotes in sig description --- lib/vote_smart/rating.rb | 3 +++ spec/responses/Rating.get_sig.1863.js | 2 +- spec/vote_smart/rating_spec.rb | 6 ++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/vote_smart/rating.rb b/lib/vote_smart/rating.rb index 5da3136..b9dcb21 100644 --- a/lib/vote_smart/rating.rb +++ b/lib/vote_smart/rating.rb @@ -16,6 +16,9 @@ def self.get_sig_list category_id, state_id = 'NA' def self.get_sig sig_id result = request("Rating.getSig", "sigId" => sig_id) # PVS return utf control codes for punction in descriptions + if result['sig']['description'].first == '"' + result['sig']['description'] = result['sig']['description'][1..-2] + end result['sig']['description'] = result['sig']['description'].unpack("U*").map do |char| case char when 146 # 0092 diff --git a/spec/responses/Rating.get_sig.1863.js b/spec/responses/Rating.get_sig.1863.js index 353fa2a..5930ca9 100644 --- a/spec/responses/Rating.get_sig.1863.js +++ b/spec/responses/Rating.get_sig.1863.js @@ -1 +1 @@ -{"sig":{"contactName":"","city":"Washington","address":"601 E Street Northwest","name":"AARP","generalInfo":{"title":"Project Vote Smart - Interest Group Ratings","linkBack":"http://votesmart.org/issue_rating.php"},"zip":"20049","stateId":"NA","url":"http://www.aarp.org","phone1":"888-687-2277","sigId":"1863","phone2":"202-434-3525","fax":"","parentId":"-1","description":"\"Founded in 1958, AARP is a nonprofit, nonpartisan membership organization that helps people 50 and over improve the quality of their lives. AARP works tirelessly to fulfill its vision: a society in which everyone ages with dignity and purpose, and in which AARP helps people fulfill their goals and dreams. AARP speaks with one voice - united by a common motto: \"To serve, not be served.\" \"","email":"","state":"DC"}} \ No newline at end of file +{"sig":{"contactName":"","city":"Washington","address":"601 E Street Northwest","name":"AARP","generalInfo":{"title":"Project Vote Smart - Interest Group Ratings","linkBack":"http://votesmart.org/issue_rating.php"},"zip":"20049","stateId":"NA","url":"http://www.aarp.org","phone1":"888-687-2277","sigId":"1863","phone2":"202-434-3525","fax":"","parentId":"-1","description":"Founded in 1958, AARP is a nonprofit, nonpartisan membership organization that helps people 50 and over improve the quality of their lives. AARP works tirelessly to fulfill its vision: a society in which everyone ages with dignity and purpose, and in which AARP helps people fulfill their goals and dreams. AARP speaks with one voice - united by a common motto: \"To serve, not be served.\" ","email":"","state":"DC"}} \ No newline at end of file diff --git a/spec/vote_smart/rating_spec.rb b/spec/vote_smart/rating_spec.rb index f41ef2b..4ec9d08 100644 --- a/spec/vote_smart/rating_spec.rb +++ b/spec/vote_smart/rating_spec.rb @@ -5,5 +5,11 @@ it "should properly handle UTF characters" do VoteSmart::Rating.get_sig('1863')['sig']['description'].unpack("U*").should_not include(148) end + + it "shouldn't have a quoted description" do + description = VoteSmart::Rating.get_sig('1863')['sig']['description'] + description.first.should_not == '"' + description.last.should_not == '"' + end end end From 5b4b72e0e49a5729dbc06717ff52508f3f892ab7 Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Thu, 25 Mar 2010 01:13:30 -0400 Subject: [PATCH 16/55] Bump to 0.3.0 --- History.txt | 16 ++++++++++++++++ VERSION.yml | 4 ++-- votesmart.gemspec | 7 +++++-- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/History.txt b/History.txt index 55fba27..dea73f5 100644 --- a/History.txt +++ b/History.txt @@ -1,3 +1,19 @@ +== 0.3.0 2010-03-25 + +* 3 major enhancement: + * Rename the project/gem to just 'votesmart' + * Move http access to Patron for performance + * Add retry logic on HTTP failure, with exponential backoff + +* 2 minor enhancements: + * Add Official#party to reflect the PVS officeParties data + * Sig descriptions: + * sometimes included UTF control characters for punctuation, which are now translated to ascii + * often started and ended in a quote, which is now avoided + +* 1 bug fix: + * Fix that Rating.get_sig_list would blow up on a bad parameter + == 0.0.1 2009-02-10 * 1 major enhancement: diff --git a/VERSION.yml b/VERSION.yml index e4ba134..4acb62a 100644 --- a/VERSION.yml +++ b/VERSION.yml @@ -1,4 +1,4 @@ --- :major: 0 -:minor: 2 -:patch: 4 +:minor: 3 +:patch: 0 diff --git a/votesmart.gemspec b/votesmart.gemspec index af42155..23be581 100644 --- a/votesmart.gemspec +++ b/votesmart.gemspec @@ -5,11 +5,11 @@ Gem::Specification.new do |s| s.name = %q{votesmart} - s.version = "0.2.4" + s.version = "0.3.0" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Dan Cunning", "Ben Woosley"] - s.date = %q{2010-03-22} + s.date = %q{2010-03-25} s.description = %q{A wrapper for the Project Vote Smart API} s.email = %q{ben.woosley@gmail.com} s.extra_rdoc_files = [ @@ -73,6 +73,7 @@ Gem::Specification.new do |s| "spec/responses/Official.get_by_office_state.44.GA.js", "spec/responses/Official.get_by_office_state.45.GA.js", "spec/responses/Official.get_by_office_state.53.GA.js", + "spec/responses/Rating.get_sig.1863.js", "spec/responses/State.get_state.GA.js", "spec/responses/State.get_state_ids.js", "spec/responses/authorization_failed.js", @@ -80,6 +81,7 @@ Gem::Specification.new do |s| "spec/vote_smart/district_spec.rb", "spec/vote_smart/office_spec.rb", "spec/vote_smart/official_spec.rb", + "spec/vote_smart/rating_spec.rb", "spec/vote_smart/state_spec.rb", "tasks/spec_json.rake", "votesmart.gemspec" @@ -94,6 +96,7 @@ Gem::Specification.new do |s| "spec/vote_smart/district_spec.rb", "spec/vote_smart/office_spec.rb", "spec/vote_smart/official_spec.rb", + "spec/vote_smart/rating_spec.rb", "spec/vote_smart/state_spec.rb" ] From be5b5b4f10ad600033b9127c0f201f20621c0155 Mon Sep 17 00:00:00 2001 From: Derek Willis Date: Fri, 4 Jun 2010 04:42:53 +0800 Subject: [PATCH 17/55] added getByZip responses --- lib/vote_smart/candidate.rb | 7 +++++-- lib/vote_smart/district.rb | 6 +++++- lib/vote_smart/election.rb | 4 ++++ lib/vote_smart/official.rb | 6 +++++- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/vote_smart/candidate.rb b/lib/vote_smart/candidate.rb index e6b4e31..04ea736 100644 --- a/lib/vote_smart/candidate.rb +++ b/lib/vote_smart/candidate.rb @@ -26,7 +26,10 @@ def self.get_by_election election_id def self.get_by_district district_id, election_year = nil request("Candidates.getByDistrict", "districtId" => district_id, "electionYear" => election_year) end - + + # Returns candidates in the provided zip code, with optional zip+4 and stage + def self.get_by_zip zip5, election_year=nil, zip4=nil, stage_id=nil + request("Candidates.getByZip", "zip5" => zip5, "electionYear" => election_year, "zip4" => zip4, "stageId" => stage_id) + end end - end diff --git a/lib/vote_smart/district.rb b/lib/vote_smart/district.rb index 25f692c..625354e 100644 --- a/lib/vote_smart/district.rb +++ b/lib/vote_smart/district.rb @@ -33,6 +33,10 @@ def self.find_all_by_office_id_and_state_id office_id, state_id def self.get_by_office_state office_id, state_id = 'NA', district_name = '' request("District.getByOfficeState", "officeId" => office_id, "stateId" => state_id, "districtName" => district_name) end - + + # Returns districts in the provided zip code, with optional zip+4 + def self.get_by_zip zip5, zip4=nil + request("District.getByZip", "zip5" => zip5, "zip4" => zip4) + end end end diff --git a/lib/vote_smart/election.rb b/lib/vote_smart/election.rb index 66d05f6..5d2004f 100644 --- a/lib/vote_smart/election.rb +++ b/lib/vote_smart/election.rb @@ -17,5 +17,9 @@ def self.get_stage_candidates election_id, stage_id, party = "" request("Election.getStageCandidates", "electionId" => election_id, "stageId" => stage_id, "party" => party) end + # Returns elections in the provided zip code, with optional zip+4 and election_year + def self.get_by_zip zip5, zip4=nil, election_year=nil + request("Election.getElectionByZip", "zip5" => zip5, "zip4" => zip4, "year" => election_year) + end end end diff --git a/lib/vote_smart/official.rb b/lib/vote_smart/official.rb index 41fc1f4..a96a08b 100644 --- a/lib/vote_smart/official.rb +++ b/lib/vote_smart/official.rb @@ -126,6 +126,10 @@ def self.get_by_election election_id def self.get_by_district district_id request("Officials.getByDistrict", "districtId" => district_id) end - + + # Returns incumbents in the provided zip code, with optional zip+4 and stage + def self.get_by_zip zip5, election_year=nil, zip4=nil, stage_id=nil + request("Officials.getByZip", "zip5" => zip5, "electionYear" => election_year, "zip4" => zip4, "stageId" => stage_id) + end end end From ce9461a0e39cf3025a6169f93d10b5d163fe3b5f Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Sat, 19 Jun 2010 14:57:35 -0400 Subject: [PATCH 18/55] Expose Officials.getStatewide Expose Officials.getStatewide as Official.get_statewide --- lib/vote_smart/official.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/vote_smart/official.rb b/lib/vote_smart/official.rb index a96a08b..e252dd9 100644 --- a/lib/vote_smart/official.rb +++ b/lib/vote_smart/official.rb @@ -47,8 +47,6 @@ def self.find_by_office_id_and_state_id office_id, state_id official end - - def self.find_all_by_address address, city, state, zip placemark = Geocoding.get("#{address} #{city}, #{state} #{zip}").first @@ -101,6 +99,9 @@ def self.find_state_legislators state_id, senate_district, house_district, assem officials end + def self.get_statewide(state_id = 'NA') + request("Officials.getStatewide", "stateId" => state_id) + end # Returns a list of incumbents that fit the criteria def self.get_by_office_state office_id, state_id = 'NA' From a3cc2f441e827fd456f4e885283eb17e6858a1e2 Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Sat, 19 Jun 2010 15:01:10 -0400 Subject: [PATCH 19/55] Version bump to 0.3.1 --- History.txt | 6 ++++++ VERSION.yml | 3 ++- votesmart.gemspec | 8 ++++---- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/History.txt b/History.txt index dea73f5..9dfbe22 100644 --- a/History.txt +++ b/History.txt @@ -1,3 +1,9 @@ +== 0.3.1 2010-06-19 + +* 2 major enhancements: + * Add Candidate.get_by_zip, District.get_by_zip, Election.get_by_zip and Official.get_by_zip (dwillis) + * Add Official.get_statewide (empact) + == 0.3.0 2010-03-25 * 3 major enhancement: diff --git a/VERSION.yml b/VERSION.yml index 4acb62a..4c08124 100644 --- a/VERSION.yml +++ b/VERSION.yml @@ -1,4 +1,5 @@ --- +:patch: 1 +:build: :major: 0 :minor: 3 -:patch: 0 diff --git a/votesmart.gemspec b/votesmart.gemspec index 23be581..ced759a 100644 --- a/votesmart.gemspec +++ b/votesmart.gemspec @@ -5,11 +5,11 @@ Gem::Specification.new do |s| s.name = %q{votesmart} - s.version = "0.3.0" + s.version = "0.3.1" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Dan Cunning", "Ben Woosley"] - s.date = %q{2010-03-25} + s.date = %q{2010-06-19} s.description = %q{A wrapper for the Project Vote Smart API} s.email = %q{ben.woosley@gmail.com} s.extra_rdoc_files = [ @@ -89,7 +89,7 @@ Gem::Specification.new do |s| s.homepage = %q{http://github.com/Empact/votesmart} s.rdoc_options = ["--charset=UTF-8"] s.require_paths = ["lib"] - s.rubygems_version = %q{1.3.6} + s.rubygems_version = %q{1.3.7} s.summary = %q{A wrapper for the Project Vote Smart API} s.test_files = [ "spec/spec_helper.rb", @@ -104,7 +104,7 @@ Gem::Specification.new do |s| current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION s.specification_version = 3 - if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then + if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then s.add_runtime_dependency(%q, [">= 0.4.6"]) else s.add_dependency(%q, [">= 0.4.6"]) From 3fae5c95fb8b7f5bb9a755b162d4de46ba282023 Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Sun, 20 Jun 2010 00:22:07 -0400 Subject: [PATCH 20/55] Bump up the patron timeouts as the response is sometimes slow... --- lib/vote_smart/common.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/vote_smart/common.rb b/lib/vote_smart/common.rb index 8fcd8bc..77c7fe2 100644 --- a/lib/vote_smart/common.rb +++ b/lib/vote_smart/common.rb @@ -66,7 +66,9 @@ def self.hash2get(h) end def self.session - @session ||= Patron::Session.new + @session ||= Patron::Session.new.tap do |session| + session.timeout = 15 + end end # Use the Net::HTTP and JSON libraries to make the API call From 82d61b5531f3695c3d970e5b37356f14aa045464 Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Sat, 18 Sep 2010 12:33:51 -0400 Subject: [PATCH 21/55] Move Commmon self. methods into class << self --- lib/vote_smart/common.rb | 130 +++++++++++++++++++-------------------- 1 file changed, 65 insertions(+), 65 deletions(-) diff --git a/lib/vote_smart/common.rb b/lib/vote_smart/common.rb index 77c7fe2..1bc22e2 100644 --- a/lib/vote_smart/common.rb +++ b/lib/vote_smart/common.rb @@ -9,16 +9,77 @@ class Common class << self attr_reader :attribute_map + + def set_attribute_map map + @attribute_map = map + end + + def response_child response, *children + for child in children + response = response[child] if response + end + + response || {} + end + + def request(api_method, params = {}) + url = construct_url api_method, params + + json = get_json_data(url) + + if json['error'] and json['error']['errorMessage'] == 'Authorization failed' + raise RequestFailed.new(json['error']['errorMessage']) + end + + json + end + + # Constructs a VoteSmart API-friendly URL + def construct_url(api_method, params = {}) + "#{API_URL}#{api_method}?key=#{VoteSmart.api_key}&o=#{API_FORMAT}#{hash2get(params)}" + end + + # Converts a hash to a GET string + def hash2get(h) + h.map do |(key, value)| + "&#{key.to_s}=#{CGI::escape(value.to_s)}" if value + end.compact.join + end + + def session + @session ||= Patron::Session.new.tap do |session| + session.timeout = 15 + end + end + + # Use the Net::HTTP and JSON libraries to make the API call + # + # Usage: + # District.get_json_data("http://someurl.com") # returns Hash of data or nil + def get_json_data(url) + response = session.get(url) + if response.status != 200 + raise RequestFailed.new("Request was not OK: #{response.class}: #{url} #{response.body}") + end + JSON.parse(response.body) + rescue + @json_retries ||= 0 + if @json_retries < 5 + puts "Retrying #{url}" + sleep(2 ** @json_retries) + @json_retries += 1 + retry + end + raise + ensure + @json_retries = 0 + end end def initialize attributes = {} update_attributes attributes end - def self.set_attribute_map map - @attribute_map = map - end - def update_attributes attributes map = self.class.attribute_map raise "map not set over-ride needed" unless map @@ -32,68 +93,7 @@ def update_attributes attributes end end end - - def self.response_child response, *children - for child in children - response = response[child] if response - end - - response || {} - end - def self.request(api_method, params = {}) - url = construct_url api_method, params - - json = get_json_data(url) - - if json['error'] and json['error']['errorMessage'] == 'Authorization failed' - raise RequestFailed.new(json['error']['errorMessage']) - end - - json - end - - # Constructs a VoteSmart API-friendly URL - def self.construct_url(api_method, params = {}) - "#{API_URL}#{api_method}?key=#{VoteSmart.api_key}&o=#{API_FORMAT}#{hash2get(params)}" - end - - # Converts a hash to a GET string - def self.hash2get(h) - h.map do |(key, value)| - "&#{key.to_s}=#{CGI::escape(value.to_s)}" if value - end.compact.join - end - - def self.session - @session ||= Patron::Session.new.tap do |session| - session.timeout = 15 - end - end - - # Use the Net::HTTP and JSON libraries to make the API call - # - # Usage: - # District.get_json_data("http://someurl.com") # returns Hash of data or nil - def self.get_json_data(url) - response = session.get(url) - if response.status != 200 - raise RequestFailed.new("Request was not OK: #{response.class}: #{url} #{response.body}") - end - JSON.parse(response.body) - rescue - @json_retries ||= 0 - if @json_retries < 5 - puts "Retrying #{url}" - sleep(2 ** @json_retries) - @json_retries += 1 - retry - end - raise - ensure - @json_retries = 0 - end - end end From 37a8813ff69c4fd365dfe7076336444912fc4e4c Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Sun, 19 Sep 2010 16:54:00 -0400 Subject: [PATCH 22/55] Allow running parallel requests via Typhoeus, currently only setup for Rating.get_candidate_rating --- lib/vote_smart/common.rb | 58 +++++++++++++++++++++++++++++++--------- lib/vote_smart/rating.rb | 4 +-- votesmart.gemspec | 2 +- 3 files changed, 48 insertions(+), 16 deletions(-) diff --git a/lib/vote_smart/common.rb b/lib/vote_smart/common.rb index 1bc22e2..09b3668 100644 --- a/lib/vote_smart/common.rb +++ b/lib/vote_smart/common.rb @@ -4,12 +4,44 @@ require 'ym4r/google_maps/geocoding' module VoteSmart - + module ParallelQueries + def session + @session ||= Typhoeus::Hydra.new + end + + def request(api_method, params = {}) + raise "on_complete block required" unless block_given? + + url = construct_url api_method, params + + new_request = Typhoeus::Request.new(url) + new_request.on_complete do |response| + json = JSON.parse(response.body) + + if json['error'] and json['error']['errorMessage'] == 'Authorization failed' + raise RequestFailed.new(json['error']['errorMessage']) + end + + yield json + end + session.queue new_request + end + + def run + session.run + end + end + class Common class << self attr_reader :attribute_map + def parallelize! + gem 'typhoeus' + extend ParallelQueries + end + def set_attribute_map map @attribute_map = map end @@ -22,18 +54,6 @@ def response_child response, *children response || {} end - def request(api_method, params = {}) - url = construct_url api_method, params - - json = get_json_data(url) - - if json['error'] and json['error']['errorMessage'] == 'Authorization failed' - raise RequestFailed.new(json['error']['errorMessage']) - end - - json - end - # Constructs a VoteSmart API-friendly URL def construct_url(api_method, params = {}) "#{API_URL}#{api_method}?key=#{VoteSmart.api_key}&o=#{API_FORMAT}#{hash2get(params)}" @@ -46,6 +66,18 @@ def hash2get(h) end.compact.join end + def request(api_method, params = {}) + url = construct_url api_method, params + + json = get_json_data(url) + + if json['error'] and json['error']['errorMessage'] == 'Authorization failed' + raise RequestFailed.new(json['error']['errorMessage']) + end + + json + end + def session @session ||= Patron::Session.new.tap do |session| session.timeout = 15 diff --git a/lib/vote_smart/rating.rb b/lib/vote_smart/rating.rb index b9dcb21..f563310 100644 --- a/lib/vote_smart/rating.rb +++ b/lib/vote_smart/rating.rb @@ -35,8 +35,8 @@ def self.get_sig sig_id end # Returns an SIG's rating on a specific candidate - def self.get_candidate_rating candidate_id, sig_id - request("Rating.getCandidateRating", "candidateId" => candidate_id, "sigId" => sig_id) + def self.get_candidate_rating candidate_id, sig_id, &block + request("Rating.getCandidateRating", {"candidateId" => candidate_id, "sigId" => sig_id}, &block) end end diff --git a/votesmart.gemspec b/votesmart.gemspec index ced759a..b12807c 100644 --- a/votesmart.gemspec +++ b/votesmart.gemspec @@ -9,7 +9,7 @@ Gem::Specification.new do |s| s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Dan Cunning", "Ben Woosley"] - s.date = %q{2010-06-19} + s.date = %q{2010-09-19} s.description = %q{A wrapper for the Project Vote Smart API} s.email = %q{ben.woosley@gmail.com} s.extra_rdoc_files = [ From d6c24064f882f9086d31da5514ed572d6f7bc1d4 Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Mon, 20 Sep 2010 03:16:49 -0400 Subject: [PATCH 23/55] Include CandiateBio.get_bio in the parallelizable requests --- lib/vote_smart/candidate_bio.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/vote_smart/candidate_bio.rb b/lib/vote_smart/candidate_bio.rb index 5d8ba8f..9630d2e 100644 --- a/lib/vote_smart/candidate_bio.rb +++ b/lib/vote_smart/candidate_bio.rb @@ -3,8 +3,8 @@ module VoteSmart class CandidateBio < Common # Returns basic bio details on a candidate - def self.get_bio can_id - request("CandidateBio.getBio", "candidateId" => can_id) + def self.get_bio can_id, &block + request("CandidateBio.getBio", {"candidateId" => can_id}, &block) end # From 02a9f53d4041d3db82c741bd56544567604f49a0 Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Wed, 29 Sep 2010 20:07:15 -0400 Subject: [PATCH 24/55] Fix for error: A JSON text must at least contain two octets, on parrallel runs --- lib/vote_smart/common.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/vote_smart/common.rb b/lib/vote_smart/common.rb index 09b3668..aca2b3b 100644 --- a/lib/vote_smart/common.rb +++ b/lib/vote_smart/common.rb @@ -16,6 +16,7 @@ def request(api_method, params = {}) new_request = Typhoeus::Request.new(url) new_request.on_complete do |response| + next if response.body.size < 2 json = JSON.parse(response.body) if json['error'] and json['error']['errorMessage'] == 'Authorization failed' From 6a89c362dc2acd42acefa4602a5f3752197f2249 Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Tue, 5 Oct 2010 14:38:51 -0700 Subject: [PATCH 25/55] Version bump to 0.3.2 --- History.txt | 5 +++++ VERSION.yml | 2 +- votesmart.gemspec | 4 ++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/History.txt b/History.txt index 9dfbe22..0db420d 100644 --- a/History.txt +++ b/History.txt @@ -1,3 +1,8 @@ +== 0.3.2 2010-10-05 + +* 1 major enhancement + * Add support for parallel requests via Typhoeus. Currently only available on Candiate.get_bio and Rating.get_candidate_rating + == 0.3.1 2010-06-19 * 2 major enhancements: diff --git a/VERSION.yml b/VERSION.yml index 4c08124..257c8f7 100644 --- a/VERSION.yml +++ b/VERSION.yml @@ -1,5 +1,5 @@ --- -:patch: 1 +:patch: 2 :build: :major: 0 :minor: 3 diff --git a/votesmart.gemspec b/votesmart.gemspec index b12807c..ca88486 100644 --- a/votesmart.gemspec +++ b/votesmart.gemspec @@ -5,11 +5,11 @@ Gem::Specification.new do |s| s.name = %q{votesmart} - s.version = "0.3.1" + s.version = "0.3.2" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Dan Cunning", "Ben Woosley"] - s.date = %q{2010-09-19} + s.date = %q{2010-10-05} s.description = %q{A wrapper for the Project Vote Smart API} s.email = %q{ben.woosley@gmail.com} s.extra_rdoc_files = [ From c675804944215e43ec130d2d86ecaef0d1fa77e2 Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Wed, 6 Oct 2010 13:06:30 -0700 Subject: [PATCH 26/55] Set a max rate limit for concurrent requests, at PVS' request. Sorry Clinton! :-P --- lib/vote_smart/common.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vote_smart/common.rb b/lib/vote_smart/common.rb index aca2b3b..50c3dfa 100644 --- a/lib/vote_smart/common.rb +++ b/lib/vote_smart/common.rb @@ -6,7 +6,7 @@ module VoteSmart module ParallelQueries def session - @session ||= Typhoeus::Hydra.new + @session ||= Typhoeus::Hydra.new(:max_concurrency => 20) end def request(api_method, params = {}) From d7da4ddb2c976d249dec9e320d4b3e00974e110c Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Wed, 6 Oct 2010 13:08:26 -0700 Subject: [PATCH 27/55] Version bump to 0.3.3 --- History.txt | 5 +++++ VERSION.yml | 2 +- votesmart.gemspec | 4 ++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/History.txt b/History.txt index 0db420d..535e167 100644 --- a/History.txt +++ b/History.txt @@ -1,3 +1,8 @@ +== 0.3.3 2010-10-06 + +* 1 minor enhancement: + * Rate-limit parallel requests to 20/second. Note that higher rates is acceptable for off hours, as per Clinton Adams, 2010-10-06: "Could you lower that to 20/second if it's occurring between 8AM-8PM EST? In the off hours 200/second is fine." + == 0.3.2 2010-10-05 * 1 major enhancement diff --git a/VERSION.yml b/VERSION.yml index 257c8f7..fe7b965 100644 --- a/VERSION.yml +++ b/VERSION.yml @@ -1,5 +1,5 @@ --- -:patch: 2 +:patch: 3 :build: :major: 0 :minor: 3 diff --git a/votesmart.gemspec b/votesmart.gemspec index ca88486..0ec689e 100644 --- a/votesmart.gemspec +++ b/votesmart.gemspec @@ -5,11 +5,11 @@ Gem::Specification.new do |s| s.name = %q{votesmart} - s.version = "0.3.2" + s.version = "0.3.3" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Dan Cunning", "Ben Woosley"] - s.date = %q{2010-10-05} + s.date = %q{2010-10-06} s.description = %q{A wrapper for the Project Vote Smart API} s.email = %q{ben.woosley@gmail.com} s.extra_rdoc_files = [ From 075b20253379968572e334802fa2c3978bf2372d Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Wed, 10 Nov 2010 18:10:53 -0500 Subject: [PATCH 28/55] Don't include Ym4r::GoogleMaps into the global namespace --- lib/vote_smart.rb | 1 - lib/vote_smart/official.rb | 2 +- spec/vote_smart/official_spec.rb | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/vote_smart.rb b/lib/vote_smart.rb index c72be2b..40ded02 100644 --- a/lib/vote_smart.rb +++ b/lib/vote_smart.rb @@ -1,7 +1,6 @@ require 'rubygems' require 'ym4r/google_maps/geocoding' require 'active_support' -include Ym4r::GoogleMaps module VoteSmart API_URL = "http://api.votesmart.org/" diff --git a/lib/vote_smart/official.rb b/lib/vote_smart/official.rb index e252dd9..743cde5 100644 --- a/lib/vote_smart/official.rb +++ b/lib/vote_smart/official.rb @@ -48,7 +48,7 @@ def self.find_by_office_id_and_state_id office_id, state_id end def self.find_all_by_address address, city, state, zip - placemark = Geocoding.get("#{address} #{city}, #{state} #{zip}").first + placemark = Ym4r::GoogleMaps::Geocoding.get("#{address} #{city}, #{state} #{zip}").first return [] unless placemark diff --git a/spec/vote_smart/official_spec.rb b/spec/vote_smart/official_spec.rb index 6332a95..5a15a40 100644 --- a/spec/vote_smart/official_spec.rb +++ b/spec/vote_smart/official_spec.rb @@ -41,7 +41,7 @@ def do_find describe "find by address" do before :each do mcll4r = {"response" => {"state_lower" => {"district" => "1"}, "state_upper" => {"district" => "2"}}} - Geocoding.should_receive(:get).once.and_return([mock("placemark", :latitude => 2, :longitude => 10)]) + Ym4r::GoogleMaps::Geocoding.should_receive(:get).once.and_return([mock("placemark", :latitude => 2, :longitude => 10)]) Mcll4r.should_receive(:new).once.and_return(mock("mcll4r", :district_lookup => mcll4r)) end From ca426677551462363b82cad883bf73931cd1e792 Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Wed, 10 Nov 2010 18:11:37 -0500 Subject: [PATCH 29/55] Don't assume rubygems - the provision of libraries is the job of the caller --- lib/vote_smart.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/vote_smart.rb b/lib/vote_smart.rb index 40ded02..bff0aa5 100644 --- a/lib/vote_smart.rb +++ b/lib/vote_smart.rb @@ -1,4 +1,3 @@ -require 'rubygems' require 'ym4r/google_maps/geocoding' require 'active_support' From 94a7565a69f2dfb531827c5cd0e29b7b137edba9 Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Wed, 10 Nov 2010 18:15:33 -0500 Subject: [PATCH 30/55] Drop some '.rb's from the require paths --- lib/vote_smart.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/vote_smart.rb b/lib/vote_smart.rb index bff0aa5..25814e1 100644 --- a/lib/vote_smart.rb +++ b/lib/vote_smart.rb @@ -12,8 +12,8 @@ class RequestFailed < Exception; end VoteSmart.api_key = "key" -require "#{File.dirname(__FILE__)}/mcll4r/mcll4r.rb" -require "#{File.dirname(__FILE__)}/vote_smart/common.rb" +require "#{File.dirname(__FILE__)}/mcll4r/mcll4r" +require "#{File.dirname(__FILE__)}/vote_smart/common" Dir["#{File.dirname(__FILE__)}/vote_smart/*.rb"].each do |source_file| require source_file unless source_file == "#{File.dirname(__FILE__)}/vote_smart/common.rb" From ee3dc0fad4c6169a624c90b9c729730b04ecd97f Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Wed, 17 Nov 2010 19:27:12 -0800 Subject: [PATCH 31/55] Move mcll4r out of the default inclusion (this will prob have to change but this is expedient) --- lib/vote_smart.rb | 12 ++++++------ lib/vote_smart/common.rb | 1 - lib/vote_smart/official.rb | 4 ++++ 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/vote_smart.rb b/lib/vote_smart.rb index 25814e1..7c983fd 100644 --- a/lib/vote_smart.rb +++ b/lib/vote_smart.rb @@ -1,18 +1,18 @@ -require 'ym4r/google_maps/geocoding' require 'active_support' module VoteSmart API_URL = "http://api.votesmart.org/" API_FORMAT = "JSON" - - mattr_accessor :api_key - - class RequestFailed < Exception; end + + class << self + attr_accessor :api_key + end + + class RequestFailed < StandardError; end end VoteSmart.api_key = "key" -require "#{File.dirname(__FILE__)}/mcll4r/mcll4r" require "#{File.dirname(__FILE__)}/vote_smart/common" Dir["#{File.dirname(__FILE__)}/vote_smart/*.rb"].each do |source_file| diff --git a/lib/vote_smart/common.rb b/lib/vote_smart/common.rb index 50c3dfa..9ea24f9 100644 --- a/lib/vote_smart/common.rb +++ b/lib/vote_smart/common.rb @@ -1,7 +1,6 @@ require 'json' require 'cgi' require 'patron' -require 'ym4r/google_maps/geocoding' module VoteSmart module ParallelQueries diff --git a/lib/vote_smart/official.rb b/lib/vote_smart/official.rb index 743cde5..69b5331 100644 --- a/lib/vote_smart/official.rb +++ b/lib/vote_smart/official.rb @@ -48,6 +48,8 @@ def self.find_by_office_id_and_state_id office_id, state_id end def self.find_all_by_address address, city, state, zip + require 'ym4r/google_maps/geocoding' + placemark = Ym4r::GoogleMaps::Geocoding.get("#{address} #{city}, #{state} #{zip}").first return [] unless placemark @@ -58,6 +60,8 @@ def self.find_all_by_address address, city, state, zip end def self.find_all_by_state_and_latitude_and_longitude state, latitude, longitude + require "#{File.dirname(__FILE__)}/../mcll4r/mcll4r" + response = Mcll4r.new.district_lookup(latitude, longitude) response = response["response"] if response From 21bd630d5d5e04f2eacee6177f2ca620dc851338 Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Wed, 17 Nov 2010 19:28:50 -0800 Subject: [PATCH 32/55] Comment out SpecTask use for now, given that it isn't present in rspec 2.0 --- Rakefile | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Rakefile b/Rakefile index f087588..d7fc043 100644 --- a/Rakefile +++ b/Rakefile @@ -18,17 +18,17 @@ end Dir['tasks/**/*.rake'].each { |t| load t } -require 'spec/rake/spectask' -Spec::Rake::SpecTask.new(:spec) do |spec| - spec.libs << 'lib' << 'spec' - spec.spec_files = FileList['spec/**/*_spec.rb'] -end - -Spec::Rake::SpecTask.new(:rcov) do |spec| - spec.libs << 'lib' << 'spec' - spec.pattern = 'spec/**/*_spec.rb' - spec.rcov = true -end +# require 'spec/rake/spectask' +# Spec::Rake::SpecTask.new(:spec) do |spec| +# spec.libs << 'lib' << 'spec' +# spec.spec_files = FileList['spec/**/*_spec.rb'] +# end +# +# Spec::Rake::SpecTask.new(:rcov) do |spec| +# spec.libs << 'lib' << 'spec' +# spec.pattern = 'spec/**/*_spec.rb' +# spec.rcov = true +# end task :spec => :check_dependencies From a0dd4a3c31470118117bfe76452f569f5c043fa2 Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Wed, 17 Nov 2010 19:29:08 -0800 Subject: [PATCH 33/55] Version bump to 0.4.0 --- VERSION.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/VERSION.yml b/VERSION.yml index fe7b965..9623d36 100644 --- a/VERSION.yml +++ b/VERSION.yml @@ -1,5 +1,5 @@ --- -:patch: 3 -:build: :major: 0 -:minor: 3 +:minor: 4 +:patch: 0 +:build: From 8e463aa964d9551e8c931794c7724603b71d5a71 Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Thu, 9 Feb 2012 00:39:43 -0800 Subject: [PATCH 34/55] Stop using a deprecated rdoc task --- Rakefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Rakefile b/Rakefile index d7fc043..35a4be5 100644 --- a/Rakefile +++ b/Rakefile @@ -34,8 +34,8 @@ task :spec => :check_dependencies task :default => :spec -require 'rake/rdoctask' -Rake::RDocTask.new do |rdoc| +require 'rdoc/task' +RDoc::Task.new do |rdoc| version = File.exist?('VERSION') ? File.read('VERSION') : "" rdoc.rdoc_dir = 'rdoc' From 53c0cb709ad88b1c666052a3a7f4991d12a308c0 Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Thu, 9 Feb 2012 00:41:30 -0800 Subject: [PATCH 35/55] :check_dependencies doesn't seem to be a part of Jeweler now, as it's handed by bundler. --- Rakefile | 1 - 1 file changed, 1 deletion(-) diff --git a/Rakefile b/Rakefile index 35a4be5..a316927 100644 --- a/Rakefile +++ b/Rakefile @@ -30,7 +30,6 @@ Dir['tasks/**/*.rake'].each { |t| load t } # spec.rcov = true # end -task :spec => :check_dependencies task :default => :spec From 2c73849d257ccefe23afcb1c8b814e797da2bc4f Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Thu, 9 Feb 2012 00:42:23 -0800 Subject: [PATCH 36/55] Add some basic development dependencies to the gemspec --- Rakefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Rakefile b/Rakefile index a316927..6c956ab 100644 --- a/Rakefile +++ b/Rakefile @@ -10,6 +10,8 @@ begin s.description = "A wrapper for the Project Vote Smart API" s.authors = ["Dan Cunning", "Ben Woosley"] s.add_dependency 'patron', '>=0.4.6' + s.add_development_dependency 'rspec', '<2.0.0' + s.add_development_dependency 'rake' end Jeweler::GemcutterTasks.new rescue LoadError From 566a3f31fb396f2bfc8723540caf20c4aff0d340 Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Thu, 9 Feb 2012 00:42:38 -0800 Subject: [PATCH 37/55] Update the gemspec --- votesmart.gemspec | 177 +++++++++++++++++++++++----------------------- 1 file changed, 89 insertions(+), 88 deletions(-) diff --git a/votesmart.gemspec b/votesmart.gemspec index 0ec689e..d155980 100644 --- a/votesmart.gemspec +++ b/votesmart.gemspec @@ -1,116 +1,117 @@ # Generated by jeweler # DO NOT EDIT THIS FILE DIRECTLY -# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command +# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec' # -*- encoding: utf-8 -*- Gem::Specification.new do |s| - s.name = %q{votesmart} - s.version = "0.3.3" + s.name = "votesmart" + s.version = "0.4.0" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Dan Cunning", "Ben Woosley"] - s.date = %q{2010-10-06} - s.description = %q{A wrapper for the Project Vote Smart API} - s.email = %q{ben.woosley@gmail.com} + s.date = "2012-02-09" + s.description = "A wrapper for the Project Vote Smart API" + s.email = "ben.woosley@gmail.com" s.extra_rdoc_files = [ "README.rdoc" ] s.files = [ - ".gitignore", - "History.txt", - "README.rdoc", - "Rakefile", - "VERSION.yml", - "lib/mcll4r/MIT-LICENSE", - "lib/mcll4r/README", - "lib/mcll4r/mcll4r.rb", - "lib/mcll4r/mcll4r_test.rb", - "lib/vote_smart.rb", - "lib/vote_smart/address.rb", - "lib/vote_smart/candidate.rb", - "lib/vote_smart/candidate_bio.rb", - "lib/vote_smart/candidate_office.rb", - "lib/vote_smart/committee.rb", - "lib/vote_smart/common.rb", - "lib/vote_smart/district.rb", - "lib/vote_smart/election.rb", - "lib/vote_smart/leadership.rb", - "lib/vote_smart/local.rb", - "lib/vote_smart/measure.rb", - "lib/vote_smart/notes.rb", - "lib/vote_smart/npat.rb", - "lib/vote_smart/office.rb", - "lib/vote_smart/official.rb", - "lib/vote_smart/phone.rb", - "lib/vote_smart/rating.rb", - "lib/vote_smart/state.rb", - "lib/vote_smart/vote.rb", - "lib/votesmart.rb", - "script/autospec", - "script/console", - "script/destroy", - "script/generate", - "script/is_gem_built", - "spec/responses/Address.get_office.106446.js", - "spec/responses/Address.get_office.1721.js", - "spec/responses/District.get_by_office_state.7.GA.js", - "spec/responses/District.get_by_office_state.8.GA.js", - "spec/responses/District.get_by_office_state.9.GA.js", - "spec/responses/Office.get_offices_by_type.C.js", - "spec/responses/Office.get_offices_by_type.L.js", - "spec/responses/Office.get_offices_by_type.P.js", - "spec/responses/Office.get_offices_by_type.S.js", - "spec/responses/Office.get_types.js", - "spec/responses/Official.get_by_district.20451.js", - "spec/responses/Official.get_by_district.20689.js", - "spec/responses/Official.get_by_district.21397.js", - "spec/responses/Official.get_by_district.21946.js", - "spec/responses/Official.get_by_office_state.12.CO.js", - "spec/responses/Official.get_by_office_state.12.GA.js", - "spec/responses/Official.get_by_office_state.13.GA.js", - "spec/responses/Official.get_by_office_state.33.GA.js", - "spec/responses/Official.get_by_office_state.42.GA.js", - "spec/responses/Official.get_by_office_state.44.GA.js", - "spec/responses/Official.get_by_office_state.45.GA.js", - "spec/responses/Official.get_by_office_state.53.GA.js", - "spec/responses/Rating.get_sig.1863.js", - "spec/responses/State.get_state.GA.js", - "spec/responses/State.get_state_ids.js", - "spec/responses/authorization_failed.js", - "spec/spec_helper.rb", - "spec/vote_smart/district_spec.rb", - "spec/vote_smart/office_spec.rb", - "spec/vote_smart/official_spec.rb", - "spec/vote_smart/rating_spec.rb", - "spec/vote_smart/state_spec.rb", - "tasks/spec_json.rake", - "votesmart.gemspec" - ] - s.homepage = %q{http://github.com/Empact/votesmart} - s.rdoc_options = ["--charset=UTF-8"] - s.require_paths = ["lib"] - s.rubygems_version = %q{1.3.7} - s.summary = %q{A wrapper for the Project Vote Smart API} - s.test_files = [ + "History.txt", + "README.rdoc", + "Rakefile", + "VERSION.yml", + "lib/mcll4r/MIT-LICENSE", + "lib/mcll4r/README", + "lib/mcll4r/mcll4r.rb", + "lib/mcll4r/mcll4r_test.rb", + "lib/vote_smart.rb", + "lib/vote_smart/address.rb", + "lib/vote_smart/candidate.rb", + "lib/vote_smart/candidate_bio.rb", + "lib/vote_smart/candidate_office.rb", + "lib/vote_smart/committee.rb", + "lib/vote_smart/common.rb", + "lib/vote_smart/district.rb", + "lib/vote_smart/election.rb", + "lib/vote_smart/leadership.rb", + "lib/vote_smart/local.rb", + "lib/vote_smart/measure.rb", + "lib/vote_smart/notes.rb", + "lib/vote_smart/npat.rb", + "lib/vote_smart/office.rb", + "lib/vote_smart/official.rb", + "lib/vote_smart/phone.rb", + "lib/vote_smart/rating.rb", + "lib/vote_smart/state.rb", + "lib/vote_smart/vote.rb", + "lib/votesmart.rb", + "script/autospec", + "script/console", + "script/destroy", + "script/generate", + "script/is_gem_built", + "spec/responses/Address.get_office.106446.js", + "spec/responses/Address.get_office.1721.js", + "spec/responses/District.get_by_office_state.7.GA.js", + "spec/responses/District.get_by_office_state.8.GA.js", + "spec/responses/District.get_by_office_state.9.GA.js", + "spec/responses/Office.get_offices_by_type.C.js", + "spec/responses/Office.get_offices_by_type.L.js", + "spec/responses/Office.get_offices_by_type.P.js", + "spec/responses/Office.get_offices_by_type.S.js", + "spec/responses/Office.get_types.js", + "spec/responses/Official.get_by_district.20451.js", + "spec/responses/Official.get_by_district.20689.js", + "spec/responses/Official.get_by_district.21397.js", + "spec/responses/Official.get_by_district.21946.js", + "spec/responses/Official.get_by_office_state.12.CO.js", + "spec/responses/Official.get_by_office_state.12.GA.js", + "spec/responses/Official.get_by_office_state.13.GA.js", + "spec/responses/Official.get_by_office_state.33.GA.js", + "spec/responses/Official.get_by_office_state.42.GA.js", + "spec/responses/Official.get_by_office_state.44.GA.js", + "spec/responses/Official.get_by_office_state.45.GA.js", + "spec/responses/Official.get_by_office_state.53.GA.js", + "spec/responses/Rating.get_sig.1863.js", + "spec/responses/State.get_state.GA.js", + "spec/responses/State.get_state_ids.js", + "spec/responses/authorization_failed.js", "spec/spec_helper.rb", - "spec/vote_smart/district_spec.rb", - "spec/vote_smart/office_spec.rb", - "spec/vote_smart/official_spec.rb", - "spec/vote_smart/rating_spec.rb", - "spec/vote_smart/state_spec.rb" + "spec/vote_smart/district_spec.rb", + "spec/vote_smart/office_spec.rb", + "spec/vote_smart/official_spec.rb", + "spec/vote_smart/rating_spec.rb", + "spec/vote_smart/state_spec.rb", + "tasks/spec_json.rake", + "votesmart.gemspec" ] + s.homepage = "http://github.com/Empact/votesmart" + s.require_paths = ["lib"] + s.rubygems_version = "1.8.10" + s.summary = "A wrapper for the Project Vote Smart API" if s.respond_to? :specification_version then - current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION s.specification_version = 3 if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then + s.add_runtime_dependency(%q, [">= 0"]) + s.add_development_dependency(%q, ["< 2.0.0"]) s.add_runtime_dependency(%q, [">= 0.4.6"]) + s.add_development_dependency(%q, ["< 2.0.0"]) + s.add_development_dependency(%q, [">= 0"]) else + s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, ["< 2.0.0"]) s.add_dependency(%q, [">= 0.4.6"]) + s.add_dependency(%q, ["< 2.0.0"]) + s.add_dependency(%q, [">= 0"]) end else + s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, ["< 2.0.0"]) s.add_dependency(%q, [">= 0.4.6"]) + s.add_dependency(%q, ["< 2.0.0"]) + s.add_dependency(%q, [">= 0"]) end end From beab0e29e1f190fb863cbbbc23559281d404044e Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Thu, 9 Feb 2012 00:43:20 -0800 Subject: [PATCH 38/55] Use a gemfile to manage development --- .gitignore | 1 + Gemfile | 3 +++ 2 files changed, 4 insertions(+) create mode 100644 Gemfile diff --git a/.gitignore b/.gitignore index 01d0a08..9008ca4 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ pkg/ +Gemfile.lock diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..e8e3471 --- /dev/null +++ b/Gemfile @@ -0,0 +1,3 @@ +source "http://www.rubygems.org" + +gemspec From b4ab5d64f399d4a7d7537311660b75c0de1bc3f8 Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Thu, 9 Feb 2012 01:00:11 -0800 Subject: [PATCH 39/55] Add jeweler as a dependency --- Rakefile | 29 +++++++++++++---------------- votesmart.gemspec | 4 ++++ 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/Rakefile b/Rakefile index 6c956ab..31c9533 100644 --- a/Rakefile +++ b/Rakefile @@ -1,22 +1,19 @@ %w[rubygems rake rake/clean fileutils].each { |f| require f } -begin - require 'jeweler' - Jeweler::Tasks.new do |s| - s.name = "votesmart" - s.summary = "A wrapper for the Project Vote Smart API" - s.email = "ben.woosley@gmail.com" - s.homepage = "http://github.com/Empact/votesmart" - s.description = "A wrapper for the Project Vote Smart API" - s.authors = ["Dan Cunning", "Ben Woosley"] - s.add_dependency 'patron', '>=0.4.6' - s.add_development_dependency 'rspec', '<2.0.0' - s.add_development_dependency 'rake' - end - Jeweler::GemcutterTasks.new -rescue LoadError - puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com" +require 'jeweler' +Jeweler::Tasks.new do |s| + s.name = "votesmart" + s.summary = "A wrapper for the Project Vote Smart API" + s.email = "ben.woosley@gmail.com" + s.homepage = "http://github.com/Empact/votesmart" + s.description = "A wrapper for the Project Vote Smart API" + s.authors = ["Dan Cunning", "Ben Woosley"] + s.add_dependency 'patron', '>=0.4.6' + s.add_development_dependency 'rspec', '<2.0.0' + s.add_development_dependency 'rake' + s.add_development_dependency 'jeweler' end +Jeweler::GemcutterTasks.new Dir['tasks/**/*.rake'].each { |t| load t } diff --git a/votesmart.gemspec b/votesmart.gemspec index d155980..6ea8c74 100644 --- a/votesmart.gemspec +++ b/votesmart.gemspec @@ -16,6 +16,7 @@ Gem::Specification.new do |s| "README.rdoc" ] s.files = [ + "Gemfile", "History.txt", "README.rdoc", "Rakefile", @@ -99,12 +100,14 @@ Gem::Specification.new do |s| s.add_runtime_dependency(%q, [">= 0.4.6"]) s.add_development_dependency(%q, ["< 2.0.0"]) s.add_development_dependency(%q, [">= 0"]) + s.add_development_dependency(%q, [">= 0"]) else s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, ["< 2.0.0"]) s.add_dependency(%q, [">= 0.4.6"]) s.add_dependency(%q, ["< 2.0.0"]) s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, [">= 0"]) end else s.add_dependency(%q, [">= 0"]) @@ -112,6 +115,7 @@ Gem::Specification.new do |s| s.add_dependency(%q, [">= 0.4.6"]) s.add_dependency(%q, ["< 2.0.0"]) s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, [">= 0"]) end end From 0d7cebac2c2a770d56139c756ddd7abf3e3a7b26 Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Thu, 9 Feb 2012 01:00:31 -0800 Subject: [PATCH 40/55] Return spec tasks to their former glory --- Rakefile | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/Rakefile b/Rakefile index 31c9533..a19807a 100644 --- a/Rakefile +++ b/Rakefile @@ -17,18 +17,17 @@ Jeweler::GemcutterTasks.new Dir['tasks/**/*.rake'].each { |t| load t } -# require 'spec/rake/spectask' -# Spec::Rake::SpecTask.new(:spec) do |spec| -# spec.libs << 'lib' << 'spec' -# spec.spec_files = FileList['spec/**/*_spec.rb'] -# end -# -# Spec::Rake::SpecTask.new(:rcov) do |spec| -# spec.libs << 'lib' << 'spec' -# spec.pattern = 'spec/**/*_spec.rb' -# spec.rcov = true -# end +require 'spec/rake/spectask' +Spec::Rake::SpecTask.new(:spec) do |spec| + spec.libs << 'lib' << 'spec' + spec.spec_files = FileList['spec/**/*_spec.rb'] +end +Spec::Rake::SpecTask.new(:rcov) do |spec| + spec.libs << 'lib' << 'spec' + spec.pattern = 'spec/**/*_spec.rb' + spec.rcov = true +end task :default => :spec From 650e5f9c410bb411378044513f7d4b0bab6f6a56 Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Thu, 9 Feb 2012 01:01:07 -0800 Subject: [PATCH 41/55] =?UTF-8?q?Simplify=20the=20'spec=5Fhelper'=20requir?= =?UTF-8?q?es=20so=20they=20work=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/vote_smart/district_spec.rb | 2 +- spec/vote_smart/office_spec.rb | 2 +- spec/vote_smart/official_spec.rb | 2 +- spec/vote_smart/rating_spec.rb | 2 +- spec/vote_smart/state_spec.rb | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/spec/vote_smart/district_spec.rb b/spec/vote_smart/district_spec.rb index abecc35..9326828 100644 --- a/spec/vote_smart/district_spec.rb +++ b/spec/vote_smart/district_spec.rb @@ -1,4 +1,4 @@ -require File.dirname(__FILE__) + '/../spec_helper' +require 'spec_helper' module VoteSmart describe District do diff --git a/spec/vote_smart/office_spec.rb b/spec/vote_smart/office_spec.rb index 6b76588..afcc621 100644 --- a/spec/vote_smart/office_spec.rb +++ b/spec/vote_smart/office_spec.rb @@ -1,4 +1,4 @@ -require File.dirname(__FILE__) + '/../spec_helper' +require 'spec_helper' module VoteSmart describe Office do diff --git a/spec/vote_smart/official_spec.rb b/spec/vote_smart/official_spec.rb index 5a15a40..6431cb8 100644 --- a/spec/vote_smart/official_spec.rb +++ b/spec/vote_smart/official_spec.rb @@ -1,4 +1,4 @@ -require File.dirname(__FILE__) + '/../spec_helper' +require 'spec_helper' module VoteSmart describe Official do diff --git a/spec/vote_smart/rating_spec.rb b/spec/vote_smart/rating_spec.rb index 4ec9d08..708a9af 100644 --- a/spec/vote_smart/rating_spec.rb +++ b/spec/vote_smart/rating_spec.rb @@ -1,4 +1,4 @@ -require File.dirname(__FILE__) + '/../spec_helper' +require 'spec_helper' describe VoteSmart::Rating do describe ".get_sig" do diff --git a/spec/vote_smart/state_spec.rb b/spec/vote_smart/state_spec.rb index bea9f90..5222f81 100644 --- a/spec/vote_smart/state_spec.rb +++ b/spec/vote_smart/state_spec.rb @@ -1,4 +1,4 @@ -require File.dirname(__FILE__) + '/../spec_helper' +require 'spec_helper' module VoteSmart describe State do From dbc675a953a8ca4faea4d82aee7ad7e83803fab2 Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Thu, 9 Feb 2012 01:05:54 -0800 Subject: [PATCH 42/55] Get the spec ruby 1.9.3 compatible --- spec/spec_helper.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 839cab3..2149191 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,4 +1,3 @@ -require 'rubygems' require 'stringio' require 'spec' require "votesmart" @@ -33,7 +32,7 @@ def stub_request_method klazz, request_method, args VoteSmart::State, VoteSmart::Vote].each do |klazz| - request_methods = klazz.methods.collect { |method| method if method.starts_with?("get_") }.compact + request_methods = klazz.methods.collect { |method| method if method.to_s.start_with?("get_") }.compact request_methods.each do |request_method| From 498457c4dae68a5d82d7fe8cc35014bc6986ffd6 Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Thu, 9 Feb 2012 01:17:44 -0800 Subject: [PATCH 43/55] Add Ym4r as a development dependency as it's optional for runtime use. --- Rakefile | 1 + spec/vote_smart/official_spec.rb | 2 ++ votesmart.gemspec | 3 +++ 3 files changed, 6 insertions(+) diff --git a/Rakefile b/Rakefile index a19807a..12424bd 100644 --- a/Rakefile +++ b/Rakefile @@ -12,6 +12,7 @@ Jeweler::Tasks.new do |s| s.add_development_dependency 'rspec', '<2.0.0' s.add_development_dependency 'rake' s.add_development_dependency 'jeweler' + s.add_development_dependency 'ym4r' # optional runtime dependency, required for tests end Jeweler::GemcutterTasks.new diff --git a/spec/vote_smart/official_spec.rb b/spec/vote_smart/official_spec.rb index 6431cb8..7e425b3 100644 --- a/spec/vote_smart/official_spec.rb +++ b/spec/vote_smart/official_spec.rb @@ -40,6 +40,8 @@ def do_find describe "find by address" do before :each do + require 'ym4r/google_maps/geocoding' + mcll4r = {"response" => {"state_lower" => {"district" => "1"}, "state_upper" => {"district" => "2"}}} Ym4r::GoogleMaps::Geocoding.should_receive(:get).once.and_return([mock("placemark", :latitude => 2, :longitude => 10)]) Mcll4r.should_receive(:new).once.and_return(mock("mcll4r", :district_lookup => mcll4r)) diff --git a/votesmart.gemspec b/votesmart.gemspec index 6ea8c74..e3e2a9c 100644 --- a/votesmart.gemspec +++ b/votesmart.gemspec @@ -101,6 +101,7 @@ Gem::Specification.new do |s| s.add_development_dependency(%q, ["< 2.0.0"]) s.add_development_dependency(%q, [">= 0"]) s.add_development_dependency(%q, [">= 0"]) + s.add_development_dependency(%q, [">= 0"]) else s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, ["< 2.0.0"]) @@ -108,6 +109,7 @@ Gem::Specification.new do |s| s.add_dependency(%q, ["< 2.0.0"]) s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, [">= 0"]) end else s.add_dependency(%q, [">= 0"]) @@ -116,6 +118,7 @@ Gem::Specification.new do |s| s.add_dependency(%q, ["< 2.0.0"]) s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, [">= 0"]) end end From d37562005d7a1bf1f07f671e882f139f831bfce5 Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Thu, 9 Feb 2012 01:48:45 -0800 Subject: [PATCH 44/55] Move to managing gems in the gem file, as expected by Jeweler (but somewhat contra katz: yehudakatz.com/2010/12/16/clarifying-the-roles-of-the-gemspec-and-gemfile/) --- Gemfile | 14 +++++++++++++- Rakefile | 5 ----- votesmart.gemspec | 27 ++++++++++++--------------- 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/Gemfile b/Gemfile index e8e3471..ea298e0 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,15 @@ source "http://www.rubygems.org" -gemspec +gem 'patron', '>=0.4.6' + +# Add dependencies to develop your gem here. +# Include everything needed to run rake, tests, features, etc. +group :development do + gem "rdoc", "~> 3.12" + gem "bundler", "~> 1.0.0" + gem "jeweler", "~> 1.8.3" + gem "rcov", ">= 0" + + # optional runtime dependencies, required for tests + gem 'ym4r' +end diff --git a/Rakefile b/Rakefile index 12424bd..3b9b9b3 100644 --- a/Rakefile +++ b/Rakefile @@ -8,11 +8,6 @@ Jeweler::Tasks.new do |s| s.homepage = "http://github.com/Empact/votesmart" s.description = "A wrapper for the Project Vote Smart API" s.authors = ["Dan Cunning", "Ben Woosley"] - s.add_dependency 'patron', '>=0.4.6' - s.add_development_dependency 'rspec', '<2.0.0' - s.add_development_dependency 'rake' - s.add_development_dependency 'jeweler' - s.add_development_dependency 'ym4r' # optional runtime dependency, required for tests end Jeweler::GemcutterTasks.new diff --git a/votesmart.gemspec b/votesmart.gemspec index e3e2a9c..072a83c 100644 --- a/votesmart.gemspec +++ b/votesmart.gemspec @@ -95,29 +95,26 @@ Gem::Specification.new do |s| s.specification_version = 3 if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then - s.add_runtime_dependency(%q, [">= 0"]) - s.add_development_dependency(%q, ["< 2.0.0"]) s.add_runtime_dependency(%q, [">= 0.4.6"]) - s.add_development_dependency(%q, ["< 2.0.0"]) - s.add_development_dependency(%q, [">= 0"]) - s.add_development_dependency(%q, [">= 0"]) + s.add_development_dependency(%q, ["~> 3.12"]) + s.add_development_dependency(%q, ["~> 1.0.0"]) + s.add_development_dependency(%q, ["~> 1.8.3"]) + s.add_development_dependency(%q, [">= 0"]) s.add_development_dependency(%q, [">= 0"]) else - s.add_dependency(%q, [">= 0"]) - s.add_dependency(%q, ["< 2.0.0"]) s.add_dependency(%q, [">= 0.4.6"]) - s.add_dependency(%q, ["< 2.0.0"]) - s.add_dependency(%q, [">= 0"]) - s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, ["~> 3.12"]) + s.add_dependency(%q, ["~> 1.0.0"]) + s.add_dependency(%q, ["~> 1.8.3"]) + s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, [">= 0"]) end else - s.add_dependency(%q, [">= 0"]) - s.add_dependency(%q, ["< 2.0.0"]) s.add_dependency(%q, [">= 0.4.6"]) - s.add_dependency(%q, ["< 2.0.0"]) - s.add_dependency(%q, [">= 0"]) - s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, ["~> 3.12"]) + s.add_dependency(%q, ["~> 1.0.0"]) + s.add_dependency(%q, ["~> 1.8.3"]) + s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, [">= 0"]) end end From bb7a2b52602327a1a89e3cf65e55a4309b0eaaf3 Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Thu, 9 Feb 2012 01:50:16 -0800 Subject: [PATCH 45/55] Ditch rcov as it's failing install on 1.9.3, and we don't really make use of it. --- Gemfile | 1 - votesmart.gemspec | 3 --- 2 files changed, 4 deletions(-) diff --git a/Gemfile b/Gemfile index ea298e0..3a3b3f2 100644 --- a/Gemfile +++ b/Gemfile @@ -8,7 +8,6 @@ group :development do gem "rdoc", "~> 3.12" gem "bundler", "~> 1.0.0" gem "jeweler", "~> 1.8.3" - gem "rcov", ">= 0" # optional runtime dependencies, required for tests gem 'ym4r' diff --git a/votesmart.gemspec b/votesmart.gemspec index 072a83c..53ecac9 100644 --- a/votesmart.gemspec +++ b/votesmart.gemspec @@ -99,14 +99,12 @@ Gem::Specification.new do |s| s.add_development_dependency(%q, ["~> 3.12"]) s.add_development_dependency(%q, ["~> 1.0.0"]) s.add_development_dependency(%q, ["~> 1.8.3"]) - s.add_development_dependency(%q, [">= 0"]) s.add_development_dependency(%q, [">= 0"]) else s.add_dependency(%q, [">= 0.4.6"]) s.add_dependency(%q, ["~> 3.12"]) s.add_dependency(%q, ["~> 1.0.0"]) s.add_dependency(%q, ["~> 1.8.3"]) - s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, [">= 0"]) end else @@ -114,7 +112,6 @@ Gem::Specification.new do |s| s.add_dependency(%q, ["~> 3.12"]) s.add_dependency(%q, ["~> 1.0.0"]) s.add_dependency(%q, ["~> 1.8.3"]) - s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, [">= 0"]) end end From 54217bd5b59c2e8765dcaf4df85dde64ff8a019b Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Thu, 9 Feb 2012 01:51:12 -0800 Subject: [PATCH 46/55] Rely on newly gemified mcll4r --- Gemfile | 1 + lib/mcll4r/MIT-LICENSE | 20 -------------------- lib/mcll4r/README | 19 ------------------- lib/mcll4r/mcll4r.rb | 24 ------------------------ lib/mcll4r/mcll4r_test.rb | 35 ----------------------------------- lib/vote_smart/official.rb | 2 +- votesmart.gemspec | 7 +++---- 7 files changed, 5 insertions(+), 103 deletions(-) delete mode 100755 lib/mcll4r/MIT-LICENSE delete mode 100644 lib/mcll4r/README delete mode 100644 lib/mcll4r/mcll4r.rb delete mode 100644 lib/mcll4r/mcll4r_test.rb diff --git a/Gemfile b/Gemfile index 3a3b3f2..70a7171 100644 --- a/Gemfile +++ b/Gemfile @@ -11,4 +11,5 @@ group :development do # optional runtime dependencies, required for tests gem 'ym4r' + gem 'mcll4r' end diff --git a/lib/mcll4r/MIT-LICENSE b/lib/mcll4r/MIT-LICENSE deleted file mode 100755 index e050db1..0000000 --- a/lib/mcll4r/MIT-LICENSE +++ /dev/null @@ -1,20 +0,0 @@ -Copyright (c) 2008 Mobile Commons - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/lib/mcll4r/README b/lib/mcll4r/README deleted file mode 100644 index 73a86f8..0000000 --- a/lib/mcll4r/README +++ /dev/null @@ -1,19 +0,0 @@ -=== mcll4r - -- [Code on GitHub](http://github.com/mcommons/mcll4r) - -=== Description - -Ruby client for Mobile Commons Legislative Lookup API - -Based on the API described at http://congress.mcommons.com - - -=== Authors - -- Maintained by [Benjamin Stein](mailto:ben@mcommons.com), [Mal McKay](mailto:mal@mcommons.com) & [Nathan Woodhull](mailto:nathan@mcommons.com) - -=== License - -Copyright (c) 2008 Mobile Commons -See MIT-LICENSE in this directory. diff --git a/lib/mcll4r/mcll4r.rb b/lib/mcll4r/mcll4r.rb deleted file mode 100644 index 00e237a..0000000 --- a/lib/mcll4r/mcll4r.rb +++ /dev/null @@ -1,24 +0,0 @@ -require 'rubygems' -require 'httparty' - -class Mcll4r - include HTTParty - base_uri "http://congress.mcommons.com" - format :xml - - def district_lookup(lat, lng) - filter_for_errors self.class.get("/districts/lookup.xml", :query=>{:lat=>lat, :lng=>lng}) - end - -private - - def filter_for_errors(hash) - if hash['response']['error'] - raise DistrictNotFound.new(hash['response']['error']) - end - hash - end - -end - -class DistrictNotFound < Exception; end \ No newline at end of file diff --git a/lib/mcll4r/mcll4r_test.rb b/lib/mcll4r/mcll4r_test.rb deleted file mode 100644 index 17c98fa..0000000 --- a/lib/mcll4r/mcll4r_test.rb +++ /dev/null @@ -1,35 +0,0 @@ -require 'mcll4r' -require 'test/unit' - -class Mcll4rTest < Test::Unit::TestCase - - def setup - @mcll4r = Mcll4r.new - end - - def test_assert_we_get_back_correct_district_data - expected = { - "response" => { - "state_upper" => { "district" => "029", "display_name" => "TX 29th", "state" => "TX" }, - "federal" => { "district" => "16", "display_name" => "TX 16th", "state" => "TX" }, - "state_lower" => { "district" => "077", "display_name" => "TX 77th", "state" => "TX" }, - "lng" => "-106.490969", - "lat" => "31.76321" - } - } - assert_equal expected, @mcll4r.district_lookup(31.76321, -106.490969) - end - - def test_assert_raise_on_error - assert_raise DistrictNotFound do - @mcll4r.district_lookup(nil,nil) - end - end - - def test_assert_raise_on_district_not_found - assert_raise DistrictNotFound do - @mcll4r.district_lookup( 1.0, 1.0 ) - end - end - -end diff --git a/lib/vote_smart/official.rb b/lib/vote_smart/official.rb index 69b5331..b662f78 100644 --- a/lib/vote_smart/official.rb +++ b/lib/vote_smart/official.rb @@ -60,7 +60,7 @@ def self.find_all_by_address address, city, state, zip end def self.find_all_by_state_and_latitude_and_longitude state, latitude, longitude - require "#{File.dirname(__FILE__)}/../mcll4r/mcll4r" + require "mcll4r" response = Mcll4r.new.district_lookup(latitude, longitude) response = response["response"] if response diff --git a/votesmart.gemspec b/votesmart.gemspec index 53ecac9..013e8be 100644 --- a/votesmart.gemspec +++ b/votesmart.gemspec @@ -21,10 +21,6 @@ Gem::Specification.new do |s| "README.rdoc", "Rakefile", "VERSION.yml", - "lib/mcll4r/MIT-LICENSE", - "lib/mcll4r/README", - "lib/mcll4r/mcll4r.rb", - "lib/mcll4r/mcll4r_test.rb", "lib/vote_smart.rb", "lib/vote_smart/address.rb", "lib/vote_smart/candidate.rb", @@ -100,12 +96,14 @@ Gem::Specification.new do |s| s.add_development_dependency(%q, ["~> 1.0.0"]) s.add_development_dependency(%q, ["~> 1.8.3"]) s.add_development_dependency(%q, [">= 0"]) + s.add_development_dependency(%q, [">= 0"]) else s.add_dependency(%q, [">= 0.4.6"]) s.add_dependency(%q, ["~> 3.12"]) s.add_dependency(%q, ["~> 1.0.0"]) s.add_dependency(%q, ["~> 1.8.3"]) s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, [">= 0"]) end else s.add_dependency(%q, [">= 0.4.6"]) @@ -113,6 +111,7 @@ Gem::Specification.new do |s| s.add_dependency(%q, ["~> 1.0.0"]) s.add_dependency(%q, ["~> 1.8.3"]) s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, [">= 0"]) end end From 69354111f16d14ca728b9ecb94f148edb6ce14ee Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Thu, 9 Feb 2012 01:52:28 -0800 Subject: [PATCH 47/55] We don't appear to be needing active_support, at least in 1.9.3 --- lib/vote_smart.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/vote_smart.rb b/lib/vote_smart.rb index 7c983fd..1839300 100644 --- a/lib/vote_smart.rb +++ b/lib/vote_smart.rb @@ -1,5 +1,3 @@ -require 'active_support' - module VoteSmart API_URL = "http://api.votesmart.org/" API_FORMAT = "JSON" From 37c93059130f8dc7e1ca16e061bb711884297783 Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Thu, 9 Feb 2012 01:55:31 -0800 Subject: [PATCH 48/55] #first and #last aren't on String in 1.9 --- spec/vote_smart/rating_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/vote_smart/rating_spec.rb b/spec/vote_smart/rating_spec.rb index 708a9af..70269cc 100644 --- a/spec/vote_smart/rating_spec.rb +++ b/spec/vote_smart/rating_spec.rb @@ -8,8 +8,8 @@ it "shouldn't have a quoted description" do description = VoteSmart::Rating.get_sig('1863')['sig']['description'] - description.first.should_not == '"' - description.last.should_not == '"' + description[0].should_not == '"' + description[-1].should_not == '"' end end end From 5826c3365a77a837ceab0595749fef47a8e32cc1 Mon Sep 17 00:00:00 2001 From: Daniel Leavitt Date: Sun, 18 Mar 2012 17:06:16 -0700 Subject: [PATCH 49/55] explicitly add dependency on older version of rspec --- Gemfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Gemfile b/Gemfile index 70a7171..d024291 100644 --- a/Gemfile +++ b/Gemfile @@ -5,6 +5,7 @@ gem 'patron', '>=0.4.6' # Add dependencies to develop your gem here. # Include everything needed to run rake, tests, features, etc. group :development do + gem "rspec", "< 2" gem "rdoc", "~> 3.12" gem "bundler", "~> 1.0.0" gem "jeweler", "~> 1.8.3" From 6dded7f1f10a103095ed8ee5e8ac7260ea07dc88 Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Mon, 26 Mar 2012 00:59:23 -0700 Subject: [PATCH 50/55] Add a missing require for mcll4r --- spec/vote_smart/official_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/vote_smart/official_spec.rb b/spec/vote_smart/official_spec.rb index 7e425b3..cb667fa 100644 --- a/spec/vote_smart/official_spec.rb +++ b/spec/vote_smart/official_spec.rb @@ -40,6 +40,7 @@ def do_find describe "find by address" do before :each do + require 'mcll4r' require 'ym4r/google_maps/geocoding' mcll4r = {"response" => {"state_lower" => {"district" => "1"}, "state_upper" => {"district" => "2"}}} From 139e11ae9654ca202d57f8ac5b1251b6837d3bd4 Mon Sep 17 00:00:00 2001 From: Daniel Leavitt Date: Sun, 18 Mar 2012 17:21:12 -0700 Subject: [PATCH 51/55] fix incorrectly named parameters and methods for offices --- lib/vote_smart/office.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/vote_smart/office.rb b/lib/vote_smart/office.rb index dd6955d..aee8475 100644 --- a/lib/vote_smart/office.rb +++ b/lib/vote_smart/office.rb @@ -67,7 +67,7 @@ def self.get_levels # Returns a list of offices by office type def self.get_offices_by_type type_id - request("Office.getOfficesByType", "typeId" => type_id) + request("Office.getOfficesByType", "officeTypeId" => type_id) end # Returns a list of offices by level of government @@ -77,7 +77,7 @@ def self.get_offices_by_level level_id # Returns a list of offices by office type and level of government def self.get_offices_by_type_level type_id, level_id - request("Office.getOfficesByType", "levelId" => level_id, "typeId" => type_id) + request("Office.getOfficesByTypeLevel", "levelId" => level_id, "typeId" => type_id) end # Returns a list of offices by branch and level of government From b0637220c94d50b25bf9e43ed75f5c56c9f6eddd Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Mon, 26 Mar 2012 01:06:59 -0700 Subject: [PATCH 52/55] Correct another incorrect param name to officeTypeId --- lib/vote_smart/office.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vote_smart/office.rb b/lib/vote_smart/office.rb index aee8475..3f0cfe8 100644 --- a/lib/vote_smart/office.rb +++ b/lib/vote_smart/office.rb @@ -77,7 +77,7 @@ def self.get_offices_by_level level_id # Returns a list of offices by office type and level of government def self.get_offices_by_type_level type_id, level_id - request("Office.getOfficesByTypeLevel", "levelId" => level_id, "typeId" => type_id) + request("Office.getOfficesByTypeLevel", "levelId" => level_id, "officeTypeId" => type_id) end # Returns a list of offices by branch and level of government From 569e0cb9230b5bf48c6898d2bad55009a69042c2 Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Mon, 26 Mar 2012 01:11:00 -0700 Subject: [PATCH 53/55] Split the Office::Type spec out from the Office spec --- spec/vote_smart/office/type_spec.rb | 49 +++++++++++++++++++++++++++++ spec/vote_smart/office_spec.rb | 46 --------------------------- 2 files changed, 49 insertions(+), 46 deletions(-) create mode 100644 spec/vote_smart/office/type_spec.rb diff --git a/spec/vote_smart/office/type_spec.rb b/spec/vote_smart/office/type_spec.rb new file mode 100644 index 0000000..bcd4de8 --- /dev/null +++ b/spec/vote_smart/office/type_spec.rb @@ -0,0 +1,49 @@ +require 'spec_helper' + +module VoteSmart + describe Office::Type do + + describe "all" do + + def do_find + Office::Type.all + end + + it_should_find :count => 10, :first => {:name => "Presidential and Cabinet", :id => "P"}, + :last => {:name => "Local Executive", :id => "M"} + + end + + describe "find_by_name" do + + def do_find + Office::Type.find_by_name("State Legislature") + end + + it_should_find :item => {:name => "State Legislature", :id => "L"} + + end + + describe "offices" do + + def do_find + Office::Type.find_by_name("Presidential and Cabinet").offices + end + + it_should_find :count => 17, :first => {:name => "President", :id => "1"}, + :last => {:name => "Vice President", :id => "2"} + + end + + describe "offices_by_name" do + + def do_find + Office::Type.find_by_name("Presidential and Cabinet").offices_by_name(["President", "Vice President"]) + end + + it_should_find :count => 2, :first => {:name => "President", :id => "1"}, + :last => {:name => "Vice President", :id => "2"} + + end + end +end diff --git a/spec/vote_smart/office_spec.rb b/spec/vote_smart/office_spec.rb index afcc621..ee87b2c 100644 --- a/spec/vote_smart/office_spec.rb +++ b/spec/vote_smart/office_spec.rb @@ -47,50 +47,4 @@ def do_find end end - - describe Office::Type do - - describe "all" do - - def do_find - Office::Type.all - end - - it_should_find :count => 10, :first => {:name => "Presidential and Cabinet", :id => "P"}, - :last => {:name => "Local Executive", :id => "M"} - - end - - describe "find_by_name" do - - def do_find - Office::Type.find_by_name("State Legislature") - end - - it_should_find :item => {:name => "State Legislature", :id => "L"} - - end - - describe "offices" do - - def do_find - Office::Type.find_by_name("Presidential and Cabinet").offices - end - - it_should_find :count => 17, :first => {:name => "President", :id => "1"}, - :last => {:name => "Vice President", :id => "2"} - - end - - describe "offices_by_name" do - - def do_find - Office::Type.find_by_name("Presidential and Cabinet").offices_by_name(["President", "Vice President"]) - end - - it_should_find :count => 2, :first => {:name => "President", :id => "1"}, - :last => {:name => "Vice President", :id => "2"} - - end - end end \ No newline at end of file From 455cc2467da1457f4c789b6650124d2c2cc4cb79 Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Mon, 26 Mar 2012 01:13:08 -0700 Subject: [PATCH 54/55] Version bump to 0.4.1 --- VERSION.yml | 4 ++-- votesmart.gemspec | 10 +++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/VERSION.yml b/VERSION.yml index 9623d36..e04aeaf 100644 --- a/VERSION.yml +++ b/VERSION.yml @@ -1,5 +1,5 @@ ---- +--- :major: 0 :minor: 4 -:patch: 0 +:patch: 1 :build: diff --git a/votesmart.gemspec b/votesmart.gemspec index 013e8be..374a593 100644 --- a/votesmart.gemspec +++ b/votesmart.gemspec @@ -5,11 +5,11 @@ Gem::Specification.new do |s| s.name = "votesmart" - s.version = "0.4.0" + s.version = "0.4.1" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Dan Cunning", "Ben Woosley"] - s.date = "2012-02-09" + s.date = "2012-03-26" s.description = "A wrapper for the Project Vote Smart API" s.email = "ben.woosley@gmail.com" s.extra_rdoc_files = [ @@ -75,6 +75,7 @@ Gem::Specification.new do |s| "spec/responses/authorization_failed.js", "spec/spec_helper.rb", "spec/vote_smart/district_spec.rb", + "spec/vote_smart/office/type_spec.rb", "spec/vote_smart/office_spec.rb", "spec/vote_smart/official_spec.rb", "spec/vote_smart/rating_spec.rb", @@ -84,7 +85,7 @@ Gem::Specification.new do |s| ] s.homepage = "http://github.com/Empact/votesmart" s.require_paths = ["lib"] - s.rubygems_version = "1.8.10" + s.rubygems_version = "1.8.11" s.summary = "A wrapper for the Project Vote Smart API" if s.respond_to? :specification_version then @@ -92,6 +93,7 @@ Gem::Specification.new do |s| if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then s.add_runtime_dependency(%q, [">= 0.4.6"]) + s.add_development_dependency(%q, ["< 2"]) s.add_development_dependency(%q, ["~> 3.12"]) s.add_development_dependency(%q, ["~> 1.0.0"]) s.add_development_dependency(%q, ["~> 1.8.3"]) @@ -99,6 +101,7 @@ Gem::Specification.new do |s| s.add_development_dependency(%q, [">= 0"]) else s.add_dependency(%q, [">= 0.4.6"]) + s.add_dependency(%q, ["< 2"]) s.add_dependency(%q, ["~> 3.12"]) s.add_dependency(%q, ["~> 1.0.0"]) s.add_dependency(%q, ["~> 1.8.3"]) @@ -107,6 +110,7 @@ Gem::Specification.new do |s| end else s.add_dependency(%q, [">= 0.4.6"]) + s.add_dependency(%q, ["< 2"]) s.add_dependency(%q, ["~> 3.12"]) s.add_dependency(%q, ["~> 1.0.0"]) s.add_dependency(%q, ["~> 1.8.3"]) From 0c8ff17a63af42837ac5e4d22b4d8f8a6773511c Mon Sep 17 00:00:00 2001 From: "Zamechek, Shawn" Date: Sat, 29 Aug 2015 14:46:10 -0400 Subject: [PATCH 55/55] updated .get_bills_by_official_year --- lib/vote_smart/vote.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/vote_smart/vote.rb b/lib/vote_smart/vote.rb index da9c53d..96605a7 100644 --- a/lib/vote_smart/vote.rb +++ b/lib/vote_smart/vote.rb @@ -37,9 +37,10 @@ def self.get_bills_by_year_state year, state_id = 'NA' request("Votes.getBillsByYearState", "year" => year, "stateId" => state_id) end + # Gets a list of bills that fit the criteria - def self.get_bills_by_official_year can_id, year - request("Votes.getBillsByOfficialYear", "candidateId" => can_id, "year" => year) + def self.get_bills_by_official_year_office can_id, year + request("Votes.getBillsByOfficialYearOffice", "candidateId" => can_id, "year" => year) end # Gets a list of bills that fit the criteria