turbot 0.0.51 → 0.1.0

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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MTE2NmZhMWExMDIyYjg4MWYzYmFlZGE2YzgzODcxOGIyZTg4ODhlMA==
4
+ NmExMjA4OTczZWFmMzMxYTQxMDg1YjU2OGVmMGI3NWYwNDQ4NDhkOQ==
5
5
  data.tar.gz: !binary |-
6
- N2FmNDJiODE2ODkxMWFhMmZiMWYwYWVmMTY3MDFhOWUxZGIyNzhjYw==
6
+ MGJhYzJlMDkwNjI0M2Q5M2ZmZWIwYjE0NmJiYmU0YWYxNjRmZGQ3NA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NDc3MTNmZmRkNTc5MWI3YzM3M2FmZDM2NmU3OWQ3Yzg4ZmY5ZDRhMTNhMDMx
10
- ZDI4ZWFhNmU2ODhiMmY3NTJiYzYzZmYzZGEzNTFmNmQxNDZiYTYxNGQ2ZWY3
11
- OGY0MTMwMGU3MDFjZTc3YTMzYmYxYmZlOWFiOTM0Y2ExYWJhN2Y=
9
+ NTY1YWM4ZDhjM2QxN2YyMjNmMjQxYTc0YWFkOTcyNTA5MWVkM2M4MWYwM2I2
10
+ NDA2ZDhkNTRhZmVkYzZjZjlmMTJmNjRlZDMxNDdhOTBjOTQ5NWM4YzdlNDJl
11
+ YjU3MTA4YWRmMTBiZWVhMzg0YzQ1NmRiMGRkYzAxMzgzOWJlNWM=
12
12
  data.tar.gz: !binary |-
13
- OTczY2UwZGYwYTZhYTAzMGVhOTllMTUzNjRkNDc5NmQxYWZjYThlNDU0NjE4
14
- Mzg2YmIzYTMyM2ViM2JjOGZlMzM5MGIwNDE3NWU2ZGI3NGQwNTdkNjQxZGFm
15
- OTI2M2YyZTk5YWRkMzNkZDU1YmM1YWY5OTFmMDA0ODY2M2FjYzU=
13
+ NGJmYzIzYzgwMDA3Y2M4Y2NmMTM3ZWQ4NGYyNDg0ZTJmOTIwY2FiYmM4YjNk
14
+ NTZiYmVlNTIyZWQxMzFmMzNjMmFiYjFkZTRmNzEzZGU4ZmNlNGJjNTdiNjYz
15
+ M2ZlMzVkZmJkYTdmYTllN2Q4MTQxNDI2M2RkMzA4OTBkMTlmZTg=
@@ -199,7 +199,7 @@ class Turbot::Command::Bots < Turbot::Command::Base
199
199
  validate_arguments!
200
200
  config = parsed_manifest(Dir.pwd)
201
201
 
202
- %w(bot_id data_type identifying_fields files).each do |key|
202
+ %w(bot_id data_type identifying_fields files publisher).each do |key|
203
203
  error("Manifest is missing #{key}") unless config.has_key?(key)
204
204
  end
205
205
 
@@ -211,8 +211,16 @@ class Turbot::Command::Bots < Turbot::Command::Base
211
211
  error("No schema found for data_type: #{type}")
212
212
  end
213
213
 
214
- runner = ValidationRunner.new(Dir.pwd)
215
- runner.run
214
+ handler = ValidationHandler.new
215
+ runner = TurbotRunner::Runner.new(Dir.pwd, :record_handler => handler)
216
+ rc = runner.run
217
+
218
+ puts
219
+ if rc
220
+ puts "Validated #{handler.count} records!"
221
+ else
222
+ puts "Validated #{handler.count} records before bot failed!"
223
+ end
216
224
  end
217
225
 
218
226
  # bots:dump
@@ -225,8 +233,17 @@ class Turbot::Command::Bots < Turbot::Command::Base
225
233
 
226
234
  def dump
227
235
  validate_arguments!
