turbot 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MTRjNjM4ODc0ODAxZjM3OTJkNTE2MTBmMzBmZTk2NTMyNTBjZDViOA==
4
+ MTBlYjBjNWI0NzVjOWJjZTIwMjJkNGIzOGVjYzY3OTk1MGEwMzg1YQ==
5
5
  data.tar.gz: !binary |-
6
- YjEyZWVjYTZiZTdiYjNjNWY1ZDYxODIzYzM0NWMzYTAzZjc1NzYyZQ==
6
+ YTU2NzI1ZDMyZDg5ZGJmZTdiZWUyNWQ2YmE1OTQ4ODQ0MmYxYTZiYw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YjNiY2NiOTEzYzcwYjJmMmE5YTY2ODZmMmIyZTE2ODgxMTZlMTczYjA5YTkw
10
- MzkzMjRjNzAxZDUyMDlhNTZkNDAwODRjZWQ1NjBmMDhiMDdjYzVhYWY2YzFi
11
- YzJjZWEwNTE3YWRlOTJiM2ZlYjk2YjkxOWMwOTdiZDM1ZWI4NjI=
9
+ YTUwZTI0OThlZDg0NTY3NGFjZDMxNzVmYzgzYzc1MWM3NWI2OWQxMjU5Yzgx
10
+ ZjAxMGNiN2NmYzM4NDE4ODU3YTc4MGE4MDU3OTVlYzI1YzU4YmZjMDAzMzFm
11
+ NjZiNjUwYzgzNWQ3YjkwN2IxZWE0MzgzZGRkZjQwYjJiY2Q2M2E=
12
12
  data.tar.gz: !binary |-
13
- Y2VkNGM2MGIyNjcyYzA4NzY1YjJlMjBhNDY4NjgxNzI2N2M1ZTgxMGFhMjA1
14
- NWYzZWExM2M5YTJhNWQyZDQ1ZDAyNjdmNWNkZWI1ZTYyNDBiZGNiODU0OWVk
15
- Mzg3MTliYWM3OThjOTRlMWRjYzllYjYwNzQ3MTdhNmQ4NmM2ODA=
13
+ NTNiYjBjNjIyMjk0NWM2NjJiYTQ4ZTdmYTE3MGM2YmRmZmVmZTg2YjdjZDli
14
+ MjE0YmU5NDJiZTNlY2U1YjRiMWMyMmZhMGI5NGJkNzhhMmViM2VhMzZhMzA5
15
+ ZDRkMmU0MjI0ZGQwM2QzZWJkOWI1NzRiY2JjYTg2OGRiMjdhOGI=
@@ -1,4 +1,6 @@
1
1
  require "turbot/command/base"
2
+ require 'active_support/core_ext/object/blank'
3
+ require 'active_support/core_ext/hash/slice'
2
4
  require 'zip'
3
5
  require 'json-schema'
4
6
  require 'open3'
@@ -22,10 +24,10 @@ class Turbot::Command::Bots < Turbot::Command::Base
22
24
  #
23
25
  def index
24
26
  validate_arguments!
25
- bots = api.get_bots
27
+ bots = api.list_bots
26
28
  unless bots.empty?
27
29
  styled_header("Bots")
28
- styled_array(bots.map{|k,data| data['name']})
30
+ styled_array(bots.map{|bot| bot['bot_id']})
29
31
  else
30
32
  display("You have no bots.")
31
33
  end
@@ -90,9 +92,10 @@ class Turbot::Command::Bots < Turbot::Command::Base
90
92
  # Created new bot template at my_amazing_bot!
91
93
 
92
94
  def generate
95
+ puts "running generate"
93
96
  validate_arguments!
94
97
  language = options[:language] || "ruby"
95
- puts "Generating #{language} codes..."
98
+ puts "Generating #{language} code..."
96
99
  FileUtils.mkdir(bot)
97
100
  case language
98
101
  when "ruby"
@@ -102,11 +105,17 @@ class Turbot::Command::Bots < Turbot::Command::Base
102
105
  end
103
106
  manifest_template = File.expand_path("../../../../templates/manifest.json", __FILE__)
104
107
  scraper_template = File.expand_path("../../../../templates/#{scraper}", __FILE__)
105
- manifest = open(manifest_template).read.sub(/{{bot_id}}/, bot)
108
+ manifest = JSON.parse(open(manifest_template).read.sub(/{{bot_id}}/, bot))
109
+
106
110
  FileUtils.cp(scraper_template, "#{bot}/#{scraper}")
107
111
  open("#{bot}/manifest.json", "w") do |f|
108
- f.write(manifest)
112
+ f.write(manifest.to_json)
109
113
  end
114
+
115
+ api.create_bot(bot, manifest)
116
+
117
+ # TODO handle errors
118
+
110
119
  puts "Created new bot template at #{bot}!"
111
120
  end
112
121
 
@@ -134,11 +143,7 @@ class Turbot::Command::Bots < Turbot::Command::Base
134
143
  end
135
144
 
136
145
  File.open(archive_path) do |file|
137
- params = {
138
- "bot[archive]" => file,
139
- "bot[manifest]" => manifest
140
- }
141
- api.post_bot(params)
146
+ api.update_code(bot, file)
142
147
  end
143
148
  end
144
149
 
@@ -155,6 +160,11 @@ class Turbot::Command::Bots < Turbot::Command::Base
155
160
  scraper_path = shift_argument || scraper_file(Dir.pwd)
