hdo-storting-importer 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +1 -1
- data/lib/hdo/storting_importer/category.rb +5 -1
- data/lib/hdo/storting_importer/committee.rb +8 -2
- data/lib/hdo/storting_importer/district.rb +8 -2
- data/lib/hdo/storting_importer/parliament_issue.rb +8 -2
- data/lib/hdo/storting_importer/party.rb +5 -1
- data/lib/hdo/storting_importer/promise.rb +8 -2
- data/lib/hdo/storting_importer/proposition.rb +8 -2
- data/lib/hdo/storting_importer/representative.rb +8 -2
- data/lib/hdo/storting_importer/schema/promise.json +1 -1
- data/lib/hdo/storting_importer/schema/vote.json +3 -3
- data/lib/hdo/storting_importer/version.rb +1 -1
- data/lib/hdo/storting_importer/vote.rb +5 -1
- data/lib/hdo/storting_importer.rb +0 -1
- data/spec/hdo/storting_importer/category_spec.rb +4 -0
- data/spec/hdo/storting_importer/committee_spec.rb +6 -0
- data/spec/hdo/storting_importer/district_spec.rb +6 -0
- data/spec/hdo/storting_importer/parliament_issue_spec.rb +6 -0
- data/spec/hdo/storting_importer/party_spec.rb +5 -0
- data/spec/hdo/storting_importer/promise_spec.rb +6 -0
- data/spec/hdo/storting_importer/proposition_spec.rb +5 -0
- data/spec/hdo/storting_importer/representative_spec.rb +8 -3
- data/spec/hdo/storting_importer/vote_spec.rb +5 -0
- metadata +2 -3
- data/lib/hdo/storting_importer/fusion_table.rb +0 -52
data/.travis.yml
CHANGED
@@ -10,10 +10,14 @@ module Hdo
|
|
10
10
|
|
11
11
|
schema_path StortingImporter.lib.join("hdo/storting_importer/schema/category.json").to_s
|
12
12
|
|
13
|
-
def self.example
|
13
|
+
def self.example(overrides = nil)
|
14
14
|
cat = new("5", "Employment")
|
15
15
|
cat.children << new("6", "Wages")
|
16
16
|
|
17
|
+
if overrides
|
18
|
+
cat = from_hash(cat.to_hash.merge(overrides))
|
19
|
+
end
|
20
|
+
|
17
21
|
cat
|
18
22
|
end
|
19
23
|
|
@@ -9,8 +9,14 @@ module Hdo
|
|
9
9
|
|
10
10
|
schema_path StortingImporter.lib.join("hdo/storting_importer/schema/committee.json").to_s
|
11
11
|
|
12
|
-
def self.example
|
13
|
-
new "ARBSOS", "Arbeids- og sosialkomiteen"
|
12
|
+
def self.example(overrides = nil)
|
13
|
+
obj = new "ARBSOS", "Arbeids- og sosialkomiteen"
|
14
|
+
|
15
|
+
if overrides
|
16
|
+
obj = from_hash(obj.to_hash.merge(overrides))
|
17
|
+
end
|
18
|
+
|
19
|
+
obj
|
14
20
|
end
|
15
21
|
|
16
22
|
def self.from_storting_doc(doc)
|
@@ -9,8 +9,14 @@ module Hdo
|
|
9
9
|
|
10
10
|
schema_path StortingImporter.lib.join("hdo/storting_importer/schema/district.json").to_s
|
11
11
|
|
12
|
-
def self.example
|
13
|
-
new("Db", "Duckburg")
|
12
|
+
def self.example(overrides = nil)
|
13
|
+
obj = new("Db", "Duckburg")
|
14
|
+
|
15
|
+
if overrides
|
16
|
+
obj = from_hash(obj.to_hash.merge(overrides))
|
17
|
+
end
|
18
|
+
|
19
|
+
obj
|
14
20
|
end
|
15
21
|
|
16
22
|
def self.from_storting_doc(doc)
|
@@ -12,8 +12,8 @@ module Hdo
|
|
12
12
|
|
13
13
|
schema_path StortingImporter.lib.join("hdo/storting_importer/schema/parliament_issue.json").to_s
|
14
14
|
|
15
|
-
def self.example
|
16
|
-
new(
|
15
|
+
def self.example(overrides = nil)
|
16
|
+
obj = new(
|
17
17
|
"53520",
|
18
18
|
"Inngåelse av avtale om opprettelse av sekretariatet for Den nordlige dimensjons partnerskap for helse og livskvalitet (NDPHS)",
|
19
19
|
"Samtykke til inngåelse av avtale av 25. november 2011 om opprettelse av sekretariatet for Den nordlige dimensjons partnerskap for helse og livskvalitet (NDPHS)",
|
@@ -25,6 +25,12 @@ module Hdo
|
|
25
25
|
"Transport- og kommunikasjonskomiteen",
|
26
26
|
['UTENRIKSSAKER', 'TRAKTATER', 'NORDISK SAMARBEID']
|
27
27
|
)
|
28
|
+
|
29
|
+
if overrides
|
30
|
+
obj = from_hash(obj.to_hash.merge(overrides))
|
31
|
+
end
|
32
|
+
|
33
|
+
obj
|
28
34
|
end
|
29
35
|
|
30
36
|
def self.json_example
|
@@ -10,10 +10,14 @@ module Hdo
|
|
10
10
|
|
11
11
|
schema_path StortingImporter.lib.join("hdo/storting_importer/schema/party.json").to_s
|
12
12
|
|
13
|
-
def self.example
|
13
|
+
def self.example(overrides = nil)
|
14
14
|
obj = new("A", "Arbeiderpartiet")
|
15
15
|
obj.governing_periods = [GoverningPeriod.new('2005-10-17', '2013-10-14')]
|
16
16
|
|
17
|
+
if overrides
|
18
|
+
obj = from_hash(obj.to_hash.merge(overrides))
|
19
|
+
end
|
20
|
+
|
17
21
|
obj
|
18
22
|
end
|
19
23
|
|
@@ -14,8 +14,8 @@ module Hdo
|
|
14
14
|
|
15
15
|
schema_path StortingImporter.lib.join("hdo/storting_importer/schema/promise.json").to_s
|
16
16
|
|
17
|
-
def self.example
|
18
|
-
new(
|
17
|
+
def self.example(overrides = nil)
|
18
|
+
obj = new(
|
19
19
|
"1",
|
20
20
|
["H"],
|
21
21
|
"Stille strengere krav til orden og oppførsel for å hindre at uro ødelegger undervisningen.",
|
@@ -25,6 +25,12 @@ module Hdo
|
|
25
25
|
8,
|
26
26
|
'2009-06-01'
|
27
27
|
)
|
28
|
+
|
29
|
+
if overrides
|
30
|
+
obj = from_hash(obj.to_hash.merge(overrides))
|
31
|
+
end
|
32
|
+
|
33
|
+
obj
|
28
34
|
end
|
29
35
|
|
30
36
|
def self.json_example
|
@@ -9,8 +9,14 @@ module Hdo
|
|
9
9
|
|
10
10
|
schema_path StortingImporter.lib.join("hdo/storting_importer/schema/proposition.json").to_s
|
11
11
|
|
12
|
-
def self.example
|
13
|
-
new('1234', 'description', 'on behalf of', 'body', Representative.example)
|
12
|
+
def self.example(overrides = nil)
|
13
|
+
obj = new('1234', 'description', 'on behalf of', 'body', Representative.example)
|
14
|
+
|
15
|
+
if overrides
|
16
|
+
obj = from_hash(obj.to_hash.merge(overrides))
|
17
|
+
end
|
18
|
+
|
19
|
+
obj
|
14
20
|
end
|
15
21
|
|
16
22
|
def self.json_example
|
@@ -14,8 +14,8 @@ module Hdo
|
|
14
14
|
|
15
15
|
schema_path StortingImporter.lib.join("hdo/storting_importer/schema/representative.json").to_s
|
16
16
|
|
17
|
-
def self.example
|
18
|
-
new(
|
17
|
+
def self.example(overrides = nil)
|
18
|
+
obj = new(
|
19
19
|
'ADA',
|
20
20
|
'André Oktay',
|
21
21
|
'Dahl',
|
@@ -27,6 +27,12 @@ module Hdo
|
|
27
27
|
['Justiskomiteen'],
|
28
28
|
'2011-2012'
|
29
29
|
)
|
30
|
+
|
31
|
+
if overrides
|
32
|
+
obj = from_hash(obj.to_hash.merge(overrides))
|
33
|
+
end
|
34
|
+
|
35
|
+
obj
|
30
36
|
end
|
31
37
|
|
32
38
|
def self.json_example
|
@@ -22,9 +22,9 @@
|
|
22
22
|
"description": "Count of for, against or absent representatives.",
|
23
23
|
"required": true,
|
24
24
|
"properties": {
|
25
|
-
"for": { "type": "
|
26
|
-
"against": { "type": "
|
27
|
-
"absent": { "type": "
|
25
|
+
"for": { "type": "integer" },
|
26
|
+
"against": { "type": "integer" },
|
27
|
+
"absent": { "type": "integer" }
|
28
28
|
}
|
29
29
|
},
|
30
30
|
"personal": {
|
@@ -16,7 +16,7 @@ module Hdo
|
|
16
16
|
|
17
17
|
schema_path StortingImporter.lib.join("hdo/storting_importer/schema/vote.json").to_s
|
18
18
|
|
19
|
-
def self.example
|
19
|
+
def self.example(overrides = nil)
|
20
20
|
vote = new('2175', '51448', true, false, 'Forslag 24 - 26 på vegne av Per Olaf Lundteigen', 'ikke_spesifisert', 'ikke_spesifisert', '2012-04-12T16:37:27.053', 2, 96, 71)
|
21
21
|
|
22
22
|
rep = Representative.example
|
@@ -27,6 +27,10 @@ module Hdo
|
|
27
27
|
|
28
28
|
vote.propositions << prop
|
29
29
|
|
30
|
+
if overrides
|
31
|
+
vote = from_hash(vote.to_hash.merge(overrides))
|
32
|
+
end
|
33
|
+
|
30
34
|
vote
|
31
35
|
end
|
32
36
|
|
@@ -111,7 +111,6 @@ require 'hdo/storting_importer/ivar_equality'
|
|
111
111
|
require 'hdo/storting_importer/inspectable'
|
112
112
|
require 'hdo/storting_importer/has_json_schema'
|
113
113
|
require 'hdo/storting_importer/util'
|
114
|
-
require 'hdo/storting_importer/fusion_table'
|
115
114
|
require 'hdo/storting_importer/in_memory_cache'
|
116
115
|
|
117
116
|
require 'hdo/storting_importer/data_source'
|
@@ -71,8 +71,6 @@ module Hdo
|
|
71
71
|
end
|
72
72
|
|
73
73
|
it 'is invalid if the voteResult property is invalid' do
|
74
|
-
pending "find a validator that checks format"
|
75
|
-
|
76
74
|
invalid = <<-JSON
|
77
75
|
{
|
78
76
|
"kind": "hdo#representative",
|
@@ -91,7 +89,9 @@ module Hdo
|
|
91
89
|
|
92
90
|
JSON
|
93
91
|
|
94
|
-
|
92
|
+
expect {
|
93
|
+
Representative.from_json(invalid)
|
94
|
+
}.to raise_error(ValidationError)
|
95
95
|
end
|
96
96
|
|
97
97
|
it 'unescapes non-ASCII characters in the external id' do
|
@@ -101,6 +101,11 @@ module Hdo
|
|
101
101
|
rep.external_id.should == "ÆØÅ"
|
102
102
|
end
|
103
103
|
|
104
|
+
it 'can create a customized example' do
|
105
|
+
obj = Representative.example('firstName' => 'foo')
|
106
|
+
obj.first_name.should == 'foo'
|
107
|
+
end
|
108
|
+
|
104
109
|
end
|
105
110
|
end
|
106
111
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hdo-storting-importer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-09-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: builder
|
@@ -281,7 +281,6 @@ files:
|
|
281
281
|
- lib/hdo/storting_importer/data_source.rb
|
282
282
|
- lib/hdo/storting_importer/disk_data_source.rb
|
283
283
|
- lib/hdo/storting_importer/district.rb
|
284
|
-
- lib/hdo/storting_importer/fusion_table.rb
|
285
284
|
- lib/hdo/storting_importer/governing_period.rb
|
286
285
|
- lib/hdo/storting_importer/has_json_schema.rb
|
287
286
|
- lib/hdo/storting_importer/in_memory_cache.rb
|
@@ -1,52 +0,0 @@
|
|
1
|
-
module Hdo
|
2
|
-
module StortingImporter
|
3
|
-
#
|
4
|
-
# Simple query public Fusion Tables (onle need API key for auth).
|
5
|
-
# If we need to write to the table programatically, see https://gist.github.com/3265043.
|
6
|
-
#
|
7
|
-
|
8
|
-
class FusionTable
|
9
|
-
def initialize(api_key)
|
10
|
-
@api_key = api_key
|
11
|
-
end
|
12
|
-
|
13
|
-
def query(sql, opts = {})
|
14
|
-
resp = fix_request_failure do
|
15
|
-
RestClient.get("https://www.googleapis.com/fusiontables/v1/query", :params => {:sql => sql, :key => @api_key})
|
16
|
-
end
|
17
|
-
|
18
|
-
data = MultiJson.decode(resp)
|
19
|
-
|
20
|
-
if opts[:rows]
|
21
|
-
data.fetch('rows')
|
22
|
-
else
|
23
|
-
cols = data.fetch('columns')
|
24
|
-
rows = data.fetch('rows')
|
25
|
-
|
26
|
-
rows.map do |row|
|
27
|
-
res = {}
|
28
|
-
cols.each_with_index { |col, idx| res[col] = row[idx] }
|
29
|
-
|
30
|
-
res
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def columns_for(table_id)
|
36
|
-
resp = fix_request_failure do
|
37
|
-
RestClient.get("https://www.googleapis.com/fusiontables/v1/tables/#{table_id}/columns", :params => {:key => @api_key})
|
38
|
-
end
|
39
|
-
|
40
|
-
data = MultiJson.decode(resp)
|
41
|
-
data['items']
|
42
|
-
end
|
43
|
-
|
44
|
-
def fix_request_failure(&blk)
|
45
|
-
yield
|
46
|
-
rescue RestClient::RequestFailed => ex
|
47
|
-
raise unless ex.respond_to?(:http_body)
|
48
|
-
raise "#{ex.message}: #{ex.http_body}"
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|