washoe_polls 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ coverage
2
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/Changelog ADDED
File without changes
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in gem_template.gemspec
4
+ gemspec
5
+
data/Gemfile.lock ADDED
@@ -0,0 +1,43 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ washoe_polls (0.1.0)
5
+ faraday (~> 0.7.5)
6
+ hashie (~> 1.0.0)
7
+ nokogiri (~> 1.5.0)
8
+
9
+ GEM
10
+ remote: http://rubygems.org/
11
+ specs:
12
+ addressable (2.2.6)
13
+ crack (0.3.1)
14
+ diff-lcs (1.1.3)
15
+ faraday (0.7.5)
16
+ addressable (~> 2.2.6)
17
+ multipart-post (~> 1.1.3)
18
+ rack (< 2, >= 1.1.0)
19
+ hashie (1.0.0)
20
+ multipart-post (1.1.3)
21
+ nokogiri (1.5.0)
22
+ rack (1.3.4)
23
+ rspec (2.6.0)
24
+ rspec-core (~> 2.6.0)
25
+ rspec-expectations (~> 2.6.0)
26
+ rspec-mocks (~> 2.6.0)
27
+ rspec-core (2.6.4)
28
+ rspec-expectations (2.6.0)
29
+ diff-lcs (~> 1.1.2)
30
+ rspec-mocks (2.6.0)
31
+ webmock (1.7.7)
32
+ addressable (> 2.2.5, ~> 2.2)
33
+ crack (>= 0.1.7)
34
+
35
+ PLATFORMS
36
+ ruby
37
+
38
+ DEPENDENCIES
39
+ hashie (~> 1.0.0)
40
+ nokogiri (~> 1.5.0)
41
+ rspec (~> 2.6)
42
+ washoe_polls!
43
+ webmock (~> 1.7)
data/LICENSE ADDED
File without changes
data/README.rdoc ADDED
@@ -0,0 +1,26 @@
1
+ = Overview
2
+
3
+ WashoePolls is a gem for fetching voter roll and polling place information for Washoe County, Nevada.
4
+
5
+ == Usage
6
+
7
+ First:
8
+
9
+ <tt>gem install washoe_polls</tt>
10
+
11
+ Then:
12
+
13
+ <tt>voter_id = WashoePolls.lookup(last_name,birth_date)</tt>
14
+
15
+ And Finally:
16
+
17
+ <tt>info = WashoePolls.fetch(voter_id) # returns your voter roll information.</tt>
18
+
19
+
20
+ == Compatibility
21
+
22
+ WashoePolls is developed against 1.9.2.
23
+
24
+ = Credits
25
+
26
+ Javier Muniz
@@ -0,0 +1,65 @@
1
+ module WashoePolls
2
+ class Client
3
+
4
+ def initialize()
5
+ end
6
+
7
+ def lookup(last_name,birth_date)
8
+ post_vars = {
9
+ :submit => "on",
10
+ :color => "blue",
11
+ :text_version => "",
12
+ :Last => last_name,
13
+ :Birth => birth_date
14
+ }
15
+ response = post 'http://www.co.washoe.nv.us/voters/regsearch.php', post_vars
16
+ doc = Nokogiri::HTML(response)
17
+ id = /.*?~details=(\d+)&/.match(doc.xpath('//table')[1].xpath('tr')[1].at_xpath('td/a').attr('href'))[1]
18
+ id.to_i
19
+ end
20
+
21
+ def fetch(voter_id)
22
+ response = get "http://www.co.washoe.nv.us/voters/regsearch.php~details=#{voter_id}"
23
+ doc = Nokogiri::HTML(response)
24
+ doc.css('br').each{ |br| br.replace("\n") }
25
+ nodes = doc.xpath('//table')[1].xpath('tr//td[2]')
26
+ info = {
27
+ :name => nodes[0].content,
28
+ :birth_date => nodes[1].content,
29
+ :precinct => nodes[2].content,
30
+ :place => nodes[3].content.gsub(/\nclick for directions/,''),
31
+ :address => nodes[4].content,
32
+ :party => nodes[5].content,
33
+ :registered => nodes[6].content
34
+ }
35
+ end
36
+
37
+ private
38
+
39
+ def connection
40
+ options = {
41
+ :headers => {'Accept' => 'application/html'}
42
+ }
43
+
44
+ Faraday::Connection.new(options) do |builder|
45
+ builder.use Faraday::Request::UrlEncoded
46
+ builder.adapter(Faraday.default_adapter)
47
+ end
48
+ end
49
+
50
+ def post(path,post_vars)
51
+ response = connection.post do |request|
52
+ request.url path
53
+ request.body = post_vars
54
+ end
55
+ response.body
56
+ end
57
+
58
+ def get(path)
59
+ response = connection.get do |request|
60
+ request.url path
61
+ end
62
+ response.body
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,3 @@
1
+ module WashoePolls
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,21 @@
1
+ require 'faraday'
2
+ require 'nokogiri'
3
+ require 'washoe_polls/client'
4
+ require 'washoe_polls/version'
5
+
6
+ module WashoePolls
7
+ # Alias for WashoePolls::Client.new
8
+ #
9
+ # @return [WashoePolls::Client]
10
+ def self.client()
11
+ WashoePolls::Client.new()
12
+ end
13
+
14
+ def self.lookup(last_name,birth_date)
15
+ client.lookup(last_name,birth_date)
16
+ end
17
+
18
+ def self.fetch(voter_id)
19
+ client.fetch(voter_id)
20
+ end
21
+ end