turkee-mongoid 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. data/.document +5 -0
  2. data/.gitignore +27 -0
  3. data/.travis.yml +8 -0
  4. data/Gemfile +14 -0
  5. data/Gemfile.lock +136 -0
  6. data/Guardfile +12 -0
  7. data/LICENSE +188 -0
  8. data/README.rdoc +219 -0
  9. data/Rakefile +50 -0
  10. data/VERSION +1 -0
  11. data/lib/generators/turkee/templates/turkee.rb +8 -0
  12. data/lib/generators/turkee/turkee_generator.rb +13 -0
  13. data/lib/helpers/turkee_forms_helper.rb +69 -0
  14. data/lib/models/turkee_imported_assignment.rb +19 -0
  15. data/lib/models/turkee_study.rb +17 -0
  16. data/lib/models/turkee_task.rb +273 -0
  17. data/lib/tasks/turkee.rb +29 -0
  18. data/lib/turkee.rb +9 -0
  19. data/spec/dummy/Rakefile +7 -0
  20. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  21. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  22. data/spec/dummy/app/models/survey.rb +6 -0
  23. data/spec/dummy/app/views/layouts/application.html.erb +20 -0
  24. data/spec/dummy/config.ru +4 -0
  25. data/spec/dummy/config/application.rb +21 -0
  26. data/spec/dummy/config/boot.rb +10 -0
  27. data/spec/dummy/config/environment.rb +5 -0
  28. data/spec/dummy/config/environments/development.rb +24 -0
  29. data/spec/dummy/config/environments/production.rb +51 -0
  30. data/spec/dummy/config/environments/test.rb +37 -0
  31. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  32. data/spec/dummy/config/initializers/inflections.rb +10 -0
  33. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  34. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  35. data/spec/dummy/config/initializers/session_store.rb +8 -0
  36. data/spec/dummy/config/locales/en.yml +5 -0
  37. data/spec/dummy/config/mongoid.yml +21 -0
  38. data/spec/dummy/config/routes.rb +2 -0
  39. data/spec/dummy/db/seeds.rb +0 -0
  40. data/spec/dummy/public/404.html +26 -0
  41. data/spec/dummy/public/422.html +26 -0
  42. data/spec/dummy/public/500.html +26 -0
  43. data/spec/dummy/public/favicon.ico +0 -0
  44. data/spec/dummy/public/javascripts/application.js +2 -0
  45. data/spec/dummy/public/javascripts/controls.js +965 -0
  46. data/spec/dummy/public/javascripts/dragdrop.js +974 -0
  47. data/spec/dummy/public/javascripts/effects.js +1123 -0
  48. data/spec/dummy/public/javascripts/prototype.js +6001 -0
  49. data/spec/dummy/public/javascripts/rails.js +191 -0
  50. data/spec/dummy/public/stylesheets/.gitkeep +0 -0
  51. data/spec/dummy/public/stylesheets/scaffold.css +56 -0
  52. data/spec/dummy/script/rails +6 -0
  53. data/spec/factories/survey_factory.rb +7 -0
  54. data/spec/factories/turkee_task_factory.rb +21 -0
  55. data/spec/helpers/turkee_forms_helper_spec.rb +75 -0
  56. data/spec/models/turkee_study_spec.rb +19 -0
  57. data/spec/models/turkee_task_spec.rb +139 -0
  58. data/spec/spec.opts +1 -0
  59. data/spec/spec_helper.rb +49 -0
  60. data/turkee.gemspec +60 -0
  61. metadata +243 -0
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,27 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ *.gem
5
+ build.sh
6
+
7
+ ## TEXTMATE
8
+ *.tmproj
9
+ tmtags
10
+ *.log
11
+
12
+ ## EMACS
13
+ *~
14
+ \#*
15
+ .\#*
16
+
17
+ ## VIM
18
+ *.swp
19
+
20
+ ## PROJECT::GENERAL
21
+ coverage
22
+ rdoc
23
+ pkg
24
+
25
+ .idea
26
+
27
+ ## PROJECT::SPECIFIC
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ env:
2
+ - "RAILS_VERSION=3.1.0"
3
+ - "RAILS_VERSION=3.2.0"
4
+ - "RAILS_VERSION=4.0.0"
5
+ - "RAILS_VERSION=master"
6
+ rvm:
7
+ - 1.9.3
8
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ rails_version = ENV["RAILS_VERSION"] || "default"
6
+
7
+ rails = case rails_version
8
+ when "master"
9
+ {github: "rails/rails"}
10
+ when "default"
11
+ "~> 4.0.0"
12
+ else
13
+ "~> #{rails_version}"
14
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,136 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ turkee (2.0.2)
5
+ lockfile
6
+ mongoid (>= 4.0.0.alpha1)
7
+ rails (>= 4.0.0)
8
+ rturk (>= 2.4.1)
9
+
10
+ GEM
11
+ remote: http://rubygems.org/
12
+ specs:
13
+ actionmailer (4.0.2)
14
+ actionpack (= 4.0.2)
15
+ mail (~> 2.5.4)
16
+ actionpack (4.0.2)
17
+ activesupport (= 4.0.2)
18
+ builder (~> 3.1.0)
19
+ erubis (~> 2.7.0)
20
+ rack (~> 1.5.2)
21
+ rack-test (~> 0.6.2)
22
+ activemodel (4.0.2)
23
+ activesupport (= 4.0.2)
24
+ builder (~> 3.1.0)
25
+ activerecord (4.0.2)
26
+ activemodel (= 4.0.2)
27
+ activerecord-deprecated_finders (~> 1.0.2)
28
+ activesupport (= 4.0.2)
29
+ arel (~> 4.0.0)
30
+ activerecord-deprecated_finders (1.0.3)
31
+ activesupport (4.0.2)
32
+ i18n (~> 0.6, >= 0.6.4)
33
+ minitest (~> 4.2)
34
+ multi_json (~> 1.3)
35
+ thread_safe (~> 0.1)
36
+ tzinfo (~> 0.3.37)
37
+ arel (4.0.1)
38
+ atomic (1.1.14)
39
+ bson (2.0.0)
40
+ builder (3.1.4)
41
+ connection_pool (1.2.0)
42
+ diff-lcs (1.2.5)
43
+ erector (0.9.0)
44
+ treetop (>= 1.2.3)
45
+ erubis (2.7.0)
46
+ factory_girl (4.3.0)
47
+ activesupport (>= 3.0.0)
48
+ hike (1.2.3)
49
+ i18n (0.6.9)
50
+ lockfile (2.1.0)
51
+ mail (2.5.4)
52
+ mime-types (~> 1.16)
53
+ treetop (~> 1.4.8)
54
+ metaclass (0.0.1)
55
+ mime-types (1.25.1)
56
+ mini_portile (0.5.2)
57
+ minitest (4.7.5)
58
+ mocha (0.14.0)
59
+ metaclass (~> 0.0.1)
60
+ mongoid (4.0.0.alpha1)
61
+ activemodel (~> 4.0.0)
62
+ moped (~> 2.0.beta4)
63
+ origin (~> 1.0)
64
+ tzinfo (~> 0.3.37)
65
+ moped (2.0.0.beta4)
66
+ bson (~> 2.0)
67
+ connection_pool (~> 1.2)
68
+ optionable (~> 0.2.0)
69
+ multi_json (1.8.2)
70
+ nokogiri (1.6.1)
71
+ mini_portile (~> 0.5.0)
72
+ optionable (0.2.0)
73
+ origin (1.1.0)
74
+ polyglot (0.3.3)
75
+ rack (1.5.2)
76
+ rack-test (0.6.2)
77
+ rack (>= 1.0)
78
+ rails (4.0.2)
79
+ actionmailer (= 4.0.2)
80
+ actionpack (= 4.0.2)
81
+ activerecord (= 4.0.2)
82
+ activesupport (= 4.0.2)
83
+ bundler (>= 1.3.0, < 2.0)
84
+ railties (= 4.0.2)
85
+ sprockets-rails (~> 2.0.0)
86
+ railties (4.0.2)
87
+ actionpack (= 4.0.2)
88
+ activesupport (= 4.0.2)
89
+ rake (>= 0.8.7)
90
+ thor (>= 0.18.1, < 2.0)
91
+ rake (10.1.0)
92
+ rest-client (1.6.7)
93
+ mime-types (>= 1.16)
94
+ rspec-core (2.14.7)
95
+ rspec-expectations (2.14.4)
96
+ diff-lcs (>= 1.1.3, < 2.0)
97
+ rspec-mocks (2.14.4)
98
+ rspec-rails (2.14.0)
99
+ actionpack (>= 3.0)
100
+ activesupport (>= 3.0)
101
+ railties (>= 3.0)
102
+ rspec-core (~> 2.14.0)
103
+ rspec-expectations (~> 2.14.0)
104
+ rspec-mocks (~> 2.14.0)
105
+ rturk (2.12.1)
106
+ erector
107
+ nokogiri
108
+ rest-client
109
+ spork (0.9.2)
110
+ sprockets (2.10.1)
111
+ hike (~> 1.2)
112
+ multi_json (~> 1.0)
113
+ rack (~> 1.0)
114
+ tilt (~> 1.1, != 1.3.0)
115
+ sprockets-rails (2.0.1)
116
+ actionpack (>= 3.0)
117
+ activesupport (>= 3.0)
118
+ sprockets (~> 2.8)
119
+ thor (0.18.1)
120
+ thread_safe (0.1.3)
121
+ atomic
122
+ tilt (1.4.1)
123
+ treetop (1.4.15)
124
+ polyglot
125
+ polyglot (>= 0.3.1)
126
+ tzinfo (0.3.38)
127
+
128
+ PLATFORMS
129
+ ruby
130
+
131
+ DEPENDENCIES
132
+ factory_girl (>= 4.3.0)
133
+ mocha
134
+ rspec-rails (~> 2.14.0)
135
+ spork
136
+ turkee!
data/Guardfile ADDED
@@ -0,0 +1,12 @@
1
+ guard 'spork', :rspec_env => { 'RAILS_ENV' => 'test' } do
2
+ watch('spec/spec_helper.rb')
3
+ end
4
+
5
+
6
+ guard 'rspec', :version => 2, :cli => "--drb" do
7
+ watch(%r{^spec/.+_spec\.rb$})
8
+
9
+ # lib/
10
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
11
+ end
12
+
data/LICENSE ADDED
@@ -0,0 +1,188 @@
1
+ Turkee Copyright (c) 2010 Jim Jones
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ Turkee Mongoid (c) 2013 Numerico
23
+
24
+ GNU LESSER GENERAL PUBLIC LICENSE
25
+ Version 3, 29 June 2007
26
+
27
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
28
+ Everyone is permitted to copy and distribute verbatim copies
29
+ of this license document, but changing it is not allowed.
30
+
31
+
32
+ This version of the GNU Lesser General Public License incorporates
33
+ the terms and conditions of version 3 of the GNU General Public
34
+ License, supplemented by the additional permissions listed below.
35
+
36
+ 0. Additional Definitions.
37
+
38
+ As used herein, "this License" refers to version 3 of the GNU Lesser
39
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
40
+ General Public License.
41
+
42
+ "The Library" refers to a covered work governed by this License,
43
+ other than an Application or a Combined Work as defined below.
44
+
45
+ An "Application" is any work that makes use of an interface provided
46
+ by the Library, but which is not otherwise based on the Library.
47
+ Defining a subclass of a class defined by the Library is deemed a mode
48
+ of using an interface provided by the Library.
49
+
50
+ A "Combined Work" is a work produced by combining or linking an
51
+ Application with the Library. The particular version of the Library
52
+ with which the Combined Work was made is also called the "Linked
53
+ Version".
54
+
55
+ The "Minimal Corresponding Source" for a Combined Work means the
56
+ Corresponding Source for the Combined Work, excluding any source code
57
+ for portions of the Combined Work that, considered in isolation, are
58
+ based on the Application, and not on the Linked Version.
59
+
60
+ The "Corresponding Application Code" for a Combined Work means the
61
+ object code and/or source code for the Application, including any data
62
+ and utility programs needed for reproducing the Combined Work from the
63
+ Application, but excluding the System Libraries of the Combined Work.
64
+
65
+ 1. Exception to Section 3 of the GNU GPL.
66
+
67
+ You may convey a covered work under sections 3 and 4 of this License
68
+ without being bound by section 3 of the GNU GPL.
69
+
70
+ 2. Conveying Modified Versions.
71
+
72
+ If you modify a copy of the Library, and, in your modifications, a
73
+ facility refers to a function or data to be supplied by an Application
74
+ that uses the facility (other than as an argument passed when the
75
+ facility is invoked), then you may convey a copy of the modified
76
+ version:
77
+
78
+ a) under this License, provided that you make a good faith effort to
79
+ ensure that, in the event an Application does not supply the
80
+ function or data, the facility still operates, and performs
81
+ whatever part of its purpose remains meaningful, or
82
+
83
+ b) under the GNU GPL, with none of the additional permissions of
84
+ this License applicable to that copy.
85
+
86
+ 3. Object Code Incorporating Material from Library Header Files.
87
+
88
+ The object code form of an Application may incorporate material from
89
+ a header file that is part of the Library. You may convey such object
90
+ code under terms of your choice, provided that, if the incorporated
91
+ material is not limited to numerical parameters, data structure
92
+ layouts and accessors, or small macros, inline functions and templates
93
+ (ten or fewer lines in length), you do both of the following:
94
+
95
+ a) Give prominent notice with each copy of the object code that the
96
+ Library is used in it and that the Library and its use are
97
+ covered by this License.
98
+
99
+ b) Accompany the object code with a copy of the GNU GPL and this license
100
+ document.
101
+
102
+ 4. Combined Works.
103
+
104
+ You may convey a Combined Work under terms of your choice that,
105
+ taken together, effectively do not restrict modification of the
106
+ portions of the Library contained in the Combined Work and reverse
107
+ engineering for debugging such modifications, if you also do each of
108
+ the following:
109
+
110
+ a) Give prominent notice with each copy of the Combined Work that
111
+ the Library is used in it and that the Library and its use are
112
+ covered by this License.
113
+
114
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
115
+ document.
116
+
117
+ c) For a Combined Work that displays copyright notices during
118
+ execution, include the copyright notice for the Library among
119
+ these notices, as well as a reference directing the user to the
120
+ copies of the GNU GPL and this license document.
121
+
122
+ d) Do one of the following:
123
+
124
+ 0) Convey the Minimal Corresponding Source under the terms of this
125
+ License, and the Corresponding Application Code in a form
126
+ suitable for, and under terms that permit, the user to
127
+ recombine or relink the Application with a modified version of
128
+ the Linked Version to produce a modified Combined Work, in the
129
+ manner specified by section 6 of the GNU GPL for conveying
130
+ Corresponding Source.
131
+
132
+ 1) Use a suitable shared library mechanism for linking with the
133
+ Library. A suitable mechanism is one that (a) uses at run time
134
+ a copy of the Library already present on the user's computer
135
+ system, and (b) will operate properly with a modified version
136
+ of the Library that is interface-compatible with the Linked
137
+ Version.
138
+
139
+ e) Provide Installation Information, but only if you would otherwise
140
+ be required to provide such information under section 6 of the
141
+ GNU GPL, and only to the extent that such information is
142
+ necessary to install and execute a modified version of the
143
+ Combined Work produced by recombining or relinking the
144
+ Application with a modified version of the Linked Version. (If
145
+ you use option 4d0, the Installation Information must accompany
146
+ the Minimal Corresponding Source and Corresponding Application
147
+ Code. If you use option 4d1, you must provide the Installation
148
+ Information in the manner specified by section 6 of the GNU GPL
149
+ for conveying Corresponding Source.)
150
+
151
+ 5. Combined Libraries.
152
+
153
+ You may place library facilities that are a work based on the
154
+ Library side by side in a single library together with other library
155
+ facilities that are not Applications and are not covered by this
156
+ License, and convey such a combined library under terms of your
157
+ choice, if you do both of the following:
158
+
159
+ a) Accompany the combined library with a copy of the same work based
160
+ on the Library, uncombined with any other library facilities,
161
+ conveyed under the terms of this License.
162
+
163
+ b) Give prominent notice with the combined library that part of it
164
+ is a work based on the Library, and explaining where to find the
165
+ accompanying uncombined form of the same work.
166
+
167
+ 6. Revised Versions of the GNU Lesser General Public License.
168
+
169
+ The Free Software Foundation may publish revised and/or new versions
170
+ of the GNU Lesser General Public License from time to time. Such new
171
+ versions will be similar in spirit to the present version, but may
172
+ differ in detail to address new problems or concerns.
173
+
174
+ Each version is given a distinguishing version number. If the
175
+ Library as you received it specifies that a certain numbered version
176
+ of the GNU Lesser General Public License "or any later version"
177
+ applies to it, you have the option of following the terms and
178
+ conditions either of that published version or of any later version
179
+ published by the Free Software Foundation. If the Library as you
180
+ received it does not specify a version number of the GNU Lesser
181
+ General Public License, you may choose any version of the GNU Lesser
182
+ General Public License ever published by the Free Software Foundation.
183
+
184
+ If the Library as you received it specifies that a proxy can decide
185
+ whether future versions of the GNU Lesser General Public License shall
186
+ apply, that proxy's public statement of acceptance of any version is
187
+ permanent authorization for you to choose that version for the
188
+ Library.
data/README.rdoc ADDED
@@ -0,0 +1,219 @@
1
+ == MONGOID
2
+
3
+ This is a Mongoid port of Turkee gem, for the original one and credits see {aantix/turkee}[https://github.com/aantix/turkee]
4
+
5
+ == MAINTENANCE
6
+
7
+ To be honest, this gem won't get much maintenance.
8
+
9
+ If Turkee adds new features, please fork this repository and:
10
+
11
+ 1) Add Turkee as a remote:
12
+
13
+ git remote add turkee git@github.com:aantix/turkee.git
14
+
15
+ 2) Pull it
16
+
17
+ git pull turkee master
18
+
19
+ 3) Run tests
20
+
21
+ bundle exec rspec
22
+
23
+ Any new features would then appear, with new tests failing probably: that's where you comme into scene ;)
24
+
25
+ == RAILS 4 SUPPORT
26
+ Rails 4 support is currently being tested. To try it out, just use Turkee's master branch. In your Gemfile, add the following :
27
+ gem 'turkee', :git => 'https://github.com/aantix/turkee.git', branch: 'master'
28
+
29
+ == WHAT TURKEE CAN DO
30
+
31
+ * Perform user feedback studies easily.
32
+ http://i.imgur.com/wIU40BAl.png
33
+
34
+ * Seamlessly convert your Rails forms for use on Mechanical Turk.
35
+ * Easily import the data posted by the Mechanical Turk workers back into your data models.
36
+
37
+ External forms are created using a simple form helper. HITs are created by issuing a rake command. Retrieving submitted response data and importing that data into your model(s) requires just one more rake command.
38
+
39
+
40
+ == INSTALL/UPGRADE
41
+
42
+ Add turkee to your Gemfile as a gem dependency, then do a 'bundle install':
43
+
44
+ gem 'turkee'
45
+
46
+
47
+ If you're upgrading Turkee (1.1.1 and prior) or installing for the first time, run:
48
+
49
+ rails g turkee --skip
50
+
51
+ (the skip flag will ensure that you don't overwrite prior Turkee initializers and migrations.)
52
+
53
+ This will copy the needed migrations and config/initializer into your application directory.
54
+
55
+ To access the Turkee rake tasks, add the following to your application's Rakefile:
56
+ require 'tasks/turkee'
57
+
58
+ If you haven't created a Mechanical Turk account, surf on over to {Amazon's Web Services}[http://aws.amazon.com/] and create an AWS account.
59
+
60
+ Once you have your account created, you can access your AWS access key and secret access key from {here.}[https://aws-portal.amazon.com/gp/aws/developer/account/index.html?action=access-key]
61
+
62
+
63
+ == CONFIGURATION
64
+
65
+ Inside the config/initializers directory, you'll see the file turkee.rb. Edit the file with your Amazon credentials.
66
+
67
+ AWSACCESSKEYID = 'XXXXXXXXXXXXXXXXXX'
68
+ AWSSECRETACCESSKEY = 'YYYYYYYYYYYYYYYYYYYYYYYYYYYY'
69
+
70
+ RTurk::logger.level = Logger::DEBUG
71
+ RTurk.setup(AWSACCESSKEYID, AWSSECRETACCESSKEY, :sandbox => (Rails.env == 'production' ? false : true))
72
+
73
+ Run the migrations :
74
+
75
+ rake db:migrate
76
+
77
+ == BASIC FORMS
78
+
79
+ 1) You should disable form controls if the Turker hasn't accepted the HIT. You can determine this from your controller:
80
+ class SurveysController < ApplicationController
81
+
82
+ def new
83
+ @disabled = Turkee::TurkeeFormHelper::disable_form_fields?(params)
84
+
85
+ # If you wanted to find the associated turkee_task, you could do a find by hitId
86
+ # Not necessary in a simple example.
87
+ # @turkee_task = Turkee::TurkeeTask.find_by_hit_id(params[:hitId]).id rescue nil
88
+
89
+ ...
90
+ @survey = Survey.new
91
+ end
92
+
93
+ 2) Change your forms to use the form helper.
94
+
95
+ <%= turkee_form_for(@survey, params) do |f| %>
96
+ <p><%= f.text_area :value, :disabled => @disabled %></p>
97
+ <p><%= f.submit 'Create', :disabled => @disabled %></p>
98
+ <% end %>
99
+
100
+ Using the turkee_form_for helper will post the form to the Mechanical Turk sandbox if you're in development/test mode, otherwise it will be posted to Mechanical Turk production/live site.
101
+
102
+
103
+ 3) Run the following rake task to post to Mechanical Turk :
104
+ # Host URL of your application
105
+ # Title of your HIT
106
+ # Description of your HIT
107
+ # Model name of your task form (the New action should be implemented)
108
+ # Number of assignments for HIT
109
+ # The reward for a successful completion
110
+ # The lifetime of the HIT in days (e.g. 5 days)
111
+
112
+ rake turkee:post_hit[<Host>, <Title>, <Description>, <Model>, <Number of Assignments>, <Reward>, <Lifetime>]
113
+
114
+ e.g. :
115
+ rake turkee:post_hit["https://www.yourapp.com","Please complete our survey","Tell us your favorite color.","Survey",100,0.05,5,1]
116
+ ** Do not put spaces before or after commas for the rake task parameters
117
+
118
+ This will insert a row for the requested HIT into the turkee_tasks table. The turkee_tasks entry stores (along with the other properties) the HIT URL (e.g. http://workersandbox.mturk.com/mturk/preview?groupId=1HGHJJGHQSJB7WMWJ33YS8WM169XNIL ) and HIT ID (e.g. 1J1EXO8SUQ3URTTUYGHJ7EKUT11 ). These values are returned from Mechanical Turk when the HIT request is posted.
119
+
120
+ When a Turk worker views your HIT, the HIT will display your form within an iFrame. With the above example, Mechanical Turk will open an iFrame for the HIT assignment displaying the form http://www.yourapp.com/surveys/new
121
+
122
+ == USER FEEDBACK STUDIES
123
+
124
+ 1) Add the following method call to your app/views/layouts/application.html.haml file :
125
+
126
+ <%= turkee_study %>
127
+
128
+ 2) Call the create_study rake task :
129
+
130
+ rake turkee:create_study[<Application Page URL>, <HIT Title>, <HIT Description>, <Number of Assignments>, <Reward>, <Lifetime of HIT>]
131
+
132
+ # 30 Assignments at a quarter each requesting feedback on my site
133
+ RAILS_ENV=production rake turkee:create_study['https://yoursite.com/page-to-be-test',"Can you help me test my website?","Give feedback below on what you didn't like about my site. Click submit below when you're finished.", 30,0.25, 20]
134
+
135
+ 3) The Turker will see a feedback form overlayed over your website. Within this textarea, they can provide feedback.
136
+
137
+ Screenshot:
138
+
139
+ http://i.imgur.com/wIU40BA.png
140
+
141
+ == RETRIEVING RESULTS
142
+
143
+ 1) Run the rake task that retrieves the values from Mechanical Turk and stores the user entered values into your model.
144
+ rake turkee:get_all_results
145
+
146
+ Rerun this task periodically to retrieve newly entered form values. You can setup this task as a cronjob to automate this.
147
+
148
+ crontab -e
149
+
150
+ # E.g. run every five minutes
151
+ */5 * * * * cd /var/www/your/turk/application && rake turkee:get_all_results
152
+
153
+ Or you can directly call :
154
+
155
+ Turkee::TurkeeTask.process_hits
156
+
157
+
158
+ == DATA RETRIEVAL; THE INS AND OUTS
159
+
160
+ 1) When a response is retrieved from Mechanical Turk, Turkee attempts to create a data row for the model specified using the corresponding retrieved data. If the row cannot be created (input failed model validations), the assignment is rejected.
161
+ As for Mechanical Turk approval, if the row is created and you haven't specified your own custom approve? method for the model, the assignment will automatically be approved. If you'd like to add your own custom approval method, add the approve? instance method to your model. E.g. :
162
+ class Survey < ActiveRecord::Base
163
+ def approve?
164
+ (!response.blank? && !comment.blank?)
165
+ end
166
+ end
167
+
168
+ 2) When all specified assignments for a HIT have been completed, Turkee will attempt to call the optional hit_complete class method for the model. This can be used for any cleanup logic. E.g. :
169
+ class Survey < ActiveRecord::Base
170
+ def self.hit_complete(turkee_task)
171
+ #do something
172
+ end
173
+ end
174
+
175
+ 3) If all of specified assignments for a HIT have not been completed by the end of the HITs lifetime, Turkee will attempt to call the optional hit_expired class method for the model. This can be used for any cleanup logic. E.g. :
176
+ class Survey < ActiveRecord::Base
177
+ def self.hit_expired(turkee_task)
178
+ #do something
179
+ end
180
+ end
181
+
182
+
183
+ == Advanced Usage
184
+
185
+ 1) You can use the params hash to pass object IDs to your forms. E.g. if you wanted to setup a form of questions about a given URL (let's call the model UrlSurvey), your code would look something like :
186
+
187
+ URL.all do |url|
188
+ Turkee::TurkeeTask.create_hit(host, "Enter the address displayed for the given url.",
189
+ hit_description, UrlSurvey, num_assignments, reward,
190
+ lifetime, duration, {}, {:url_id => url.id}, {})
191
+ end
192
+
193
+ Then when displaying your form, you can find the URL object via the params[:url_id] value.
194
+
195
+ 2) You can pass in qualifications to allow only certain Turkers to work on your HIT.
196
+
197
+ E.g. qualifications = {:approval_rate => {:gt => 70}, :country => {:eql => 'US'}}
198
+
199
+ Turkee::TurkeeTask.create_hit(host, hit_title, hit_description, UrlSurvey, num_assignments, reward, lifetime, duration, qualifications, {}, {})
200
+
201
+ * The rake task does not support the passing of qualifications.
202
+
203
+ 3) Turkee assumes that the form url will be the new action for the class passed to create_hit. If you have a more complex form url which would be the case for nested resources, you can use the :form_url
204
+ option to designate a form url different from the default.
205
+
206
+ form_url = Rails.application.routes.url_helpers.send("new_user_survey_path",@my_survey)
207
+
208
+ Turkee::TurkeeTask.create_hit(host, hit_title, hit_description, :Survey, num_assignments, reward,
209
+ lifetime, duration, {}, {}, {:form_url => form_url})
210
+
211
+
212
+ == Gotchas
213
+
214
+ 1) The application that hosts your external forms preferably should have an https interface (you're going to have to buy an SSL certificate). If the forms are hosted on an unsecured host (http), because Mechanical Turk defaults to https, you're going to receive the ugly popup from IE regarding "mixed content" (http://msdn.microsoft.com/en-us/library/ee264315%28v=vs.85%29.aspx).
215
+
216
+
217
+ == Copyright
218
+
219
+ Copyright (c) 2010 - 2012 Jim Jones. See LICENSE for details.