cloudfactory 0.1.20 → 0.1.21

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.1.21 (2011-08-25)
2
+
3
+ * Line listing with pagination with custom flags
4
+ * cf login now stores account_name and email as well
5
+ * Fixed the line listing issue
6
+
1
7
  ## 0.1.20 (2011-08-24)
2
8
 
3
9
  * Fixed Line listing and deletion issue
@@ -19,6 +19,11 @@ Before('@too_slow_process') do
19
19
  end
20
20
 
21
21
  if ENV['TEST_CLI']
22
+
23
+ require 'ruby-debug'
24
+ ::Debugger.start
25
+ ::Debugger.settings[:autoeval] = true if ::Debugger.respond_to?(:settings)
26
+
22
27
  API_CONFIG = YAML.load_file(File.expand_path("../../../fixtures/api_credentials.yml", __FILE__))
23
28
  CF.configure do |config|
24
29
  config.api_version = API_CONFIG['api_version']
data/lib/cf.rb CHANGED
@@ -89,6 +89,6 @@ require "#{directory}/cf/form_field"
89
89
  require "#{directory}/cf/custom_task_form"
90
90
  require "#{directory}/cf/run"
91
91
  require "#{directory}/cf/department"
92
- require "#{directory}/cf/final_output"
93
92
  require "#{directory}/cf/robot_worker"
94
- require "#{directory}/cf/version"
93
+ require "#{directory}/cf/version"
94
+ require "#{directory}/cf/output_format"
data/lib/cf/account.rb CHANGED
@@ -32,6 +32,7 @@ module CF
32
32
  # CF::Account.login("sprout@sprout-technology.com", "password")
33
33
  def login(email, passwd)
34
34
  resp = post('/account_login.json', :user => {:email => email, :password => passwd})
35
+ self.errors = resp.error.message if resp.code != 200
35
36
  resp
36
37
  end
37
38
  end
data/lib/cf/cli.rb CHANGED
@@ -42,8 +42,9 @@ module Cf # :nodoc: all
42
42
 
43
43
  set_target_uri(false)
44
44
  resp = CF::Account.login(email, passwd)
45
+
45
46
  if resp.error.blank? and resp.api_key.present?
46
- File.open(config_file, 'w') {|f| f.write("#Don't change this file unless you know what you're doing\n" + { :target_url => CF.api_url, :api_version => CF.api_version, :api_key => resp.api_key }.to_yaml) }
47
+ File.open(config_file, 'w') {|f| f.write("#Don't change this file unless you know what you're doing\n" + { :target_url => CF.api_url, :api_version => CF.api_version, :api_key => resp.api_key, :account_name => resp.account_name, :email => email.strip }.to_yaml) }
47
48
  say("\nNow you're logged in.\nTo get started, run cf help\n", :green)
48
49
  else
49
50
  say("\n#{resp.error.message}\nTry again with valid one.\n", :red)
@@ -53,7 +54,7 @@ module Cf # :nodoc: all
53
54
  no_tasks do
54
55
  def ask_password(message)
55
56
  ::HighLine.new.ask(message) do |q|
56
- q.echo = false
57
+ q.echo = '*'
57
58
  end
58
59
  end
59
60
  end
data/lib/cf/cli/line.rb CHANGED
@@ -267,6 +267,13 @@ module Cf # :nodoc: all
267
267
  end
268
268
 
269
269
  end
270
+
271
+ output_formats = line_dump['output_formats'].presence
272
+ if output_formats
273
+ output_format = CF::OutputFormat.new(output_formats.merge(:line => line))
274
+ say "Adding Output Format #{output_formats}", :green
275
+ display_error(line_title, "#{output_format.errors}") if output_format.errors.present?
276
+ end
270
277
  end
271
278
  say " ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁", :white
272
279
  say "Line was successfully created.", :green
@@ -275,6 +282,8 @@ module Cf # :nodoc: all
275
282
  end
276
283
 
277
284
  desc "line list", "List your lines"
285
+ method_option :page, :type => :numeric, :aliases => '-p', :desc => "page number"
286
+ method_option :all, :type => :boolean, :default => false, :aliases => '-a', :desc => "list all the lines without pagination"
278
287
  def list
279
288
  line_source = Dir.pwd
280
289
  yaml_source = "#{line_source}/line.yml"
@@ -282,11 +291,28 @@ module Cf # :nodoc: all
282
291
  set_target_uri(false)
283
292
  set_api_key(yaml_source)
284
293
  CF.account_name = CF::Account.info.name
285
- lines = CF::Line.all
294
+
295
+ if options.all
296
+ resp_lines = CF::Line.all(:page => 'all')
297
+ current_page = 1
298
+ else
299
+ if page = options['page'].presence
300
+ resp_lines = CF::Line.all(:page => page)
301
+ current_page = page
302
+ else
303
+ resp_lines = CF::Line.all
304
+ current_page = 1
305
+ end
306
+ end
307
+
308
+ lines = resp_lines['lines'].presence
286
309
  say "\n"
287
310
  say("You don't have any lines to list", :yellow) and return if lines.blank?
288
311
 
289
- lines.sort! {|a, b| a[:name] <=> b[:name] }
312
+ if resp_lines['total_pages']
313
+ say("Showing page #{current_page} of #{resp_lines['total_pages']} (Total lines: #{resp_lines['total_lines']})")
314
+ end
315
+ lines.sort! { |a, b| a['title'] <=> b['title'] }
290
316
  lines_table = table do |t|
