datacatalog-importer 0.1.16 → 0.1.17
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/VERSION +1 -1
- data/datacatalog-importer.gemspec +5 -5
- data/lib/pusher.rb +34 -4
- data/lib/utility.rb +14 -3
- data/spec/utility_spec.rb +21 -0
- metadata +4 -4
- data/spec/datacatalog-importer_spec.rb +0 -7
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.17
|
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{datacatalog-importer}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.17"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["David James"]
|
@@ -32,9 +32,9 @@ Gem::Specification.new do |s|
|
|
32
32
|
"lib/sort_yaml_hash.rb",
|
33
33
|
"lib/tasks.rb",
|
34
34
|
"lib/utility.rb",
|
35
|
-
"spec/datacatalog-importer_spec.rb",
|
36
35
|
"spec/spec.opts",
|
37
|
-
"spec/spec_helper.rb"
|
36
|
+
"spec/spec_helper.rb",
|
37
|
+
"spec/utility_spec.rb"
|
38
38
|
]
|
39
39
|
s.homepage = %q{http://github.com/djsun/datacatalog-importer}
|
40
40
|
s.rdoc_options = ["--charset=UTF-8"]
|
@@ -42,8 +42,8 @@ Gem::Specification.new do |s|
|
|
42
42
|
s.rubygems_version = %q{1.3.6}
|
43
43
|
s.summary = %q{A framework to write National Data Catalog importers}
|
44
44
|
s.test_files = [
|
45
|
-
"spec/
|
46
|
-
"spec/
|
45
|
+
"spec/spec_helper.rb",
|
46
|
+
"spec/utility_spec.rb"
|
47
47
|
]
|
48
48
|
|
49
49
|
if s.respond_to? :specification_version then
|
data/lib/pusher.rb
CHANGED
@@ -87,7 +87,14 @@ module DataCatalog
|
|
87
87
|
n = docs.length
|
88
88
|
if n == 0
|
89
89
|
puts "Creating Organization: #{name}"
|
90
|
-
|
90
|
+
begin
|
91
|
+
DataCatalog::Organization.create(data)
|
92
|
+
rescue DataCatalog::BadRequest => e
|
93
|
+
error("Cannot create Organization", {
|
94
|
+
:params => data,
|
95
|
+
:errors => e.errors,
|
96
|
+
})
|
97
|
+
end
|
91
98
|
else
|
92
99
|
if n > 1
|
93
100
|
warning("Cannot find unique Source with url : #{url}", {
|
@@ -96,7 +103,14 @@ module DataCatalog
|
|
96
103
|
})
|
97
104
|
end
|
98
105
|
puts "Updating Organization: #{name}"
|
99
|
-
|
106
|
+
begin
|
107
|
+
DataCatalog::Organization.update(docs[0].id, data)
|
108
|
+
rescue DataCatalog::BadRequest => e
|
109
|
+
error("Cannot update Organization with id : #{docs[0].id}", {
|
110
|
+
:params => data,
|
111
|
+
:errors => e.errors,
|
112
|
+
})
|
113
|
+
end
|
100
114
|
end
|
101
115
|
end
|
102
116
|
|
@@ -161,10 +175,24 @@ module DataCatalog
|
|
161
175
|
case n
|
162
176
|
when 0
|
163
177
|
puts "- Creating Download: #{data[:format]}"
|
164
|
-
|
178
|
+
begin
|
179
|
+
DataCatalog::Download.create(data)
|
180
|
+
rescue DataCatalog::BadRequest => e
|
181
|
+
error("Cannot create Download", {
|
182
|
+
:params => data,
|
183
|
+
:errors => e.errors,
|
184
|
+
})
|
185
|
+
end
|
165
186
|
when 1
|
166
187
|
puts "- Updating Download: #{data[:format]}"
|
167
|
-
|
188
|
+
begin
|
189
|
+
DataCatalog::Download.update(docs[0].id, data)
|
190
|
+
rescue DataCatalog::BadRequest => e
|
191
|
+
error("Cannot update Download with id : #{docs[0].id}", {
|
192
|
+
:params => data,
|
193
|
+
:errors => e.errors,
|
194
|
+
})
|
195
|
+
end
|
168
196
|
else
|
169
197
|
error("Cannot find unique Download with source_id : #{source.id} and format : #{data[:format]}", {
|
170
198
|
:error => "#{n} matches: " + docs.map { |x| x.id }.join(" ")
|
@@ -232,6 +260,8 @@ module DataCatalog
|
|
232
260
|
:object => object,
|
233
261
|
})
|
234
262
|
nil
|
263
|
+
rescue DataCatalog::BadRequest => e
|
264
|
+
raise Error, "Could not upload Report to API: #{e.errors.inspect}"
|
235
265
|
end
|
236
266
|
|
237
267
|
end
|
data/lib/utility.rb
CHANGED
@@ -9,7 +9,15 @@ module DataCatalog
|
|
9
9
|
# == URLs ==
|
10
10
|
|
11
11
|
def self.absolute_url(page_url, url)
|
12
|
-
|
12
|
+
plain_string(URI.parse(page_url).merge(url).to_s)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.normalize_url(url)
|
16
|
+
uri = URI.parse(url).normalize
|
17
|
+
unless uri.scheme
|
18
|
+
uri = URI.parse("http://#{url}").normalize
|
19
|
+
end
|
20
|
+
uri.to_s
|
13
21
|
end
|
14
22
|
|
15
23
|
# == Cleaning ==
|
@@ -42,7 +50,7 @@ module DataCatalog
|
|
42
50
|
|
43
51
|
def self.headers
|
44
52
|
{
|
45
|
-
"UserAgent" => "National Data Catalog Importer/0.1.
|
53
|
+
"UserAgent" => "National Data Catalog Importer/0.1.17",
|
46
54
|
}
|
47
55
|
end
|
48
56
|
|
@@ -51,7 +59,9 @@ module DataCatalog
|
|
51
59
|
# For background on rescuing net/http errors, see:
|
52
60
|
# * http://jerith.livejournal.com/40063.html
|
53
61
|
# * http://lindsaar.net/2007/12/9/rbuf_filltimeout-error
|
54
|
-
def self.fetch(uri,
|
62
|
+
def self.fetch(uri, options={})
|
63
|
+
max_attempts = options[:max_attempts] || 3
|
64
|
+
retry_delay = options[:retry_delay] || 5
|
55
65
|
attempts = 0
|
56
66
|
loop do
|
57
67
|
begin
|
@@ -63,6 +73,7 @@ module DataCatalog
|
|
63
73
|
puts " Attempt ##{attempts} failed."
|
64
74
|
puts " Error: #{e.inspect}"
|
65
75
|
break if attempts >= max_attempts
|
76
|
+
sleep(retry_delay)
|
66
77
|
end
|
67
78
|
end
|
68
79
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
U = DataCatalog::ImporterFramework::Utility
|
4
|
+
|
5
|
+
describe "Utility" do
|
6
|
+
|
7
|
+
describe "normalize_url" do
|
8
|
+
it "add trailing slash if missing" do
|
9
|
+
U.normalize_url("sunlightlabs.com").should == "http://sunlightlabs.com/"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "lowercases" do
|
13
|
+
U.normalize_url("http://SunlightLabs.com/").should == "http://sunlightlabs.com/"
|
14
|
+
end
|
15
|
+
|
16
|
+
it "adds http if missing" do
|
17
|
+
U.normalize_url("sunlightlabs.com/").should == "http://sunlightlabs.com/"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 17
|
9
|
+
version: 0.1.17
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- David James
|
@@ -84,9 +84,9 @@ files:
|
|
84
84
|
- lib/sort_yaml_hash.rb
|
85
85
|
- lib/tasks.rb
|
86
86
|
- lib/utility.rb
|
87
|
-
- spec/datacatalog-importer_spec.rb
|
88
87
|
- spec/spec.opts
|
89
88
|
- spec/spec_helper.rb
|
89
|
+
- spec/utility_spec.rb
|
90
90
|
has_rdoc: true
|
91
91
|
homepage: http://github.com/djsun/datacatalog-importer
|
92
92
|
licenses: []
|
@@ -118,5 +118,5 @@ signing_key:
|
|
118
118
|
specification_version: 3
|
119
119
|
summary: A framework to write National Data Catalog importers
|
120
120
|
test_files:
|
121
|
-
- spec/datacatalog-importer_spec.rb
|
122
121
|
- spec/spec_helper.rb
|
122
|
+
- spec/utility_spec.rb
|