cloudfactory 0.0.13

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.
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/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
4
+ tmp
5
+ rdoc
6
+ !bin/cf
7
+ vendor/*
8
+ fixtures/api_credentials.yml
9
+ fixtures/cassette_library/*
10
+ .sass-cache/
11
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "http://rubygems.org"
2
+
3
+ group :development do
4
+ gem 'aruba', :git => 'git://github.com/cucumber/aruba.git'
5
+ gem 'ruby-debug', :platforms => :mri_18
6
+ gem 'ruby-debug19', :require => 'ruby-debug', :platforms => :mri_19
7
+ end
8
+
9
+ # All the gem's dependencies are specified in cloud_factory.gemspec
10
+ gemspec
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # CloudFactory Gem
2
+
3
+ A ruby library to interact with the [CloudFactory](http://cloudfactory.com) RESTFul API.
4
+
5
+ Currently tested with:
6
+ * ruby-1.9.2-p180
7
+
8
+ ## Getting Started
9
+
10
+ ```ruby
11
+ gem install cloudfactory
12
+ ```
13
+
14
+ After installing the gem, you will get a `cf` cmd tool.
15
+
16
+ ## Generate a line
17
+ ```bash
18
+ cf line generate first-line
19
+ ```
20
+
21
+ Change the `api_key` in the generated `first-line/line.yml` file.
22
+ Then run `cf production start first-line-run --input-data=first-line-run.csv`
23
+ This should create a line and do production run.
24
+
25
+ ```bash
26
+ ± cf
27
+ Tasks:
28
+ cf form # Commands to generate custom task forms. For more info, cf form help
29
+ cf help [TASK] # Describe available tasks or one specific task
30
+ cf line # Commands to manage the Lines. For more info, cf line help
31
+ cf login --url=URL # Setup the cloudfactory credentials
32
+ cf production # Commands to create production runs. For more info, cf production help
33
+
34
+
35
+ ± cf line help
36
+ Tasks:
37
+ cf help [COMMAND] # Describe subcommands or one specific subcommand
38
+ cf line create # takes the yaml file at line.yml and creates a new line at http://cloudfactory.com
39
+ cf line generate LINE-TITLE # genarates a line template at <line-title>/line.yml
40
+ ```
41
+
42
+ ## Development
43
+ ```ruby
44
+ RESTCLIENT_LOG=stdout TEST=1 be rspec spec/line_spec.rb -d
data/Rakefile ADDED
@@ -0,0 +1,40 @@
1
+ require 'bundler'
2
+ require 'rubygems'
3
+ require 'rake'
4
+ require 'rdoc/rdoc'
5
+ Bundler::GemHelper.install_tasks
6
+
7
+ begin
8
+ task :default => :build
9
+ require 'rake/rdoctask'
10
+
11
+ html_dir = 'doc/rdoc'
12
+ library = 'CloudFactory'
13
+ Rake::RDocTask.new do |rdoc|
14
+ rdoc.rdoc_dir = "#{html_dir}"
15
+ rdoc.options << '--fmt' << 'darkfish'
16
+ rdoc.title = "#{library} Ruby Gem API Documentation"
17
+ rdoc.rdoc_files.include('README*')
18
+ rdoc.rdoc_files.include('lib/**/*.rb')
19
+ end
20
+
21
+ # Setting up the rake task to generate and upload the documentation to remote
22
+ rdoc_upload_path = "/var/www"
23
+ user = "vagrant"
24
+ remote_host = "33.33.33.10"
25
+
26
+ desc 'Upload documentation to Dev CloudFactory'
27
+ task 'upload-docs' => ['rdoc'] do
28
+ sh "scp -r #{html_dir}/* #{user}@#{remote_host}:#{rdoc_upload_path}/cf-doc"
29
+ end
30
+
31
+ # website_dir = 'site'
32
+ # desc 'Update project website to RubyForge.'
33
+ # task 'upload-site' do
34
+ # sh "scp -r #{website_dir}/* " +
35
+ # "#{rubyforge_user}@rubyforge.org:/var/www/gforge-projects/project/"
36
+ # end
37
+
38
+ # desc 'Update API docs and project website to RubyForge.'
39
+ # task 'publish' => ['upload-docs', 'upload-site']
40
+ end
data/bin/cf ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
4
+ $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
5
+
6
+ require 'cf/cli'
7
+
8
+ Cf::CLI.start
data/cf.gemspec ADDED
@@ -0,0 +1,76 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "cf/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "cloudfactory"
7
+ s.version = CF::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["CloudFactory.com"]
10
+ s.email = ["info@cloudfactory.com"]
11
+ s.homepage = "http://cloudfactory.com"
12
+ s.summary = %q{A Ruby wrapper and CLI for Cloudfactory.com}
13
+ s.description = %q{A Ruby wrapper and CLI for to interact with Cloudfactory.com REST API}
14
+
15
+ s.rubyforge_project = "cloudfactory"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = ["cf"]
20
+ s.require_paths = ["lib"]
21
+
22
+ s.post_install_message =<<EOF
23
+ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁
24
+
25
+ Sweet. You now have the 'cf' command installed. Test drive it with:
26
+ > cf help
27
+
28
+ 1. Sign up for your CloudFactory account and get your API key
29
+ http://cloudfactory.com/users/sign_up
30
+ Get API key from welcome email or http://cloudfactory.com/account#settings
31
+
32
+ 2. Generate your first assembly line...
33
+ > cf line generate <line-title>
34
+
35
+ 3. Edit the generated line.yml to design your perfect assembly line
36
+ See http://developers.cloudfactory.com/lines/yaml.html
37
+
38
+ 4. Create your line in CloudFactory
39
+ > cf line create
40
+
41
+ 5. Do a test production run in the sandbox first...
42
+ > cf production start TITLE -i=INPUT_DATA.CSV
43
+
44
+ 6. Go live! Send your production run to real workers...
45
+ > cf production start TITLE -i=INPUT_DATA.CSV --live
46
+
47
+ ------------------------------------------------------------------------------
48
+
49
+ Follow @thecloudfactory on Twitter for announcements, updates, and news.
50
+ https://twitter.com/thecloudfactory
51
+
52
+ Add your project or organization to the apps wiki!
53
+ https://github.com/sprout/cloudfactory_ruby/wiki/Apps
54
+
55
+ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁
56
+ EOF
57
+
58
+ s.add_dependency "i18n"
59
+ s.add_dependency "activesupport", '~> 3.0.3'
60
+ s.add_dependency "hashie", "~> 1.0.0"
61
+ s.add_dependency "rest-client"
62
+ s.add_dependency "json"
63
+ s.add_dependency "thor", "~> 0.14.6"
64
+ s.add_dependency "httparty", "~> 0.7.8"
65
+ s.add_dependency "terminal-table", "~> 1.4.2"
66
+
67
+ s.add_development_dependency "rails", "~> 3.0.3"
68
+ s.add_development_dependency "bundler", "~> 1.0.0"
69
+ s.add_development_dependency "generator_spec", "~> 0.8.3"
70
+ s.add_development_dependency "rspec-rails"
71
+ s.add_development_dependency "cucumber"
72
+ s.add_development_dependency "rdoc", "~> 3.5.3"
73
+ s.add_development_dependency "vcr"
74
+ s.add_development_dependency "rake"
75
+ s.add_development_dependency "webmock"
76
+ end
@@ -0,0 +1,12 @@
1
+ source :rubygems
2
+
3
+ gem 'sinatra'
4
+ gem 'shotgun'
5
+ gem 'haml'
6
+ if RUBY_VERSION < '1.9'
7
+ gem "ruby-debug", ">= 0.10.3"
8
+ else
9
+ gem "ruby-debug19", :require => 'ruby-debug'
10
+ end
11
+
12
+ gem 'cf', :path => "../../"
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ Bundler.require
5
+
6
+ require './google_translator_app'
7
+ run GoogleTranslatorApp
@@ -0,0 +1,4 @@
1
+ Company,Website
2
+ Apple,apple.com
3
+ Facebook,facebook.com
4
+ Gmail,gmail.com
@@ -0,0 +1,53 @@
1
+ class GoogleTranslatorApp < Sinatra::Base
2
+
3
+ set :haml, :format => :html5
4
+ set :sass, :style => :compact # default Sass style is :nested
5
+
6
+ configure do
7
+ # CF.api_key = "133fcabc51e35903e616c25aace7ffccc819c8f0"
8
+ # CF.email = "sachin@sproutify.com"
9
+ # CF.api_url = "sprout.lvh.me:3000/api/"
10
+ # CF.api_version = "v1"
11
+ end
12
+
13
+ get '/' do
14
+ haml :index
15
+
16
+ end
17
+
18
+ get '/run' do
19
+ # CF.api_url = "sprout.lvh.me:3000/api/"
20
+ response = RestClient.get 'http://sprout.lvh.me:3000/api/v1/lines.json', {:accept => :json}
21
+ # @categories = CF::Category.all
22
+
23
+ # @categories = RestClient.get 'http://sprout.lvh.me:3000/api/v1/categories.json', {:accept => :json}
24
+ # attrs = {:label => "image_url",
25
+ # :field_type => "text_data",
26
+ # :value => "http://s3.amazon.com/bizcardarmy/medium/1.jpg",
27
+ # :required => true,
28
+ # :validation_format => "url"
29
+ # }
30
+ #
31
+ # line = CF::Line.new("Demo Line","Survey")
32
+
33
+ # line = CF::Line.create("Demo Line","Survey") do |l|
34
+ # CF::InputHeader.new(line, attrs)
35
+ # CF::Station.create(l, :type => "work") do |s|
36
+ # CF::HumanWorker.new(s, 2, 0.2)
37
+ # CF::StandardInstruction.create(s,{:title => "Enter name of the CEO of Google", :description => "Enter name of the CEO of Google"}) do |i|
38
+ # CF::FormField.new(s, {:label => "First Name", :field_type => "SA", :required => "true"})
39
+ # CF::FormField.new(s, {:label => "Middle Name", :field_type => "SA"})
40
+ # CF::FormField.new(s, {:label => "Last Name", :field_type => "SA", :required => "true"})
41
+ # end
42
+ # end
43
+ # end
44
+ # run = CF::Run.create(line, "run name", File.expand_path("test.csv", __FILE__))
45
+ #
46
+ haml :run
47
+ end
48
+
49
+ get '/style.css' do
50
+ sass :style, :style => :expanded # overridden
51
+ end
52
+
53
+ end
@@ -0,0 +1,2 @@
1
+ %h1
2
+ Welcome to Translator CF App
@@ -0,0 +1,7 @@
1
+ !!!
2
+ %html
3
+ %title Googke Translator CF App
4
+ %link{:rel => "stylesheet", :type=> "text/css", :href => "/style.css"}
5
+
6
+ %body
7
+ = yield
@@ -0,0 +1,4 @@
1
+ %h2
2
+ Run created.
3
+
4
+ = @categories.inspect
@@ -0,0 +1,2 @@
1
+ body
2
+ background: #444
@@ -0,0 +1,12 @@
1
+ source :rubygems
2
+
3
+ gem 'sinatra'
4
+ gem 'shotgun'
5
+ gem 'haml'
6
+ if RUBY_VERSION < '1.9'
7
+ gem "ruby-debug", ">= 0.10.3"
8
+ else
9
+ gem "ruby-debug19", :require => 'ruby-debug'
10
+ end
11
+
12
+ gem 'cloud_factory', :path => "../../", :require => "cf"
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ Bundler.require
5
+
6
+ require './human_worker_app'
7
+ run HumanWorkerApp
@@ -0,0 +1,55 @@
1
+ class HumanWorkerApp < Sinatra::Base
2
+
3
+ enable :logging
4
+
5
+ set :haml, :format => :html5
6
+ set :sass, :style => :compact # default Sass style is :nested
7
+
8
+ configure do
9
+ CF.api_key = "f488a62d0307e79ec4f1e6131fa220be47e83d44"
10
+ CF.api_url = "http://manish.lvh.me:3000/api/"
11
+ CF.api_version = "v1"
12
+ end
13
+
14
+ helpers do
15
+ include Rack::Utils
16
+ alias_method :h, :escape_html
17
+ end
18
+
19
+ get '/' do
20
+ haml :index
21
+ end
22
+
23
+ post '/run' do
24
+ response = RestClient.get 'http://sprout.lvh.me:3000/api/v1/lines.json', {:accept => :json}
25
+ line = CF::Line.create("Nepali Politicians","Survey") do |l|
26
+ CF::Station.create({:line => l, :type => "work"}) do |s|
27
+ CF::InputFormat.new({:station => s, :name => "Politician Name", :required => true, :valid_type => "general"})
28
+ CF::HumanWorker.new({:station => s, :number => 1, :reward => 20})
29
+ CF::TaskForm.create({:station => s, :title => "Gem Sinatra App -2", :instruction => "Guess the amount they have earned through bribe in Rupees"}) do |f|
30
+ CF::FormField.new({:form => f, :label => "Amount", :field_type => "SA", :required => "true"})
31
+ end
32
+ end
33
+ end
34
+
35
+ input_data_array = []
36
+
37
+ params['names'].each do |data|
38
+ input_data_array << {"Politician Name" => data, "meta_data_name" => data}
39
+ end.join(",")
40
+ @run = CF::Run.create(line, "2011 Ghotala", input_data_array)
41
+
42
+ haml :run
43
+ end
44
+
45
+ get '/result/:run' do
46
+ run_id = params[:run]
47
+ @got_result = CF::Run.get_final_output(run_id)
48
+ haml :result
49
+ end
50
+
51
+ get '/style.css' do
52
+ sass :style, :style => :expanded # overridden
53
+ end
54
+
55
+ end
@@ -0,0 +1,5 @@
1
+ Politician Name
2
+ Madhav Kumar Nepal
3
+ Ram Chandra Poudel
4
+ Jhal Nath Khanal
5
+ Sher Bahadur Deuwa
@@ -0,0 +1,12 @@
1
+ $(document).ready(function() {
2
+
3
+ $(".add").click(function() {
4
+ $("form > p:first-child").clone(true).insertAfter("form > p:first-child");
5
+ return false;
6
+ });
7
+
8
+ $(".remove").click(function() {
9
+ $(this).parent().remove();
10
+ });
11
+
12
+ });
@@ -0,0 +1,3 @@
1
+ Politician Name, meta_data_name
2
+ Khurra,Khurra
3
+ Politician Name, meta_data_name
@@ -0,0 +1,15 @@
1
+ %h1
2
+ Bribery App
3
+
4
+ #container
5
+ %form{:action => "/run", :method => :post, :name => :the_form}
6
+ %p
7
+ %label Enter the politician name
8
+ %input{:type => :text, :name => "names[]"}
9
+ %span.remove Remove
10
+
11
+
12
+ %span.add Add More Politician
13
+
14
+ %p
15
+ %input{:type => :submit, :value => "Find It"}
@@ -0,0 +1,10 @@
1
+ !!!
2
+ %html
3
+ %title CloudFactory App
4
+ %link{:rel => "stylesheet", :type=> "text/css", :href => "/style.css"}
5
+
6
+ %script{:type => "text/javascript", :src => "http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"}
7
+ %script{:type => "text/javascript", :src => "/app.js"}
8
+
9
+ %body
10
+ = yield