govkit-ca 0.0.11 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +2 -0
- data/.travis.yml +1 -1
- data/Gemfile +2 -2
- data/README.md +9 -13
- data/govkit-ca.gemspec +5 -6
- data/lib/gov_kit-ca/postal_code.rb +4 -4
- data/lib/gov_kit-ca/postal_code/strategy/cbc_ca.rb +1 -1
- data/lib/gov_kit-ca/postal_code/strategy/elections_ca.rb +4 -4
- data/lib/gov_kit-ca/postal_code/strategy/greenparty_ca.rb +1 -1
- data/lib/gov_kit-ca/represent.rb +7 -7
- data/lib/gov_kit-ca/version.rb +1 -1
- data/lib/{data/rid_to_edid.yml → rid_to_edid.yml} +0 -0
- data/spec/cbc_ca_spec.rb +4 -4
- data/spec/conservative_ca_spec.rb +7 -7
- data/spec/digital-copyright_ca_spec.rb +4 -4
- data/spec/elections_ca_spec.rb +6 -6
- data/spec/greenparty_ca_spec.rb +12 -6
- data/spec/liberal_ca_spec.rb +4 -4
- data/spec/ndp_ca_spec.rb +4 -4
- data/spec/parl_gc_ca_spec.rb +1 -1
- data/spec/postal_code_spec.rb +10 -10
- data/spec/represent_spec.rb +87 -87
- data/spec/spec_helper.rb +5 -8
- data/spec/strategy_set_spec.rb +7 -7
- data/tasks/tasks.rb +1 -1
- metadata +19 -20
- data/spec/spec.opts +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 60277f47ef35ddd41b20164989eb02e673e0b6ff
|
4
|
+
data.tar.gz: 5b1c0312a70afa33193bc0a676959d18755e5c02
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8013b9e8b88f57696fca95e51009b4e5a787170eb7873b2db2c105213f9a8729433ddd5204063f79aa832a58c7a84d0194ae5f424280129a32a81604aef656ce
|
7
|
+
data.tar.gz: cb0376eba458d2778c83a9a1040838068ffb188b878879c7c495e8e6d33c41919c76e992f26b054bdddbe25d7798063ef2404ee2a188958953c5eaf458136b73
|
data/.rspec
ADDED
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# GovKit-CA
|
2
2
|
|
3
|
-
[![Gem Version](https://badge.fury.io/rb/govkit-ca.svg)](
|
4
|
-
[![Build Status](https://secure.travis-ci.org/opennorth/govkit-ca.png)](
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/govkit-ca.svg)](https://badge.fury.io/rb/govkit-ca)
|
4
|
+
[![Build Status](https://secure.travis-ci.org/opennorth/govkit-ca.png)](https://travis-ci.org/opennorth/govkit-ca)
|
5
5
|
[![Dependency Status](https://gemnasium.com/opennorth/govkit-ca.png)](https://gemnasium.com/opennorth/govkit-ca)
|
6
6
|
[![Coverage Status](https://coveralls.io/repos/opennorth/govkit-ca/badge.png?branch=master)](https://coveralls.io/r/opennorth/govkit-ca)
|
7
7
|
[![Code Climate](https://codeclimate.com/github/opennorth/govkit-ca.png)](https://codeclimate.com/github/opennorth/govkit-ca)
|
@@ -14,7 +14,7 @@ GovKit-CA is a Ruby gem that provides easy access to Canadian civic information
|
|
14
14
|
|
15
15
|
## Represent API
|
16
16
|
|
17
|
-
GovKit-CA provides a [Represent API](
|
17
|
+
GovKit-CA provides a [Represent API](https://represent.opennorth.ca/api/) client. First, create a client:
|
18
18
|
|
19
19
|
```ruby
|
20
20
|
require 'govkit-ca'
|
@@ -22,31 +22,31 @@ require 'govkit-ca'
|
|
22
22
|
client = GovKit::CA::Represent.new
|
23
23
|
```
|
24
24
|
|
25
|
-
Send a request to the [`/postcodes` endpoint](
|
25
|
+
Send a request to the [`/postcodes` endpoint](https://represent.opennorth.ca/api/#postcode):
|
26
26
|
|
27
27
|
```ruby
|
28
28
|
client.postcodes('A1A1A1')
|
29
29
|
```
|
30
30
|
|
31
|
-
Send a request to the [`/representative-sets` endpoint](
|
31
|
+
Send a request to the [`/representative-sets` endpoint](https://represent.opennorth.ca/api/#representativeset):
|
32
32
|
|
33
33
|
```ruby
|
34
34
|
client.representative_sets(limit: 0)
|
35
35
|
```
|
36
36
|
|
37
|
-
Send a request to the [`/representatives` endpoint](
|
37
|
+
Send a request to the [`/representatives` endpoint](https://represent.opennorth.ca/api/#representative):
|
38
38
|
|
39
39
|
```ruby
|
40
40
|
client.representatives(representative_set: 'toronto-city-council')
|
41
41
|
```
|
42
42
|
|
43
|
-
Send a request to the [`/boundary-sets` endpoint](
|
43
|
+
Send a request to the [`/boundary-sets` endpoint](https://represent.opennorth.ca/api/#boundaryset):
|
44
44
|
|
45
45
|
```ruby
|
46
46
|
client.boundary_sets(limit: 0)
|
47
47
|
```
|
48
48
|
|
49
|
-
Send a request to the [`/boundaries` endpoint](
|
49
|
+
Send a request to the [`/boundaries` endpoint](https://represent.opennorth.ca/api/#boundary):
|
50
50
|
|
51
51
|
```ruby
|
52
52
|
client.boundaries(boundary_set: 'toronto-wards')
|
@@ -62,7 +62,7 @@ GovKit-CA provides an API for free postal code to electoral district lookups, us
|
|
62
62
|
* [parl.gc.ca](http://www.parl.gc.ca/)
|
63
63
|
* [conservative.ca](http://www.conservative.ca/)
|
64
64
|
* [greenparty.ca](http://www.greenparty.ca/)
|
65
|
-
* [liberal.ca](
|
65
|
+
* [liberal.ca](https://www.liberal.ca/)
|
66
66
|
* [ndp.ca](http://www.ndp.ca/)
|
67
67
|
* [cbc.ca](http://www.cbc.ca/)
|
68
68
|
* [digital-copyright.ca](http://www.digital-copyright.ca/)
|
@@ -94,8 +94,4 @@ GovKit-CA will raise `GovKit::CA::ResourceNotFound` if the electoral districts w
|
|
94
94
|
|
95
95
|
GovKit-CA interoperates with the [Participatory Politics Foundation](http://www.participatorypolitics.org/)'s [GovKit](https://github.com/opengovernment/govkit). GovKit-CA is not affiliated with the Participatory Politics Foundation or GovKit.
|
96
96
|
|
97
|
-
## Bugs? Questions?
|
98
|
-
|
99
|
-
This gem's main repository is on GitHub: [http://github.com/opennorth/govkit-ca](http://github.com/opennorth/govkit-ca), where your contributions, forks, bug reports, feature requests, and feedback are greatly welcomed.
|
100
|
-
|
101
97
|
Copyright (c) 2011 Open North Inc., released under the MIT license
|
data/govkit-ca.gemspec
CHANGED
@@ -7,11 +7,9 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.platform = Gem::Platform::RUBY
|
8
8
|
s.authors = ["Open North"]
|
9
9
|
s.email = ["info@opennorth.ca"]
|
10
|
-
s.homepage = "
|
10
|
+
s.homepage = "https://github.com/opennorth/govkit-ca"
|
11
11
|
s.summary = %q{Easy access to Canadian civic data around the web}
|
12
12
|
s.description = %q{GovKit-CA lets you quickly get encapsulated Ruby objects for Canadian civic data.}
|
13
|
-
|
14
|
-
s.rubyforge_project = "govkit-ca"
|
15
13
|
s.license = 'MIT'
|
16
14
|
|
17
15
|
s.files = `git ls-files`.split("\n")
|
@@ -22,9 +20,10 @@ Gem::Specification.new do |s|
|
|
22
20
|
s.add_runtime_dependency('faraday')
|
23
21
|
s.add_runtime_dependency('httparty', '~> 0.10.0')
|
24
22
|
s.add_runtime_dependency('nokogiri', '~> 1.6.0')
|
25
|
-
|
26
|
-
s.add_development_dependency('rspec', '~> 2.6.0')
|
27
|
-
s.add_development_dependency('rake', '~> 10.1.0')
|
23
|
+
|
28
24
|
s.add_development_dependency('coveralls')
|
25
|
+
s.add_development_dependency('json', '~> 1.8') # to silence coveralls warning
|
26
|
+
s.add_development_dependency('rake')
|
27
|
+
s.add_development_dependency('rspec', '~> 3.1')
|
29
28
|
s.add_development_dependency('mime-types', '~> 1.16')
|
30
29
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
module GovKit
|
2
2
|
module CA
|
3
3
|
# A collection of postal code helpers.
|
4
|
-
# @see
|
4
|
+
# @see https://en.wikipedia.org/wiki/Postal_codes_in_Canada Postal codes in Canada
|
5
5
|
module PostalCode
|
6
6
|
# @param [String] postal_code a postal code
|
7
7
|
# @return [Boolean] whether the postal code is properly formatted
|
8
|
-
# @see
|
8
|
+
# @see https://en.wikipedia.org/wiki/Postal_codes_in_Canada#Number_of_possible_postal_codes Possible postal codes
|
9
9
|
def self.valid?(postal_code)
|
10
10
|
!!postal_code.match(/\A[ABCEGHJKLMNPRSTVXY][0-9][ABCEGHJKLMNPRSTVWXYZ][0-9][ABCEGHJKLMNPRSTVWXYZ][0-9]\z/)
|
11
11
|
end
|
@@ -32,7 +32,7 @@ module GovKit
|
|
32
32
|
# @param [String] postal_code a postal code
|
33
33
|
# @return [String] the province that the postal code belongs to
|
34
34
|
# @raise [ResourceNotFound] if the province cannot be determined
|
35
|
-
# @see
|
35
|
+
# @see https://en.wikipedia.org/wiki/List_of_postal_codes_in_Canada List of postal codes in Canada
|
36
36
|
def self.find_province_by_postal_code(postal_code)
|
37
37
|
case format_postal_code(postal_code)
|
38
38
|
when /\AA/
|
@@ -55,7 +55,7 @@ module GovKit
|
|
55
55
|
'Alberta'
|
56
56
|
when /\AV/
|
57
57
|
'British Columbia'
|
58
|
-
#
|
58
|
+
# https://en.wikipedia.org/wiki/List_of_X_postal_codes_of_Canada
|
59
59
|
when /\AX0[ABC]/
|
60
60
|
'Nunavut'
|
61
61
|
when /\AX0[EG]/, /\AX1A/
|
@@ -21,7 +21,7 @@ module GovKit
|
|
21
21
|
# canonical electoral district ID.
|
22
22
|
# @return [Hash] a map of cbc.ca riding ID to electoral district ID
|
23
23
|
def self.rid_to_edid
|
24
|
-
@@yml ||= YAML.load_file(File.expand_path('../../../../
|
24
|
+
@@yml ||= YAML.load_file(File.expand_path('../../../../rid_to_edid.yml', __FILE__))
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
@@ -5,17 +5,17 @@ module GovKit
|
|
5
5
|
class ElectionsCa < Base
|
6
6
|
base_uri 'elections.ca'
|
7
7
|
http_method :post
|
8
|
-
path '/Scripts/vis/FindED?L=e&PAGEID=20'
|
9
|
-
post_data 'CommonSearchTxt=<%= @postal_code
|
8
|
+
path '/Scripts/vis/FindED?L=e&QID=-1&PAGEID=20'
|
9
|
+
post_data 'CommonSearchTxt=<%= @postal_code %>&CivicSearchTxt=1'
|
10
10
|
|
11
11
|
private
|
12
12
|
|
13
13
|
def electoral_districts!
|
14
|
-
[
|
14
|
+
[response.headers['location'][/\bED=(\d{5})&/, 1]]
|
15
15
|
end
|
16
16
|
|
17
17
|
def valid?
|
18
|
-
!response.headers['location'][/
|
18
|
+
!response.headers['location']['/ShowStreets?']
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
data/lib/gov_kit-ca/represent.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module GovKit
|
2
2
|
module CA
|
3
3
|
# A Ruby wrapper for the Represent API.
|
4
|
-
# @see
|
4
|
+
# @see https://represent.opennorth.ca/api/
|
5
5
|
class Represent
|
6
6
|
# @param [Faraday::Connection] connection a Faraday connection
|
7
7
|
def initialize(connection = nil)
|
@@ -14,7 +14,7 @@ module GovKit
|
|
14
14
|
# @option opts [String] :boundary_set a boundary set
|
15
15
|
# @option opts [Integer] :limit
|
16
16
|
# @option opts [Integer] :offset
|
17
|
-
# @see
|
17
|
+
# @see https://represent.opennorth.ca/api/#boundaryset
|
18
18
|
def boundary_sets(opts = {})
|
19
19
|
request(['boundary-sets', opts.delete(:boundary_set)], opts)
|
20
20
|
end
|
@@ -31,7 +31,7 @@ module GovKit
|
|
31
31
|
# @option opts [String] :intersects a boundary
|
32
32
|
# @option opts [Integer] :limit
|
33
33
|
# @option opts [Integer] :offset
|
34
|
-
# @see
|
34
|
+
# @see https://represent.opennorth.ca/api/#boundary
|
35
35
|
def boundaries(opts = {})
|
36
36
|
if Array === opts[:sets]
|
37
37
|
opts[:sets] = opts[:sets].join(',')
|
@@ -54,7 +54,7 @@ module GovKit
|
|
54
54
|
# @option opts [Array<String>,String] :sets comma-separated list of boundary sets
|
55
55
|
# @option opts [Integer] :limit
|
56
56
|
# @option opts [Integer] :offset
|
57
|
-
# @see
|
57
|
+
# @see https://represent.opennorth.ca/api/#postcode
|
58
58
|
def postcodes(postcode, opts = {})
|
59
59
|
if Array === opts[:sets]
|
60
60
|
opts[:sets] = opts[:sets].join(',')
|
@@ -68,7 +68,7 @@ module GovKit
|
|
68
68
|
# @option opts [String] :representative_set a representative set
|
69
69
|
# @option opts [Integer] :limit
|
70
70
|
# @option opts [Integer] :offset
|
71
|
-
# @see
|
71
|
+
# @see https://represent.opennorth.ca/api/#representativeset
|
72
72
|
def representative_sets(opts = {})
|
73
73
|
request ['representative-sets', opts.delete(:representative_set)], opts
|
74
74
|
end
|
@@ -81,7 +81,7 @@ module GovKit
|
|
81
81
|
# @option opts [Array<Strong>,String] :districts a comma-separated list of boundaries
|
82
82
|
# @option opts [Integer] :limit
|
83
83
|
# @option opts [Integer] :offset
|
84
|
-
# @see
|
84
|
+
# @see https://represent.opennorth.ca/api/#representative
|
85
85
|
def representatives(opts = {})
|
86
86
|
if Array === opts[:point]
|
87
87
|
opts[:point] = opts[:point].join(',')
|
@@ -96,7 +96,7 @@ module GovKit
|
|
96
96
|
|
97
97
|
def request(parts, opts)
|
98
98
|
begin
|
99
|
-
url = "
|
99
|
+
url = "https://represent.opennorth.ca/#{parts.compact.join('/')}/"
|
100
100
|
response = @client.get(url, opts)
|
101
101
|
case response.status
|
102
102
|
when 200
|
data/lib/gov_kit-ca/version.rb
CHANGED
File without changes
|
data/spec/cbc_ca_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
|
-
describe GovKit::CA::PostalCode::Strategy::CBCCa do
|
3
|
+
RSpec.describe GovKit::CA::PostalCode::Strategy::CBCCa do
|
4
4
|
describe '#electoral_districts', :broken => true do
|
5
5
|
it 'should return the electoral districts within a postal code' do
|
6
6
|
{ 'G0C2Y0' => [24019],
|
@@ -8,16 +8,16 @@ describe GovKit::CA::PostalCode::Strategy::CBCCa do
|
|
8
8
|
'B0J2L0' => [12002, 12007, 12008],
|
9
9
|
'K0A1K0' => [35025, 35052, 35063, 35064],
|
10
10
|
}.each do |postal_code,electoral_districts|
|
11
|
-
GovKit::CA::PostalCode::Strategy::CBCCa.new(postal_code).electoral_districts.
|
11
|
+
expect(GovKit::CA::PostalCode::Strategy::CBCCa.new(postal_code).electoral_districts).to eq(electoral_districts)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'should return false if a postal code contains no electoral districts' do
|
16
|
-
GovKit::CA::PostalCode::Strategy::CBCCa.new('H0H0H0').electoral_districts.
|
16
|
+
expect(GovKit::CA::PostalCode::Strategy::CBCCa.new('H0H0H0').electoral_districts).to eq(false)
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'should return false if a postal code does not exist' do
|
20
|
-
GovKit::CA::PostalCode::Strategy::CBCCa.new('X1B1B1').electoral_districts.
|
20
|
+
expect(GovKit::CA::PostalCode::Strategy::CBCCa.new('X1B1B1').electoral_districts).to eq(false)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
@@ -1,27 +1,27 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
|
-
describe GovKit::CA::PostalCode::Strategy::ConservativeCa do
|
3
|
+
RSpec.describe GovKit::CA::PostalCode::Strategy::ConservativeCa do
|
4
4
|
describe '#electoral_districts' do
|
5
5
|
it 'should return the electoral districts within a postal code' do
|
6
6
|
{ 'T1P1K1' => [48010],
|
7
7
|
'K0A1K0' => [35025, 35052, 35063],
|
8
8
|
}.each do |postal_code,electoral_districts|
|
9
|
-
GovKit::CA::PostalCode::Strategy::ConservativeCa.new(postal_code).electoral_districts.
|
9
|
+
expect(GovKit::CA::PostalCode::Strategy::ConservativeCa.new(postal_code).electoral_districts).to eq(electoral_districts)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'should (unfortunately) return false if a postal code is held by another party' do
|
14
|
-
GovKit::CA::PostalCode::Strategy::ConservativeCa.new('G0C2Y0').electoral_districts.
|
15
|
-
GovKit::CA::PostalCode::Strategy::ConservativeCa.new('T5S2B9').electoral_districts.
|
16
|
-
GovKit::CA::PostalCode::Strategy::ConservativeCa.new('B0J2L0').electoral_districts.
|
14
|
+
expect(GovKit::CA::PostalCode::Strategy::ConservativeCa.new('G0C2Y0').electoral_districts).to eq(false)
|
15
|
+
expect(GovKit::CA::PostalCode::Strategy::ConservativeCa.new('T5S2B9').electoral_districts).to eq(false)
|
16
|
+
expect(GovKit::CA::PostalCode::Strategy::ConservativeCa.new('B0J2L0').electoral_districts).to eq(false)
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'should return false if a postal code contains no electoral districts' do
|
20
|
-
GovKit::CA::PostalCode::Strategy::ConservativeCa.new('H0H0H0').electoral_districts.
|
20
|
+
expect(GovKit::CA::PostalCode::Strategy::ConservativeCa.new('H0H0H0').electoral_districts).to eq(false)
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'should return false if a postal code does not exist' do
|
24
|
-
GovKit::CA::PostalCode::Strategy::ConservativeCa.new('X1B1B1').electoral_districts.
|
24
|
+
expect(GovKit::CA::PostalCode::Strategy::ConservativeCa.new('X1B1B1').electoral_districts).to eq(false)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
|
-
describe GovKit::CA::PostalCode::Strategy::DigitalCopyrightCa do
|
3
|
+
RSpec.describe GovKit::CA::PostalCode::Strategy::DigitalCopyrightCa do
|
4
4
|
describe '#electoral_districts' do
|
5
5
|
it 'should return the electoral districts within a postal code' do
|
6
6
|
{ 'G0C2Y0' => [24019, 24039], # too many 24019
|
@@ -8,16 +8,16 @@ describe GovKit::CA::PostalCode::Strategy::DigitalCopyrightCa do
|
|
8
8
|
'B0J2L0' => [12002, 12007, 12008],
|
9
9
|
'K0A1K0' => [35025, 35052, 35063],
|
10
10
|
}.each do |postal_code,electoral_districts|
|
11
|
-
GovKit::CA::PostalCode::Strategy::DigitalCopyrightCa.new(postal_code).electoral_districts.
|
11
|
+
expect(GovKit::CA::PostalCode::Strategy::DigitalCopyrightCa.new(postal_code).electoral_districts).to eq(electoral_districts)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'should return false if a postal code contains no electoral districts' do
|
16
|
-
GovKit::CA::PostalCode::Strategy::DigitalCopyrightCa.new('H0H0H0').electoral_districts.
|
16
|
+
expect(GovKit::CA::PostalCode::Strategy::DigitalCopyrightCa.new('H0H0H0').electoral_districts).to eq(false)
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'should return false if a postal code does not exist' do
|
20
|
-
GovKit::CA::PostalCode::Strategy::DigitalCopyrightCa.new('X1B1B1').electoral_districts.
|
20
|
+
expect(GovKit::CA::PostalCode::Strategy::DigitalCopyrightCa.new('X1B1B1').electoral_districts).to eq(false)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
data/spec/elections_ca_spec.rb
CHANGED
@@ -1,26 +1,26 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
|
-
describe GovKit::CA::PostalCode::Strategy::ElectionsCa do
|
3
|
+
RSpec.describe GovKit::CA::PostalCode::Strategy::ElectionsCa do
|
4
4
|
describe '#electoral_districts' do
|
5
5
|
it 'should return the electoral districts within a postal code' do
|
6
6
|
{ 'G0C2Y0' => [24019],
|
7
7
|
'T5S2B9' => [48015],
|
8
8
|
}.each do |postal_code,electoral_districts|
|
9
|
-
GovKit::CA::PostalCode::Strategy::ElectionsCa.new(postal_code).electoral_districts.
|
9
|
+
expect(GovKit::CA::PostalCode::Strategy::ElectionsCa.new(postal_code).electoral_districts).to eq(electoral_districts)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'should (unfortunately) return false if a postal code contains multiple electoral districts' do
|
14
|
-
GovKit::CA::PostalCode::Strategy::ElectionsCa.new('B0J2L0').electoral_districts.
|
15
|
-
GovKit::CA::PostalCode::Strategy::ElectionsCa.new('K0A1K0').electoral_districts.
|
14
|
+
expect(GovKit::CA::PostalCode::Strategy::ElectionsCa.new('B0J2L0').electoral_districts).to eq(false)
|
15
|
+
expect(GovKit::CA::PostalCode::Strategy::ElectionsCa.new('K0A1K0').electoral_districts).to eq(false)
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'should return false if a postal code contains no electoral districts' do
|
19
|
-
GovKit::CA::PostalCode::Strategy::ElectionsCa.new('H0H0H0').electoral_districts.
|
19
|
+
expect(GovKit::CA::PostalCode::Strategy::ElectionsCa.new('H0H0H0').electoral_districts).to eq(false)
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'should return false if a postal code does not exist' do
|
23
|
-
GovKit::CA::PostalCode::Strategy::ElectionsCa.new('X1B1B1').electoral_districts.
|
23
|
+
expect(GovKit::CA::PostalCode::Strategy::ElectionsCa.new('X1B1B1').electoral_districts).to eq(false)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
data/spec/greenparty_ca_spec.rb
CHANGED
@@ -1,20 +1,26 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
|
-
describe GovKit::CA::PostalCode::Strategy::GreenPartyCa do
|
3
|
+
RSpec.describe GovKit::CA::PostalCode::Strategy::GreenPartyCa do
|
4
4
|
describe '#electoral_districts' do
|
5
5
|
it 'should return the electoral districts within a postal code' do
|
6
6
|
{ 'G0C2Y0' => [24026],
|
7
7
|
'T5S2B9' => [48031],
|
8
|
-
'B0J2L0' => [12002], # too few
|
9
|
-
'K0A1K0' => [35076], # too few
|
10
|
-
'H0H0H0' => [24036], # wrong
|
11
8
|
}.each do |postal_code,electoral_districts|
|
12
|
-
GovKit::CA::PostalCode::Strategy::GreenPartyCa.new(postal_code).electoral_districts.
|
9
|
+
expect(GovKit::CA::PostalCode::Strategy::GreenPartyCa.new(postal_code).electoral_districts).to eq(electoral_districts)
|
13
10
|
end
|
14
11
|
end
|
15
12
|
|
13
|
+
it 'should (unfortunately) return false if a postal code contains multiple electoral districts' do
|
14
|
+
expect(GovKit::CA::PostalCode::Strategy::GreenPartyCa.new('B0J2L0').electoral_districts).to eq(false)
|
15
|
+
expect(GovKit::CA::PostalCode::Strategy::GreenPartyCa.new('K0A1K0').electoral_districts).to eq(false)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should return false if a postal code contains no electoral districts' do
|
19
|
+
expect(GovKit::CA::PostalCode::Strategy::GreenPartyCa.new('H0H0H0').electoral_districts).to eq(false)
|
20
|
+
end
|
21
|
+
|
16
22
|
it 'should return false if a postal code does not exist' do
|
17
|
-
GovKit::CA::PostalCode::Strategy::GreenPartyCa.new('X1B1B1').electoral_districts.
|
23
|
+
expect(GovKit::CA::PostalCode::Strategy::GreenPartyCa.new('X1B1B1').electoral_districts).to eq(false)
|
18
24
|
end
|
19
25
|
end
|
20
26
|
end
|
data/spec/liberal_ca_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
|
-
describe GovKit::CA::PostalCode::Strategy::LiberalCa do
|
3
|
+
RSpec.describe GovKit::CA::PostalCode::Strategy::LiberalCa do
|
4
4
|
describe '#electoral_districts' do
|
5
5
|
it 'should return the electoral districts within a postal code' do
|
6
6
|
{ 'G0C2Y0' => [24026],
|
@@ -8,16 +8,16 @@ describe GovKit::CA::PostalCode::Strategy::LiberalCa do
|
|
8
8
|
'B0J2L0' => [12002], # too few
|
9
9
|
'K0A1K0' => [35076], # too few
|
10
10
|
}.each do |postal_code,electoral_districts|
|
11
|
-
GovKit::CA::PostalCode::Strategy::LiberalCa.new(postal_code).electoral_districts.
|
11
|
+
expect(GovKit::CA::PostalCode::Strategy::LiberalCa.new(postal_code).electoral_districts).to eq(electoral_districts)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'should return false if a postal code contains no electoral districts' do
|
16
|
-
GovKit::CA::PostalCode::Strategy::LiberalCa.new('H0H0H0').electoral_districts.
|
16
|
+
expect(GovKit::CA::PostalCode::Strategy::LiberalCa.new('H0H0H0').electoral_districts).to eq(false)
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'should return false if a postal code does not exist' do
|
20
|
-
GovKit::CA::PostalCode::Strategy::LiberalCa.new('X1B1B1').electoral_districts.
|
20
|
+
expect(GovKit::CA::PostalCode::Strategy::LiberalCa.new('X1B1B1').electoral_districts).to eq(false)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
data/spec/ndp_ca_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
|
-
describe GovKit::CA::PostalCode::Strategy::NDPCa do
|
3
|
+
RSpec.describe GovKit::CA::PostalCode::Strategy::NDPCa do
|
4
4
|
describe '#electoral_districts' do
|
5
5
|
it 'should return the electoral districts within a postal code' do
|
6
6
|
{ 'G0C2Y0' => [24026],
|
@@ -8,16 +8,16 @@ describe GovKit::CA::PostalCode::Strategy::NDPCa do
|
|
8
8
|
'B0J2L0' => [12002], # too few
|
9
9
|
'K0A1K0' => [35031, 35076, 35088],
|
10
10
|
}.each do |postal_code,electoral_districts|
|
11
|
-
GovKit::CA::PostalCode::Strategy::NDPCa.new(postal_code).electoral_districts.
|
11
|
+
expect(GovKit::CA::PostalCode::Strategy::NDPCa.new(postal_code).electoral_districts).to eq(electoral_districts)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'should return false if a postal code contains no electoral districts' do
|
16
|
-
GovKit::CA::PostalCode::Strategy::NDPCa.new('H0H0H0').electoral_districts.
|
16
|
+
expect(GovKit::CA::PostalCode::Strategy::NDPCa.new('H0H0H0').electoral_districts).to eq(false)
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'should return false if a postal code does not exist' do
|
20
|
-
GovKit::CA::PostalCode::Strategy::NDPCa.new('X1B1B1').electoral_districts.
|
20
|
+
expect(GovKit::CA::PostalCode::Strategy::NDPCa.new('X1B1B1').electoral_districts).to eq(false)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
data/spec/parl_gc_ca_spec.rb
CHANGED
data/spec/postal_code_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
|
-
describe GovKit::CA::PostalCode do
|
3
|
+
RSpec.describe GovKit::CA::PostalCode do
|
4
4
|
before :all do
|
5
5
|
GovKit::CA::PostalCode::StrategySet.register GovKit::CA::PostalCode::Strategy::ElectionsCa
|
6
6
|
GovKit::CA::PostalCode::StrategySet.register GovKit::CA::PostalCode::Strategy::LiberalCa
|
@@ -19,7 +19,7 @@ describe GovKit::CA::PostalCode do
|
|
19
19
|
'Q1Q1Q1', # Q as letter
|
20
20
|
'a1a1a1', # lowercase
|
21
21
|
].each do |postal_code|
|
22
|
-
subject.valid?(postal_code).
|
22
|
+
expect(subject.valid?(postal_code)).to eq(false)
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -28,7 +28,7 @@ describe GovKit::CA::PostalCode do
|
|
28
28
|
'H0H0H0', # doesn't exist
|
29
29
|
'A1A1A1', # does exist
|
30
30
|
].each do |postal_code|
|
31
|
-
subject.valid?(postal_code).
|
31
|
+
expect(subject.valid?(postal_code)).to eq(true)
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
@@ -38,16 +38,16 @@ describe GovKit::CA::PostalCode do
|
|
38
38
|
{ 'A1A1A1' => [10007],
|
39
39
|
'K0A1K0' => [35076],
|
40
40
|
}.each do |postal_code,electoral_districts|
|
41
|
-
subject.find_electoral_districts_by_postal_code(postal_code).
|
41
|
+
expect(subject.find_electoral_districts_by_postal_code(postal_code)).to eq(electoral_districts)
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
45
|
it 'should raise an error if the postal code cannot be determined' do
|
46
|
-
lambda{subject.find_electoral_districts_by_postal_code('H0H0H0')}.
|
46
|
+
expect(lambda{subject.find_electoral_districts_by_postal_code('H0H0H0')}).to raise_error(GovKit::CA::ResourceNotFound)
|
47
47
|
end
|
48
48
|
|
49
49
|
it 'should raise an error if the postal code is invalid' do
|
50
|
-
lambda{subject.find_electoral_districts_by_postal_code('AAAAAA')}.
|
50
|
+
expect(lambda{subject.find_electoral_districts_by_postal_code('AAAAAA')}).to raise_error(GovKit::CA::InvalidRequest)
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
@@ -76,19 +76,19 @@ describe GovKit::CA::PostalCode do
|
|
76
76
|
'X0G' => 'Northwest Territories',
|
77
77
|
'X1A' => 'Northwest Territories',
|
78
78
|
'Y' => 'Yukon',
|
79
|
-
}.each do |postal_code,
|
80
|
-
subject.find_province_by_postal_code(postal_code).
|
79
|
+
}.each do |postal_code,province|
|
80
|
+
expect(subject.find_province_by_postal_code(postal_code)).to eq(province)
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
84
|
it 'should raise an error if the province cannot be determined' do
|
85
|
-
lambda{subject.find_province_by_postal_code('X1B1B1')}.
|
85
|
+
expect(lambda{subject.find_province_by_postal_code('X1B1B1')}).to raise_error(GovKit::CA::ResourceNotFound)
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
89
89
|
describe '#format_postal_code' do
|
90
90
|
it 'should format a postal code' do
|
91
|
-
subject.format_postal_code("+a1a 1a1\n").
|
91
|
+
expect(subject.format_postal_code("+a1a 1a1\n")).to eq('A1A1A1')
|
92
92
|
end
|
93
93
|
end
|
94
94
|
end
|
data/spec/represent_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
|
-
describe GovKit::CA::Represent do
|
3
|
+
RSpec.describe GovKit::CA::Represent do
|
4
4
|
describe '#boundary_sets' do
|
5
5
|
let :api do
|
6
6
|
GovKit::CA::Represent.new
|
@@ -16,27 +16,27 @@ describe GovKit::CA::Represent do
|
|
16
16
|
|
17
17
|
it 'should return boundary sets' do
|
18
18
|
response = api.boundary_sets
|
19
|
-
response.
|
20
|
-
response.
|
21
|
-
response.
|
19
|
+
expect(response).to be_a(Hash)
|
20
|
+
expect(response).to have_key('objects')
|
21
|
+
expect(response).to have_key('meta')
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'should return a boundary set' do
|
25
25
|
response = api.boundary_sets(:boundary_set => 'federal-electoral-districts')
|
26
|
-
response.
|
27
|
-
response.
|
26
|
+
expect(response).to be_a(Hash)
|
27
|
+
expect(response).to have_key('related')
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'should raise an error if the boundary set does not exist' do
|
31
|
-
expect{api.boundary_sets(:boundary_set => 'foo')}.to raise_error(GovKit::CA::ResourceNotFound, "404
|
31
|
+
expect{api.boundary_sets(:boundary_set => 'foo')}.to raise_error(GovKit::CA::ResourceNotFound, "404 https://represent.opennorth.ca/boundary-sets/foo/?")
|
32
32
|
end
|
33
33
|
|
34
34
|
it 'should raise an error if the limit is invalid' do
|
35
|
-
expect{api.boundary_sets(:limit => -1)}.to raise_error(GovKit::CA::InvalidRequest, "400
|
35
|
+
expect{api.boundary_sets(:limit => -1)}.to raise_error(GovKit::CA::InvalidRequest, "400 https://represent.opennorth.ca/boundary-sets/?limit=-1 Invalid limit '-1' provided. Please provide a positive integer >= 0.")
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'should raise an error if the offset is invalid' do
|
39
|
-
expect{api.boundary_sets(:offset => -1)}.to raise_error(GovKit::CA::InvalidRequest, "400
|
39
|
+
expect{api.boundary_sets(:offset => -1)}.to raise_error(GovKit::CA::InvalidRequest, "400 https://represent.opennorth.ca/boundary-sets/?offset=-1 Invalid offset '-1' provided. Please provide a positive integer >= 0.")
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
@@ -47,27 +47,27 @@ describe GovKit::CA::Represent do
|
|
47
47
|
|
48
48
|
it 'should return representative sets' do
|
49
49
|
response = api.representative_sets
|
50
|
-
response.
|
51
|
-
response.
|
52
|
-
response.
|
50
|
+
expect(response).to be_a(Hash)
|
51
|
+
expect(response).to have_key('objects')
|
52
|
+
expect(response).to have_key('meta')
|
53
53
|
end
|
54
54
|
|
55
55
|
it 'should return a representative set' do
|
56
56
|
response = api.representative_sets(:representative_set => 'house-of-commons')
|
57
|
-
response.
|
58
|
-
response.
|
57
|
+
expect(response).to be_a(Hash)
|
58
|
+
expect(response).to have_key('related')
|
59
59
|
end
|
60
60
|
|
61
61
|
it 'should raise an error if the representative set does not exist' do
|
62
|
-
expect{api.representative_sets(:representative_set => 'foo')}.to raise_error(GovKit::CA::ResourceNotFound, "404
|
62
|
+
expect{api.representative_sets(:representative_set => 'foo')}.to raise_error(GovKit::CA::ResourceNotFound, "404 https://represent.opennorth.ca/representative-sets/foo/?")
|
63
63
|
end
|
64
64
|
|
65
65
|
it 'should raise an error if the limit is invalid' do
|
66
|
-
expect{api.representative_sets(:limit => -1)}.to raise_error(GovKit::CA::InvalidRequest, "400
|
66
|
+
expect{api.representative_sets(:limit => -1)}.to raise_error(GovKit::CA::InvalidRequest, "400 https://represent.opennorth.ca/representative-sets/?limit=-1 Invalid limit '-1' provided. Please provide a positive integer >= 0.")
|
67
67
|
end
|
68
68
|
|
69
69
|
it 'should raise an error if the offset is invalid' do
|
70
|
-
expect{api.representative_sets(:offset => -1)}.to raise_error(GovKit::CA::InvalidRequest, "400
|
70
|
+
expect{api.representative_sets(:offset => -1)}.to raise_error(GovKit::CA::InvalidRequest, "400 https://represent.opennorth.ca/representative-sets/?offset=-1 Invalid offset '-1' provided. Please provide a positive integer >= 0.")
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
@@ -78,24 +78,24 @@ describe GovKit::CA::Represent do
|
|
78
78
|
|
79
79
|
it 'should query by postal code' do
|
80
80
|
response = api.postcodes('A1A1A1')
|
81
|
-
response.
|
82
|
-
response.
|
81
|
+
expect(response).to be_a(Hash)
|
82
|
+
expect(response).to have_key('code')
|
83
83
|
end
|
84
84
|
|
85
85
|
it 'should accept an array of boundary sets' do
|
86
86
|
response = api.postcodes('A1A1A1', :sets => ['federal-electoral-districts', 'census-subdivisions'])
|
87
|
-
response.
|
88
|
-
(response['boundaries_centroid'] + response['boundaries_concordance']).
|
87
|
+
expect(response).to be_a(Hash)
|
88
|
+
expect((response['boundaries_centroid'] + response['boundaries_concordance']).size).to eq(2)
|
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
|
-
response.
|
94
|
-
(response['boundaries_centroid'] + response['boundaries_concordance']).
|
93
|
+
expect(response).to be_a(Hash)
|
94
|
+
expect((response['boundaries_centroid'] + response['boundaries_concordance']).size).to eq(2)
|
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
|
98
|
+
expect{api.postcodes('foo')}.to raise_error(GovKit::CA::ResourceNotFound, "404 https://represent.opennorth.ca/postcodes/FOO/?")
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
@@ -106,81 +106,81 @@ describe GovKit::CA::Represent do
|
|
106
106
|
|
107
107
|
it 'should return boundaries' do
|
108
108
|
response = api.boundaries
|
109
|
-
response.
|
110
|
-
response.
|
111
|
-
response.
|
112
|
-
response['meta']['next'].
|
109
|
+
expect(response).to be_a(Hash)
|
110
|
+
expect(response).to have_key('objects')
|
111
|
+
expect(response).to have_key('meta')
|
112
|
+
expect(response['meta']['next']).to_not be_nil
|
113
113
|
end
|
114
114
|
|
115
115
|
it 'should return boundaries from a boundary set' do
|
116
116
|
response = api.boundaries(:boundary_set => 'st-johns-wards')
|
117
|
-
response.
|
118
|
-
response.
|
119
|
-
response.
|
120
|
-
response['objects'].
|
117
|
+
expect(response).to be_a(Hash)
|
118
|
+
expect(response).to have_key('objects')
|
119
|
+
expect(response).to have_key('meta')
|
120
|
+
expect(response['objects'].size).to eq(5)
|
121
121
|
end
|
122
122
|
|
123
123
|
it 'should return a boundary from a boundary set' do
|
124
124
|
response = api.boundaries(:boundary_set => 'st-johns-wards', :boundary => 'ward-1')
|
125
|
-
response.
|
126
|
-
response.
|
125
|
+
expect(response).to be_a(Hash)
|
126
|
+
expect(response).to have_key('related')
|
127
127
|
end
|
128
128
|
|
129
129
|
it 'should return the representatives of a boundary from a boundary set' do
|
130
130
|
response = api.boundaries(:boundary_set => 'st-johns-wards', :boundary => 'ward-1', :representatives => true)
|
131
|
-
response.
|
132
|
-
response.
|
133
|
-
response.
|
134
|
-
response['meta']['next'].
|
131
|
+
expect(response).to be_a(Hash)
|
132
|
+
expect(response).to have_key('objects')
|
133
|
+
expect(response).to have_key('meta')
|
134
|
+
expect(response['meta']['next']).to be_nil
|
135
135
|
end
|
136
136
|
|
137
137
|
it 'should return boundaries from many boundary sets as an array' do
|
138
138
|
response = api.boundaries(:sets => ['st-johns-wards','caledon-wards'])
|
139
|
-
response.
|
140
|
-
response.
|
141
|
-
response.
|
142
|
-
response['objects'].
|
139
|
+
expect(response).to be_a(Hash)
|
140
|
+
expect(response).to have_key('objects')
|
141
|
+
expect(response).to have_key('meta')
|
142
|
+
expect(response['objects'].size).to eq(10)
|
143
143
|
end
|
144
144
|
|
145
145
|
it 'should return boundaries from many boundary sets as a comma-separated list' do
|
146
146
|
response = api.boundaries(:sets => 'st-johns-wards,caledon-wards')
|
147
|
-
response.
|
148
|
-
response.
|
149
|
-
response.
|
150
|
-
response['objects'].
|
147
|
+
expect(response).to be_a(Hash)
|
148
|
+
expect(response).to have_key('objects')
|
149
|
+
expect(response).to have_key('meta')
|
150
|
+
expect(response['objects'].size).to eq(10)
|
151
151
|
end
|
152
152
|
|
153
153
|
it 'should accept a point as an array' do
|
154
154
|
response = api.boundaries(:contains => ['47.5699', '-52.6954'])
|
155
|
-
response.
|
156
|
-
response.
|
157
|
-
response.
|
158
|
-
response['meta']['next'].
|
155
|
+
expect(response).to be_a(Hash)
|
156
|
+
expect(response).to have_key('objects')
|
157
|
+
expect(response).to have_key('meta')
|
158
|
+
expect(response['meta']['next']).to be_nil
|
159
159
|
end
|
160
160
|
|
161
161
|
it 'should accept a point as a comma-separated list' do
|
162
162
|
response = api.boundaries(:contains => '47.5699,-52.6954')
|
163
|
-
response.
|
164
|
-
response.
|
165
|
-
response.
|
166
|
-
response['meta']['next'].
|
163
|
+
expect(response).to be_a(Hash)
|
164
|
+
expect(response).to have_key('objects')
|
165
|
+
expect(response).to have_key('meta')
|
166
|
+
expect(response['meta']['next']).to be_nil
|
167
167
|
end
|
168
168
|
|
169
169
|
it 'should raise an error if the point is invalid' do
|
170
|
-
expect{api.boundaries(:contains => '0,0,0')}.to raise_error(GovKit::CA::InvalidRequest, "400
|
170
|
+
expect{api.boundaries(:contains => '0,0,0')}.to raise_error(GovKit::CA::InvalidRequest, "400 https://represent.opennorth.ca/boundaries/?contains=0,0,0 Invalid latitude,longitude '0,0,0' provided.")
|
171
171
|
end
|
172
172
|
|
173
173
|
it 'should raise an error if the boundary set does not exist' do
|
174
|
-
expect{api.boundaries(:boundary_set => 'foo')}.to raise_error(GovKit::CA::ResourceNotFound, "404
|
174
|
+
expect{api.boundaries(:boundary_set => 'foo')}.to raise_error(GovKit::CA::ResourceNotFound, "404 https://represent.opennorth.ca/boundaries/foo/?")
|
175
175
|
end
|
176
176
|
|
177
177
|
context 'when retrieving a boundary' do
|
178
178
|
it 'should raise an error if the boundary set does not exist' do
|
179
|
-
expect{api.boundaries(:boundary_set => 'foo', :boundary => 'ward-1')}.to raise_error(GovKit::CA::ResourceNotFound, "404
|
179
|
+
expect{api.boundaries(:boundary_set => 'foo', :boundary => 'ward-1')}.to raise_error(GovKit::CA::ResourceNotFound, "404 https://represent.opennorth.ca/boundaries/foo/ward-1/?")
|
180
180
|
end
|
181
181
|
|
182
182
|
it 'should raise an error if the boundary does not exist' do
|
183
|
-
expect{api.boundaries(:boundary_set => 'st-johns-wards', :boundary => 'foo')}.to raise_error(GovKit::CA::ResourceNotFound, "404
|
183
|
+
expect{api.boundaries(:boundary_set => 'st-johns-wards', :boundary => 'foo')}.to raise_error(GovKit::CA::ResourceNotFound, "404 https://represent.opennorth.ca/boundaries/st-johns-wards/foo/?")
|
184
184
|
end
|
185
185
|
|
186
186
|
it 'should raise an error if the boundary set is not given' do
|
@@ -207,11 +207,11 @@ describe GovKit::CA::Represent do
|
|
207
207
|
end
|
208
208
|
|
209
209
|
it 'should raise an error if the limit is invalid' do
|
210
|
-
expect{api.boundaries(:limit => -1)}.to raise_error(GovKit::CA::InvalidRequest, "400
|
210
|
+
expect{api.boundaries(:limit => -1)}.to raise_error(GovKit::CA::InvalidRequest, "400 https://represent.opennorth.ca/boundaries/?limit=-1 Invalid limit '-1' provided. Please provide a positive integer >= 0.")
|
211
211
|
end
|
212
212
|
|
213
213
|
it 'should raise an error if the offset is invalid' do
|
214
|
-
expect{api.boundaries(:offset => -1)}.to raise_error(GovKit::CA::InvalidRequest, "400
|
214
|
+
expect{api.boundaries(:offset => -1)}.to raise_error(GovKit::CA::InvalidRequest, "400 https://represent.opennorth.ca/boundaries/?offset=-1 Invalid offset '-1' provided. Please provide a positive integer >= 0.")
|
215
215
|
end
|
216
216
|
end
|
217
217
|
|
@@ -222,54 +222,54 @@ describe GovKit::CA::Represent do
|
|
222
222
|
|
223
223
|
it 'should return representatives' do
|
224
224
|
response = api.representatives
|
225
|
-
response.
|
226
|
-
response.
|
227
|
-
response.
|
228
|
-
response['meta']['next'].
|
225
|
+
expect(response).to be_a(Hash)
|
226
|
+
expect(response).to have_key('objects')
|
227
|
+
expect(response).to have_key('meta')
|
228
|
+
expect(response['meta']['next']).to_not be_nil
|
229
229
|
end
|
230
230
|
|
231
231
|
it 'should return representatives from a representative set' do
|
232
232
|
response = api.representatives(:representative_set => 'st-johns-city-council')
|
233
|
-
response.
|
234
|
-
response.
|
235
|
-
response.
|
236
|
-
response['meta']['next'].
|
233
|
+
expect(response).to be_a(Hash)
|
234
|
+
expect(response).to have_key('objects')
|
235
|
+
expect(response).to have_key('meta')
|
236
|
+
expect(response['meta']['next']).to be_nil
|
237
237
|
end
|
238
238
|
|
239
239
|
it 'should accept a point as an array' do
|
240
240
|
response = api.representatives(:point => ['47.5699', '-52.6954'])
|
241
|
-
response.
|
242
|
-
response.
|
243
|
-
response.
|
244
|
-
response['meta']['next'].
|
241
|
+
expect(response).to be_a(Hash)
|
242
|
+
expect(response).to have_key('objects')
|
243
|
+
expect(response).to have_key('meta')
|
244
|
+
expect(response['meta']['next']).to be_nil
|
245
245
|
end
|
246
246
|
|
247
247
|
it 'should accept a point as a comma-separated list' do
|
248
248
|
response = api.representatives(:point => '47.5699,-52.6954')
|
249
|
-
response.
|
250
|
-
response.
|
251
|
-
response.
|
252
|
-
response['meta']['next'].
|
249
|
+
expect(response).to be_a(Hash)
|
250
|
+
expect(response).to have_key('objects')
|
251
|
+
expect(response).to have_key('meta')
|
252
|
+
expect(response['meta']['next']).to be_nil
|
253
253
|
end
|
254
254
|
|
255
255
|
it 'should accept an array of districts' do
|
256
256
|
response = api.representatives(:districts => ['federal-electoral-districts/10007', 'census-subdivisions/1001519'])
|
257
|
-
response.
|
258
|
-
response.
|
259
|
-
response.
|
260
|
-
response['meta']['next'].
|
257
|
+
expect(response).to be_a(Hash)
|
258
|
+
expect(response).to have_key('objects')
|
259
|
+
expect(response).to have_key('meta')
|
260
|
+
expect(response['meta']['next']).to be_nil
|
261
261
|
end
|
262
262
|
|
263
263
|
it 'should accept a comma-separated list of districts' do
|
264
264
|
response = api.representatives(:districts => 'federal-electoral-districts/10007,census-subdivisions/1001519')
|
265
|
-
response.
|
266
|
-
response.
|
267
|
-
response.
|
268
|
-
response['meta']['next'].
|
265
|
+
expect(response).to be_a(Hash)
|
266
|
+
expect(response).to have_key('objects')
|
267
|
+
expect(response).to have_key('meta')
|
268
|
+
expect(response['meta']['next']).to be_nil
|
269
269
|
end
|
270
270
|
|
271
271
|
it 'should raise an error if the point is invalid' do
|
272
|
-
expect{api.representatives(:point => '0,0,0')}.to raise_error(GovKit::CA::InvalidRequest, "400
|
272
|
+
expect{api.representatives(:point => '0,0,0')}.to raise_error(GovKit::CA::InvalidRequest, "400 https://represent.opennorth.ca/representatives/?point=0,0,0 Invalid latitude,longitude '0,0,0' provided.")
|
273
273
|
end
|
274
274
|
|
275
275
|
it 'should not raise an error if the representative set does not exist' do
|
@@ -277,11 +277,11 @@ describe GovKit::CA::Represent do
|
|
277
277
|
end
|
278
278
|
|
279
279
|
it 'should raise an error if the limit is invalid' do
|
280
|
-
expect{api.representatives(:limit => -1)}.to raise_error(GovKit::CA::InvalidRequest, "400
|
280
|
+
expect{api.representatives(:limit => -1)}.to raise_error(GovKit::CA::InvalidRequest, "400 https://represent.opennorth.ca/representatives/?limit=-1 Invalid limit '-1' provided. Please provide a positive integer >= 0.")
|
281
281
|
end
|
282
282
|
|
283
283
|
it 'should raise an error if the offset is invalid' do
|
284
|
-
expect{api.representatives(:offset => -1)}.to raise_error(GovKit::CA::InvalidRequest, "400
|
284
|
+
expect{api.representatives(:offset => -1)}.to raise_error(GovKit::CA::InvalidRequest, "400 https://represent.opennorth.ca/representatives/?offset=-1 Invalid offset '-1' provided. Please provide a positive integer >= 0.")
|
285
285
|
end
|
286
286
|
end
|
287
287
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,18 +1,15 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
|
3
|
+
require 'simplecov'
|
3
4
|
require 'coveralls'
|
4
|
-
Coveralls
|
5
|
+
SimpleCov.formatter = Coveralls::SimpleCov::Formatter
|
6
|
+
SimpleCov.start do
|
7
|
+
add_filter 'spec'
|
8
|
+
end
|
5
9
|
|
6
10
|
require 'rspec'
|
7
11
|
require File.dirname(__FILE__) + '/../lib/gov_kit-ca'
|
8
12
|
|
9
|
-
module Helpers
|
10
|
-
def fixture_path(*args)
|
11
|
-
File.join(File.dirname(__FILE__), 'fixtures', *args)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
13
|
RSpec.configure do |config|
|
16
|
-
config.include Helpers
|
17
14
|
config.filter_run_excluding :broken => true
|
18
15
|
end
|
data/spec/strategy_set_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
|
-
describe GovKit::CA::PostalCode::StrategySet do
|
3
|
+
RSpec.describe GovKit::CA::PostalCode::StrategySet do
|
4
4
|
let :strategy do
|
5
5
|
Class.new
|
6
6
|
end
|
@@ -14,27 +14,27 @@ describe GovKit::CA::PostalCode::StrategySet do
|
|
14
14
|
|
15
15
|
describe '#strategies' do
|
16
16
|
it 'should return the strategies' do
|
17
|
-
GovKit::CA::PostalCode::StrategySet.strategies[0..4].
|
17
|
+
expect(GovKit::CA::PostalCode::StrategySet.strategies[0..4]).to eq([
|
18
18
|
GovKit::CA::PostalCode::Strategy::ElectionsCa,
|
19
19
|
GovKit::CA::PostalCode::Strategy::LiberalCa,
|
20
20
|
GovKit::CA::PostalCode::Strategy::NDPCa,
|
21
21
|
# GovKit::CA::PostalCode::Strategy::GreenPartyCa,
|
22
22
|
# GovKit::CA::PostalCode::Strategy::CBCCa,
|
23
23
|
# GovKit::CA::PostalCode::Strategy::ConservativeCa,
|
24
|
-
]
|
24
|
+
])
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
28
|
describe '#register' do
|
29
29
|
it 'should append a strategy' do
|
30
30
|
GovKit::CA::PostalCode::StrategySet.register(strategy)
|
31
|
-
GovKit::CA::PostalCode::StrategySet.strategies.last.
|
31
|
+
expect(GovKit::CA::PostalCode::StrategySet.strategies.last).to eq(strategy)
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
35
|
describe '#run' do
|
36
36
|
it 'should run the strategies' do
|
37
|
-
GovKit::CA::PostalCode::StrategySet.run('A1A1A1').
|
37
|
+
expect(GovKit::CA::PostalCode::StrategySet.run('A1A1A1')).to eq([10007])
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
@@ -46,14 +46,14 @@ describe GovKit::CA::PostalCode::StrategySet do
|
|
46
46
|
|
47
47
|
describe '#strategies' do
|
48
48
|
it 'should return the strategies' do
|
49
|
-
GovKit::CA::PostalCode::StrategySet.strategies.
|
49
|
+
expect(GovKit::CA::PostalCode::StrategySet.strategies).to eq([])
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
53
|
describe '#register' do
|
54
54
|
it 'should add a strategy' do
|
55
55
|
GovKit::CA::PostalCode::StrategySet.register(strategy)
|
56
|
-
GovKit::CA::PostalCode::StrategySet.strategies.
|
56
|
+
expect(GovKit::CA::PostalCode::StrategySet.strategies).to eq([strategy])
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
data/tasks/tasks.rb
CHANGED
@@ -31,7 +31,7 @@ task :trim_postal_codes, :file do |t,args|
|
|
31
31
|
# Get the minimum number of postal codes to cover all electoral districts.
|
32
32
|
# This is an instance of the set cover problem, which is NP-complete. Use the
|
33
33
|
# greedy algorithm, which is the best-possible polynomial time approximation
|
34
|
-
# algorithm for set cover.
|
34
|
+
# algorithm for set cover. https://en.wikipedia.org/wiki/Set_cover_problem
|
35
35
|
postal_codes = []
|
36
36
|
until postal_to_edid.empty?
|
37
37
|
postal_code, edids = postal_to_edid.max{|_,v| v.size}
|
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.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Open North
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-04-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -53,7 +53,7 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 1.6.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: coveralls
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
@@ -67,47 +67,47 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: json
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: '1.8'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: '1.8'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rake
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - "
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
89
|
+
version: '0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - "
|
94
|
+
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
96
|
+
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: rspec
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- - "
|
101
|
+
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
103
|
+
version: '3.1'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- - "
|
108
|
+
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
110
|
+
version: '3.1'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: mime-types
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -131,6 +131,7 @@ extensions: []
|
|
131
131
|
extra_rdoc_files: []
|
132
132
|
files:
|
133
133
|
- ".gitignore"
|
134
|
+
- ".rspec"
|
134
135
|
- ".travis.yml"
|
135
136
|
- ".yardopts"
|
136
137
|
- Gemfile
|
@@ -139,7 +140,6 @@ files:
|
|
139
140
|
- Rakefile
|
140
141
|
- USAGE
|
141
142
|
- govkit-ca.gemspec
|
142
|
-
- lib/data/rid_to_edid.yml
|
143
143
|
- lib/gov_kit-ca.rb
|
144
144
|
- lib/gov_kit-ca/postal_code.rb
|
145
145
|
- lib/gov_kit-ca/postal_code/strategy/base.rb
|
@@ -155,6 +155,7 @@ files:
|
|
155
155
|
- lib/gov_kit-ca/represent.rb
|
156
156
|
- lib/gov_kit-ca/version.rb
|
157
157
|
- lib/govkit-ca.rb
|
158
|
+
- lib/rid_to_edid.yml
|
158
159
|
- spec/cbc_ca_spec.rb
|
159
160
|
- spec/conservative_ca_spec.rb
|
160
161
|
- spec/digital-copyright_ca_spec.rb
|
@@ -165,12 +166,11 @@ files:
|
|
165
166
|
- spec/parl_gc_ca_spec.rb
|
166
167
|
- spec/postal_code_spec.rb
|
167
168
|
- spec/represent_spec.rb
|
168
|
-
- spec/spec.opts
|
169
169
|
- spec/spec_helper.rb
|
170
170
|
- spec/strategy_set_spec.rb
|
171
171
|
- tasks/postal-code-for-districts.csv
|
172
172
|
- tasks/tasks.rb
|
173
|
-
homepage:
|
173
|
+
homepage: https://github.com/opennorth/govkit-ca
|
174
174
|
licenses:
|
175
175
|
- MIT
|
176
176
|
metadata: {}
|
@@ -189,7 +189,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
189
189
|
- !ruby/object:Gem::Version
|
190
190
|
version: '0'
|
191
191
|
requirements: []
|
192
|
-
rubyforge_project:
|
192
|
+
rubyforge_project:
|
193
193
|
rubygems_version: 2.2.2
|
194
194
|
signing_key:
|
195
195
|
specification_version: 4
|
@@ -205,6 +205,5 @@ test_files:
|
|
205
205
|
- spec/parl_gc_ca_spec.rb
|
206
206
|
- spec/postal_code_spec.rb
|
207
207
|
- spec/represent_spec.rb
|
208
|
-
- spec/spec.opts
|
209
208
|
- spec/spec_helper.rb
|
210
209
|
- spec/strategy_set_spec.rb
|