govkit-ca 0.0.14 → 0.0.15

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 552c21addb48040ade097636fd88ec1e60464d4b
4
- data.tar.gz: 4a99ef183fefcddfdd06516aaaf968c8bcb55f03
3
+ metadata.gz: 2051edb2b22dbfb63480ac487f4fe82c4cd5f7f1
4
+ data.tar.gz: 762e642d14e7869f88ea766eaf33d8ca2b64442a
5
5
  SHA512:
6
- metadata.gz: 964b1d7bfb550b526a8ed5cc7cd7f093aab3d2f096f182abe41a492e867fcf43ab31d115051f53968665da977cdc07abb95c41e50de1dc533f79b66be9d082ea
7
- data.tar.gz: e9f9c2b9923969bbdf265a5fcef8d376058fcd87ed067e22068137a800f88786c5f7e0c09ba5da825cc3efc2c1c4e3efefffb90cd425b4f8a0caa97ff90c86e9
6
+ metadata.gz: 8ac0daf7e97e39bdf8f6eff4bdb3d3611c55604fc980570558ffeb59c0bec4ba24dd2207ebe58fef4565159978d23e25d16feeb01f8f07f729e3413933d8f62b
7
+ data.tar.gz: d07c817b8b21b71559d1fd0e69ffd7edfd18875a4f461e9ec00d2d66b277ac633153292bbd44d946c1232d81f149d63565cf06c415a8c22cf0ac04172979a5c2
data/README.md CHANGED
@@ -22,36 +22,48 @@ require 'govkit-ca'
22
22
  client = GovKit::CA::Represent.new
23
23
  ```
24
24
 
25
- Send a request to the [`/postcodes` endpoint](https://represent.opennorth.ca/api/#postcode):
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](https://represent.opennorth.ca/api/#representativeset):
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](https://represent.opennorth.ca/api/#representative):
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](https://represent.opennorth.ca/api/#boundaryset):
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](https://represent.opennorth.ca/api/#boundary):
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')
53
53
  ```
54
54
 