291
317
  t.headings = ["Line Title", 'URL']
292
318
  lines.each do |line|
@@ -20,13 +20,13 @@ department: Web Research
20
20
  input_formats:
21
21
  # - name: email
22
22
  # required: true
23
- # valid_type: email # email, url, number, date, phone
23
+ # valid_type: email # email, url, number, date, time, datetime
24
24
  # - name: location
25
25
  # required: true
26
- # valid_type: text # email, url, number, date, phone
26
+ # valid_type: text # email, url, number, date, time, datetime
27
27
  # - name: photo
28
28
  # required: true
29
- # valid_type: url # email, url, number, date, phone
29
+ # valid_type: url # email, url, number, date, time, datetime
30
30
  # # Stations (see http://cloudfactory.com/developers/resources/station.html)
31
31
  stations:
32
32
  # # Sample Station #1: WORKER looks at photo of person seeking a date and determines their gender and approximate age
@@ -153,6 +153,7 @@ module CF
153
153
  }
154
154
  }
155
155
  resp = HTTParty.post("#{CF.api_url}#{CF.api_version}/lines/#{CF.account_name}/#{@station.line['title'].downcase}/stations/#{@station.index}/workers/#{self.id}/badge.json",request)
156
+ self.errors = resp['error']['message'] if resp.code != 200
156
157
  self.skill_badges << resp.parsed_response['skill_badges']
157
158
  end
158
159
 
data/lib/cf/line.rb CHANGED
@@ -26,7 +26,7 @@ module CF
26
26
  attr_accessor :input_formats
27
27
 
28
28
  # Contains Error Messages
29
- attr_accessor :errors
29
+ attr_accessor :errors, :output_formats
30
30
 
31
31
  # ==Initializes a new line
32
32
  # ==Usage of line.new("line_name")
@@ -186,6 +186,28 @@ module CF
186
186
  @input_formats << input_formats_value
187
187
  end
188
188
 
189
+ def output_formats output_format = nil
190
+ if output_format
191
+ settings = output_format.settings
192
+ request =
193
+ {
194
+ :body =>
195
+ {
196
+ :api_key => CF.api_key,
197
+ :output_formats => settings
198
+ }
199
+ }
200
+ resp = HTTParty.post("#{CF.api_url}#{CF.api_version}/lines/#{CF.account_name}/#{self.title.downcase}/output_format.json",request)
201
+ output_format.errors = resp.parsed_response['error']['message'] if resp.code != 200
202
+ self.output_formats = output_format
203
+ else
204
+ @output_formats
205
+ end
206
+ end
207
+
208
+ def output_formats=(output_format)
209
+ @output_formats = output_format
210
+ end
189
211
  # ==Returns the content of a line by making an Api call
190
212
  # ===Usage Example:
191
213
  # CF::Line.info(line)
@@ -197,6 +219,8 @@ module CF
197
219
  else
198
220
  resp = get("/lines/#{CF.account_name}/#{line.downcase}.json")
199
221
  end
222
+ @errors = resp.error.message if resp.code != 200
223
+ return resp
200
224
  end
201
225
 
202
226
  # ==Finds a line
@@ -216,6 +240,7 @@ module CF
216
240
  resp = get("/lines/#{CF.account_name}/#{line.downcase}.json")
217
241
  end
218
242
  end
243
+ @errors = resp.error.message if resp.code != 200
219
244
  return resp.to_hash
220
245
  end
221
246
 
@@ -223,19 +248,23 @@ module CF
223
248
  # ===Syntax for all method is
224
249
  # CF::Line.all
225
250
  def self.all(options={})
226
- page = options[:page].nil? ? nil : options[:page]
251
+ page = options[:page].presence
227
252
  if page
228
253
  resp = get("/lines/#{CF.account_name}.json", :page => page)
229
254
  else
230
255
  resp = get("/lines/#{CF.account_name}.json")
231
256
  end
257
+ @errors = resp.error.message if resp.code != 200
232
258
  new_resp = []
233
- if resp.count > 0
234
- resp.each do |l|
235
- new_resp << l.to_hash
259
+ if resp.lines
260
+ if resp.lines.count > 0
261
+ resp.lines.each do |l|
262
+ new_resp << l.to_hash
263
+ end
236
264
  end
237
265
  end
238
- return new_resp
266
+ send_resp = {"lines" => new_resp, "total_pages" => resp.total_pages, "total_lines" => resp.total_lines}
267
+ return send_resp
239
268
  end
240
269
 
241
270
  # ==Returns all the stations of a line
@@ -293,11 +322,14 @@ module CF
293
322
  else
294
323
  resp = delete("/lines/#{CF.account_name}/#{title.downcase}.json")
295
324
  end
325
+ @errors = resp.error.message if resp.code != 200
326
+ return resp
296
327
  end
297
328
 
298
329
  def self.inspect(line_title)
299
330
  resp = get("/lines/#{CF.account_name}/#{line_title.downcase}/inspect.json")
300
- if !resp.code == 200
331
+ @errors = resp.error.message if resp.code != 200
332
+ if resp.code == 200
301
333
  send_resp = resp.to_hash
302
334
  @line_input_formats = []
303
335
  resp.input_formats.each do |l_i|