228
- runner = DumpRunner.new(Dir.pwd)
229
- runner.run
236
+
237
+ handler = DumpHandler.new
238
+ runner = TurbotRunner::Runner.new(Dir.pwd, :record_handler => handler)
239
+ rc = runner.run
240
+
241
+ puts
242
+ if rc
243
+ puts "Bot ran successfully!"
244
+ else
245
+ puts "Bot failed!"
246
+ end
230
247
  end
231
248
 
232
249
  # # bots:single
@@ -266,12 +283,24 @@ class Turbot::Command::Bots < Turbot::Command::Base
266
283
  api.destroy_draft_data(bot)
267
284
  puts "Sending to turbot... "
268
285
 
269
- runner = PreviewRunner.new(bot, api)
270
- Signal.trap("INT") do
271
- Process.kill("ABRT", runner.wait_thread[:pid])
272
- runner.interrupt
286
+ handler = PreviewHandler.new(bot, api)
287
+ runner = TurbotRunner::Runner.new(Dir.pwd, :record_handler => handler)
288
+ rc = runner.run
289
+
290
+ puts
291
+
292
+ if rc
293
+ response = handler.submit_batch
294
+ if handler.count > 0
295
+ puts "Submitted #{handler.count} records to turbot"
296
+ puts "View your records at #{response.data[:url]}"
297
+ else
298
+ puts "No records sent"
299
+ end
300
+ else
301
+ puts
302
+ puts "Bot failed!"
273
303
  end
274
- runner.run
275
304
  end
276
305
 
277
306
  private
@@ -320,28 +349,10 @@ class Turbot::Command::Bots < Turbot::Command::Base
320
349
  end
321
350
  end
322
351
 
323
- class PreviewRunner < TurbotRunner::BaseRunner
324
- def initialize(bot_name, api)
325
- @bot_name = bot_name
326
- @api = api
327
- @batch = []
328
- @count = 0
329
- super(Dir.pwd)
330
- end
331
-
332
- def handle_valid_record(record, data_type)
333
- #spinner(@count)
334
- @count += 1
335
- @batch << record.merge(:data_type => data_type)
336
-
337
- if @count % 20 == 0
338
- result = submit_batch
339
- end
340
- end
341
-
352
+ class TurbotClientHandler < TurbotRunner::BaseHandler
342
353
  def handle_invalid_record(record, data_type, errors)
343
354
  puts
344
- puts "The following record was not sent to turbot because it didn't validate against the schema:"
355
+ puts "The following record is invalid:"
345
356
  puts record.to_json
346
357
  errors.each {|error| puts " * #{error}"}
347
358
  puts
@@ -351,72 +362,20 @@ class PreviewRunner < TurbotRunner::BaseRunner
351
362
  puts
352
363
  puts "The following line was not valid JSON:"
353
364
  puts line
354
- interrupt
355
- end
356
-
357
- def handle_interrupted_run
358
- puts
359
- result = submit_batch
360
- puts "Run interrupted!"
361
- puts "Sent #{@count} records."
362
- puts "View your records at #{result.data[:url]}"
363
- end
364
-
365
- def handle_successful_run
366
- result = submit_batch
367
- if result.is_a? Turbot::API::FailureResponse
368
- @status = :failed
369
- handle_failed_run(result.message)
370
- else
371
- puts "Run completed!"
372
- if @count > 0
373
- puts "Sent #{@count} records"
374
- puts "View your records at #{result.data[:url]}"
375
- else
376
- puts "No records sent"
377
- end
378
- end
379
- end
380
-
381
- def handle_failed_run(message=nil)
382
- STDERR.puts("Error:")
383
- STDERR.puts(message) if message
384
- end
385
-
386
- private
387
- def submit_batch
388
- STDOUT.write('.')
389
- result = @api.create_draft_data(@bot_name, @batch.to_json)
390
- @batch = []
391
- result
392
365
  end
393
366
  end
394
367
 
