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 CHANGED
@@ -3,7 +3,7 @@ rvm:
3
3
  - 1.9.3
4
4
  notifications:
5
5
  recipients:
6
- - jari.bakken@gmail.com
6
+ - jari@holderdeord.no
7
7
  irc:
8
8
  channels:
9
9
  - "irc.freenode.net#holderdeord"
@@ -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
@@ -39,7 +39,7 @@
39
39
  "required": true
40
40
  },
41
41
  "page": {
42
- "type": "number",
42
+ "type": "integer",
43
43
  "description": "What page in the source the promise was found on"
44
44
  },
45
45
  "body": {
@@ -22,9 +22,9 @@
22
22
  "description": "Count of for, against or absent representatives.",
23
23
  "required": true,
24
24
  "properties": {
25
- "for": { "type": "number" },
26
- "against": { "type": "number" },
27
- "absent": { "type": "number" }
25
+ "for": { "type": "integer" },
26
+ "against": { "type": "integer" },
27
+ "absent": { "type": "integer" }
28
28
  }
29
29
  },
30
30
  "personal": {
@@ -1,5 +1,5 @@
1
1
  module Hdo
2
2
  module StortingImporter
3
- VERSION = "0.2.1"
3
+ VERSION = "0.2.2"
4
4
  end
5
5
  end
@@ -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'
@@ -59,6 +59,10 @@ module Hdo
59
59
  }')
60
60
  end
61
61
 
62
+ it 'can create a customized example' do
63
+ obj = Category.example('name' => 'foo')
64
+ obj.name.should == 'foo'
65
+ end
62
66
 
63
67
  end
64
68
  end
@@ -40,6 +40,12 @@ module Hdo
40
40
  JSON
41
41
  end
42
42
 
43
+ it 'can create a customized example' do
44
+ obj = Committee.example('name' => 'foo')
45
+ obj.name.should == 'foo'
46
+ end
47
+
48
+
43
49
  end
44
50
  end
45
51
  end
@@ -49,6 +49,12 @@ module Hdo
49
49
  District.new("Ak", "Akershus").to_json.should be_json(expected)
50
50
  end
51
51
 
52
+ it 'can create a customized example' do
53
+ obj = District.example('name' => 'foo')
54
+ obj.name.should == 'foo'
55
+ end
56
+
57
+
52
58
  end
53
59
  end
54
60
  end
@@ -90,6 +90,12 @@ module Hdo
90
90
  JSON
91
91
  end
92
92
 
93
+ it 'can create a customized example' do
94
+ obj = ParliamentIssue.example('status' => 'behandlet')
95
+ obj.status.should == 'behandlet'
96
+ end
97
+
98
+
93
99
  end
94
100
  end
95
101
  end
@@ -53,6 +53,11 @@ module Hdo
53
53
  party.external_id.should == "ÆØÅ"
54
54
  end
55
55
 
56
+ it 'can create a customized example' do
57
+ party = Party.example('name' => 'foo')
58
+ party.name.should == 'foo'
59
+ end
60
+
56
61
  end
57
62
  end
58
63
  end
@@ -39,6 +39,12 @@ module Hdo
39
39
  promise.categories.should == ["FOO"]
40
40
  end
41
41
 
42
+ it 'can create a customized example' do
43
+ obj = Promise.example('body' => 'foo')
44
+ obj.body.should == 'foo'
45
+ end
46
+
47
+
42
48
  end
43
49
  end
44
50
  end
@@ -82,6 +82,11 @@ module Hdo
82
82
  prop.body.should_not be_empty
83
83
  end
84
84
 
85
+ it 'can create a customized example' do
86
+ obj = Proposition.example('body' => 'foo')
87
+ obj.body.should == 'foo'
88
+ end
89
+
85
90
  end
86
91
  end
87
92
  end
@@ -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
- Representative.from_json(invalid).should_not be_valid
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
@@ -134,6 +134,11 @@ module Hdo
134
134
  JSON
135
135
  end
136
136
 
137
+ it 'can create a customized example' do
138
+ obj = Vote.example('subject' => 'foo')
139
+ obj.subject.should == 'foo'
140
+ end
141
+
137
142
  end
138
143
  end
139
144
  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.1
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-08-22 00:00:00.000000000 Z
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