@@ -0,0 +1,30 @@
1
+ module CF
2
+ class OutputFormat
3
+ require 'httparty'
4
+ include Client
5
+
6
+ # type of the station, e.g. station = Station.new({:type => "Work"})
7
+ attr_accessor :settings, :errors, :line, :output_formats_settings
8
+
9
+ def initialize(options={})
10
+ if !options.blank?
11
+ @settings = options
12
+ @line = options[:line] if options[:line].nil? ? nil : options[:line]
13
+ if !@line.nil?
14
+ options.delete(:line)
15
+ request =
16
+ {
17
+ :body =>
18
+ {
19
+ :api_key => CF.api_key,
20
+ :output_formats => options
21
+ }
22
+ }
23
+ resp = HTTParty.post("#{CF.api_url}#{CF.api_version}/lines/#{CF.account_name}/#{@line.title.downcase}/output_format.json",request)
24
+ self.errors = resp.parsed_response['error']['message'] if resp.code != 200
25
+ self.line.output_formats = self
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
data/lib/cf/run.rb CHANGED
@@ -86,11 +86,28 @@ module CF
86
86
  Run.new(line, title, file)
87
87
  end
88
88
 
89
+ def self.add_units(options={})
90
+ units = options[:units].presence
91
+ run_title = options[:run_title].presence
92
+
93
+ request =
94
+ {
95
+ :body =>
96
+ {
97
+ :api_key => CF.api_key,
98
+ :data => units
99
+ }
100
+ }
101
+ resp = HTTParty.post("#{CF.api_url}#{CF.api_version}/runs/#{CF.account_name}/#{run_title.downcase}/units.json",request)
102
+ @errors = resp['error']['message'] if resp.code != 200
103
+ return resp.parsed_response
104
+ end
89
105
  # ==Returns Final Output of production Run
90
106
  # ===Usage Example:
91
107
  # run_object.final_output
92
108
  def final_output
93
109
  resp = self.class.get("/runs/#{CF.account_name}/#{self.title.downcase}/output.json")
110
+ self.errors = resp.error.message if resp.code != 200
94
111
  output = []
95
112
  if resp['output'].class == Array
96
113
  resp['output'].each do |o|
@@ -105,6 +122,7 @@ module CF
105
122
  # CF::Run.final_output("run_title")
106
123
  def self.final_output(title)
107
124
  resp = get("/runs/#{CF.account_name}/#{title.downcase}/output.json")
125
+ @errors = resp.error.message if resp.code != 200
108
126
  output = []
109
127
  if resp['output'].class == Array
110
128
  resp['output'].each do |o|
@@ -122,6 +140,7 @@ module CF
122
140
  station_no = options[:station]
123
141
  title = options[:title]
124
142
  resp = get("/runs/#{CF.account_name}/#{title.downcase}/output/#{station_no}.json")
143
+ @errors = resp.error.message if resp.code != 200
125
144
  output = []
126
145
  if resp['output'].class == Array
127
146
  resp['output'].each do |o|
@@ -138,6 +157,7 @@ module CF
138
157
  def output(options={})
139
158
  station_no = options[:station]
140
159
  resp = self.class.get("/runs/#{CF.account_name}/#{self.title.downcase}/output/#{station_no}.json")
160
+ self.errors = resp.error.message if resp.code != 200
141
161
  output = []
142
162
  if resp['output'].class == Array
143
163
  resp['output'].each do |o|
@@ -153,6 +173,7 @@ module CF
153
173
  def self.find(title)
154
174
  resp = get("/runs/#{CF.account_name}/#{title.downcase}.json")
155
175
  if resp.code != 200
176
+ @errors = resp.error.message
156
177
  resp.error = resp.error.message
157
178
  resp.merge!(:errors => "#{resp.error}")
158
179
  resp.delete(:error)
@@ -192,22 +213,28 @@ module CF
192
213
  if page.nil?
193
214
  resp = get("/lines/#{CF.account_name}/#{line_title}/list_runs.json")
194
215
  else
195
- resp = get("/lines/#{CF.account_name}/#{line_title}/list_runs.json")
216
+ resp = get("/lines/#{CF.account_name}/#{line_title}/list_runs.json", :page => page)
196
217
  end
197
218
  end
198
-
219
+ @errors = resp.error.message if resp.code != 200
199
220
  new_resp = []
200
-
201
- if resp.count > 0
202
- resp.each do |r|
203
- new_resp << r.to_hash
221
+ if resp.code == 200
222
+ if resp.runs
223
+ if resp.runs.count > 0
224
+ resp.runs.each do |r|
225
+ new_resp << r.to_hash
226
+ end
227
+ end
204
228
  end
229
+ send_resp = {"runs" => new_resp, "total_pages" => resp.total_pages}
230
+ return send_resp
205
231
  end
206
- return new_resp
207
232
  end
208
233
 
209
234
  def self.resume(run_title)
210
- post("/runs/#{CF.account_name}/#{run_title}/resume.json")
235
+ resp = post("/runs/#{CF.account_name}/#{run_title}/resume.json")
236
+ @errors = resp.error.message if resp.code != 200
237
+ return resp
211
238
  end
212
239
  end
213
240
  end
data/lib/cf/station.rb CHANGED
@@ -265,6 +265,7 @@ module CF
265
265
  # returns the station object
266
266
  def get
267
267
  resp = self.class.get("/lines/#{CF.account_name}/#{self.line_title.downcase}/stations/#{self.index}.json")
268
+ self.errors = resp.error.message if resp.code != 200
268
269
  return resp
269
270
  end
270
271
 
@@ -272,7 +273,9 @@ module CF
272
273
  # ===Usage example:
