govkit-ca 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/README.md +42 -8
- data/lib/gov_kit-ca.rb +10 -0
- data/lib/gov_kit-ca/postal_code.rb +0 -26
- data/lib/gov_kit-ca/postal_code/strategy/cbc_ca.rb +0 -2
- data/lib/gov_kit-ca/postal_code/strategy/conservative_ca.rb +0 -2
- data/lib/gov_kit-ca/postal_code/strategy/digital-copyright_ca.rb +0 -2
- data/lib/gov_kit-ca/postal_code/strategy/elections_ca.rb +1 -3
- data/lib/gov_kit-ca/postal_code/strategy/greenparty_ca.rb +4 -5
- data/lib/gov_kit-ca/postal_code/strategy/liberal_ca.rb +3 -5
- data/lib/gov_kit-ca/postal_code/strategy/ndp_ca.rb +0 -2
- data/lib/gov_kit-ca/postal_code/strategy/parl_gc_ca.rb +0 -2
- data/lib/gov_kit-ca/postal_code/strategy_set.rb +1 -1
- data/lib/gov_kit-ca/version.rb +1 -1
- data/spec/cbc_ca_spec.rb +2 -2
- data/spec/conservative_ca_spec.rb +2 -2
- data/spec/digital-copyright_ca_spec.rb +3 -4
- data/spec/elections_ca_spec.rb +3 -3
- data/spec/greenparty_ca_spec.rb +5 -11
- data/spec/liberal_ca_spec.rb +5 -6
- data/spec/ndp_ca_spec.rb +4 -5
- data/spec/parl_gc_ca_spec.rb +0 -1
- data/spec/postal_code_spec.rb +7 -1
- data/spec/represent_spec.rb +3 -3
- data/spec/strategy_set_spec.rb +27 -19
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ae05fc85b84b282bab633a2f50fe5aea6758511
|
4
|
+
data.tar.gz: 7f7cf3d90f90e54368342a5077427b48f08fd422
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4f04a41569fce7b696d8865c9cac932e85d65428dec27862e9f09cbcfbdce1b74dedf209c178ecfc9b840a3bf1fdd1fba5039576ac71cf8a8cb157fffc0665d
|
7
|
+
data.tar.gz: b363b08cf0c3867180c033e761c7a891573cbbb384fe690909d2e9c2ddbf711d38bb5eeaea4a7cef7f5237ae90fef1c2a32f558a62515771d06f2123cf035253
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# GovKit-CA
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/govkit-ca.svg)](http://badge.fury.io/rb/govkit-ca)
|
3
4
|
[![Build Status](https://secure.travis-ci.org/opennorth/govkit-ca.png)](http://travis-ci.org/opennorth/govkit-ca)
|
4
5
|
[![Dependency Status](https://gemnasium.com/opennorth/govkit-ca.png)](https://gemnasium.com/opennorth/govkit-ca)
|
5
6
|
[![Coverage Status](https://coveralls.io/repos/opennorth/govkit-ca/badge.png?branch=master)](https://coveralls.io/r/opennorth/govkit-ca)
|
@@ -13,15 +14,41 @@ GovKit-CA is a Ruby gem that provides easy access to Canadian civic information
|
|
13
14
|
|
14
15
|
## Represent API
|
15
16
|
|
16
|
-
GovKit-CA provides a Represent API client.
|
17
|
+
GovKit-CA provides a [Represent API](http://represent.opennorth.ca/api/) client. First, create a client:
|
17
18
|
|
18
19
|
```ruby
|
19
20
|
require 'govkit-ca'
|
21
|
+
|
20
22
|
client = GovKit::CA::Represent.new
|
23
|
+
```
|
24
|
+
|
25
|
+
Send a request to the [`/postcodes` endpoint](http://represent.opennorth.ca/api/#postcode):
|
26
|
+
|
27
|
+
```ruby
|
21
28
|
client.postcodes('A1A1A1')
|
29
|
+
```
|
30
|
+
|
31
|
+
Send a request to the [`/representative-sets` endpoint](http://represent.opennorth.ca/api/#representativeset):
|
32
|
+
|
33
|
+
```ruby
|
22
34
|
client.representative_sets(limit: 0)
|
35
|
+
```
|
36
|
+
|
37
|
+
Send a request to the [`/representatives` endpoint](http://represent.opennorth.ca/api/#representative):
|
38
|
+
|
39
|
+
```ruby
|
23
40
|
client.representatives(representative_set: 'toronto-city-council')
|
41
|
+
```
|
42
|
+
|
43
|
+
Send a request to the [`/boundary-sets` endpoint](http://represent.opennorth.ca/api/#boundaryset):
|
44
|
+
|
45
|
+
```ruby
|
24
46
|
client.boundary_sets(limit: 0)
|
47
|
+
```
|
48
|
+
|
49
|
+
Send a request to the [`/boundaries` endpoint](http://represent.opennorth.ca/api/#boundary):
|
50
|
+
|
51
|
+
```ruby
|
25
52
|
client.boundaries(boundary_set: 'toronto-wards')
|
26
53
|
```
|
27
54
|
|
@@ -29,22 +56,29 @@ Read the full documentation on [RubyDoc.info](http://rubydoc.info/gems/govkit-ca
|
|
29
56
|
|
30
57
|
## Postal code to electoral district lookup
|
31
58
|
|
32
|
-
GovKit-CA provides an API for free postal code to electoral district lookups, using the
|
59
|
+
GovKit-CA provides an API for free postal code to electoral district lookups, using the sources:
|
33
60
|
|
34
61
|
* [elections.ca](http://elections.ca/)
|
35
|
-
* [cbc.ca](http://www.cbc.ca/)
|
36
|
-
* [ndp.ca](http://www.ndp.ca/)
|
37
|
-
* [digital-copyright.ca](http://www.digital-copyright.ca/)
|
38
|
-
* [liberal.ca](http://www.liberal.ca/)
|
39
|
-
* [greenparty.ca](http://www.greenparty.ca/)
|
40
62
|
* [parl.gc.ca](http://www.parl.gc.ca/)
|
41
63
|
* [conservative.ca](http://www.conservative.ca/)
|
64
|
+
* [greenparty.ca](http://www.greenparty.ca/)
|
65
|
+
* [liberal.ca](http://www.liberal.ca/)
|
66
|
+
* [ndp.ca](http://www.ndp.ca/)
|
67
|
+
* [cbc.ca](http://www.cbc.ca/)
|
68
|
+
* [digital-copyright.ca](http://www.digital-copyright.ca/)
|
69
|
+
|
70
|
+
These sources can be unstable or incorrect.
|
42
71
|
|
43
72
|
```ruby
|
44
73
|
require 'govkit-ca'
|
45
74
|
|
75
|
+
# Register the sources to use.
|
76
|
+
GovKit::CA::PostalCode::StrategySet.register(GovKit::CA::PostalCode::Strategy::ElectionsCa)
|
77
|
+
GovKit::CA::PostalCode::StrategySet.register(GovKit::CA::PostalCode::Strategy::LiberalCa)
|
78
|
+
GovKit::CA::PostalCode::StrategySet.register(GovKit::CA::PostalCode::Strategy::NDPCa)
|
79
|
+
|
46
80
|
GovKit::CA::PostalCode.find_electoral_districts_by_postal_code('A1A1A1') # [10007]
|
47
|
-
GovKit::CA::PostalCode.find_electoral_districts_by_postal_code('K0A1K0') # [
|
81
|
+
GovKit::CA::PostalCode.find_electoral_districts_by_postal_code('K0A1K0') # [35076]
|
48
82
|
GovKit::CA::PostalCode.find_electoral_districts_by_postal_code('H0H0H0') # raises GovKit::CA::ResourceNotFound
|
49
83
|
|
50
84
|
GovKit::CA::PostalCode.find_province_by_postal_code('A1A1A1') # "Newfoundland and Labrador"
|
data/lib/gov_kit-ca.rb
CHANGED
@@ -15,4 +15,14 @@ module GovKit
|
|
15
15
|
end
|
16
16
|
|
17
17
|
require 'gov_kit-ca/postal_code'
|
18
|
+
require 'gov_kit-ca/postal_code/strategy_set'
|
19
|
+
require 'gov_kit-ca/postal_code/strategy/base'
|
20
|
+
require 'gov_kit-ca/postal_code/strategy/cbc_ca'
|
21
|
+
require 'gov_kit-ca/postal_code/strategy/conservative_ca'
|
22
|
+
require 'gov_kit-ca/postal_code/strategy/digital-copyright_ca'
|
23
|
+
require 'gov_kit-ca/postal_code/strategy/elections_ca'
|
24
|
+
require 'gov_kit-ca/postal_code/strategy/greenparty_ca'
|
25
|
+
require 'gov_kit-ca/postal_code/strategy/liberal_ca'
|
26
|
+
require 'gov_kit-ca/postal_code/strategy/ndp_ca'
|
27
|
+
require 'gov_kit-ca/postal_code/strategy/parl_gc_ca'
|
18
28
|
require 'gov_kit-ca/represent'
|
@@ -76,29 +76,3 @@ module GovKit
|
|
76
76
|
end
|
77
77
|
end
|
78
78
|
end
|
79
|
-
|
80
|
-
require 'gov_kit-ca/postal_code/strategy_set'
|
81
|
-
require 'gov_kit-ca/postal_code/strategy/base'
|
82
|
-
|
83
|
-
# Only riding name and not implemented.
|
84
|
-
# require 'gov_kit-ca/postal_code/strategy/parl_gc_ca'
|
85
|
-
|
86
|
-
# Only one-to-one.
|
87
|
-
require 'gov_kit-ca/postal_code/strategy/elections_ca'
|
88
|
-
|
89
|
-
require 'gov_kit-ca/postal_code/strategy/ndp_ca'
|
90
|
-
|
91
|
-
# Only one-to-one.
|
92
|
-
require 'gov_kit-ca/postal_code/strategy/greenparty_ca'
|
93
|
-
|
94
|
-
# Only riding name if not held by a Conservative MP.
|
95
|
-
# require 'gov_kit-ca/postal_code/strategy/conservative_ca'
|
96
|
-
|
97
|
-
# 2014-02-12: Occasionally renders HTML instead of redirect.
|
98
|
-
# require 'gov_kit-ca/postal_code/strategy/liberal_ca'
|
99
|
-
|
100
|
-
# 2014-02-12: Broken until next election.
|
101
|
-
# require 'gov_kit-ca/postal_code/strategy/cbc_ca'
|
102
|
-
|
103
|
-
# Too many or too few ridings.
|
104
|
-
# require 'gov_kit-ca/postal_code/strategy/digital-copyright_ca'
|
@@ -5,7 +5,7 @@ module GovKit
|
|
5
5
|
class ElectionsCa < Base
|
6
6
|
base_uri 'elections.ca'
|
7
7
|
http_method :post
|
8
|
-
path '/Scripts/vis/FindED'
|
8
|
+
path '/Scripts/vis/FindED?L=e&PAGEID=20'
|
9
9
|
post_data 'CommonSearchTxt=<%= @postal_code %>'
|
10
10
|
|
11
11
|
private
|
@@ -18,8 +18,6 @@ module GovKit
|
|
18
18
|
!response.headers['location'][/EDNotFound|MultipleEDs/]
|
19
19
|
end
|
20
20
|
end
|
21
|
-
|
22
|
-
StrategySet.register ElectionsCa
|
23
21
|
end
|
24
22
|
end
|
25
23
|
end
|
@@ -4,8 +4,9 @@ module GovKit
|
|
4
4
|
module Strategy
|
5
5
|
class GreenPartyCa < Base
|
6
6
|
base_uri 'www.greenparty.ca'
|
7
|
-
http_method :
|
8
|
-
path '/
|
7
|
+
http_method :post
|
8
|
+
path '/en/party/find-your-riding'
|
9
|
+
post_data 'form_id=gpc_glue_riding_lookup_form&postal_code=<%= @postal_code %>'
|
9
10
|
|
10
11
|
private
|
11
12
|
|
@@ -14,11 +15,9 @@ module GovKit
|
|
14
15
|
end
|
15
16
|
|
16
17
|
def valid?
|
17
|
-
response.headers['location'] != 'http://www.greenparty.ca/
|
18
|
+
response.headers['location'] != 'http://www.greenparty.ca/en/party/find-your-riding'
|
18
19
|
end
|
19
20
|
end
|
20
|
-
|
21
|
-
StrategySet.register GreenPartyCa
|
22
21
|
end
|
23
22
|
end
|
24
23
|
end
|
@@ -6,20 +6,18 @@ module GovKit
|
|
6
6
|
follow_redirects true
|
7
7
|
base_uri 'www.liberal.ca'
|
8
8
|
http_method :get
|
9
|
-
path '/
|
9
|
+
path '/ridings/<%= @postal_code %>/'
|
10
10
|
|
11
11
|
private
|
12
12
|
|
13
13
|
def electoral_districts!
|
14
|
-
|
14
|
+
[response.parsed_response[%r{https://action.liberal.ca/en/donate/riding/(\d{5})}, 1]]
|
15
15
|
end
|
16
16
|
|
17
17
|
def valid?
|
18
|
-
!response.parsed_response["
|
18
|
+
!response.parsed_response["We couldn't find a riding for that postal code."]
|
19
19
|
end
|
20
20
|
end
|
21
|
-
|
22
|
-
StrategySet.register LiberalCa
|
23
21
|
end
|
24
22
|
end
|
25
23
|
end
|
@@ -13,7 +13,7 @@ module GovKit
|
|
13
13
|
# @param [Strategy::Base] strategy a strategy
|
14
14
|
# @return [Array<Strategy::Base>] the strategy set
|
15
15
|
def self.register(strategy)
|
16
|
-
strategies << strategy
|
16
|
+
strategies << strategy unless strategies.include?(strategy)
|
17
17
|
end
|
18
18
|
|
19
19
|
# Runs through the strategies in order of registration. Returns the
|
data/lib/gov_kit-ca/version.rb
CHANGED
data/spec/cbc_ca_spec.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
require 'gov_kit-ca/postal_code/strategy/cbc_ca'
|
3
2
|
|
4
3
|
describe GovKit::CA::PostalCode::Strategy::CBCCa do
|
5
4
|
describe '#electoral_districts', :broken => true do
|
6
5
|
it 'should return the electoral districts within a postal code' do
|
7
6
|
{ 'G0C2Y0' => [24019],
|
8
|
-
'T5S2B9' => [48015, 48017],
|
7
|
+
'T5S2B9' => [48015, 48017], # too many 48015
|
8
|
+
'B0J2L0' => [12002, 12007, 12008],
|
9
9
|
'K0A1K0' => [35025, 35052, 35063, 35064],
|
10
10
|
}.each do |postal_code,electoral_districts|
|
11
11
|
GovKit::CA::PostalCode::Strategy::CBCCa.new(postal_code).electoral_districts.should == electoral_districts
|
@@ -1,12 +1,10 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
require 'gov_kit-ca/postal_code/strategy/conservative_ca'
|
3
2
|
|
4
3
|
describe GovKit::CA::PostalCode::Strategy::ConservativeCa do
|
5
4
|
describe '#electoral_districts' do
|
6
5
|
it 'should return the electoral districts within a postal code' do
|
7
6
|
{ 'T1P1K1' => [48010],
|
8
7
|
'K0A1K0' => [35025, 35052, 35063],
|
9
|
-
# returns nothing for B0J2L0
|
10
8
|
}.each do |postal_code,electoral_districts|
|
11
9
|
GovKit::CA::PostalCode::Strategy::ConservativeCa.new(postal_code).electoral_districts.should == electoral_districts
|
12
10
|
end
|
@@ -14,6 +12,8 @@ describe GovKit::CA::PostalCode::Strategy::ConservativeCa do
|
|
14
12
|
|
15
13
|
it 'should (unfortunately) return false if a postal code is held by another party' do
|
16
14
|
GovKit::CA::PostalCode::Strategy::ConservativeCa.new('G0C2Y0').electoral_districts.should be_false
|
15
|
+
GovKit::CA::PostalCode::Strategy::ConservativeCa.new('T5S2B9').electoral_districts.should be_false
|
16
|
+
GovKit::CA::PostalCode::Strategy::ConservativeCa.new('B0J2L0').electoral_districts.should be_false
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'should return false if a postal code contains no electoral districts' do
|
@@ -1,13 +1,12 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
require 'gov_kit-ca/postal_code/strategy/digital-copyright_ca'
|
3
2
|
|
4
3
|
describe GovKit::CA::PostalCode::Strategy::DigitalCopyrightCa do
|
5
4
|
describe '#electoral_districts' do
|
6
5
|
it 'should return the electoral districts within a postal code' do
|
7
|
-
{ 'G0C2Y0' => [24019, 24039], #
|
8
|
-
'T5S2B9' => [48012, 48013, 48014, 48015, 48017, 48018], #
|
9
|
-
'K0A1K0' => [35025, 35052, 35063],
|
6
|
+
{ 'G0C2Y0' => [24019, 24039], # too many 24019
|
7
|
+
'T5S2B9' => [48012, 48013, 48014, 48015, 48017, 48018], # too many 48015
|
10
8
|
'B0J2L0' => [12002, 12007, 12008],
|
9
|
+
'K0A1K0' => [35025, 35052, 35063],
|
11
10
|
}.each do |postal_code,electoral_districts|
|
12
11
|
GovKit::CA::PostalCode::Strategy::DigitalCopyrightCa.new(postal_code).electoral_districts.should == electoral_districts
|
13
12
|
end
|
data/spec/elections_ca_spec.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
require 'gov_kit-ca/postal_code/strategy/elections_ca'
|
3
2
|
|
4
3
|
describe GovKit::CA::PostalCode::Strategy::ElectionsCa do
|
5
4
|
describe '#electoral_districts' do
|
6
5
|
it 'should return the electoral districts within a postal code' do
|
7
6
|
{ 'G0C2Y0' => [24019],
|
8
|
-
|
7
|
+
'T5S2B9' => [48015],
|
9
8
|
}.each do |postal_code,electoral_districts|
|
10
9
|
GovKit::CA::PostalCode::Strategy::ElectionsCa.new(postal_code).electoral_districts.should == electoral_districts
|
11
10
|
end
|
12
11
|
end
|
13
12
|
|
14
13
|
it 'should (unfortunately) return false if a postal code contains multiple electoral districts' do
|
15
|
-
GovKit::CA::PostalCode::Strategy::ElectionsCa.new('
|
14
|
+
GovKit::CA::PostalCode::Strategy::ElectionsCa.new('B0J2L0').electoral_districts.should be_false
|
15
|
+
GovKit::CA::PostalCode::Strategy::ElectionsCa.new('K0A1K0').electoral_districts.should be_false
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'should return false if a postal code contains no electoral districts' do
|
data/spec/greenparty_ca_spec.rb
CHANGED
@@ -1,24 +1,18 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
require 'gov_kit-ca/postal_code/strategy/greenparty_ca'
|
3
2
|
|
4
3
|
describe GovKit::CA::PostalCode::Strategy::GreenPartyCa do
|
5
4
|
describe '#electoral_districts' do
|
6
5
|
it 'should return the electoral districts within a postal code' do
|
7
|
-
{ 'G0C2Y0' => [
|
8
|
-
'T5S2B9' => [
|
6
|
+
{ 'G0C2Y0' => [24026],
|
7
|
+
'T5S2B9' => [48031],
|
8
|
+
'B0J2L0' => [12002], # too few
|
9
|
+
'K0A1K0' => [35076], # too few
|
10
|
+
'H0H0H0' => [24036], # wrong
|
9
11
|
}.each do |postal_code,electoral_districts|
|
10
12
|
GovKit::CA::PostalCode::Strategy::GreenPartyCa.new(postal_code).electoral_districts.should == electoral_districts
|
11
13
|
end
|
12
14
|
end
|
13
15
|
|
14
|
-
it 'should (unfortunately) return false if a postal code contains multiple electoral districts' do
|
15
|
-
GovKit::CA::PostalCode::Strategy::GreenPartyCa.new('K0A1K0').electoral_districts.should be_false # B0J2L0
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'should return false if a postal code contains no electoral districts' do
|
19
|
-
GovKit::CA::PostalCode::Strategy::GreenPartyCa.new('H0H0H0').electoral_districts.should be_false
|
20
|
-
end
|
21
|
-
|
22
16
|
it 'should return false if a postal code does not exist' do
|
23
17
|
GovKit::CA::PostalCode::Strategy::GreenPartyCa.new('X1B1B1').electoral_districts.should be_false
|
24
18
|
end
|
data/spec/liberal_ca_spec.rb
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
require 'gov_kit-ca/postal_code/strategy/liberal_ca'
|
3
2
|
|
4
3
|
describe GovKit::CA::PostalCode::Strategy::LiberalCa do
|
5
|
-
describe '#electoral_districts'
|
4
|
+
describe '#electoral_districts' do
|
6
5
|
it 'should return the electoral districts within a postal code' do
|
7
|
-
{ 'G0C2Y0' => [
|
8
|
-
'T5S2B9' => [
|
9
|
-
'
|
10
|
-
|
6
|
+
{ 'G0C2Y0' => [24026],
|
7
|
+
'T5S2B9' => [48031],
|
8
|
+
'B0J2L0' => [12002], # too few
|
9
|
+
'K0A1K0' => [35076], # too few
|
11
10
|
}.each do |postal_code,electoral_districts|
|
12
11
|
GovKit::CA::PostalCode::Strategy::LiberalCa.new(postal_code).electoral_districts.should == electoral_districts
|
13
12
|
end
|
data/spec/ndp_ca_spec.rb
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
require 'gov_kit-ca/postal_code/strategy/ndp_ca'
|
3
2
|
|
4
3
|
describe GovKit::CA::PostalCode::Strategy::NDPCa do
|
5
4
|
describe '#electoral_districts' do
|
6
5
|
it 'should return the electoral districts within a postal code' do
|
7
|
-
{ 'G0C2Y0' => [
|
8
|
-
'T5S2B9' => [
|
9
|
-
'
|
10
|
-
'
|
6
|
+
{ 'G0C2Y0' => [24026],
|
7
|
+
'T5S2B9' => [48020, 48031], # too many 48031
|
8
|
+
'B0J2L0' => [12002], # too few
|
9
|
+
'K0A1K0' => [35031, 35076, 35088],
|
11
10
|
}.each do |postal_code,electoral_districts|
|
12
11
|
GovKit::CA::PostalCode::Strategy::NDPCa.new(postal_code).electoral_districts.should == electoral_districts
|
13
12
|
end
|
data/spec/parl_gc_ca_spec.rb
CHANGED
data/spec/postal_code_spec.rb
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
3
|
describe GovKit::CA::PostalCode do
|
4
|
+
before :all do
|
5
|
+
GovKit::CA::PostalCode::StrategySet.register GovKit::CA::PostalCode::Strategy::ElectionsCa
|
6
|
+
GovKit::CA::PostalCode::StrategySet.register GovKit::CA::PostalCode::Strategy::LiberalCa
|
7
|
+
GovKit::CA::PostalCode::StrategySet.register GovKit::CA::PostalCode::Strategy::NDPCa
|
8
|
+
end
|
9
|
+
|
4
10
|
describe '#valid?' do
|
5
11
|
it 'should return false if the postal code is not properly formatted' do
|
6
12
|
[ 'A1A1A', # too short
|
@@ -30,7 +36,7 @@ describe GovKit::CA::PostalCode do
|
|
30
36
|
describe '#find_electoral_districts_by_postal_code' do
|
31
37
|
it 'should return the electoral districts within a postal code' do
|
32
38
|
{ 'A1A1A1' => [10007],
|
33
|
-
'K0A1K0' => [
|
39
|
+
'K0A1K0' => [35076],
|
34
40
|
}.each do |postal_code,electoral_districts|
|
35
41
|
subject.find_electoral_districts_by_postal_code(postal_code).should == electoral_districts
|
36
42
|
end
|
data/spec/represent_spec.rb
CHANGED
@@ -85,17 +85,17 @@ describe GovKit::CA::Represent do
|
|
85
85
|
it 'should accept an array of boundary sets' do
|
86
86
|
response = api.postcodes('A1A1A1', :sets => ['federal-electoral-districts', 'census-subdivisions'])
|
87
87
|
response.should be_a(Hash)
|
88
|
-
response['boundaries_centroid'].should have(2).items
|
88
|
+
(response['boundaries_centroid'] + response['boundaries_concordance']).should have(2).items
|
89
89
|
end
|
90
90
|
|
91
91
|
it 'should accept a comma-separated list of boundary sets' do
|
92
92
|
response = api.postcodes('A1A1A1', :sets => 'federal-electoral-districts,census-subdivisions')
|
93
93
|
response.should be_a(Hash)
|
94
|
-
response['boundaries_centroid'].should have(2).items
|
94
|
+
(response['boundaries_centroid'] + response['boundaries_concordance']).should have(2).items
|
95
95
|
end
|
96
96
|
|
97
97
|
it 'should raise an error if the postal code does not exist' do
|
98
|
-
expect{api.postcodes('foo')}.to raise_error(GovKit::CA::ResourceNotFound, "404 http://represent.opennorth.ca/postcodes/
|
98
|
+
expect{api.postcodes('foo')}.to raise_error(GovKit::CA::ResourceNotFound, "404 http://represent.opennorth.ca/postcodes/FOO/?")
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
data/spec/strategy_set_spec.rb
CHANGED
@@ -5,29 +5,37 @@ describe GovKit::CA::PostalCode::StrategySet do
|
|
5
5
|
Class.new
|
6
6
|
end
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
GovKit::CA::PostalCode::StrategySet.
|
11
|
-
|
12
|
-
|
13
|
-
# GovKit::CA::PostalCode::Strategy::LiberalCa,
|
14
|
-
GovKit::CA::PostalCode::Strategy::GreenPartyCa,
|
15
|
-
GovKit::CA::PostalCode::Strategy::CBCCa,
|
16
|
-
GovKit::CA::PostalCode::Strategy::ConservativeCa,
|
17
|
-
]
|
8
|
+
context 'with strategy set' do
|
9
|
+
before :all do
|
10
|
+
GovKit::CA::PostalCode::StrategySet.register GovKit::CA::PostalCode::Strategy::ElectionsCa
|
11
|
+
GovKit::CA::PostalCode::StrategySet.register GovKit::CA::PostalCode::Strategy::LiberalCa
|
12
|
+
GovKit::CA::PostalCode::StrategySet.register GovKit::CA::PostalCode::Strategy::NDPCa
|
18
13
|
end
|
19
|
-
end
|
20
14
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
15
|
+
describe '#strategies' do
|
16
|
+
it 'should return the strategies' do
|
17
|
+
GovKit::CA::PostalCode::StrategySet.strategies[0..4].should == [
|
18
|
+
GovKit::CA::PostalCode::Strategy::ElectionsCa,
|
19
|
+
GovKit::CA::PostalCode::Strategy::LiberalCa,
|
20
|
+
GovKit::CA::PostalCode::Strategy::NDPCa,
|
21
|
+
# GovKit::CA::PostalCode::Strategy::GreenPartyCa,
|
22
|
+
# GovKit::CA::PostalCode::Strategy::CBCCa,
|
23
|
+
# GovKit::CA::PostalCode::Strategy::ConservativeCa,
|
24
|
+
]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#register' do
|
29
|
+
it 'should append a strategy' do
|
30
|
+
GovKit::CA::PostalCode::StrategySet.register(strategy)
|
31
|
+
GovKit::CA::PostalCode::StrategySet.strategies.last.should == strategy
|
32
|
+
end
|
25
33
|
end
|
26
|
-
end
|
27
34
|
|
28
|
-
|
29
|
-
|
30
|
-
|
35
|
+
describe '#run' do
|
36
|
+
it 'should run the strategies' do
|
37
|
+
GovKit::CA::PostalCode::StrategySet.run('A1A1A1').should == [10007]
|
38
|
+
end
|
31
39
|
end
|
32
40
|
end
|
33
41
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: govkit-ca
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Open North
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|