hdo-storting-importer 0.0.7 → 0.0.8
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.
- data/Rakefile +21 -0
- data/hdo-storting-importer.gemspec +1 -0
- data/lib/hdo/storting_importer/api_data_source.rb +3 -2
- data/lib/hdo/storting_importer/promise.rb +11 -0
- data/lib/hdo/storting_importer/version.rb +1 -1
- data/lib/hdo/storting_importer/vote.rb +1 -0
- data/lib/hdo/storting_importer.rb +59 -0
- metadata +18 -2
data/Rakefile
CHANGED
@@ -1,11 +1,32 @@
|
|
1
1
|
require 'rake'
|
2
2
|
require 'rspec/core/rake_task'
|
3
|
+
require 'pry'
|
3
4
|
|
4
5
|
RSpec::Core::RakeTask.new
|
5
6
|
|
6
7
|
require 'cucumber/rake/task'
|
7
8
|
Cucumber::Rake::Task.new
|
8
9
|
|
10
|
+
task :env do
|
11
|
+
$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
|
12
|
+
require 'hdo/storting_importer'
|
13
|
+
end
|
14
|
+
|
15
|
+
namespace :doc do
|
16
|
+
task :types => :env do
|
17
|
+
Hdo::StortingImporter.print_types
|
18
|
+
end
|
19
|
+
|
20
|
+
desc 'Like `rake docs`, but includes XML examples.'
|
21
|
+
task :xml => :env do
|
22
|
+
Hdo::StortingImporter.print_types :xml => true
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
desc 'Print docs for each import type.'
|
27
|
+
task :doc => %w[doc:types]
|
28
|
+
|
29
|
+
desc 'Default task runs all tests.'
|
9
30
|
task :default => [:spec, :cucumber]
|
10
31
|
|
11
32
|
require "bundler/gem_tasks"
|
@@ -1,9 +1,10 @@
|
|
1
1
|
module Hdo
|
2
2
|
module StortingImporter
|
3
3
|
class ApiDataSource < DataSource
|
4
|
+
USER_AGENT = "holderdeord-storting-importer"
|
4
5
|
|
5
6
|
def initialize(url)
|
6
|
-
@resource = RestClient::Resource.new(URI.parse(url))
|
7
|
+
@resource = RestClient::Resource.new(URI.parse(url), )
|
7
8
|
end
|
8
9
|
|
9
10
|
def representatives(period = DEFAULT_PERIOD)
|
@@ -52,7 +53,7 @@ module Hdo
|
|
52
53
|
sub_resource = @resource[path]
|
53
54
|
Hdo::StortingImporter.logger.info "parsing #{sub_resource}"
|
54
55
|
|
55
|
-
parse sub_resource.get
|
56
|
+
parse sub_resource.get(:user_agent => USER_AGENT)
|
56
57
|
end
|
57
58
|
|
58
59
|
end
|
@@ -79,6 +79,15 @@ module Hdo
|
|
79
79
|
end.compact
|
80
80
|
end
|
81
81
|
|
82
|
+
def self.from_fusion_table(table_id, api_key)
|
83
|
+
url = "https://www.googleapis.com/fusiontables/v1/query"
|
84
|
+
|
85
|
+
resp = RestClient.get(url, :params => {:sql => "select * from #{table_id}", :key => api_key})
|
86
|
+
MultiJson.decode(resp).fetch('rows').map { |data| new(*data) }
|
87
|
+
rescue RestClient::RequestFailed => ex
|
88
|
+
raise "#{ex.message}: #{ex.http_body}"
|
89
|
+
end
|
90
|
+
|
82
91
|
def initialize(party, body, general, categories, source, page)
|
83
92
|
@party = party
|
84
93
|
@body = body
|
@@ -103,6 +112,8 @@ module Hdo
|
|
103
112
|
private
|
104
113
|
|
105
114
|
def clean_categories(categories)
|
115
|
+
categories = categories.split(",") if categories.kind_of?(String)
|
116
|
+
|
106
117
|
categories.map(&:strip).
|
107
118
|
reject(&:empty?).
|
108
119
|
map { |e| UnicodeUtils.upcase(e) }
|
@@ -27,6 +27,7 @@ module Hdo
|
|
27
27
|
Field.new(:externalIssueId, true, :string, "The id (matching the issue's externalId) of the issue being voted on."),
|
28
28
|
Field.new(:counts, true, :element, "An element with <for>, <against> and <absent> counts (see example)."),
|
29
29
|
Field.new(:enacted, true, :boolean, "Whether the proposal was enacted."),
|
30
|
+
Field.new(:personal, true, :boolean, "Whether the vote was done using the voting system. If not, we attempt to infer the representative list from other votes on the same day."),
|
30
31
|
Field.new(:subject, true, :string, "The subject of the vote."),
|
31
32
|
Field.new(:method, true, :string, "??"),
|
32
33
|
Field.new(:resultType, true, :string, "??"),
|
@@ -7,6 +7,8 @@ require 'erb'
|
|
7
7
|
require 'logger'
|
8
8
|
require 'builder'
|
9
9
|
require 'unicode_utils'
|
10
|
+
require 'uri'
|
11
|
+
require 'multi_json'
|
10
12
|
|
11
13
|
module Hdo
|
12
14
|
module StortingImporter
|
@@ -14,6 +16,63 @@ module Hdo
|
|
14
16
|
@root ||= File.expand_path("../../..", __FILE__)
|
15
17
|
end
|
16
18
|
|
19
|
+
def self.types
|
20
|
+
[
|
21
|
+
Party,
|
22
|
+
Committee,
|
23
|
+
District,
|
24
|
+
Representative,
|
25
|
+
Category,
|
26
|
+
Issue,
|
27
|
+
Vote,
|
28
|
+
Vote::Proposition,
|
29
|
+
Promise
|
30
|
+
]
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.print_types(opts = {})
|
34
|
+
out = opts[:io] || $stdout
|
35
|
+
xml = !!opts[:xml]
|
36
|
+
|
37
|
+
max_name_size = 0
|
38
|
+
max_type_size = 0
|
39
|
+
|
40
|
+
type_strings = []
|
41
|
+
|
42
|
+
|
43
|
+
types.each do |type|
|
44
|
+
type.fields.each do |e|
|
45
|
+
required = 'required' if e.required
|
46
|
+
type_strings << (type_string = "#{required}:#{e.type}")
|
47
|
+
|
48
|
+
max_name_size = [e.name.size, max_name_size].max
|
49
|
+
max_type_size = [type_string.size, max_type_size].max
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
types.each_with_index do |type, type_idx|
|
54
|
+
out.puts "\x1b[1m#{type.type_name}\x1b[0m\n"
|
55
|
+
|
56
|
+
type.fields.each_with_index do |field, field_idx|
|
57
|
+
|
58
|
+
parts = [
|
59
|
+
field.name.to_s.rjust(max_name_size + 5),
|
60
|
+
type_strings[type_idx + field_idx].rjust(max_type_size),
|
61
|
+
"\t#{field.description}"
|
62
|
+
]
|
63
|
+
|
64
|
+
out.puts parts.join ' '
|
65
|
+
end
|
66
|
+
|
67
|
+
out.puts "\n\n"
|
68
|
+
|
69
|
+
if xml
|
70
|
+
puts type.xml_example.split("\n")
|
71
|
+
puts "\n\n"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
17
76
|
def self.logger
|
18
77
|
@logger ||= (
|
19
78
|
out = $stderr # should be able to pipe output to a file
|
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.0.
|
4
|
+
version: 0.0.8
|
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-08-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: builder
|
@@ -107,6 +107,22 @@ dependencies:
|
|
107
107
|
- - ! '>='
|
108
108
|
- !ruby/object:Gem::Version
|
109
109
|
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: multi_json
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
110
126
|
description: Gem to process data from data.stortinget.no
|
111
127
|
email:
|
112
128
|
- jari.bakken@gmail.com
|