395
- class DumpRunner < TurbotRunner::BaseRunner
368
+
369
+ class DumpHandler < TurbotClientHandler
396
370
  def handle_valid_record(record, data_type)
397
371
  puts record.to_json
398
372
  end
373
+ end
399
374
 
400
- def handle_invalid_record(record, data_type, errors)
401
- puts
402
- puts "The following record is invalid:"
403
- puts record.to_json
404
- errors.each {|error| puts " * #{error}"}
405
- puts
406
- end
407
375
 
408
- def handle_non_json_output(line)
409
- puts "The following line was not valid JSON:"
410
- puts line
411
- interrupt
412
- end
376
+ class ValidationHandler < TurbotClientHandler
377
+ attr_reader :count
413
378
 
414
- def handle_failed_run
415
- puts "Bot did not run to completion:"
416
- end
417
- end
418
-
419
- class ValidationRunner < TurbotRunner::BaseRunner
420
379
  def initialize(*)
421
380
  @count = 0
422
381
  super
@@ -424,6 +383,7 @@ class ValidationRunner < TurbotRunner::BaseRunner
424
383
 
425
384
  def handle_valid_record(record, data_type)
426
385
  @count += 1
386
+ STDOUT.write('.')
427
387
  end
428
388
 
429
389
  def handle_invalid_record(record, data_type, errors)
@@ -432,24 +392,37 @@ class ValidationRunner < TurbotRunner::BaseRunner
432
392
  puts record.to_json
433
393
  errors.each {|error| puts " * #{error}"}
434
394
  puts
435
- interrupt
436
395
  end
437
396
 
438
- def handle_non_json_output(line)
397
+ def handle_invalid_json(line)
398
+ puts
439
399
  puts "The following line was not valid JSON:"
440
400
  puts line
441
- interrupt
442
401
  end
402
+ end
443
403
 
444
- def handle_failed_run
445
- puts "Bot did not run to completion:"
404
+
405
+ class PreviewHandler < TurbotClientHandler
406
+ attr_reader :count
407
+
408
+ def initialize(bot_name, api)
409
+ @bot_name = bot_name
410
+ @api = api
411
+ @batch = []
412
+ @count = 0
413
+ super()
446
414
  end
447
415
 
448
- def handle_interrupted_run
449
- puts "Validated #{@count} records before finding invalid record"
416
+ def handle_valid_record(record, data_type)
417
+ @count += 1
418
+ STDOUT.write('.')
419
+ @batch << record.merge(:data_type => data_type)
420
+ submit_batch if @count % 20 == 0
450
421
  end
451
422
 
452
- def handle_successful_run
453
- puts "Validated #{@count} records"
423
+ def submit_batch
424
+ result = @api.create_draft_data(@bot_name, @batch.to_json)
425
+ @batch = []
426
+ result
454
427
  end
455
428
  end
@@ -1,3 +1,3 @@
1
1
  module Turbot
2
- VERSION = "0.0.51"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -6,5 +6,11 @@
6
6
  "data_type": "primary data",
7
7
  "identifying_fields": ["number"],
8
8
  "files": ["{{scraper_name}}"],
9
- "frequency": "monthly"
9
+ "frequency": "monthly",
10
+ "publisher": {
11
+ "name": "Publisher of the data",
12
+ "url": "Publisher's website",
13
+ "terms": "Copyright terms (e.g. Open Government License, n/a, etc)",
14
+ "terms_url": "A place where these terms can be checked or verified"
15
+ }
10
16
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turbot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.51
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Turbot
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-16 00:00:00.000000000 Z
11
+ date: 2014-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: netrc
@@ -114,14 +114,14 @@ dependencies:
114
114
  requirements:
115
115
  - - '='
116
116
  - !ruby/object:Gem::Version
117
- version: 0.0.19
117
+ version: 0.1.4
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - '='
123
123
  - !ruby/object:Gem::Version
124
- version: 0.0.19
124
+ version: 0.1.4
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: excon
127
127
  requirement: !ruby/object:Gem::Requirement