273
274
  # @got_form = line.stations[0].get_form
274
275
  def get_form
275
- self.class.get("/lines/#{CF.account_name}/#{self.line_title.downcase}/stations/#{self.index}/form.json")
276
+ resp = self.class.get("/lines/#{CF.account_name}/#{self.line_title.downcase}/stations/#{self.index}/form.json")
277
+ self.errors = resp.error.message if resp.code != 200
278
+ return resp
276
279
  end
277
280
 
278
281
  # ==Returns all the stations associated with a particular line
@@ -292,7 +295,9 @@ module CF
292
295
  #
293
296
  # line.stations.first.delete
294
297
  def delete
295
- self.class.delete("/lines/#{CF.account_name}/#{self.line_title.downcase}/stations/#{self.index}.json")
298
+ resp = self.class.delete("/lines/#{CF.account_name}/#{self.line_title.downcase}/stations/#{self.index}.json")
299
+ self.errors = resp.error.message if resp.code != 200
300
+ return resp
296
301
  end
297
302
 
298
303
  def to_s
data/lib/cf/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module CF # :nodoc: all
2
- VERSION = "0.1.20"
2
+ VERSION = "0.1.21"
3
3
  end
data/spec/line_spec.rb CHANGED
@@ -103,7 +103,7 @@ describe CF::Line do
103
103
  CF::Line.new("Digitizeard---#{i}", "Digitization", {:public => false, :description => "#{i}-this is description"})
104
104
  end
105
105
  lines = CF::Line.all
106
- lines.last['title'].should eq("digitizeard---4")
106
+ lines.class.should eql(Hash)
107
107
  end
108
108
  end
109
109
 
@@ -176,7 +176,7 @@ describe CF::Line do
176
176
  resp = CF::Line.destroy("Digitizerd-2")
177
177
  resp.code.should eql(200)
178
178
  deleted_resp = CF::Line.info(line)
179
- deleted_resp.error.message.should eql("Line document not found using selector: {:public=>true, :title=>\"digitizerd-2\"}")
179
+ deleted_resp.error.message.should eql("Line not found for title: digitizerd-2 under your account")
180
180
  end
181
181
  end
182
182
  end
@@ -427,7 +427,19 @@ describe CF::Line do
427
427
  VCR.use_cassette "lines/plain-ruby/line_pagination", :record => :new_episodes do
428
428
  # WebMock.allow_net_connect!
429
429
  line = CF::Line.all(:page => 1)
430
- line.class.should eql(Array)
430
+ line.class.should eql(Hash)
431
+ end
432
+ end
433
+
434
+ it "should get all lines with pagination all" do
435
+ VCR.use_cassette "lines/plain-ruby/line_pagination_all", :record => :new_episodes do
436
+ # WebMock.allow_net_connect!
437
+ 25.times do |i|
438
+ CF::Line.new("lines-listing--#{i}", "Digitization", {:public => true, :description => "#{i}-this is description"})
439
+ end
440
+ line = CF::Line.all(:page => "all")
441
+ line['total_pages'].should eql(1)
442
+ line['lines'].class.should eql(Array)
431
443
  end
432
444
  end
433
445
  end
@@ -455,4 +467,94 @@ describe CF::Line do
455
467
  end
456
468
  end
457
469
  end
470
+
471
+ context "create line with output format" do
472
+ it "should create in block Dsl way with two stations" do
473
+ # WebMock.allow_net_connect!
474
+ VCR.use_cassette "lines/block/create-output-format", :record => :new_episodes do
475
+ line = CF::Line.create("line_with_output_format","Digitization") do |l|
476
+ CF::InputFormat.new({:line => l, :name => "Company", :required => true, :valid_type => "general"})
477
+ CF::InputFormat.new({:line => l, :name => "Website", :required => true, :valid_type => "url"})
478
+ CF::Station.create({:line => l, :type => "work"}) do |s|
479
+ CF::HumanWorker.new({:station => s, :number => 1, :reward => 10})
480
+ CF::TaskForm.create({:station => s, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
481
+ CF::FormField.new({:form => i, :label => "First Name", :field_type => "short_answer", :required => "true"})
482
+ CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "short_answer"})
483
+ CF::FormField.new({:form => i, :label => "Last Name", :field_type => "short_answer", :required => "true"})
484
+ end
485
+ end
486
+ CF::Station.create({:line => l, :type => "work"}) do |s|
487
+ CF::HumanWorker.new({:station => s, :number => 1, :reward => 20})
488
+ CF::TaskForm.create({:station => s, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
489
+ CF::FormField.new({:form => i, :label => "Address", :field_type => "short_answer", :required => "true"})
490
+ CF::FormField.new({:form => i, :label => "Mobile", :field_type => "short_answer"})
491
+ CF::FormField.new({:form => i, :label => "Email", :field_type => "email", :required => "true"})
492
+ end
493
+ end
494
+ CF::OutputFormat.new({:line => l, :station_1 => [{:name => "First Name"}],:station_2 => [{:name => "Mobile", :except => true}]})
495
+ end
496
+ line.title.should eq("line_with_output_format")
497
+ line.input_formats.first.name.should eql("Company")
498
+ line.stations.first.type.should eq("WorkStation")
499
+ line.stations.first.worker.number.should eq(1)
500
+ line.stations.first.worker.reward.should eq(10)
501
+ line.output_formats.settings.should eql({:station_1 => [{:name => "First Name"}],:station_2 => [{:name => "Mobile", :except => true}]})
502
+ end
503
+ end
504
+
505
+ it "should create in plain ruby way with two stations" do
506
+ # WebMock.allow_net_connect!
507
+ VCR.use_cassette "lines/plain-ruby/create-output-format", :record => :new_episodes do
508
+ line = CF::Line.create("line_with_output_format_1","Digitization") do |l|
509
+ CF::InputFormat.new({:line => l, :name => "Company", :required => true, :valid_type => "general"})
510
+ CF::InputFormat.new({:line => l, :name => "Website", :required => true, :valid_type => "url"})
511
+ CF::Station.create({:line => l, :type => "work"}) do |s|
512
+ CF::HumanWorker.new({:station => s, :number => 1, :reward => 10})
513
+ CF::TaskForm.create({:station => s, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
514
+ CF::FormField.new({:form => i, :label => "First Name", :field_type => "short_answer", :required => "true"})
515
+ CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "short_answer"})
516
+ CF::FormField.new({:form => i, :label => "Last Name", :field_type => "short_answer", :required => "true"})
517
+ end
518
+ end
519
+ CF::Station.create({:line => l, :type => "work"}) do |s|
520
+ CF::HumanWorker.new({:station => s, :number => 1, :reward => 20})
521
+ CF::TaskForm.create({:station => s, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
522
+ CF::FormField.new({:form => i, :label => "Address", :field_type => "short_answer", :required => "true"})
523
+ CF::FormField.new({:form => i, :label => "Mobile", :field_type => "short_answer"})
524
+ CF::FormField.new({:form => i, :label => "Email", :field_type => "email", :required => "true"})
525
+ end
526
+ end
527
+ end
528
+ output_format = CF::OutputFormat.new({:station_1 => [{:name => "First Name"}],:station_2 => [{:name => "Mobile", :except => true}]})
529
+ line.output_formats output_format
530
+ line.title.should eq("line_with_output_format_1")
531
+ line.input_formats.first.name.should eql("Company")
532
+ line.stations.first.type.should eq("WorkStation")
533
+ line.stations.first.worker.number.should eq(1)
534
+ line.stations.first.worker.reward.should eq(10)
535
+ line.output_formats.settings.should eql({:station_1 => [{:name => "First Name"}],:station_2 => [{:name => "Mobile", :except => true}]})
536
+ end
537
+ end
538
+
539
+ it "should through error if line is incomplete" do
540
+ # WebMock.allow_net_connect!
541
+ VCR.use_cassette "lines/block/create-output-format-error", :record => :new_episodes do
542
+ line = CF::Line.create("line_with_output_format","Digitization") do |l|
543
+ CF::InputFormat.new({:line => l, :name => "Company", :required => true, :valid_type => "general"})
544
+ CF::InputFormat.new({:line => l, :name => "Website", :required => true, :valid_type => "url"})
545
+ CF::Station.create({:line => l, :type => "work"}) do |s|
546
+ CF::HumanWorker.new({:station => s, :number => 1, :reward => 10})
547
+ # CF::TaskForm.new({:station => s, :title => "Enter text from a business card image", :instruction => "Describe"})
548
+ end
549
+ CF::OutputFormat.new({:line => l, :station_1 => [{:name => "First Name"}],:station_2 => [{:name => "Mobile", :except => true}]})
550
+ end
551
+ line.title.should eq("line_with_output_format")
552
+ line.input_formats.first.name.should eql("Company")
553
+ line.stations.first.type.should eq("WorkStation")
554
+ line.stations.first.worker.number.should eq(1)
555
+ line.stations.first.worker.reward.should eq(10)
556
+ line.output_formats.errors.should eql("Line is not complete or valid")
557
+ end
558
+ end
559
+ end
458
560
  end
data/spec/run_spec.rb CHANGED
@@ -378,10 +378,8 @@ module CF
378
378
  run_2 = CF::Run.create(line_2, "progress_run_32", [{"url"=> "http://www.sprout-technology.com"}])
379
379
 
380
380
  got_run = CF::Run.all
381
- got_run.first['line']['title'].should eql("keyword_matching_robot_result")
382
- got_run.first['title'].should eql("keyword_matching_robot_run_result")
383
- got_run.last['line']['title'].should eql("digarde-007")
384
- got_run.last['title'].should eql("runnamee1")
381
+ got_run['runs'].class.should eql(Array)
382
+ got_run['total_pages'].should eql(2)
385
383
  end
386
384
  end
387
385
 
@@ -398,9 +396,9 @@ module CF
398
396
  run_1 = CF::Run.create(line, "progress_run_12", [{"url"=> "http://www.sprout-technology.com"}])
399
397
  run_2 = CF::Run.create(line, "progress_run_13", [{"url"=> "http://www.sprout-technology.com"}])
400
398
  got_run = CF::Run.all({:line_title => "progress_run_line_11"})
401
- got_run[0]['title'].should eql("progress_run_11")
402
- got_run[1]['title'].should eql("progress_run_12")
403
- got_run[2]['title'].should eql("progress_run_13")
399
+ got_run['runs'][0]['title'].should eql("progress_run_11")
400
+ got_run['runs'][1]['title'].should eql("progress_run_12")
401
+ got_run['runs'][2]['title'].should eql("progress_run_13")
404
402
  end
405
403
  end
406
404
 
@@ -408,7 +406,25 @@ module CF
408
406
  VCR.use_cassette "run/plain-ruby/get-run-with-page", :record => :new_episodes do
409
407
  # WebMock.allow_net_connect!
410
408
  run = CF::Run.all({:page => 1})
411
- run.class.should eql(Array)
409
+ run['runs'].class.should eql(Array)
410
+ end
411
+ end
412
+
413
+ it "should get all runs with pagination all" do
414
+ VCR.use_cassette "run/plain-ruby/get-run-with-page-all", :record => :new_episodes do
415
+ # WebMock.allow_net_connect!
416
+ line = CF::Line.create("pagination_line","Digitization") do |l|
417
+ CF::InputFormat.new({:line => l, :name => "url", :valid_type => "url", :required => "true"})
418
+ CF::Station.create({:line => l, :type => "work"}) do |s|
419
+ CF::RobotWorker.create({:station => s, :settings => {:url => ["{{url}}"], :max_retrieve => 5, :show_source_text => true}, :type => "term_extraction_robot"})
420
+ end
421
+ end
422
+ 25.times do |i|
423
+ CF::Run.create(line, "pagination_run#{i}", [{"url"=> "http://www.sprout-technology.com"}])
424
+ end
425
+ run = CF::Run.all({:page => "all"})
426
+ run['total_pages'].should eql(1)
427
+ run['runs'].class.should eql(Array)
412
428
  end
413
429
  end
414
430
  end
@@ -441,5 +457,73 @@ module CF
441
457
  end
442
458
  end
443
459
  end
460
+
461
+ context "creation of run by adding units" do
462
+ it "should manually add units" do
463
+ VCR.use_cassette "run/block/adding_units", :record => :new_episodes do
464
+ # WebMock.allow_net_connect!
465
+ line = CF::Line.create("adding_units","Digitization") do |l|
466
+ CF::InputFormat.new({:line => l, :name => "Company", :required => true, :valid_type => "general"})
467
+ CF::InputFormat.new({:line => l, :name => "Website", :required => true, :valid_type => "url"})
468
+ CF::Station.create({:line => l, :type => "work"}) do |s|
469
+ CF::HumanWorker.new({:station => s, :number => 1, :reward => 20})
470
+ CF::TaskForm.create({:station => s, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
471
+ CF::FormField.new({:form => i, :label => "First Name", :field_type => "short_answer", :required => "true"})
472
+ CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "short_answer"})
473
+ CF::FormField.new({:form => i, :label => "Last Name", :field_type => "short_answer", :required => "true"})
474
+ end
475
+ end
476
+ end
477
+ run = CF::Run.create(line, "adding_units_run", [{"Company"=>"Apple,Inc","Website"=>"Apple.com"}])
478
+ added_units = CF::Run.add_units(:run_title => "adding_units_run", :units => [{"Company"=>"Apple,Inc","Website"=>"Apple.com"}, {"Company"=>"Sprout","Website"=>"sprout.com"}])
479
+ added_units['successfull'].should eql("sucessfully added 2 units, failed :0")
480
+ run.title.should eql("adding_units_run")
481
+ end
482
+ end
483
+
484
+ it "should throw errors for invalid input while adding units" do
485
+ VCR.use_cassette "run/block/adding_units_errors", :record => :new_episodes do
486
+ # WebMock.allow_net_connect!
487
+ line = CF::Line.create("adding_units_error","Digitization") do |l|
488
+ CF::InputFormat.new({:line => l, :name => "Company", :required => true, :valid_type => "general"})
489
+ CF::InputFormat.new({:line => l, :name => "Website", :required => true, :valid_type => "url"})
490
+ CF::Station.create({:line => l, :type => "work"}) do |s|
491
+ CF::HumanWorker.new({:station => s, :number => 1, :reward => 20})
492
+ CF::TaskForm.create({:station => s, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
493
+ CF::FormField.new({:form => i, :label => "First Name", :field_type => "short_answer", :required => "true"})
494
+ CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "short_answer"})
495
+ CF::FormField.new({:form => i, :label => "Last Name", :field_type => "short_answer", :required => "true"})
496
+ end
497
+ end
498
+ end
499
+ run = CF::Run.create(line, "adding_units_error_run", [{"Company"=>"Apple,Inc","Website"=>"Apple.com"}])
500
+ added_units = CF::Run.add_units(:run_title => "adding_units_error_run", :units => [{"Company"=>"Sprout","Url"=>"sprout.com"}])
501
+ added_units['error']['message'].should eql(["Extra Headers in file: [url]", "Insufficient Headers in file: [website]"])
502
+ run.title.should eql("adding_units_error_run")
503
+ end
504
+ end
505
+
506
+ xit "should throw errors for empty input while adding units" do
507
+ VCR.use_cassette "run/block/adding_units_empty_errors", :record => :new_episodes do
508
+ # WebMock.allow_net_connect!
509
+ line = CF::Line.create("adding_units_error_1","Digitization") do |l|
510
+ CF::InputFormat.new({:line => l, :name => "Company", :required => true, :valid_type => "general"})
511
+ CF::InputFormat.new({:line => l, :name => "Website", :required => true, :valid_type => "url"})
512
+ CF::Station.create({:line => l, :type => "work"}) do |s|
513
+ CF::HumanWorker.new({:station => s, :number => 1, :reward => 20})
514
+ CF::TaskForm.create({:station => s, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
515
+ CF::FormField.new({:form => i, :label => "First Name", :field_type => "short_answer", :required => "true"})
516
+ CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "short_answer"})
517
+ CF::FormField.new({:form => i, :label => "Last Name", :field_type => "short_answer", :required => "true"})
518
+ end
519
+ end
520
+ end
521
+ run = CF::Run.create(line, "adding_units_error_run_1", [{"Company"=>"Apple,Inc","Website"=>"Apple.com"}])
522
+ added_units = CF::Run.add_units(:run_title => "adding_units_error_run", :units => [])
523
+ added_units['error']['message'].should eql(["Extra Headers in file: [url]", "Insufficient Headers in file: [website]"])
524
+ run.title.should eql("adding_units_error_run_1")
525
+ end
526
+ end
527
+ end
444
528
  end
445
529
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudfactory
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.20
4
+ version: 0.1.21
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-24 00:00:00.000000000Z
12
+ date: 2011-08-25 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: i18n
16
- requirement: &2156814280 !ruby/object:Gem::Requirement
16
+ requirement: &2154423560 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2156814280
24
+ version_requirements: *2154423560
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: activesupport
27
- requirement: &2156813780 !ruby/object:Gem::Requirement
27
+ requirement: &2154423060 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '3.0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2156813780
35
+ version_requirements: *2154423060
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: hashie
38
- requirement: &2156813280 !ruby/object:Gem::Requirement
38
+ requirement: &2154422560 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '1.0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *2156813280
46
+ version_requirements: *2154422560
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rest-client
49
- requirement: &2156812900 !ruby/object:Gem::Requirement
49
+ requirement: &2157390480 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *2156812900
57
+ version_requirements: *2157390480
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: json
60
- requirement: &2156812440 !ruby/object:Gem::Requirement
60
+ requirement: &2157390020 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *2156812440
68
+ version_requirements: *2157390020
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: thor
71
- requirement: &2156811940 !ruby/object:Gem::Requirement
71
+ requirement: &2157389520 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0.14'
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *2156811940
79
+ version_requirements: *2157389520
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: highline
82
- requirement: &2156811520 !ruby/object:Gem::Requirement
82
+ requirement: &2157389100 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :runtime
89
89
  prerelease: false
90
- version_requirements: *2156811520
90
+ version_requirements: *2157389100
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: httparty
93
- requirement: &2156810980 !ruby/object:Gem::Requirement
93
+ requirement: &2157388560 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ~>
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '0.7'
99
99
  type: :runtime
100
100
  prerelease: false
101
- version_requirements: *2156810980
101
+ version_requirements: *2157388560
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: terminal-table
104
- requirement: &2156810480 !ruby/object:Gem::Requirement
104
+ requirement: &2157388060 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ~>
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: '1.4'
110
110
  type: :runtime
111
111
  prerelease: false
112
- version_requirements: *2156810480
112
+ version_requirements: *2157388060
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: millisami-csv-hash
115
- requirement: &2156810100 !ruby/object:Gem::Requirement
115
+ requirement: &2157387680 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ! '>='
@@ -120,10 +120,10 @@ dependencies:
120
120
  version: '0'
121
121
  type: :runtime
122
122
  prerelease: false
123
- version_requirements: *2156810100
123
+ version_requirements: *2157387680
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: awesome_print
126
- requirement: &2156809640 !ruby/object:Gem::Requirement
126
+ requirement: &2157387220 !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
129
129
  - - ! '>='
@@ -131,10 +131,10 @@ dependencies:
131
131
  version: '0'
132
132
  type: :runtime
133
133
  prerelease: false
134
- version_requirements: *2156809640
134
+ version_requirements: *2157387220
135
135
  - !ruby/object:Gem::Dependency
136
136
  name: ruby-debug19
137
- requirement: &2156809220 !ruby/object:Gem::Requirement
137
+ requirement: &2157386800 !ruby/object:Gem::Requirement
138
138
  none: false
139
139
  requirements:
140
140
  - - ! '>='
@@ -142,10 +142,10 @@ dependencies:
142
142
  version: '0'
143
143
  type: :development
144
144
  prerelease: false
145
- version_requirements: *2156809220
145
+ version_requirements: *2157386800
146
146
  - !ruby/object:Gem::Dependency
147
147
  name: aruba
148
- requirement: &2156808800 !ruby/object:Gem::Requirement
148
+ requirement: &2157386380 !ruby/object:Gem::Requirement
149
149
  none: false
150
150
  requirements:
151
151
  - - ! '>='
@@ -153,10 +153,10 @@ dependencies:
153
153
  version: '0'
154
154
  type: :development
155
155
  prerelease: false
156
- version_requirements: *2156808800
156
+ version_requirements: *2157386380
157
157
  - !ruby/object:Gem::Dependency
158
158
  name: rails
159
- requirement: &2156808300 !ruby/object:Gem::Requirement
159
+ requirement: &2157385880 !ruby/object:Gem::Requirement
160
160
  none: false
161
161
  requirements:
162
162
  - - ~>
@@ -164,10 +164,10 @@ dependencies:
164
164
  version: 3.0.3
165
165
  type: :development
166
166
  prerelease: false
167
- version_requirements: *2156808300
167
+ version_requirements: *2157385880
168
168
  - !ruby/object:Gem::Dependency
169
169
  name: bundler
170
- requirement: &2156824160 !ruby/object:Gem::Requirement
170
+ requirement: &2157385380 !ruby/object:Gem::Requirement
171
171
  none: false
172
172
  requirements:
173
173
  - - ~>
@@ -175,10 +175,10 @@ dependencies:
175
175
  version: 1.0.0
176
176
  type: :development
177
177
  prerelease: false
178
- version_requirements: *2156824160
178
+ version_requirements: *2157385380
179
179
  - !ruby/object:Gem::Dependency
180
180
  name: generator_spec
181
- requirement: &2156823700 !ruby/object:Gem::Requirement
181
+ requirement: &2157384920 !ruby/object:Gem::Requirement
182
182
  none: false
183
183
  requirements:
184
184
  - - ~>
@@ -186,10 +186,10 @@ dependencies:
186
186
  version: 0.8.3
187
187
  type: :development
188
188
  prerelease: false
189
- version_requirements: *2156823700
189
+ version_requirements: *2157384920
190
190
  - !ruby/object:Gem::Dependency
191
191
  name: rspec-rails
192
- requirement: &2156823320 !ruby/object:Gem::Requirement
192
+ requirement: &2157384540 !ruby/object:Gem::Requirement
193
193
  none: false
194
194
  requirements:
195
195
  - - ! '>='
@@ -197,10 +197,10 @@ dependencies:
197
197
  version: '0'
198
198
  type: :development
199
199
  prerelease: false
200
- version_requirements: *2156823320
200
+ version_requirements: *2157384540
201
201
  - !ruby/object:Gem::Dependency
202
202
  name: cucumber
203
- requirement: &2156822860 !ruby/object:Gem::Requirement
203
+ requirement: &2157384080 !ruby/object:Gem::Requirement
204
204
  none: false
205
205
  requirements:
206
206
  - - ! '>='
@@ -208,10 +208,10 @@ dependencies:
208
208
  version: '0'
209
209
  type: :development
210
210
  prerelease: false
211
- version_requirements: *2156822860
211
+ version_requirements: *2157384080
212
212
  - !ruby/object:Gem::Dependency
213
213
  name: rdoc
214
- requirement: &2156822360 !ruby/object:Gem::Requirement
214
+ requirement: &2157383580 !ruby/object:Gem::Requirement
215
215
  none: false
216
216
  requirements:
217
217
  - - ~>
@@ -219,10 +219,10 @@ dependencies:
219
219
  version: 3.5.3
220
220
  type: :development
221
221
  prerelease: false
222
- version_requirements: *2156822360
222
+ version_requirements: *2157383580
223
223
  - !ruby/object:Gem::Dependency
224
224
  name: vcr
225
- requirement: &2156821940 !ruby/object:Gem::Requirement
225
+ requirement: &2157383160 !ruby/object:Gem::Requirement
226
226
  none: false
227
227
  requirements:
228
228
  - - ! '>='
@@ -230,10 +230,10 @@ dependencies:
230
230
  version: '0'
231
231
  type: :development
232
232
  prerelease: false
233
- version_requirements: *2156821940
233
+ version_requirements: *2157383160
234
234
  - !ruby/object:Gem::Dependency
235
235
  name: rake
236
- requirement: &2156821480 !ruby/object:Gem::Requirement
236
+ requirement: &2157382700 !ruby/object:Gem::Requirement
237
237
  none: false
238
238
  requirements:
239
239
  - - ! '>='
@@ -241,10 +241,10 @@ dependencies:
241
241
  version: '0'
242
242
  type: :development
243
243
  prerelease: false
244
- version_requirements: *2156821480
244
+ version_requirements: *2157382700
245
245
  - !ruby/object:Gem::Dependency
246
246
  name: webmock
247
- requirement: &2156821060 !ruby/object:Gem::Requirement
247
+ requirement: &2157398660 !ruby/object:Gem::Requirement
248
248
  none: false
249
249
  requirements:
250
250
  - - ! '>='
@@ -252,10 +252,10 @@ dependencies:
252
252
  version: '0'
253
253
  type: :development
254
254
  prerelease: false
255
- version_requirements: *2156821060
255
+ version_requirements: *2157398660
256
256
  - !ruby/object:Gem::Dependency
257
257
  name: timecop
258
- requirement: &2156820640 !ruby/object:Gem::Requirement
258
+ requirement: &2157398240 !ruby/object:Gem::Requirement
259
259
  none: false
260
260
  requirements:
261
261
  - - ! '>='
@@ -263,7 +263,7 @@ dependencies:
263
263
  version: '0'
264
264
  type: :development
265
265
  prerelease: false
266
- version_requirements: *2156820640
266
+ version_requirements: *2157398240
267
267
  description: A Ruby wrapper and CLI for to interact with Cloudfactory.com REST API
268
268
  email:
269
269
  - info@cloudfactory.com
@@ -318,11 +318,11 @@ files:
318
318
  - lib/cf/client.rb
319
319
  - lib/cf/custom_task_form.rb
320
320
  - lib/cf/department.rb
321
- - lib/cf/final_output.rb
322
321
  - lib/cf/form_field.rb
323
322
  - lib/cf/human_worker.rb
324
323
  - lib/cf/input_format.rb
325
324
  - lib/cf/line.rb
325
+ - lib/cf/output_format.rb
326
326
  - lib/cf/robot_worker.rb
327
327
  - lib/cf/run.rb
328
328
  - lib/cf/station.rb
@@ -1,6 +0,0 @@
1
- module CF # :nodoc:
2
- class FinalOutput # :nodoc:
3
- include Client
4
- attr_accessor :final_outputs, :unit_id, :final_output, :output
5
- end
6
- end