55
+ Send a request to the [`/elections/` endpoint](https://represent.opennorth.ca/api/#election):
56
+
57
+ ```ruby
58
+ client.elections(limit: 0)
59
+ ```
60
+
61
+ Send a request to the [`/candidates/` endpoint](https://represent.opennorth.ca/api/#candidate):
62
+
63
+ ```ruby
64
+ client.candidates(election: 'house-of-commons')
65
+ ```
66
+
55
67
  Read the full documentation on [RubyDoc.info](http://rubydoc.info/gems/govkit-ca/GovKit/CA/Represent).
56
68
 
57
69
  ## Postal code to electoral district lookup
@@ -64,7 +76,6 @@ GovKit-CA provides an API for free postal code to electoral district lookups, us
64
76
  * [greenparty.ca](http://www.greenparty.ca/)
65
77
  * [liberal.ca](https://www.liberal.ca/)
66
78
  * [ndp.ca](http://www.ndp.ca/)
67
- * [cbc.ca](http://www.cbc.ca/)
68
79
  * [digital-copyright.ca](http://www.digital-copyright.ca/)
69
80
 
70
81
  These sources can be unstable or incorrect.
@@ -17,7 +17,6 @@ end
17
17
  require 'gov_kit-ca/postal_code'
18
18
  require 'gov_kit-ca/postal_code/strategy_set'
19
19
  require 'gov_kit-ca/postal_code/strategy/base'
20
- require 'gov_kit-ca/postal_code/strategy/cbc_ca'
21
20
  require 'gov_kit-ca/postal_code/strategy/conservative_ca'
22
21
  require 'gov_kit-ca/postal_code/strategy/digital-copyright_ca'
23
22
  require 'gov_kit-ca/postal_code/strategy/elections_ca'
@@ -106,7 +106,7 @@ module GovKit
106
106
  # Get candidates.
107
107
  #
108
108
  # @param [Hash] opts optional arguments
109
- # @option opts [String] :electon an election
109
+ # @option opts [String] :election an election
110
110
  # @option opts [Array<Float>,String] :point a comma-separated latitude and longitude
111
111
  # @option opts [Array<Strong>,String] :districts a comma-separated list of boundaries
112
112
  # @option opts [Integer] :limit
@@ -119,7 +119,7 @@ module GovKit
119
119
  if Array === opts[:districts]
120
120
  opts[:districts] = opts[:districts].join(',')
121
121
  end
122
- request(['candidates', opts.delete(:candidate)], opts)
122
+ request(['candidates', opts.delete(:election)], opts)
123
123
  end
124
124
 
125
125
  private
@@ -1,5 +1,5 @@
1
1
  module GovKit
2
2
  module CA
3
- VERSION = "0.0.14"
3
+ VERSION = "0.0.15"
4
4
  end
5
5
  end
@@ -1,137 +1,45 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  RSpec.describe GovKit::CA::Represent do
4
- describe '#boundary_sets' do
5
- let :api do
6
- GovKit::CA::Represent.new
7
- end
8
-
9
- it 'should accept a custom connection' do
10
- connection = Faraday.new do |connection|
11
- connection.request :url_encoded
12
- connection.adapter Faraday.default_adapter
13
- end
14
- expect{GovKit::CA::Represent.new(connection)}.to_not raise_error
15
- end
16
-
17
- it 'should return boundary sets' do
18
- response = api.boundary_sets
19
- expect(response).to be_a(Hash)
20
- expect(response).to have_key('objects')
21
- expect(response).to have_key('meta')
22
- end
23
-
24
- it 'should return a boundary set' do
25
- response = api.boundary_sets(:boundary_set => 'federal-electoral-districts')
26
- expect(response).to be_a(Hash)
27
- expect(response).to have_key('related')
28
- end
29
-
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 https://represent.opennorth.ca/boundary-sets/foo/?")
32
- end
33
-
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 https://represent.opennorth.ca/boundary-sets/?limit=-1 Invalid limit '-1' provided. Please provide a positive integer >= 0.")
36
- end
37
-
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 https://represent.opennorth.ca/boundary-sets/?offset=-1 Invalid offset '-1' provided. Please provide a positive integer >= 0.")
4
+ it 'should accept a custom connection' do
5
+ connection = Faraday.new do |connection|
6
+ connection.request :url_encoded
7
+ connection.adapter Faraday.default_adapter
40
8
  end
9
+ expect{GovKit::CA::Represent.new(connection)}.to_not raise_error
41
10
  end
42
11
 
43
12
  describe '#representative_sets' do
44
- let :api do
45
- GovKit::CA::Represent.new
46
- end
47
-
48
- it 'should return representative sets' do
49
- response = api.representative_sets
50
- expect(response).to be_a(Hash)
51
- expect(response).to have_key('objects')
52
- expect(response).to have_key('meta')
53
- end
54
-
55
- it 'should return a representative set' do
56
- response = api.representative_sets(:representative_set => 'house-of-commons')
57
- expect(response).to be_a(Hash)
58
- expect(response).to have_key('related')
59
- end
60
-
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 https://represent.opennorth.ca/representative-sets/foo/?")
63
- end
64
-
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 https://represent.opennorth.ca/representative-sets/?limit=-1 Invalid limit '-1' provided. Please provide a positive integer >= 0.")
67
- end
68
-
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 https://represent.opennorth.ca/representative-sets/?offset=-1 Invalid offset '-1' provided. Please provide a positive integer >= 0.")
71
- end
13
+ include_examples 'set', 'representative_sets', 'house-of-commons'
72
14
  end
73
15
 
74
- describe '#postcodes' do
75
- let :api do
76
- GovKit::CA::Represent.new
77
- end
78
-
79
- it 'should query by postal code' do
80
- response = api.postcodes('A1A1A1')
81
- expect(response).to be_a(Hash)
82
- expect(response).to have_key('code')
83
- end
16
+ # @note These tests will fail if the election is inactive.
17
+ describe '#elections' do
18
+ include_examples 'set', 'elections', 'house-of-commons'
19
+ end
84
20
 
85
- it 'should accept an array of boundary sets' do
86
- response = api.postcodes('A1A1A1', :sets => ['federal-electoral-districts', 'census-subdivisions'])
87
- expect(response).to be_a(Hash)
88
- expect((response['boundaries_centroid'] + response['boundaries_concordance']).size).to eq(2)
89
- end
21
+ describe '#boundary_sets' do
22
+ include_examples 'set', 'boundary_sets', 'federal-electoral-districts'
23
+ end
90
24
 
91
- it 'should accept a comma-separated list of boundary sets' do
92
- response = api.postcodes('A1A1A1', :sets => 'federal-electoral-districts,census-subdivisions')
93
- expect(response).to be_a(Hash)
94
- expect((response['boundaries_centroid'] + response['boundaries_concordance']).size).to eq(2)
95
- end
25
+ describe '#representatives' do
26
+ include_examples 'representative', 'representatives', 'st-johns-city-council', 11, :set => :representative_set, :point => :point
27
+ end
96
28
 
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 https://represent.opennorth.ca/postcodes/FOO/?")
99
- end
29
+ # @note These tests will fail if the election is inactive.
30
+ describe '#candidates' do
31
+ include_examples 'representative', 'candidates', 'house-of-commons', 20, :set => :election, :point => :point
100
32
  end
101
33
 
102
34
  describe '#boundaries' do
35
+ include_examples 'item', 'boundaries', 'st-johns-wards', 5, :set => :boundary_set, :point => :contains
36
+
103
37
  let :api do
104
38
  GovKit::CA::Represent.new
105
39
  end
106
40
 
107
- it 'should return boundaries' do
108
- response = api.boundaries
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
- end
114
-
115
- it 'should return boundaries from a boundary set' do
116
- response = api.boundaries(:boundary_set => 'st-johns-wards')
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
- end
122
-
123
- it 'should return a boundary from a boundary set' do
124
- response = api.boundaries(:boundary_set => 'st-johns-wards', :boundary => 'ward-1')
125
- expect(response).to be_a(Hash)
126
- expect(response).to have_key('related')
127
- end
128
-
129
- it 'should return the representatives of a boundary from a boundary set' do
130
- response = api.boundaries(:boundary_set => 'st-johns-wards', :boundary => 'ward-1', :representatives => true)
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
41
+ it 'should raise an error if the boundary set does not exist' do
42
+ expect{api.boundaries(:boundary_set => 'nonexistent')}.to raise_error(GovKit::CA::ResourceNotFound, "404 https://represent.opennorth.ca/boundaries/nonexistent/?")
135
43
  end
136
44
 
137
45
  it 'should return boundaries from many boundary sets as an array' do
@@ -150,37 +58,19 @@ RSpec.describe GovKit::CA::Represent do
150
58
  expect(response['objects'].size).to eq(10)
151
59
  end
152
60
 
153
- it 'should accept a point as an array' do
154
- response = api.boundaries(:contains => ['47.5699', '-52.6954'])
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
- end
160
-
161
- it 'should accept a point as a comma-separated list' do
162
- response = api.boundaries(:contains => '47.5699,-52.6954')
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
- end
168
-
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 https://represent.opennorth.ca/boundaries/?contains=0,0,0 Invalid latitude,longitude '0,0,0' provided.")
171
- end
172
-
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 https://represent.opennorth.ca/boundaries/foo/?")
175
- end
176
-
177
61
  context 'when retrieving a boundary' do
62
+ it 'should return a boundary from a boundary set' do
63
+ response = api.boundaries(:boundary_set => 'st-johns-wards', :boundary => 'ward-1')
64
+ expect(response).to be_a(Hash)
65
+ expect(response).to have_key('related')
66
+ end
67
+
178
68
  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 https://represent.opennorth.ca/boundaries/foo/ward-1/?")
69
+ expect{api.boundaries(:boundary_set => 'nonexistent', :boundary => 'ward-1')}.to raise_error(GovKit::CA::ResourceNotFound, "404 https://represent.opennorth.ca/boundaries/nonexistent/ward-1/?")
180
70
  end
181
71
 
182
72
  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 https://represent.opennorth.ca/boundaries/st-johns-wards/foo/?")
73
+ expect{api.boundaries(:boundary_set => 'st-johns-wards', :boundary => 'nonexistent')}.to raise_error(GovKit::CA::ResourceNotFound, "404 https://represent.opennorth.ca/boundaries/st-johns-wards/nonexistent/?")
184
74
  end
185
75
 
186
76
  it 'should raise an error if the boundary set is not given' do
@@ -189,12 +79,20 @@ RSpec.describe GovKit::CA::Represent do
189
79
  end
190
80
 
191
81
  context 'when retrieving the representatives of a boundary' do
82
+ it 'should return the representatives of a boundary from a boundary set' do
83
+ response = api.boundaries(:boundary_set => 'st-johns-wards', :boundary => 'ward-1', :representatives => true)
84
+ expect(response).to be_a(Hash)
85
+ expect(response).to have_key('objects')
86
+ expect(response).to have_key('meta')
87
+ expect(response['meta']['next']).to be_nil
88
+ end
89
+
192
90
  it 'should not raise an error if the boundary set does not exist' do
193
- expect{api.boundaries(:boundary_set => 'foo', :boundary => 'ward-1', :representatives => true)}.to_not raise_error
91
+ expect{api.boundaries(:boundary_set => 'nonexistent', :boundary => 'ward-1', :representatives => true)}.to_not raise_error
194
92
  end
195
93
 
196
94
  it 'should not raise an error if the boundary does not exist' do
197
- expect{api.boundaries(:boundary_set => 'st-johns-wards', :boundary => 'foo', :representatives => true)}.to_not raise_error
95
+ expect{api.boundaries(:boundary_set => 'st-johns-wards', :boundary => 'nonexistent', :representatives => true)}.to_not raise_error
198
96
  end
199
97
 
200
98
  it 'should raise an error if the boundary set is not given' do
@@ -205,83 +103,33 @@ RSpec.describe GovKit::CA::Represent do
205
103
  expect{api.boundaries(:boundary_set => 'st-johns-wards', :representatives => true)}.to raise_error(ArgumentError, ':boundary_set and :boundary must be set if :representatives is true')
206
104
  end
207
105
  end
208
-
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 https://represent.opennorth.ca/boundaries/?limit=-1 Invalid limit '-1' provided. Please provide a positive integer >= 0.")
211
- end
212
-
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 https://represent.opennorth.ca/boundaries/?offset=-1 Invalid offset '-1' provided. Please provide a positive integer >= 0.")
215
- end
216
106
  end
217
107
 
218
- describe '#representatives' do
108
+ describe '#postcodes' do
219
109
  let :api do
220
110
  GovKit::CA::Represent.new
221
111
  end
222
112
 
223
- it 'should return representatives' do
224
- response = api.representatives
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
- end
230
-
231
- it 'should return representatives from a representative set' do
232
- response = api.representatives(:representative_set => 'st-johns-city-council')
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
- end
238
-
239
- it 'should accept a point as an array' do
240
- response = api.representatives(:point => ['47.5699', '-52.6954'])
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
- end
246
-
247
- it 'should accept a point as a comma-separated list' do
248
- response = api.representatives(:point => '47.5699,-52.6954')
113
+ it 'should query by postal code' do
114
+ response = api.postcodes('A1A1A1')
249
115
  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
116
+ expect(response).to have_key('code')
253
117
  end
254
118
 
255
- it 'should accept an array of districts' do
256
- response = api.representatives(:districts => ['federal-electoral-districts/10007', 'census-subdivisions/1001519'])
119
+ it 'should accept an array of boundary sets' do
120
+ response = api.postcodes('A1A1A1', :sets => ['federal-electoral-districts', 'census-subdivisions'])
257
121
  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
122
+ expect((response['boundaries_centroid'] + response['boundaries_concordance']).size).to eq(2)
261
123
  end
262
124
 
263
- it 'should accept a comma-separated list of districts' do
264
- response = api.representatives(:districts => 'federal-electoral-districts/10007,census-subdivisions/1001519')
125
+ it 'should accept a comma-separated list of boundary sets' do
126
+ response = api.postcodes('A1A1A1', :sets => 'federal-electoral-districts,census-subdivisions')
265
127
  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
- end
270
-
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 https://represent.opennorth.ca/representatives/?point=0,0,0 Invalid latitude,longitude '0,0,0' provided.")
273
- end
274
-
275
- it 'should not raise an error if the representative set does not exist' do
276
- expect{api.representatives(:representative_set => 'foo')}.to_not raise_error
277
- end
278
-
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 https://represent.opennorth.ca/representatives/?limit=-1 Invalid limit '-1' provided. Please provide a positive integer >= 0.")
128
+ expect((response['boundaries_centroid'] + response['boundaries_concordance']).size).to eq(2)
281
129
  end
282
130
 
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 https://represent.opennorth.ca/representatives/?offset=-1 Invalid offset '-1' provided. Please provide a positive integer >= 0.")
131
+ it 'should raise an error if the postal code does not exist' do
132
+ expect{api.postcodes('Z0Z0Z0')}.to raise_error(GovKit::CA::ResourceNotFound, "404 https://represent.opennorth.ca/postcodes/Z0Z0Z0/?")
285
133
  end
286
134
  end
287
135
  end
@@ -8,32 +8,33 @@ SimpleCov.start do
8
8
  end
9
9
 
10
10
  require 'rspec'
11
- require File.dirname(__FILE__) + '/../lib/gov_kit-ca'
12
-
13
11
  RSpec.configure do |config|
14
12
  config.filter_run_excluding :broken => true
15
13
  end
16
14
 
15
+ Dir['./spec/support/**/*.rb'].sort.each { |f| require f}
16
+ require File.dirname(__FILE__) + '/../lib/gov_kit-ca'
17
+
17
18
  EXPECTATIONS = {
18
- conservative_ca: {
19
+ :conservative_ca => {
19
20
  'T1P1K1' => [48010],
20
21
  'K0A1K0' => [35025, 35052, 35063],
21
22
  },
22
- elections_ca: {
23
+ :elections_ca => {
23
24
  'G0C2Y0' => [24026],
24
25
  'T5S2B9' => [48031],
25
26
  },
26
- green_party_ca: {
27
+ :green_party_ca => {
27
28
  'G0C2Y0' => [24026],
28
29
  'T5S2B9' => [48031],
29
30
  },
30
- liberal_ca: {
31
+ :liberal_ca => {
31
32
  'G0C2Y0' => [24026],
32
33
  'T5S2B9' => [48031],
33
34
  'B0J2L0' => [12002], # too few
34
35
  'K0A1K0' => [35076], # too few
35
36
  },
36
- ndp_ca: {
37
+ :ndp_ca => {
37
38
  'G0C2Y0' => [24026],
38
39
  'T5S2B9' => [48031],
39
40
  'B0J2L0' => [12002, 12008],
@@ -41,13 +42,7 @@ EXPECTATIONS = {
41
42
  },
42
43
 
43
44
  # Deprecated.
44
- cbc_ca: {
45
- 'G0C2Y0' => [24019],
46
- 'T5S2B9' => [48015, 48017],
47
- 'B0J2L0' => [12002, 12007, 12008],
48
- 'K0A1K0' => [35025, 35052, 35063, 35064],
49
- },
50
- digital_copyright_ca: {
45
+ :digital_copyright_ca => {
51
46
  'G0C2Y0' => [24019, 24039],
52
47
  'T5S2B9' => [48012, 48013, 48014, 48015, 48017, 48018],
53
48
  'B0J2L0' => [12002, 12007, 12008],
@@ -19,7 +19,6 @@ RSpec.describe GovKit::CA::PostalCode::StrategySet do
19
19
  GovKit::CA::PostalCode::Strategy::LiberalCa,
20
20
  GovKit::CA::PostalCode::Strategy::NDPCa,
21
21
  # GovKit::CA::PostalCode::Strategy::GreenPartyCa,
22
- # GovKit::CA::PostalCode::Strategy::CBCCa,
23
22
  # GovKit::CA::PostalCode::Strategy::ConservativeCa,
24
23
  ])
25
24
  end
@@ -0,0 +1,118 @@
1
+ RSpec.shared_examples 'pagination' do |method,endpoint|
2
+ it 'should raise an error if the limit is invalid' do
3
+ expect{api.send(method, :limit => -1)}.to raise_error(GovKit::CA::InvalidRequest, "400 https://represent.opennorth.ca/#{endpoint}/?limit=-1 Invalid limit '-1' provided. Please provide a positive integer >= 0.")
4
+ end
5
+
6
+ it 'should raise an error if the offset is invalid' do
7
+ expect{api.send(method, :offset => -1)}.to raise_error(GovKit::CA::InvalidRequest, "400 https://represent.opennorth.ca/#{endpoint}/?offset=-1 Invalid offset '-1' provided. Please provide a positive integer >= 0.")
8
+ end
9
+ end
10
+
11
+ RSpec.shared_examples 'set' do |method,set|
12
+ include_examples 'pagination', method, method.sub('_', '-')
13
+
14
+ let :option do
15
+ method.chomp('s').to_sym
16
+ end
17
+
18
+ let :endpoint do
19
+ method.sub('_', '-')
20
+ end
21
+
22
+ let :api do
23
+ GovKit::CA::Represent.new
24
+ end
25
+
26
+ it 'should return sets' do
27
+ response = api.send(method)
28
+ expect(response).to be_a(Hash)
29
+ expect(response).to have_key('objects')
30
+ expect(response).to have_key('meta')
31
+ end
32
+
33
+ it 'should return a set' do
34
+ response = api.send(method, option => set)
35
+ expect(response).to be_a(Hash)
36
+ expect(response).to have_key('related')
37
+ end
38
+
39
+ it 'should raise an error if the set does not exist' do
40
+ expect{api.send(method, option => 'nonexistent')}.to raise_error(GovKit::CA::ResourceNotFound, "404 https://represent.opennorth.ca/#{endpoint}/nonexistent/?")
41
+ end
42
+ end
43
+
44
+ RSpec.shared_examples 'item' do |method,set,size,options|
45
+ include_examples 'pagination', method, method
46
+
47
+ let :endpoint do
48
+ method
49
+ end
50
+
51
+ let :api do
52
+ GovKit::CA::Represent.new
53
+ end
54
+
55
+ it 'should return items' do
56
+ response = api.send(method)
57
+ expect(response).to be_a(Hash)
58
+ expect(response).to have_key('objects')
59
+ expect(response).to have_key('meta')
60
+ expect(response['meta']['next']).to_not be_nil
61
+ end
62
+
63
+ it 'should return items from a set' do
64
+ response = api.send(method, options.fetch(:set) => set)
65
+ expect(response).to be_a(Hash)
66
+ expect(response).to have_key('objects')
67
+ expect(response).to have_key('meta')
68
+ expect(response['objects'].size).to eq(size)
69
+ end
70
+
71
+ it 'should accept a point as an array' do
72
+ response = api.send(method, options.fetch(:point) => ['47.5699', '-52.6954'])
73
+ expect(response).to be_a(Hash)
74
+ expect(response).to have_key('objects')
75
+ expect(response).to have_key('meta')
76
+ expect(response['meta']['next']).to be_nil
77
+ end
78
+
79
+ it 'should accept a point as a comma-separated list' do
80
+ response = api.send(method, options.fetch(:point) => '47.5699,-52.6954')
81
+ expect(response).to be_a(Hash)
82
+ expect(response).to have_key('objects')
83
+ expect(response).to have_key('meta')
84
+ expect(response['meta']['next']).to be_nil
85
+ end
86
+
87
+ it 'should raise an error if the point is invalid' do
88
+ expect{api.send(method, options.fetch(:point) => '0,0,0')}.to raise_error(GovKit::CA::InvalidRequest, "400 https://represent.opennorth.ca/#{endpoint}/?#{options[:point]}=0,0,0 Invalid latitude,longitude '0,0,0' provided.")
89
+ end
90
+ end
91
+
92
+ RSpec.shared_examples 'representative' do |method,set,size,options|
93
+ include_examples 'item', method, set, size, options
94
+
95
+ let :api do
96
+ GovKit::CA::Represent.new
97
+ end
98
+
99
+ it 'should not raise an error if the set does not exist' do
100
+ expect{api.send(method, options.fetch(:set) => 'foo')}.to_not raise_error
101
+ end
102
+
103
+ it 'should accept an array of districts' do
104
+ response = api.send(method, :districts => ['federal-electoral-districts/10007', 'census-subdivisions/1001519'])
105
+ expect(response).to be_a(Hash)
106
+ expect(response).to have_key('objects')
107
+ expect(response).to have_key('meta')
108
+ expect(response['meta']['next']).to be_nil
109
+ end
110
+
111
+ it 'should accept a comma-separated list of districts' do
112
+ response = api.send(method, :districts => 'federal-electoral-districts/10007,census-subdivisions/1001519')
113
+ expect(response).to be_a(Hash)
114
+ expect(response).to have_key('objects')
115
+ expect(response).to have_key('meta')
116
+ expect(response['meta']['next']).to be_nil
117
+ end
118
+ end
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.14
4
+ version: 0.0.15
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-09-10 00:00:00.000000000 Z
11
+ date: 2015-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -142,7 +142,6 @@ files:
142
142
  - lib/gov_kit-ca.rb
143
143
  - lib/gov_kit-ca/postal_code.rb
144
144
  - lib/gov_kit-ca/postal_code/strategy/base.rb
145
- - lib/gov_kit-ca/postal_code/strategy/cbc_ca.rb
146
145
  - lib/gov_kit-ca/postal_code/strategy/conservative_ca.rb
147
146
  - lib/gov_kit-ca/postal_code/strategy/digital-copyright_ca.rb
148
147
  - lib/gov_kit-ca/postal_code/strategy/elections_ca.rb
@@ -154,8 +153,6 @@ files:
154
153
  - lib/gov_kit-ca/represent.rb
155
154
  - lib/gov_kit-ca/version.rb
156
155
  - lib/govkit-ca.rb
157
- - lib/rid_to_edid.yml
158
- - spec/cbc_ca_spec.rb
159
156
  - spec/conservative_ca_spec.rb
160
157
  - spec/digital-copyright_ca_spec.rb
161
158
  - spec/elections_ca_spec.rb
@@ -167,6 +164,7 @@ files:
167
164
  - spec/represent_spec.rb
168
165
  - spec/spec_helper.rb
169
166
  - spec/strategy_set_spec.rb
167
+ - spec/support/shared_examples_for_represent.rb
170
168
  - tasks/postal-code-for-districts.csv
171
169
  - tasks/tasks.rb
172
170
  homepage: https://github.com/opennorth/govkit-ca
@@ -194,7 +192,6 @@ signing_key:
194
192
  specification_version: 4
195
193
  summary: Easy access to Canadian civic data around the web
196
194
  test_files:
197
- - spec/cbc_ca_spec.rb
198
195
  - spec/conservative_ca_spec.rb
199
196
  - spec/digital-copyright_ca_spec.rb
200
197
  - spec/elections_ca_spec.rb
@@ -206,4 +203,5 @@ test_files:
206
203
  - spec/represent_spec.rb
207
204
  - spec/spec_helper.rb
208
205
  - spec/strategy_set_spec.rb
206
+ - spec/support/shared_examples_for_represent.rb
209
207
  has_rdoc:
@@ -1,31 +0,0 @@
1
- module GovKit
2
- module CA
3
- module PostalCode
4
- module Strategy
5
- # @deprecated Due to redistribution.
6
- class CBCCa < Base
7
- base_uri 'www.cbc.ca'
8
- http_method :get
9
- path '/news/politics/canadavotes2011/myelection/postalcodes/index.php?pc=<%= @postal_code %>'
10
-
11
- private
12
-
13
- def electoral_districts!
14
- JSON.load(response.parsed_response).map{|x| self.class.rid_to_edid[x['rid'].to_i]}
15
- end
16
-
17
- def valid?
18
- response.code != 404
19
- end
20
-
21
- # cbc.ca uses an internal riding ID, which must be matched to a
22
- # canonical electoral district ID.
23
- # @return [Hash] a map of cbc.ca riding ID to electoral district ID
24
- def self.rid_to_edid
25
- @@yml ||= YAML.load_file(File.expand_path('../../../../rid_to_edid.yml', __FILE__))
26
- end
27
- end
28
- end
29
- end
30
- end
31
- end
@@ -1,309 +0,0 @@
1
- ---
2
- 1: 10001
3
- 2: 10002
4
- 3: 10003
5
- 4: 10004
6
- 5: 10005
7
- 6: 10006
8
- 7: 10007
9
- 8: 11001
10
- 9: 11002
11
- 10: 11003
12
- 11: 11004
13
- 12: 12001
14
- 13: 12002
15
- 14: 12007
16
- 15: 12003
17
- 16: 12004
18
- 17: 12005
19
- 18: 12006
20
- 19: 12008
21
- 20: 12009
22
- 21: 12010
23
- 22: 12011
24
- 23: 13001
25
- 24: 13002
26
- 25: 13003
27
- 26: 13004
28
- 27: 13005
29
- 28: 13006
30
- 29: 13007
31
- 30: 13008
32
- 31: 13009
33
- 32: 13010
34
- 33: 24046
35
- 34: 24001
36
- 35: 24002
37
- 36: 24003
38
- 37: 24004
39
- 38: 24054
40
- 39: 24005
41
- 40: 24006
42
- 41: 24007
43
- 42: 24008
44
- 43: 24009
45
- 44: 24010
46
- 45: 24011
47
- 46: 24012
48
- 47: 24013
49
- 48: 24015
50
- 49: 24016
51
- 50: 24017
52
- 51: 24018
53
- 52: 24019
54
- 53: 24020
55
- 54: 24041
56
- 55: 24021
57
- 56: 24022
58
- 57: 24023
59
- 58: 24024
60
- 59: 24025
61
- 60: 24026
62
- 61: 24027
63
- 62: 24028
64
- 63: 24029
65
- 64: 24030
66
- 65: 24031
67
- 66: 24032
68
- 67: 24033
69
- 68: 24034
70
- 69: 24035
71
- 70: 24036
72
- 71: 24037
73
- 72: 24038
74
- 73: 24039
75
- 74: 24040
76
- 75: 24042
77
- 76: 24043
78
- 77: 24058
79
- 78: 24014
80
- 79: 24044
81
- 80: 24045
82
- 81: 24047
83
- 82: 24048
84
- 83: 24049
85
- 84: 24050
86
- 85: 24051
87
- 86: 24052
88
- 87: 24053
89
- 88: 24055
90
- 89: 24056
91
- 90: 24057
92
- 91: 24059
93
- 92: 24060
94
- 93: 24061
95
- 94: 24062
96
- 95: 24063
97
- 96: 24064
98
- 97: 24065
99
- 98: 24066
100
- 99: 24067
101
- 100: 24068
102
- 101: 24069
103
- 102: 24070
104
- 103: 24071
105
- 104: 24072
106
- 105: 24073
107
- 106: 24074
108
- 107: 24075
109
- 108: 35001
110
- 109: 35002
111
- 110: 35003
112
- 111: 35004
113
- 112: 35005
114
- 113: 35006
115
- 114: 35007
116
- 115: 35008
117
- 116: 35009
118
- 117: 35026
119
- 118: 35010
120
- 119: 35011
121
- 120: 35012
122
- 121: 35013
123
- 122: 35015
124
- 123: 35016
125
- 124: 35017
126
- 125: 35018
127
- 126: 35014
128
- 127: 35019
129
- 128: 35020
130
- 129: 35021
131
- 130: 35022
132
- 131: 35023
133
- 132: 35024
134
- 133: 35025
135
- 134: 35027
136
- 135: 35028
137
- 136: 35029
138
- 137: 35030
139
- 138: 35031
140
- 139: 35032
141
- 140: 35033
142
- 141: 35034
143
- 142: 35035
144
- 143: 35036
145
- 144: 35037
146
- 145: 35038
147
- 146: 35039
148
- 147: 35046
149
- 148: 35040
150
- 149: 35041
151
- 150: 35042
152
- 151: 35043
153
- 152: 35044
154
- 153: 35045
155
- 154: 35047
156
- 155: 35048
157
- 156: 35049
158
- 157: 35050
159
- 158: 35051
160
- 159: 35052
161
- 160: 35053
162
- 161: 35054
163
- 162: 35055
164
- 163: 35056
165
- 164: 35057
166
- 165: 35058
167
- 166: 35059
168
- 167: 35060
169
- 168: 35061
170
- 169: 35062
171
- 170: 35063
172
- 171: 35064
173
- 172: 35065
174
- 173: 35066
175
- 174: 35067
176
- 175: 35068
177
- 176: 35069
178
- 177: 35070
179
- 178: 35071
180
- 179: 35072
181
- 180: 35073
182
- 181: 35074
183
- 182: 35075
184
- 183: 35076
185
- 184: 35077
186
- 185: 35078
187
- 186: 35079
188
- 187: 35080
189
- 188: 35081
190
- 189: 35082
191
- 190: 35083
192
- 191: 35084
193
- 192: 35085
194
- 193: 35086
195
- 194: 35087
196
- 195: 35088
197
- 196: 35089
198
- 197: 35090
199
- 198: 35091
200
- 199: 35092
201
- 200: 35093
202
- 201: 35094
203
- 202: 35095
204
- 203: 35096
205
- 204: 35097
206
- 205: 35098
207
- 206: 35099
208
- 207: 35100
209
- 208: 35101
210
- 209: 35102
211
- 210: 35103
212
- 211: 35104
213
- 212: 35105
214
- 213: 35106
215
- 214: 46001
216
- 215: 46002
217
- 216: 46003
218
- 217: 46004
219
- 218: 46005
220
- 219: 46006
221
- 220: 46007
222
- 221: 46008
223
- 222: 46009
224
- 223: 46010
225
- 224: 46011
226
- 225: 46012
227
- 226: 46013
228
- 227: 46014
229
- 228: 47001
230
- 229: 47002
231
- 230: 47004
232
- 231: 47003
233
- 232: 47005
234
- 233: 47006
235
- 234: 47007
236
- 235: 47008
237
- 236: 47009
238
- 237: 47010
239
- 238: 47011
240
- 239: 47012
241
- 240: 47013
242
- 241: 47014
243
- 242: 48006
244
- 243: 48003
245
- 244: 48002
246
- 245: 48004
247
- 246: 48005
248
- 247: 48007
249
- 248: 48008
250
- 249: 48009
251
- 250: 48010
252
- 251: 48012
253
- 252: 48013
254
- 253: 48014
255
- 254: 48011
256
- 255: 48015
257
- 256: 48016
258
- 257: 48017
259
- 258: 48018
260
- 259: 48001
261
- 260: 48019
262
- 261: 48020
263
- 262: 48021
264
- 263: 48022
265
- 264: 48023
266
- 265: 48024
267
- 266: 48025
268
- 267: 48026
269
- 268: 48027
270
- 269: 48028
271
- 270: 59001
272
- 271: 59026
273
- 272: 59002
274
- 273: 59003
275
- 274: 59004
276
- 275: 59005
277
- 276: 59006
278
- 277: 59008
279
- 278: 59009
280
- 279: 59010
281
- 280: 59011
282
- 281: 59012
283
- 282: 59013
284
- 283: 59014
285
- 284: 59015
286
- 285: 59016
287
- 286: 59017
288
- 287: 59019
289
- 288: 59020
290
- 289: 59018
291
- 290: 59007
292
- 291: 59021
293
- 292: 59022
294
- 293: 59023
295
- 294: 59024
296
- 295: 59025
297
- 296: 59027
298
- 297: 59028
299
- 298: 59029
300
- 299: 59030
301
- 300: 59031
302
- 301: 59032
303
- 302: 59033
304
- 303: 59034
305
- 304: 59035
306
- 305: 59036
307
- 306: 60001
308
- 307: 61001
309
- 308: 62001
@@ -1,19 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- RSpec.describe GovKit::CA::PostalCode::Strategy::CBCCa do
4
- describe '#electoral_districts', :broken => true do
5
- it 'should return the electoral districts within a postal code' do
6
- EXPECTATIONS[:cbc_ca].each do |postal_code,electoral_districts|
7
- expect(GovKit::CA::PostalCode::Strategy::CBCCa.new(postal_code).electoral_districts).to eq(electoral_districts)
8
- end
9
- end
10
-
11
- it 'should return false if a postal code contains no electoral districts' do
12
- expect(GovKit::CA::PostalCode::Strategy::CBCCa.new('H0H0H0').electoral_districts).to eq(false)
13
- end
14
-
15
- it 'should return false if a postal code does not exist' do
16
- expect(GovKit::CA::PostalCode::Strategy::CBCCa.new('X1B1B1').electoral_districts).to eq(false)
17
- end
18
- end
19
- end