turkee 1.0.4 → 1.1.0
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.
- data/Gemfile +3 -0
- data/README.rdoc +28 -22
- data/Rakefile +4 -3
- data/lib/generators/turkee/templates/turkee.rb +8 -0
- data/{generators → lib/generators}/turkee/templates/turkee_imported_assignments.rb.erb +0 -0
- data/{generators → lib/generators}/turkee/templates/turkee_migration.rb.erb +0 -0
- data/lib/generators/turkee/turkee_generator.rb +29 -0
- data/lib/tasks/turkee.rb +2 -2
- data/lib/turkee.rb +34 -25
- metadata +43 -43
- data/generators/turkee/turkee_generator.rb +0 -15
data/Gemfile
ADDED
data/README.rdoc
CHANGED
@@ -4,41 +4,47 @@ Seamlessly convert your Rails forms for use on Mechanical Turk. Then, easily im
|
|
4
4
|
|
5
5
|
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.
|
6
6
|
|
7
|
-
== Examples
|
8
7
|
|
9
|
-
|
8
|
+
== Rails 2
|
10
9
|
|
11
|
-
|
10
|
+
I'm no longer supporting Rails 2.x. If you have Rails 2 changes, message me and we can look to maintaing a Rails 2.x branch.
|
12
11
|
|
13
|
-
Make sure that the rturk gem is installed configured with your Amazon Turk credentials. I created a config/initializers/turk_task_config.rb file with the following in it:
|
14
12
|
|
15
|
-
|
16
|
-
TURKTASK_AWSACCESSKEY = 'YYYYYYYYYYYYYYYYYYYYYYYYYYYY'
|
13
|
+
== Mechanical Turk API Changes
|
17
14
|
|
18
|
-
|
19
|
-
RTurk.setup(AWSACCESSKEYID, AWSACCESSKEY, :sandbox => (Rails.env == 'production' ? false : true))
|
20
|
-
|
21
|
-
== Install
|
22
|
-
|
23
|
-
Install the Turkee gem:
|
15
|
+
Mechanical Turk is now requiring that the hitId, workerId, and the turkSubmitTo parameters be passed in along with the assignmentId and form parameters.
|
24
16
|
|
25
|
-
|
17
|
+
What does this mean for you? Not much besides the fact that now when you construct your forms using turkee_form_for, you'll be passing in your entire params hash instead of just the assignment_id. The code snippet below reflect this change.
|
26
18
|
|
27
|
-
For Rails 2, add it to your environment.rb configuration as a gem dependency:
|
28
19
|
|
29
|
-
|
20
|
+
== Install
|
30
21
|
|
31
|
-
|
22
|
+
Add turkee to your Gemfile as a gem dependency, then do a 'bundle install':
|
32
23
|
|
33
24
|
gem 'turkee'
|
34
25
|
|
35
26
|
To access the Turkee rake tasks, add the following to your application's Rakefile:
|
36
27
|
require 'tasks/turkee'
|
37
28
|
|
38
|
-
Run the turkee generator from your application directory to copy the needed migrations into your application:
|
29
|
+
Run the turkee generator from your application directory to copy the needed migrations and config/initializer into your application:
|
30
|
+
|
31
|
+
rails g turkee
|
32
|
+
|
33
|
+
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.
|
34
|
+
|
35
|
+
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]
|
36
|
+
|
37
|
+
|
38
|
+
== Configuration
|
39
|
+
|
40
|
+
Inside the config/initializers directory, you'll see the file turkee.rb. Edit that file with your Amazon credenti.
|
41
|
+
|
42
|
+
AWSACCESSKEYID = 'XXXXXXXXXXXXXXXXXX'
|
43
|
+
AWSSECRETACCESSKEY = 'YYYYYYYYYYYYYYYYYYYYYYYYYYYY'
|
44
|
+
|
45
|
+
RTurk::logger.level = Logger::DEBUG
|
46
|
+
RTurk.setup(AWSACCESSKEYID, AWSSECRETACCESSKEY, :sandbox => (Rails.env == 'production' ? false : true))
|
39
47
|
|
40
|
-
./script/generate turkee # Rails 2
|
41
|
-
rails g turkee # Rails 3
|
42
48
|
|
43
49
|
== Use
|
44
50
|
|
@@ -50,8 +56,7 @@ Run the turkee generator from your application directory to copy the needed migr
|
|
50
56
|
class SurveysController < ApplicationController
|
51
57
|
|
52
58
|
def new
|
53
|
-
@
|
54
|
-
@disabled = Turkee::TurkeeFormHelper::disable_form_fields?(@assignment_id)
|
59
|
+
@disabled = Turkee::TurkeeFormHelper::disable_form_fields?(params)
|
55
60
|
|
56
61
|
# If you wanted to find the associated turkee_task, you could do a find by hitId
|
57
62
|
# Not necessary in a simple example.
|
@@ -62,7 +67,8 @@ Run the turkee generator from your application directory to copy the needed migr
|
|
62
67
|
end
|
63
68
|
|
64
69
|
3) Change your forms to use the form helper.
|
65
|
-
|
70
|
+
|
71
|
+
<% turkee_form_for(@survey, params) do |f| %>
|
66
72
|
<p><%= f.text_area :value, :disabled => @disabled %></p>
|
67
73
|
<p><%= f.submit 'Create', :disabled => @disabled %></p>
|
68
74
|
<% end %>
|
data/Rakefile
CHANGED
@@ -28,11 +28,12 @@ begin
|
|
28
28
|
gem.email = "jjones@aantix.com"
|
29
29
|
gem.homepage = "http://github.com/aantix/turkee"
|
30
30
|
gem.authors = ["Jim Jones"]
|
31
|
-
gem.
|
32
|
-
gem.
|
31
|
+
gem.add_dependency(%q<rails>, [">= 3.0.7"])
|
32
|
+
gem.add_dependency(%q<rturk>, [">= 2.3.0"])
|
33
|
+
gem.add_dependency(%q<lockfile>, [">= 1.4.3"])
|
33
34
|
gem.post_install_message = INSTALL_MESSAGE
|
34
35
|
gem.require_path = 'lib'
|
35
|
-
gem.files = %w(MIT-LICENSE README.textile Rakefile init.rb) + Dir.glob("{
|
36
|
+
gem.files = %w(MIT-LICENSE README.textile Gemfile Rakefile init.rb) + Dir.glob("{lib,spec}/**/*")
|
36
37
|
|
37
38
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
38
39
|
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
# Go to this page https://aws-portal.amazon.com/gp/aws/developer/account/index.html?action=access-key
|
2
|
+
# to retrieve your AWS/Mechanical Turk access keys.
|
3
|
+
|
4
|
+
AWSACCESSKEYID = 'XXXXXXXXXXXXXXXXXX'
|
5
|
+
AWSSECRETACCESSKEY = 'YYYYYYYYYYYYYYYYYYYYYYYYYYYY'
|
6
|
+
|
7
|
+
RTurk::logger.level = Logger::DEBUG
|
8
|
+
RTurk.setup(AWSACCESSKEYID, AWSSECRETACCESSKEY, :sandbox => (Rails.env == 'production' ? false : true))
|
File without changes
|
File without changes
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/migration'
|
3
|
+
|
4
|
+
class TurkeeGenerator < Rails::Generators::Base
|
5
|
+
include Rails::Generators::Migration
|
6
|
+
|
7
|
+
# Implement the required interface for Rails::Generators::Migration.
|
8
|
+
# taken from http://github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb
|
9
|
+
def self.next_migration_number(dirname)
|
10
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
11
|
+
end
|
12
|
+
|
13
|
+
source_root File.expand_path("../templates", __FILE__)
|
14
|
+
|
15
|
+
desc "Creates initializer and migrations."
|
16
|
+
|
17
|
+
def create_initializer
|
18
|
+
template "turkee.rb", "config/initializers/turkee.rb"
|
19
|
+
end
|
20
|
+
|
21
|
+
def create_migrations
|
22
|
+
migration_template "turkee_migration.rb.erb", "db/migrate/create_turkee_tasks.rb"
|
23
|
+
|
24
|
+
# Need this sleep so that we don't get the same migration timestamp for both migrations
|
25
|
+
sleep 1
|
26
|
+
|
27
|
+
migration_template "turkee_imported_assignments.rb.erb", "db/migrate/create_turkee_imported_assignments.rb"
|
28
|
+
end
|
29
|
+
end
|
data/lib/tasks/turkee.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'rake'
|
2
2
|
require 'turkee'
|
3
3
|
|
4
|
-
include ActionController::PolymorphicRoutes
|
5
|
-
include ActionView::Helpers::UrlHelper
|
4
|
+
#include ActionController::PolymorphicRoutes
|
5
|
+
#include ActionView::Helpers::UrlHelper
|
6
6
|
|
7
7
|
# clear && rake turkee:post_hit['Test title','Test desc','Joke',3,0.05,1] --trace
|
8
8
|
|
data/lib/turkee.rb
CHANGED
@@ -17,7 +17,7 @@ module Turkee
|
|
17
17
|
# belongs_to :task, :polymorphic => true
|
18
18
|
HIT_FRAMEHEIGHT = 1000
|
19
19
|
|
20
|
-
|
20
|
+
scope :unprocessed_hits, :conditions => ['complete = ?', false]
|
21
21
|
|
22
22
|
# Use this method to go out and retrieve the data for all of the posted Turk Tasks.
|
23
23
|
# Each specific TurkeeTask object (determined by task_type field) is in charge of
|
@@ -159,9 +159,11 @@ module Turkee
|
|
159
159
|
end
|
160
160
|
|
161
161
|
def self.form_url(host, typ)
|
162
|
-
@app ||= ActionController::Integration::Session.new
|
162
|
+
@app ||= ActionController::Integration::Session.new(Rails.application)
|
163
163
|
#@app.send("new_#{typ.to_s.underscore}_url(:host => '#{host}')") # Not sure why app does respond when :host is passed...
|
164
|
-
(host + @app.send("new_#{typ.to_s.underscore}_path")) # Workaround for now. :(
|
164
|
+
url = (host + @app.send("new_#{typ.to_s.underscore}_path")) # Workaround for now. :(
|
165
|
+
puts "form_url = #{url}"
|
166
|
+
url
|
165
167
|
end
|
166
168
|
|
167
169
|
end
|
@@ -169,35 +171,42 @@ module Turkee
|
|
169
171
|
|
170
172
|
module TurkeeFormHelper
|
171
173
|
|
172
|
-
# Rails
|
174
|
+
# Rails 3.0.7 form_for implementation with the exception of the form action url
|
173
175
|
# will always point to the Amazon externalSubmit interface and you must pass in the
|
174
176
|
# assignment_id parameter.
|
175
|
-
def turkee_form_for(record_or_name_or_array,
|
177
|
+
def turkee_form_for(record_or_name_or_array, params, *args, &proc)
|
176
178
|
raise ArgumentError, "Missing block" unless block_given?
|
179
|
+
raise ArgumentError, "turkee_form_for now requires that you pass in the entire params hash, instead of just the assignmentId value. " unless params.is_a?(Hash)
|
177
180
|
|
178
181
|
options = args.extract_options!
|
179
182
|
|
180
183
|
case record_or_name_or_array
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
184
|
+
when String, Symbol
|
185
|
+
ActiveSupport::Deprecation.warn("Using form_for(:name, @resource) is deprecated. Please use form_for(@resource, :as => :name) instead.", caller) unless args.empty?
|
186
|
+
object_name = record_or_name_or_array
|
187
|
+
when Array
|
188
|
+
object = record_or_name_or_array.last
|
189
|
+
object_name = options[:as] || ActiveModel::Naming.singular(object)
|
190
|
+
apply_form_for_options!(record_or_name_or_array, options)
|
191
|
+
args.unshift object
|
192
|
+
else
|
193
|
+
object = record_or_name_or_array
|
194
|
+
object_name = options[:as] || ActiveModel::Naming.singular(object)
|
195
|
+
apply_form_for_options!([object], options)
|
196
|
+
args.unshift object
|
193
197
|
end
|
194
198
|
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
199
|
+
(options[:html] ||= {})[:remote] = true if options.delete(:remote)
|
200
|
+
|
201
|
+
output = form_tag(mturk_url, options.delete(:html) || {})
|
202
|
+
params.each do |k,v|
|
203
|
+
unless k =~ /^action$/i || k =~ /^controller$/i
|
204
|
+
output.safe_concat("<input type=\"hidden\" id=\"#{k}\" name=\"#{CGI.escape(k)}\" value=\"#{CGI.escape(v)}\"/>")
|
205
|
+
end
|
206
|
+
end
|
207
|
+
options[:disabled] = true if params[:assignmentId].nil? || Turkee::TurkeeFormHelper::disable_form_fields?(params[:assignmentId])
|
208
|
+
output << fields_for(object_name, *(args << options), &proc)
|
209
|
+
output.safe_concat('</form>')
|
201
210
|
end
|
202
211
|
|
203
212
|
# Returns the external Mechanical Turk url used to post form data based on whether RTurk is cofigured
|
@@ -207,10 +216,10 @@ module Turkee
|
|
207
216
|
end
|
208
217
|
|
209
218
|
# Returns whether the form fields should be disabled or not (based on the assignment_id)
|
210
|
-
def self.disable_form_fields?(
|
219
|
+
def self.disable_form_fields?(assignment)
|
220
|
+
assignment_id = assignment.is_a?(Hash) ? assignment[:assignmentId] : assignment
|
211
221
|
(assignment_id.nil? || assignment_id == 'ASSIGNMENT_ID_NOT_AVAILABLE')
|
212
222
|
end
|
213
|
-
|
214
223
|
end
|
215
224
|
|
216
225
|
end
|
metadata
CHANGED
@@ -1,13 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: turkee
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 0
|
9
|
-
- 4
|
10
|
-
version: 1.0.4
|
4
|
+
prerelease:
|
5
|
+
version: 1.1.0
|
11
6
|
platform: ruby
|
12
7
|
authors:
|
13
8
|
- Jim Jones
|
@@ -15,41 +10,52 @@ autorequire:
|
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
12
|
|
18
|
-
date: 2011-
|
19
|
-
default_executable:
|
13
|
+
date: 2011-05-16 00:00:00 Z
|
20
14
|
dependencies:
|
21
15
|
- !ruby/object:Gem::Dependency
|
22
|
-
name:
|
23
|
-
prerelease: false
|
16
|
+
name: turkee
|
24
17
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
18
|
none: false
|
26
19
|
requirements:
|
27
20
|
- - ">="
|
28
21
|
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
- 3
|
33
|
-
- 0
|
34
|
-
version: 2.3.0
|
35
|
-
type: :development
|
22
|
+
version: "0"
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
36
25
|
version_requirements: *id001
|
37
26
|
- !ruby/object:Gem::Dependency
|
38
|
-
name:
|
39
|
-
prerelease: false
|
27
|
+
name: rails
|
40
28
|
requirement: &id002 !ruby/object:Gem::Requirement
|
41
29
|
none: false
|
42
30
|
requirements:
|
43
31
|
- - ">="
|
44
32
|
- !ruby/object:Gem::Version
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
- 4
|
49
|
-
- 3
|
50
|
-
version: 1.4.3
|
51
|
-
type: :development
|
33
|
+
version: 3.0.7
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
52
36
|
version_requirements: *id002
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rturk
|
39
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 2.3.0
|
45
|
+
type: :runtime
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *id003
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: lockfile
|
50
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 1.4.3
|
56
|
+
type: :runtime
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: *id004
|
53
59
|
description: Turkee will help you to create your Rails forms, post the HITs, and retrieve the user entered values from Mechanical Turk.
|
54
60
|
email: jjones@aantix.com
|
55
61
|
executables: []
|
@@ -60,10 +66,12 @@ extra_rdoc_files:
|
|
60
66
|
- LICENSE
|
61
67
|
- README.rdoc
|
62
68
|
files:
|
69
|
+
- Gemfile
|
63
70
|
- Rakefile
|
64
|
-
- generators/turkee/templates/
|
65
|
-
- generators/turkee/templates/
|
66
|
-
- generators/turkee/
|
71
|
+
- lib/generators/turkee/templates/turkee.rb
|
72
|
+
- lib/generators/turkee/templates/turkee_imported_assignments.rb.erb
|
73
|
+
- lib/generators/turkee/templates/turkee_migration.rb.erb
|
74
|
+
- lib/generators/turkee/turkee_generator.rb
|
67
75
|
- lib/tasks/turkee.rb
|
68
76
|
- lib/turkee.rb
|
69
77
|
- spec/spec.opts
|
@@ -71,13 +79,12 @@ files:
|
|
71
79
|
- spec/turkee_spec.rb
|
72
80
|
- LICENSE
|
73
81
|
- README.rdoc
|
74
|
-
has_rdoc: true
|
75
82
|
homepage: http://github.com/aantix/turkee
|
76
83
|
licenses: []
|
77
84
|
|
78
85
|
post_install_message: "\n ========================================================================\n Turkee Installation Complete.\n ------------------------------------------------------------------------\n\n For instructions on gem usage, visit:\n http://github.com/aantix/turkee#readme\n\n ** If you like the Turkee gem, please click the \"watch\" button on the\n Github project page. You'll make me smile and feel appreciated. :)\n http://github.com/aantix/turkee\n\n ========================================================================\n -- Gobble, gobble.\n "
|
79
|
-
rdoc_options:
|
80
|
-
|
86
|
+
rdoc_options: []
|
87
|
+
|
81
88
|
require_paths:
|
82
89
|
- lib
|
83
90
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -85,26 +92,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
85
92
|
requirements:
|
86
93
|
- - ">="
|
87
94
|
- !ruby/object:Gem::Version
|
88
|
-
hash: 3
|
89
|
-
segments:
|
90
|
-
- 0
|
91
95
|
version: "0"
|
92
96
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
97
|
none: false
|
94
98
|
requirements:
|
95
99
|
- - ">="
|
96
100
|
- !ruby/object:Gem::Version
|
97
|
-
hash: 3
|
98
|
-
segments:
|
99
|
-
- 0
|
100
101
|
version: "0"
|
101
102
|
requirements: []
|
102
103
|
|
103
104
|
rubyforge_project:
|
104
|
-
rubygems_version: 1.
|
105
|
+
rubygems_version: 1.8.1
|
105
106
|
signing_key:
|
106
107
|
specification_version: 3
|
107
108
|
summary: Turkee makes dealing with Amazon's Mechnical Turk a breeze.
|
108
|
-
test_files:
|
109
|
-
|
110
|
-
- spec/turkee_spec.rb
|
109
|
+
test_files: []
|
110
|
+
|
@@ -1,15 +0,0 @@
|
|
1
|
-
class TurkeeGenerator < Rails::Generator::Base
|
2
|
-
|
3
|
-
def manifest
|
4
|
-
record do |m|
|
5
|
-
m.migration_template "turkee_migration.rb.erb", File.join('db', 'migrate'), :migration_file_name => 'create_turkee_tasks'
|
6
|
-
m.sleep 1 # Need this sleep so that we don't get the same migration timestamp for both migrations
|
7
|
-
m.migration_template "turkee_imported_assignments.rb.erb", File.join('db', 'migrate'), :migration_file_name => 'create_turkee_imported_assignments'
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
def banner
|
12
|
-
%{Usage: #{$0} #{spec.name}\nCopies needed migrations to project.}
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|