156
161
  validate_arguments!
157
162
  config = parsed_manifest(Dir.pwd)
163
+
164
+ %w(bot_id data_type identifying_fields files).each do |key|
165
+ error("Manifest is missing #{key}") unless config.has_key?(key)
166
+ end
167
+
158
168
  type = config["data_type"]
159
169
 
160
170
  schema = get_schema(type)
@@ -166,7 +176,6 @@ class Turbot::Command::Bots < Turbot::Command::Base
166
176
  count = 0
167
177
 
168
178
  run_scraper_each_line("#{scraper_path} #{bot}") do |line|
169
- errors = ""
170
179
  errors = JSON::Validator.fully_validate(
171
180
  schema,
172
181
  line,
@@ -175,6 +184,11 @@ class Turbot::Command::Bots < Turbot::Command::Base
175
184
  if !errors.empty?
176
185
  error("LINE WITH ERROR: #{line}\n\nERRORS: #{errors}")
177
186
  end
187
+
188
+ if JSON.parse(line).slice(*config['identifying_fields']).blank?
189
+ error("LINE WITH ERROR: #{line}\n\nERRORS: No value provided for identifying fields")
190
+ end
191
+
178
192
  count += 1
179
193
  end
180
194
  puts "Validated #{count} records successfully!"
@@ -232,27 +246,25 @@ class Turbot::Command::Bots < Turbot::Command::Base
232
246
  scraper_path = shift_argument || scraper_file(Dir.pwd)
233
247
  validate_arguments!
234
248
 
235
- bots = api.get_bots
236
- raise "You have not pushed your bot" unless bots.include?(bot)
237
-
238
249
  batch = []
239
250
  count = 0
251
+ config = parsed_manifest(Dir.pwd)
240
252
  puts "Sending to angler... "
241
253
  result = ""
242
254
  run_scraper_each_line("#{scraper_path} #{bot}") do |line|
243
255
  batch << JSON.parse(line)
244
256
  spinner(count)
245
257
  if count % 20 == 0
246
- result = api.send_drafts_to_angler(bot, batch.to_json)
258
+ result = api.update_draft_data(bot, config, batch.to_json)
247
259
  batch = []
248
260
  end
249
261
  count += 1
250
262
  end
251
263
  if !batch.empty?
252
- result = api.send_drafts_to_angler(bot, batch.to_json)
264
+ result = api.update_draft_data(bot, config, batch.to_json)
253
265
  end
254
266
  puts "Sent #{count} records."
255
- puts "View your records at #{JSON.parse(result)['url']}"
267
+ puts "View your records at #{result['url']}"
256
268
  end
257
269
 
258
270
  private
@@ -1,3 +1,3 @@
1
1
  module Turbot
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -4,7 +4,13 @@ require "turbot/command/bots"
4
4
  describe Turbot::Command::Bots do
5
5
  describe "validate" do
6
6
  before do
7
- Turbot::Command::Bots.any_instance.stub(:parsed_manifest).and_return('data_type' => 'dummy')
7
+ config = {
8
+ 'bot_id' => 'dummy bot',
9
+ 'data_type' => 'dummy',
10
+ 'identifying_fields' => ['name'],
11
+ 'files' => 'scraper.rb',
12
+ }
13
+ Turbot::Command::Bots.any_instance.stub(:parsed_manifest).and_return(config)
8
14
  end
9
15
 
10
16
  context "for data_type with schema" do
@@ -36,6 +42,19 @@ describe Turbot::Command::Bots do
36
42
  stdout.should == ""
37
43
  stderr.should include 'ERRORS'
38
44
  end
45
+
46
+ context "for bot that doesn't output identifying fields" do
47
+ it "says bot is invalid" do
48
+ Turbot::Command::Bots.any_instance.
49
+ stub(:run_scraper_each_line).
50
+ and_yield({title: 'One'}.to_json)
51
+
52
+ stderr, stdout = execute("bots:validate")
53
+
54
+ stdout.should == ""
55
+ stderr.should include 'No value provided for identifying fields'
56
+ end
57
+ end
39
58
  end
40
59
 
41
60
  context "for data_type without schema" do
@@ -50,5 +69,21 @@ describe Turbot::Command::Bots do
50
69
  stderr.should include 'No schema found'
51
70
  end
52
71
  end
72
+
73
+ context "for bot with manifest missing some required fields" do
74
+ it "says bot is invalid" do
75
+ config = {
76
+ 'bot_id' => 'dummy bot',
77
+ 'identifying_fields' => ['name'],
78
+ 'files' => 'scraper.rb',
79
+ }
80
+ Turbot::Command::Bots.any_instance.stub(:parsed_manifest).and_return(config)
81
+
82
+ stderr, stdout = execute("bots:validate")
83
+
84
+ stdout.should == ""
85
+ stderr.should include 'Manifest is missing data_type'
86
+ end
87
+ end
53
88
  end
54
89
  end
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.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Turbot
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-28 00:00:00.000000000 Z
11
+ date: 2014-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: netrc
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ! '>='
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: activesupport
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: 4.0.3
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: 4.0.3
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: turbot-api
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -197,3 +211,4 @@ signing_key:
197
211
  specification_version: 4
198
212
  summary: Client library and CLI to deploy apps on Turbot.
199
213
  test_files: []
214
+ has_rdoc: