cloudfactory 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. data/.gitignore +11 -0
  2. data/.rspec +1 -0
  3. data/Gemfile +10 -0
  4. data/README.md +44 -0
  5. data/Rakefile +40 -0
  6. data/bin/cf +8 -0
  7. data/cf.gemspec +76 -0
  8. data/example/google_translate_app/Gemfile +12 -0
  9. data/example/google_translate_app/config.ru +7 -0
  10. data/example/google_translate_app/google_translate_input.csv +4 -0
  11. data/example/google_translate_app/google_translator_app.rb +53 -0
  12. data/example/google_translate_app/views/index.haml +2 -0
  13. data/example/google_translate_app/views/layout.haml +7 -0
  14. data/example/google_translate_app/views/run.haml +4 -0
  15. data/example/google_translate_app/views/style.sass +2 -0
  16. data/example/human_worker_app/Gemfile +12 -0
  17. data/example/human_worker_app/config.ru +7 -0
  18. data/example/human_worker_app/human_worker_app.rb +55 -0
  19. data/example/human_worker_app/human_worker_input.csv +5 -0
  20. data/example/human_worker_app/public/app.js +12 -0
  21. data/example/human_worker_app/temp.csv +3 -0
  22. data/example/human_worker_app/views/index.haml +15 -0
  23. data/example/human_worker_app/views/layout.haml +10 -0
  24. data/example/human_worker_app/views/result.haml +18 -0
  25. data/example/human_worker_app/views/run.haml +12 -0
  26. data/example/human_worker_app/views/style.sass +25 -0
  27. data/example/sample_yaml_files/concept_tagging_robot.yaml +18 -0
  28. data/example/sample_yaml_files/content_scraping_robot.yaml +19 -0
  29. data/example/sample_yaml_files/entity_extraction_robot.yaml +18 -0
  30. data/example/sample_yaml_files/google_translate_robot.yaml +20 -0
  31. data/example/sample_yaml_files/image_processing_robot.yaml +20 -0
  32. data/example/sample_yaml_files/keyword_matching_and_text_extraction_robot.yaml +26 -0
  33. data/example/sample_yaml_files/mailer_robot.yaml +21 -0
  34. data/example/sample_yaml_files/media_converter_robot.yaml +21 -0
  35. data/example/sample_yaml_files/media_splitting_robot.yaml +20 -0
  36. data/example/sample_yaml_files/multiple_skill_badge.yaml +75 -0
  37. data/example/sample_yaml_files/sentiment_robot.yaml +19 -0
  38. data/example/sample_yaml_files/skill_badge.yaml +56 -0
  39. data/example/sample_yaml_files/stat_badge.yaml +40 -0
  40. data/example/sample_yaml_files/term_extraction_robot.yaml +20 -0
  41. data/example/sample_yaml_files/tournament_station_and_form_fields.yaml +40 -0
  42. data/features/form_generation.feature +46 -0
  43. data/features/form_preview.feature +98 -0
  44. data/features/line_creation.feature +99 -0
  45. data/features/line_deletion.feature +50 -0
  46. data/features/line_generation.feature +57 -0
  47. data/features/run.feature +141 -0
  48. data/features/support/cli_steps.rb +16 -0
  49. data/features/support/env.rb +23 -0
  50. data/features/target_url.feature +82 -0
  51. data/fixtures/api_credentials_example.yml +4 -0
  52. data/fixtures/input_data/media_converter_robot.csv +2 -0
  53. data/fixtures/input_data/test.csv +2 -0
  54. data/lib/cf.rb +94 -0
  55. data/lib/cf/account.rb +32 -0
  56. data/lib/cf/cli.rb +52 -0
  57. data/lib/cf/cli/config.rb +87 -0
  58. data/lib/cf/cli/form.rb +82 -0
  59. data/lib/cf/cli/line.rb +237 -0
  60. data/lib/cf/cli/production.rb +62 -0
  61. data/lib/cf/cli/templates/css_file.css.erb +22 -0
  62. data/lib/cf/cli/templates/form_preview.html.erb +17 -0
  63. data/lib/cf/cli/templates/html_file.html.erb +21 -0
  64. data/lib/cf/cli/templates/js_file.js.erb +18 -0
  65. data/lib/cf/cli/templates/line.tt +55 -0
  66. data/lib/cf/cli/templates/sample-line/form.css +27 -0
  67. data/lib/cf/cli/templates/sample-line/form.html +26 -0
  68. data/lib/cf/cli/templates/sample-line/form.js +7 -0
  69. data/lib/cf/cli/templates/sample-line/line.yml.erb +67 -0
  70. data/lib/cf/cli/templates/sample-line/sample-line.csv +3 -0
  71. data/lib/cf/client.rb +56 -0
  72. data/lib/cf/custom_task_form.rb +136 -0
  73. data/lib/cf/department.rb +24 -0
  74. data/lib/cf/final_output.rb +20 -0
  75. data/lib/cf/form_field.rb +62 -0
  76. data/lib/cf/human_worker.rb +67 -0
  77. data/lib/cf/input_format.rb +134 -0
  78. data/lib/cf/line.rb +231 -0
  79. data/lib/cf/robot_worker.rb +31 -0
  80. data/lib/cf/run.rb +158 -0
  81. data/lib/cf/station.rb +340 -0
  82. data/lib/cf/task_form.rb +147 -0
  83. data/lib/cf/version.rb +3 -0
  84. data/lib/generators/cf/form/form_generator.rb +55 -0
  85. data/lib/generators/cf/form/templates/cf_form.html.erb +11 -0
  86. data/lib/generators/cf/install/install_generator.rb +22 -0
  87. data/lib/generators/cf/install/templates/README +13 -0
  88. data/lib/generators/cf/install/templates/cloud_factory.rb +7 -0
  89. data/spec/account_spec.rb +11 -0
  90. data/spec/badge_spec.rb +88 -0
  91. data/spec/concept_tagging_robot_spec.rb +54 -0
  92. data/spec/config_spec.rb +20 -0
  93. data/spec/content_scraping_robot_spec.rb +58 -0
  94. data/spec/custom_task_form_spec.rb +190 -0
  95. data/spec/department_spec.rb +14 -0
  96. data/spec/entity_extraction_robot_spec.rb +56 -0
  97. data/spec/form_field_spec.rb +126 -0
  98. data/spec/generators/form_generator_spec.rb +60 -0
  99. data/spec/generators/install_generator_spec.rb +35 -0
  100. data/spec/google_translate_robot_spec.rb +64 -0
  101. data/spec/human_worker_spec.rb +118 -0
  102. data/spec/image_processing_robot_spec.rb +56 -0
  103. data/spec/input_format_spec.rb +113 -0
  104. data/spec/keyword_matching_and_text_extraction_robot_spec.rb +73 -0
  105. data/spec/line_spec.rb +338 -0
  106. data/spec/mailer_robot_spec.rb +62 -0
  107. data/spec/media_converter_robot_spec.rb +72 -0
  108. data/spec/media_splitting_robot_spec.rb +62 -0
  109. data/spec/run_spec.rb +298 -0
  110. data/spec/sentiment_robot_spec.rb +56 -0
  111. data/spec/spec_helper.rb +39 -0
  112. data/spec/station_spec.rb +256 -0
  113. data/spec/task_form_spec.rb +96 -0
  114. data/spec/term_extraction_robot_spec.rb +58 -0
  115. data/spec/text_appending_robot_spec.rb +86 -0
  116. metadata +472 -0
