govkit-ca 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.yardopts +4 -0
- data/README.md +2 -1
- data/govkit-ca.gemspec +3 -3
- data/lib/gov_kit-ca/postal_code/strategy/liberal_ca.rb +1 -2
- data/lib/gov_kit-ca/postal_code/strategy/parl_gc_ca.rb +2 -2
- data/lib/gov_kit-ca/postal_code.rb +2 -4
- data/lib/gov_kit-ca/version.rb +1 -1
- data/lib/gov_kit-ca.rb +2 -2
- data/spec/cbc_ca_spec.rb +1 -0
- data/spec/{conservative_ca_spec.ca → conservative_ca_spec.rb} +1 -1
- data/spec/elections_ca_spec.rb +2 -2
- data/spec/fixtures/cbc_ca/A1A1A1.response +11 -0
- data/spec/fixtures/cbc_ca/G0C2Y0.response +11 -0
- data/spec/fixtures/cbc_ca/H0H0H0.response +11 -0
- data/spec/fixtures/cbc_ca/K0A1K0.response +11 -0
- data/spec/fixtures/cbc_ca/T5S2B9.response +11 -0
- data/spec/fixtures/cbc_ca/X1B1B1.response +11 -0
- data/spec/fixtures/conservative_ca/A1A1A1.response +452 -0
- data/spec/fixtures/conservative_ca/G0C2Y0.response +452 -0
- data/spec/fixtures/conservative_ca/H0H0H0.response +452 -0
- data/spec/fixtures/conservative_ca/K0A1K0.response +455 -0
- data/spec/fixtures/conservative_ca/T5S2B9.response +453 -0
- data/spec/fixtures/conservative_ca/X1B1B1.response +452 -0
- data/spec/fixtures/digital-copyright_ca/A1A1A1.response +227 -0
- data/spec/fixtures/digital-copyright_ca/G0C2Y0.response +229 -0
- data/spec/fixtures/digital-copyright_ca/H0H0H0.response +243 -0
- data/spec/fixtures/digital-copyright_ca/K0A1K0.response +230 -0
- data/spec/fixtures/digital-copyright_ca/T5S2B9.response +233 -0
- data/spec/fixtures/digital-copyright_ca/X1B1B1.response +243 -0
- data/spec/fixtures/elections_ca/A1A1A1.response +10 -0
- data/spec/fixtures/elections_ca/G0C2Y0.response +11 -0
- data/spec/fixtures/elections_ca/H0H0H0.response +10 -0
- data/spec/fixtures/elections_ca/K0A1K0.response +10 -0
- data/spec/fixtures/elections_ca/T5S2B9.response +10 -0
- data/spec/fixtures/elections_ca/X1B1B1.response +10 -0
- data/spec/fixtures/greenparty_ca/A1A1A1.response +13 -0
- data/spec/fixtures/greenparty_ca/G0C2Y0.response +13 -0
- data/spec/fixtures/greenparty_ca/H0H0H0.response +13 -0
- data/spec/fixtures/greenparty_ca/K0A1K0.response +13 -0
- data/spec/fixtures/greenparty_ca/T5S2B9.response +13 -0
- data/spec/fixtures/greenparty_ca/X1B1B1.response +13 -0
- data/spec/fixtures/liberal_ca/A1A1A1.response +702 -0
- data/spec/fixtures/liberal_ca/G0C2Y0.response +570 -0
- data/spec/fixtures/liberal_ca/H0H0H0.response +649 -0
- data/spec/fixtures/liberal_ca/K0A1K0.response +650 -0
- data/spec/fixtures/liberal_ca/T5S2B9.response +570 -0
- data/spec/fixtures/liberal_ca/X1B1B1.response +649 -0
- data/spec/fixtures/ndp_ca/A1A1A1.response +610 -0
- data/spec/fixtures/ndp_ca/G0C2Y0.response +610 -0
- data/spec/fixtures/ndp_ca/H0H0H0.response +593 -0
- data/spec/fixtures/ndp_ca/K0A1K0.response +641 -0
- data/spec/fixtures/ndp_ca/T5S2B9.response +605 -0
- data/spec/fixtures/ndp_ca/X1B1B1.response +593 -0
- data/spec/liberal_ca_spec.rb +1 -4
- data/spec/ndp_ca_spec.rb +1 -1
- data/spec/spec_helper.rb +4 -0
- data/spec/strategy_set_spec.rb +5 -0
- data/tasks/tasks.rb +4 -5
- metadata +114 -8
data/.yardopts
ADDED
data/README.md
CHANGED
@@ -2,7 +2,8 @@
|
|
2
2
|
|
3
3
|
[](http://travis-ci.org/opennorth/govkit-ca)
|
4
4
|
[](https://gemnasium.com/opennorth/govkit-ca)
|
5
|
-
[](https://coveralls.io/r/opennorth/govkit-ca)
|
6
|
+
[](https://codeclimate.com/github/opennorth/govkit-ca)
|
6
7
|
|
7
8
|
GovKit-CA is a Ruby gem that provides easy access to Canadian civic data around the web. It currently provides an API for free postal code to electoral district lookups, using the following sources:
|
8
9
|
|
data/govkit-ca.gemspec
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
require "gov_kit-ca/version"
|
2
|
+
require File.expand_path('../lib/gov_kit-ca/version', __FILE__)
|
4
3
|
|
5
4
|
Gem::Specification.new do |s|
|
6
5
|
s.name = "govkit-ca"
|
@@ -19,10 +18,11 @@ Gem::Specification.new do |s|
|
|
19
18
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
19
|
s.require_paths = ["lib"]
|
21
20
|
|
22
|
-
s.add_runtime_dependency('httparty', '~> 0.
|
21
|
+
s.add_runtime_dependency('httparty', '~> 0.10.0')
|
23
22
|
s.add_runtime_dependency('nokogiri', '~> 1.5.0')
|
24
23
|
s.add_runtime_dependency('yajl-ruby', '~> 0.8.2')
|
25
24
|
s.add_development_dependency('rspec', '~> 2.6.0')
|
26
25
|
s.add_development_dependency('fakeweb', '~> 1.3.0')
|
27
26
|
s.add_development_dependency('rake')
|
27
|
+
s.add_development_dependency('coveralls')
|
28
28
|
end
|
@@ -2,8 +2,7 @@ module GovKit
|
|
2
2
|
module CA
|
3
3
|
module PostalCode
|
4
4
|
module Strategy
|
5
|
-
# liberal.ca seems unreliable. It returns
|
6
|
-
# three ridings for K0A1K0.
|
5
|
+
# liberal.ca seems unreliable. It returns three ridings for K0A1K0.
|
7
6
|
class LiberalCa < Base
|
8
7
|
follow_redirects true
|
9
8
|
base_uri 'www.liberal.ca'
|
@@ -3,8 +3,6 @@ module GovKit
|
|
3
3
|
# A collection of postal code helpers.
|
4
4
|
# @see http://en.wikipedia.org/wiki/Postal_codes_in_Canada Postal codes in Canada
|
5
5
|
module PostalCode
|
6
|
-
autoload :StrategySet, 'gov_kit-ca/postal_code/strategy_set'
|
7
|
-
|
8
6
|
# @param [String] postal_code a postal code
|
9
7
|
# @return [Boolean] whether the postal code is properly formatted
|
10
8
|
# @see http://en.wikipedia.org/wiki/Postal_codes_in_Canada#Number_of_possible_postal_codes Possible postal codes
|
@@ -79,9 +77,9 @@ module GovKit
|
|
79
77
|
end
|
80
78
|
end
|
81
79
|
|
80
|
+
require 'gov_kit-ca/postal_code/strategy_set'
|
82
81
|
require 'gov_kit-ca/postal_code/strategy/base'
|
83
|
-
#
|
84
|
-
#require 'gov_kit-ca/postal_code/strategy/parl_gc_ca'
|
82
|
+
#require 'gov_kit-ca/postal_code/strategy/parl_gc_ca' # only riding name
|
85
83
|
require 'gov_kit-ca/postal_code/strategy/elections_ca' # only one-to-one
|
86
84
|
require 'gov_kit-ca/postal_code/strategy/ndp_ca'
|
87
85
|
require 'gov_kit-ca/postal_code/strategy/liberal_ca' # incomplete database
|
data/lib/gov_kit-ca/version.rb
CHANGED
data/lib/gov_kit-ca.rb
CHANGED
@@ -8,10 +8,10 @@ require 'yajl'
|
|
8
8
|
|
9
9
|
module GovKit
|
10
10
|
module CA
|
11
|
-
autoload :PostalCode, 'gov_kit-ca/postal_code'
|
12
|
-
|
13
11
|
class GovKitError < StandardError; end
|
14
12
|
class ResourceNotFound < GovKitError; end
|
15
13
|
class InvalidRequest < GovKitError; end
|
16
14
|
end
|
17
15
|
end
|
16
|
+
|
17
|
+
require 'gov_kit-ca/postal_code'
|
data/spec/cbc_ca_spec.rb
CHANGED
@@ -15,7 +15,7 @@ describe GovKit::CA::PostalCode::Strategy::ConservativeCa do
|
|
15
15
|
it 'should return the electoral districts within a postal code' do
|
16
16
|
{ 'T5S2B9' => [48015],
|
17
17
|
'K0A1K0' => [35025, 35052, 35063],
|
18
|
-
|
18
|
+
# returns nothing for B0J2L0
|
19
19
|
}.each do |postal_code,electoral_districts|
|
20
20
|
GovKit::CA::PostalCode::Strategy::ConservativeCa.new(postal_code).electoral_districts.should == electoral_districts
|
21
21
|
end
|
data/spec/elections_ca_spec.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
2
|
+
require 'gov_kit-ca/postal_code/strategy/elections_ca'
|
3
3
|
|
4
4
|
describe GovKit::CA::PostalCode::Strategy::ElectionsCa do
|
5
5
|
describe '#electoral_districts' do
|
@@ -14,7 +14,7 @@ describe GovKit::CA::PostalCode::Strategy::ElectionsCa do
|
|
14
14
|
|
15
15
|
it 'should return the electoral districts within a postal code' do
|
16
16
|
{ 'G0C2Y0' => [24019],
|
17
|
-
|
17
|
+
# returns nothing for T5S2B9
|
18
18
|
}.each do |postal_code,electoral_districts|
|
19
19
|
GovKit::CA::PostalCode::Strategy::ElectionsCa.new(postal_code).electoral_districts.should == electoral_districts
|
20
20
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
HTTP/1.1 200 OK
|
2
|
+
Server: Apache/2.2.3 (Red Hat)
|
3
|
+
X-Origin-Server: web17:sb17
|
4
|
+
Content-Type: text/html
|
5
|
+
Cache-Control: max-age=28
|
6
|
+
Expires: Tue, 05 Mar 2013 03:46:36 GMT
|
7
|
+
Date: Tue, 05 Mar 2013 03:46:08 GMT
|
8
|
+
Content-Length: 55
|
9
|
+
Connection: close
|
10
|
+
|
11
|
+
[{"rid":"007","name":"St. John's South - Mount Pearl"}]
|
@@ -0,0 +1,11 @@
|
|
1
|
+
HTTP/1.1 200 OK
|
2
|
+
Server: Apache/2.2.3 (Red Hat)
|
3
|
+
X-Origin-Server: web17:sb17
|
4
|
+
Content-Type: text/html
|
5
|
+
Cache-Control: max-age=29
|
6
|
+
Expires: Tue, 05 Mar 2013 03:46:37 GMT
|
7
|
+
Date: Tue, 05 Mar 2013 03:46:08 GMT
|
8
|
+
Content-Length: 66
|
9
|
+
Connection: close
|
10
|
+
|
11
|
+
[{"rid":"052","name":"Gasp\u00e9sie - \u00celes-de-la-Madeleine"}]
|
@@ -0,0 +1,11 @@
|
|
1
|
+
HTTP/1.1 404 Not Found
|
2
|
+
Server: Apache/2.2.3 (Red Hat)
|
3
|
+
X-Origin-Server: web20:sb17
|
4
|
+
Content-Length: 0
|
5
|
+
Content-Type: text/html
|
6
|
+
Vary: Accept-Encoding
|
7
|
+
Cache-Control: max-age=28
|
8
|
+
Expires: Tue, 05 Mar 2013 03:46:37 GMT
|
9
|
+
Date: Tue, 05 Mar 2013 03:46:09 GMT
|
10
|
+
Connection: close
|
11
|
+
|
@@ -0,0 +1,11 @@
|
|
1
|
+
HTTP/1.1 200 OK
|
2
|
+
Server: Apache/2.2.3 (Red Hat)
|
3
|
+
X-Origin-Server: web19:sb17
|
4
|
+
Content-Type: text/html
|
5
|
+
Cache-Control: max-age=30
|
6
|
+
Expires: Tue, 05 Mar 2013 03:46:39 GMT
|
7
|
+
Date: Tue, 05 Mar 2013 03:46:09 GMT
|
8
|
+
Content-Length: 177
|
9
|
+
Connection: close
|
10
|
+
|
11
|
+
[{"rid":"133","name":"Glengarry - Prescott - Russell"},{"rid":"159","name":"Nepean - Carleton"},{"rid":"170","name":"Ottawa - Orl\u00e9ans"},{"rid":"171","name":"Ottawa South"}]
|
@@ -0,0 +1,11 @@
|
|
1
|
+
HTTP/1.1 200 OK
|
2
|
+
Server: Apache/2.2.3 (Red Hat)
|
3
|
+
X-Origin-Server: web20:sb17
|
4
|
+
Content-Type: text/html
|
5
|
+
Cache-Control: max-age=30
|
6
|
+
Expires: Tue, 05 Mar 2013 03:46:38 GMT
|
7
|
+
Date: Tue, 05 Mar 2013 03:46:08 GMT
|
8
|
+
Content-Length: 93
|
9
|
+
Connection: close
|
10
|
+
|
11
|
+
[{"rid":"257","name":"Edmonton - Spruce Grove"},{"rid":"255","name":"Edmonton - St. Albert"}]
|
@@ -0,0 +1,11 @@
|
|
1
|
+
HTTP/1.1 404 Not Found
|
2
|
+
Server: Apache/2.2.3 (Red Hat)
|
3
|
+
X-Origin-Server: web21:sb17
|
4
|
+
Content-Length: 0
|
5
|
+
Content-Type: text/html
|
6
|
+
Vary: Accept-Encoding
|
7
|
+
Cache-Control: max-age=30
|
8
|
+
Expires: Tue, 05 Mar 2013 03:46:40 GMT
|
9
|
+
Date: Tue, 05 Mar 2013 03:46:10 GMT
|
10
|
+
Connection: close
|
11
|
+
|