data/lib/cf/version.rb ADDED
@@ -0,0 +1,3 @@
1
+ module CF
2
+ VERSION = "0.0.13"
3
+ end
@@ -0,0 +1,55 @@
1
+ module Cf
2
+ module Generators
3
+
4
+ #
5
+ # TODO: if the parameter like 'company' below is not provided, then its a survey form.
6
+ # But how to name it is not defined. If we just use survey_name,
7
+ # then it might collide if the developer generates another survey form
8
+ #
9
+ # => rails generate cf:form company ceo:string Website:url
10
+ #
11
+ # <label>{{company}}</label>
12
+ # <p><label>ceo</label><input id="ceo" type="text" name="output[ceo]" data-valid-type="string" /></p>
13
+ # <p><label>Website</label><input id="website" type="text" name="output[website]" data-valid-type="url" /></p>
14
+ #
15
+ #
16
+ # => rails generate cf:form [company,website] CEO:string Website:url
17
+ #
18
+ # <label>{{company}}</label>
19
+ # <label>{{website}}</label>
20
+ # <p><label>CEO</label><input id="ceo" type="text" name="output[ceo]" data-valid-type="string" /></p>
21
+ # <p><label>Website</label><input id="website" type="text" name="output[website]" data-valid-type="url" /></p>
22
+ #
23
+ #
24
+
25
+ class FormGenerator < Rails::Generators::Base
26
+ source_root File.expand_path("../templates", __FILE__)
27
+ argument :attributes, :type => :array, :default => [], :banner => "[label1,label2] field:type field:type"
28
+
29
+ desc "Generates a CloudFactory CustomTaskForm"
30
+ def generate_form
31
+ @labels = nil
32
+
33
+ attributes.detect {|item| @labels = item.match(/^\[(.*)\]$/) }
34
+
35
+ @labels = @labels.to_a.last unless @labels.nil?
36
+ attributes.delete(attributes.first) unless @labels.nil?
37
+
38
+ file_name = make_file_name(@labels)
39
+
40
+ say_status("Generating", "CloudFactory CustomTaskForm", :green)
41
+ template "cf_form.html.erb", "app/cf_forms/#{file_name}"
42
+ end
43
+
44
+ private
45
+
46
+ def make_file_name(attrs)
47
+ if attrs.nil?
48
+ "custom_task_form.html"
49
+ else
50
+ attrs.split(",").join("_") + "_form.html"
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,11 @@
1
+ <!-- CloudFactory Custom Task Form -->
2
+ <%- @labels.split(",").each do |label| -%>
3
+ <label>{{<%= label %>}}</label>
4
+ <%- end unless @labels.nil? -%>
5
+
6
+ <%-
7
+ attributes.each do |item|
8
+ field_name, data_input_type = item.split(":")
9
+ -%>
10
+ <p><label><%= field_name %></label><input id="<%= field_name.downcase %>" type="text" name="output[<%= field_name.downcase %>]" data-valid-type="<%= data_input_type.downcase %>" /></p>
11
+ <%- end unless attributes.blank? -%>
@@ -0,0 +1,22 @@
1
+ module Cf
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ source_root File.expand_path("../templates", __FILE__)
5
+ # argument :account_name, :required => true,
6
+ # :desc => "The account name that you used to signup at http://cloudfactory.com"
7
+ argument :api_key, :required => true,
8
+ :desc => "Your API key(s) can be found at http://cloudfactory.com/account#settings"
9
+
10
+ desc "Creates a CF initializer"
11
+ def generate_initializer
12
+ say_status("Generating", "CloudFactory initializer", :green)
13
+ template "cloud_factory.rb", "config/initializers/cloud_factory.rb"
14
+ end
15
+
16
+ def show_readme
17
+ readme 'README' if behavior == :invoke
18
+ end
19
+
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,13 @@
1
+
2
+ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁
3
+
4
+ CloudFactory initializer file successfully generated.
5
+ See the documentation at http://developers.cloudfactory.com
6
+
7
+ Or dive right in with the CloudFactory TaskForm generator. To list the commands, type:
8
+
9
+ > rails generate cf:form
10
+
11
+ > rails generate cf:form company ceo:name website:url
12
+
13
+ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁
@@ -0,0 +1,7 @@
1
+ # CloudFactory Initializer
2
+ require 'cf'
3
+ CF.configure do |config|
4
+ config.api_version = "v1"
5
+ config.api_key = "<%= api_key %>"
6
+ config.api_url = "http://cloudfactory.com/api/"
7
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe CF::Account do
4
+ it "should get the account info" do
5
+ # WebMock.allow_net_connect!
6
+ VCR.use_cassette "account/info", :record => :new_episodes do
7
+ account_info = CF::Account.info
8
+ account_info.name.should eql("manish")
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,88 @@
1
+ require 'spec_helper'
2
+
3
+ module CF
4
+ describe CF::HumanWorker do
5
+ context "create badge" do
6
+ it "should create multiple badge for worker" do
7
+ # WebMock.allow_net_connect!
8
+ VCR.use_cassette "human_worker/block/create-multiple-badge", :record => :new_episodes do
9
+ badge =
10
+ {
11
+ :title => 'Football Fanatic',
12
+ :description => "This qualification allows you to perform work at stations which have this badge.",
13
+ :max_badges => 3,
14
+ :test =>
15
+ {
16
+ :input => {:name => "Lionel Andres Messi", :country => "Argentina"},
17
+ :expected_output =>
18
+ [{:birthplace => "Rosario, Santa Fe, Argentina",:match_options => {:tolerance => 10, :ignore_case => true }},{:position => "CF",:match_options => {:tolerance => 1 }},{:"current-club" => "Barcelona",:match_options => {:tolerance => 1, :ignore_case => false }}]
19
+ }
20
+ }
21
+ badge_1 =
22
+ {
23
+ :title => 'Football Fanatic',
24
+ :description => "This qualification allows you to perform work at stations which have this badge.",
25
+ :max_badges => 3,
26
+ :test =>
27
+ {
28
+ :input => {:name => "Cristiano Ronaldo", :country => "Portugal"},
29
+ :expected_output =>
30
+ [{:birthplace => "Rosario, Santa Fe, Portugal",:match_options => {:tolerance => 10, :ignore_case => true }},{:position => "CF",:match_options => {:tolerance => 1 }},{:"current-club" => "Real Madrid",:match_options => {:tolerance => 1, :ignore_case => false }}]
31
+ }
32
+ }
33
+ line = CF::Line.create("badge_in_worker", "Digitization") do |l|
34
+ CF::InputFormat.new({:line => l, :name => "image_url", :required => true, :valid_type => "url"})
35
+ CF::Station.create({:line =>l, :type => "work"}) do |s|
36
+ CF::HumanWorker.new({:station => s, :number => 2, :reward => 20, :skill_badge => badge})
37
+ end
38
+ end
39
+ line.stations.first.worker.badge = badge_1
40
+ line.stations.first.type.should eql("WorkStation")
41
+ line.stations.first.worker.number.should eql(2)
42
+ line.stations.first.worker.reward.should eql(20)
43
+ line.stations.first.worker.skill_badges.first.should eql([{"title"=>"Football Fanatic", "description"=>"This qualification allows you to perform work at stations which have this badge.", "score"=>nil, "speed"=>nil, "quality_rating"=>nil, "max_badges"=>3, "skill_test"=>{"score_after"=>"submit", "manual_scoring"=>false, "display_answers"=>false, "edit_answers"=>true, "retries"=>0, "pass_percentage"=>100, "test_units"=>[{"input"=>{"name"=>"Lionel Andres Messi", "country"=>"Argentina"}, "expected_output"=>[{"birthplace"=>"Rosario, Santa Fe, Argentina", "match_options"=>{"tolerance"=>"1", "ignore_case"=>"false"}, "position"=>"CF", "current-club"=>"Barcelona"}], "match_options"=>{"tolerance"=>0, "ignore_case"=>false}}]}}])
44
+ line.stations.first.worker.skill_badges.last.should eql([{"title"=>"Football Fanatic", "description"=>"This qualification allows you to perform work at stations which have this badge.", "score"=>nil, "speed"=>nil, "quality_rating"=>nil, "max_badges"=>3, "skill_test"=>{"score_after"=>"submit", "manual_scoring"=>false, "display_answers"=>false, "edit_answers"=>true, "retries"=>0, "pass_percentage"=>100, "test_units"=>[{"input"=>{"name"=>"Cristiano Ronaldo", "country"=>"Portugal"}, "expected_output"=>[{"birthplace"=>"Rosario, Santa Fe, Portugal", "match_options"=>{"tolerance"=>"1", "ignore_case"=>"false"}, "position"=>"CF", "current-club"=>"Real Madrid"}], "match_options"=>{"tolerance"=>0, "ignore_case"=>false}}]}}])
45
+ line.stations.first.worker.stat_badge.should eql({"approval_rating"=>80, "assignment_duration"=>3600, "abandonment_rate"=>30, "country"=>nil})
46
+ end
47
+ end
48
+
49
+ it "should create stat badge for worker in block DSL way" do
50
+ # WebMock.allow_net_connect!
51
+ VCR.use_cassette "human_worker/block/create-stat-badge", :record => :new_episodes do
52
+ stat_badge = {:approval_rating => 40, :assignment_duration => 1800}
53
+ line = CF::Line.create("stat_badge_in_worker", "Digitization") do |l|
54
+ CF::InputFormat.new({:line => l, :name => "image_url", :required => true, :valid_type => "url"})
55
+ CF::Station.create({:line =>l, :type => "work"}) do |s|
56
+ CF::HumanWorker.new({:station => s, :number => 2, :reward => 20, :stat_badge => stat_badge})
57
+ end
58
+ end
59
+ line.stations.first.type.should eql("WorkStation")
60
+ line.stations.first.worker.number.should eql(2)
61
+ line.stations.first.worker.reward.should eql(20)
62
+ line.stations.first.worker.stat_badge.should eql({"approval_rating"=>40, "assignment_duration"=>1800, "abandonment_rate"=>30, "country"=>nil})
63
+ end
64
+ end
65
+
66
+ it "should create stat badge for worker in plain ruby way" do
67
+ # WebMock.allow_net_connect!
68
+ VCR.use_cassette "human_worker/plain-ruby/create-stat-badge", :record => :new_episodes do
69
+ stat_badge = {:approval_rating => 40, :assignment_duration => 1800}
70
+ line = CF::Line.new("stat_badge_in_worker_1", "Digitization")
71
+ input_format = CF::InputFormat.new({:name => "image_url", :required => true, :valid_type => "url"})
72
+ line.input_formats input_format
73
+
74
+ station = CF::Station.new({:type => "work"})
75
+ line.stations station
76
+
77
+ worker = CF::HumanWorker.new({:number => 2, :reward => 20, :stat_badge => stat_badge})
78
+ line.stations.first.worker = worker
79
+
80
+ line.stations.first.type.should eql("WorkStation")
81
+ line.stations.first.worker.number.should eql(2)
82
+ line.stations.first.worker.reward.should eql(20)
83
+ line.stations.first.worker.stat_badge.should eql({"approval_rating"=>40, "assignment_duration"=>1800, "abandonment_rate"=>30, "country"=>nil})
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,54 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ module CF
5
+ describe CF::RobotWorker do
6
+ context "create a concept tagging robot worker" do
7
+ it "should create concept tagging robot worker for first station in Block DSL way" do
8
+ # WebMock.allow_net_connect!
9
+ VCR.use_cassette "robot_worker/concept_tagging_robot/block/create-worker-single-station", :record => :new_episodes do
10
+ line = CF::Line.create("concept_tagging_robot","Digitization") do |l|
11
+ CF::InputFormat.new({:line => l, :name => "url", :valid_type => "url", :required => "true"})
12
+ CF::Station.create({:line => l, :type => "work"}) do |s|
13
+ CF::RobotWorker.create({:station => s, :type => "concept_tagging_robot", :settings => {:url => ["{url}"]}})
14
+ end
15
+ end
16
+ run = CF::Run.create(line, "concept_tagging_robot_run", [{"url"=>"www.mosexindex.com"}])
17
+ output = run.final_output
18
+ output.first.final_output.first.concept_tagging_of_url.should eql(["Canada", "English language"])
19
+ output.first.final_output.first.concept_tagging_relevance_of_url.should eql([89.5153, 79.0912])
20
+ line.stations.first.worker.class.should eql(CF::RobotWorker)
21
+ line.stations.first.worker.reward.should eql(1)
22
+ line.stations.first.worker.number.should eql(1)
23
+ line.stations.first.worker.settings.should eql({:url => ["{url}"]})
24
+ line.stations.first.worker.type.should eql("ConceptTaggingRobot")
25
+ end
26
+ end
27
+
28
+ it "should create content_scraping_robot worker for first station in a plain ruby way" do
29
+ # WebMock.allow_net_connect!
30
+ VCR.use_cassette "robot_worker/concept_tagging_robot/plain-ruby/create-worker-in-first-station", :record => :new_episodes do
31
+ line = CF::Line.new("concept_tagging_robot_1","Digitization")
32
+ input_format = CF::InputFormat.new({:name => "url", :required => true, :valid_type => "url"})
33
+ line.input_formats input_format
34
+
35
+ station = CF::Station.new({:type => "work"})
36
+ line.stations station
37
+
38
+ worker = CF::RobotWorker.create({:type => "concept_tagging_robot", :settings => {:url => ["{url}"]}})
39
+ line.stations.first.worker = worker
40
+
41
+ run = CF::Run.create(line, "concept_tagging_robot_run_1", [{"url"=>"www.mosexindex.com"}])
42
+ output = run.final_output
43
+ output.first.final_output.first.concept_tagging_of_url.should eql(["Canada", "English language"])
44
+ output.first.final_output.first.concept_tagging_relevance_of_url.should eql([89.5153, 79.0912])
45
+ line.stations.first.worker.class.should eql(CF::RobotWorker)
46
+ line.stations.first.worker.reward.should eql(1)
47
+ line.stations.first.worker.number.should eql(1)
48
+ line.stations.first.worker.settings.should eql({:url => ["{url}"]})
49
+ line.stations.first.worker.type.should eql("ConceptTaggingRobot")
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe CF do
4
+ context "configuration" do
5
+ it "be able to configure the api key" do
6
+ API_CONFIG = YAML.load_file(File.expand_path("../../fixtures/api_credentials.yml", __FILE__))
7
+ CF.configure do |config|
8
+ config.account_name = API_CONFIG['account_name']
9
+ config.api_version = API_CONFIG['api_version']
10
+ config.api_url = API_CONFIG['api_url']
11
+ config.api_key = API_CONFIG['api_key']
12
+ end
13
+
14
+ CF.account_name.should eql(API_CONFIG['account_name'])
15
+ CF.api_key.should eql(API_CONFIG['api_key'])
16
+ CF.api_url.should eql(API_CONFIG['api_url'])
17
+ CF.api_version.should eql(API_CONFIG['api_version'])
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,58 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ module CF
5
+ describe CF::RobotWorker do
6
+ context "create a content scraping robot worker" do
7
+ it "should create content_scraping_robot worker for first station in Block DSL way" do
8
+ # WebMock.allow_net_connect!
9
+ VCR.use_cassette "robot_worker/content_scraping_robot/block/create-worker-single-station", :record => :new_episodes do
10
+ line = CF::Line.create("content_scraping_robot","Digitization") do |l|
11
+ CF::InputFormat.new({:line => l, :name => "url", :valid_type => "url", :required => "true"})
12
+ CF::Station.create({:line => l, :type => "work"}) do |s|
13
+ CF::RobotWorker.create({:station => s, :type => "content_scraping_robot", :settings => {:document => ["http://www.sprout-technology.com"], :query => "1st 2 links after Sprout products"}})
14
+ end
15
+ end
16
+ run = CF::Run.create(line, "content_scraping_robot_run", [{"url"=> "http://www.sprout-technology.com"}])
17
+
18
+ output = run.final_output
19
+ output.first.final_output.first.scraped_link_from_document.should eql([["http://www.cloudfactory.com", "http://www.bizcardarmy.com"]])
20
+ output.first.final_output.first.query.should eql("1st 2 links after Sprout products")
21
+
22
+ line.stations.first.worker.class.should eql(CF::RobotWorker)
23
+ line.stations.first.worker.reward.should eql(10)
24
+ line.stations.first.worker.number.should eql(1)
25
+ line.stations.first.worker.settings.should eql({:document => ["http://www.sprout-technology.com"], :query => "1st 2 links after Sprout products"})
26
+ line.stations.first.worker.type.should eql("ContentScrapingRobot")
27
+ end
28
+ end
29
+
30
+ it "should create content_scraping_robot worker for first station in a plain ruby way" do
31
+ # WebMock.allow_net_connect!
32
+ VCR.use_cassette "robot_worker/content_scraping_robot/plain-ruby/create-worker-in-first-station", :record => :new_episodes do
33
+ line = CF::Line.new("content_scraping_robot_run_1","Digitization")
34
+ input_format = CF::InputFormat.new({:name => "url", :required => true, :valid_type => "url"})
35
+ line.input_formats input_format
36
+
37
+ station = CF::Station.new({:type => "work"})
38
+ line.stations station
39
+
40
+ worker = CF::RobotWorker.create({:type => "content_scraping_robot", :settings => {:document => ["http://www.sprout-technology.com"], :query => "1st 2 links after Sprout products"}})
41
+ line.stations.first.worker = worker
42
+
43
+ run = CF::Run.create(line, "content_scraping_robot_run_1", [{"url"=> "http://www.sprout-technology.com"}])
44
+
45
+ output = run.final_output
46
+ output.first.final_output.first.scraped_link_from_document.should eql([["http://www.cloudfactory.com", "http://www.bizcardarmy.com"]])
47
+ output.first.final_output.first.query.should eql("1st 2 links after Sprout products")
48
+
49
+ line.stations.first.worker.class.should eql(CF::RobotWorker)
50
+ line.stations.first.worker.reward.should eql(10)
51
+ line.stations.first.worker.number.should eql(1)
52
+ line.stations.first.worker.settings.should eql({:document => ["http://www.sprout-technology.com"], :query => "1st 2 links after Sprout products"})
53
+ line.stations.first.worker.type.should eql("ContentScrapingRobot")
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,190 @@
1
+ require 'spec_helper'
2
+
3
+ describe CF::CustomTaskForm do
4
+ context "create a standard_instruction" do
5
+ it "in block DSL way" do
6
+ # WebMock.allow_net_connect!
7
+ VCR.use_cassette "custom-task-form/block/create", :record => :new_episodes do
8
+ html = '<div id="form-content">
9
+ <div id="instructions">
10
+ <ul>
11
+ <li>Look at the business card properly and fill in asked data.</li>
12
+ <li>Make sure you enter everything found on business card.</li>
13
+ <li>Work may be rejected if it is incomplete or mistakes are found.</li>
14
+ </ul>
15
+ </div>
16
+ <div id="image-field-wrapper">
17
+ <div id = "image-panel" >
18
+ <img class="card-image" src="{{image_url}}">
19
+ </div>
20
+ <div id = "field-panel">
21
+ Name<br />
22
+ <input class="input-field first_name" type="text" name="final_output[first_name]" />
23
+ <input class="input-field middle_name" type="text" name="final_output[middle_name]" />
24
+ <input class="input-field last_name" type="text" name="final_output[last_name]" /><br />
25
+
26
+ <br />Contact<br />
27
+ <input class="input-field email" type="text" name="final_output[email]" placeholder="Email"/>
28
+ <input class="input-field phone" type="text" name="final_output[phone]" placeholder="Phone"/>
29
+ <input class="input-field mobile" type="text" name="final_output[mobile]" placeholder="Mobile"/><br />
30
+
31
+ </div>
32
+ </div>
33
+ </div>'
34
+
35
+ css = '<style>body {background:#fbfbfb;}
36
+ #instructions{
37
+ text-align:center;
38
+ }
39
+
40
+ #image-field-wrapper{
41
+ float-left;
42
+ min-width:1050px;
43
+ overflow:hidden;
44
+ }
45
+
46
+ #field-panel{
47
+ float:left;
48
+ padding: 10px 10px 0 10px;
49
+ min-width:512px;
50
+ overflow:hidden;
51
+ }
52
+
53
+ .input-field{
54
+ width:150px;
55
+ margin:4px;
56
+ }</style>'
57
+
58
+ javascript = '<script src="http://code.jquery.com/jquery-latest.js"></script>
59
+ <script type="text/javascript" src="http://www.bizcardarmy.com/javascripts/jquery.autocomplete-min.js"></script>
60
+ <script type="text/javascript">
61
+ $(document).ready(function(){
62
+ autocomplete_fields = ["first_name", "middle_name", "last_name", "company", "job_title", "city", "state", "zip"];
63
+
64
+ $.each(autocomplete_fields, function(index, value){
65
+ var inputField = "input." + value;
66
+ $(inputField).autocomplete({
67
+ serviceUrl: "http://www.bizcardarmy.com/cards/return_data_for_autocompletion.json",
68
+ maxHeight: 400,
69
+ width: 300,
70
+ zIndex: 9999,
71
+ params: { field: value }
72
+ });
73
+ });
74
+ });
75
+ </script>'
76
+
77
+
78
+ line = CF::Line.create("Digitizecustomform11", "Digitization") do
79
+ CF::InputFormat.new({:line => self, :name => "Name", :required => true, :valid_format => "general"})
80
+ CF::InputFormat.new({:line => self, :name => "Contact", :required => true, :valid_type => "url"})
81
+ CF::Station.create({:line => self, :type => "tournament", :max_judges => 10, :auto_judge => true}) do |s|
82
+ CF::HumanWorker.new({:station => s, :number => 3, :reward => 20})
83
+ CF::CustomTaskForm.create({:station => s, :title => "Enter text from a business card image", :instruction => "Describe", :raw_html => html, :raw_css => css, :raw_javascript => javascript})
84
+ end
85
+ end
86
+ line.title.should eql("Digitizecustomform11")
87
+ line.department_name.should eql("Digitization")
88
+ line.stations.first.type.should eql("TournamentStation")
89
+ CGI.unescape_html(line.stations.first.form.raw_html).should eql(html)
90
+ CGI.unescape_html(line.stations.first.form.raw_css).should eql(css)
91
+ CGI.unescape_html(line.stations.first.form.raw_javascript).should eql(javascript)
92
+ end
93
+ end
94
+
95
+ it "in plain ruby way" do
96
+ VCR.use_cassette "custom-task-form/plain/create", :record => :new_episodes do
97
+ html = '<div id="form-content">
98
+ <div id="instructions">
99
+ <ul>
100
+ <li>Look at the business card properly and fill in asked data.</li>
101
+ <li>Make sure you enter everything found on business card.</li>
102
+ <li>Work may be rejected if it is incomplete or mistakes are found.</li>
103
+ </ul>
104
+ </div>
105
+ <div id="image-field-wrapper">
106
+ <div id = "image-panel" >
107
+ <img class="card-image" src="{{image_url}}">
108
+ </div>
109
+ <div id = "field-panel">
110
+ Name<br />
111
+ <input class="input-field first_name" type="text" name="final_output[first_name]" />
112
+ <input class="input-field middle_name" type="text" name="final_output[middle_name]" />
113
+ <input class="input-field last_name" type="text" name="final_output[last_name]" /><br />
114
+
115
+ <br />Contact<br />
116
+ <input class="input-field email" type="text" name="final_output[email]" placeholder="Email"/>
117
+ <input class="input-field phone" type="text" name="final_output[phone]" placeholder="Phone"/>
118
+ <input class="input-field mobile" type="text" name="final_output[mobile]" placeholder="Mobile"/><br />
119
+
120
+ </div>
121
+ </div>
122
+ </div>'
123
+
124
+ css = '<style>body {background:#fbfbfb;}
125
+ #instructions{
126
+ text-align:center;
127
+ }
128
+
129
+ #image-field-wrapper{
130
+ float-left;
131
+ min-width:1050px;
132
+ overflow:hidden;
133
+ }
134
+
135
+ #field-panel{
136
+ float:left;
137
+ padding: 10px 10px 0 10px;
138
+ min-width:512px;
139
+ overflow:hidden;
140
+ }
141
+
142
+ .input-field{
143
+ width:150px;
144
+ margin:4px;
145
+ }</style>'
146
+
147
+ javascript = '<script src="http://code.jquery.com/jquery-latest.js"></script>
148
+ <script type="text/javascript" src="http://www.bizcardarmy.com/javascripts/jquery.autocomplete-min.js"></script>
149
+ <script type="text/javascript">
150
+ $(document).ready(function(){
151
+ autocomplete_fields = ["first_name", "middle_name", "last_name", "company", "job_title", "city", "state", "zip"];
152
+
153
+ $.each(autocomplete_fields, function(index, value){
154
+ var inputField = "input." + value;
155
+ $(inputField).autocomplete({
156
+ serviceUrl: "http://www.bizcardarmy.com/cards/return_data_for_autocompletion.json",
157
+ maxHeight: 400,
158
+ width: 300,
159
+ zIndex: 9999,
160
+ params: { field: value }
161
+ });
162
+ });
163
+ });
164
+ </script>'
165
+
166
+ line = CF::Line.new("Digitizeplainruby111", "Digitization")
167
+
168
+ input_format_1 = CF::InputFormat.new({:name => "Name", :required => true, :valid_format => "general"})
169
+ input_format_2 = CF::InputFormat.new({:name => "Contact", :required => true, :valid_type => "url"})
170
+ line.input_formats input_format_1
171
+ line.input_formats input_format_2
172
+
173
+ station = CF::Station.new({:type => "work"})
174
+ line.stations station
175
+
176
+ worker = CF::HumanWorker.new({:number => 1, :reward => 20})
177
+ line.stations.first.worker = worker
178
+
179
+ form = CF::CustomTaskForm.new({:title => "Enter text from a business card image", :instruction => "Describe", :raw_html => html, :raw_css => css, :raw_javascript => javascript})
180
+ line.stations.first.form = form
181
+ line.title.should eql("Digitizeplainruby111")
182
+ line.department_name.should eql("Digitization")
183
+ line.stations.first.type.should eql("WorkStation")
184
+ CGI.unescape_html(line.stations.first.form.raw_html).should eql(html)
185
+ CGI.unescape_html(line.stations.first.form.raw_css).should eql(css)
186
+ CGI.unescape_html(line.stations.first.form.raw_javascript).should eql(javascript)
187
+ end
188
+ end
189
+ end
190
+ end