Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial changes for Rails 3 compatibility. Rails 2 dropped.

  • Loading branch information...
commit fb6fc171c841ae9d1eb83841d1f513e2f0dc493a 1 parent 4753460
@aantix aantix authored
View
3  Gemfile
@@ -0,0 +1,3 @@
+source :rubygems
+
+gemspec
View
37 Gemfile.lock
@@ -0,0 +1,37 @@
+PATH
+ remote: .
+ specs:
+ turkee (1.1.0)
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ fakeweb (1.3.0)
+ git (1.2.5)
+ jeweler (1.6.0)
+ bundler (~> 1.0.0)
+ git (>= 1.2.5)
+ rake
+ lockfile (1.4.3)
+ mime-types (1.16)
+ nokogiri (1.4.4)
+ rake (0.8.7)
+ rest-client (1.6.1)
+ mime-types (>= 1.16)
+ rspec (1.3.2)
+ rturk (2.3.6)
+ fakeweb
+ jeweler
+ nokogiri
+ nokogiri (>= 1.4.1)
+ rest-client
+ rest-client (>= 1.4.0)
+ rspec (~> 1.3.1)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ lockfile (>= 1.4.3)
+ rturk (>= 2.3.0)
+ turkee!
View
50 README.rdoc
@@ -4,41 +4,47 @@ Seamlessly convert your Rails forms for use on Mechanical Turk. Then, easily im
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.
-== Examples
-If you'd like to jump straight into code, check out the {Turkee Iterator}[https://github.com/aantix/Turkee-Iterator] example.
+== Rails 2
-== Dependencies
+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.
-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:
- TURKTASK_AWSACCESSKEYID = 'XXXXXXXXXXXXXXXXXX'
- TURKTASK_AWSACCESSKEY = 'YYYYYYYYYYYYYYYYYYYYYYYYYYYY'
+== Mechanical Turk API Changes
- RTurk::logger.level = Logger::DEBUG
- RTurk.setup(AWSACCESSKEYID, AWSACCESSKEY, :sandbox => (Rails.env == 'production' ? false : true))
-
-== Install
-
-Install the Turkee gem:
+Mechanical Turk is now requiring that the hitId, workerId, and the turkSubmitTo parameters be passed in along with the assignmentId and form parameters.
- sudo gem install turkee
+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.
-For Rails 2, add it to your environment.rb configuration as a gem dependency:
- config.gem 'turkee'
+== Install
-For Rails 3, add it to your Gemfile as a gem dependency, then do a 'bundle install':
+Add turkee to your Gemfile as a gem dependency, then do a 'bundle install':
gem 'turkee'
To access the Turkee rake tasks, add the following to your application's Rakefile:
require 'tasks/turkee'
-Run the turkee generator from your application directory to copy the needed migrations into your application:
+Run the turkee generator from your application directory to copy the needed migrations and config/initializer into your application:
+
+ rails g turkee
+
+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.
+
+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]
+
+
+== Configuration
+
+Inside the config/initializers directory, you'll see the file turkee.rb. Edit that file with your Amazon credenti.
+
+ AWSACCESSKEYID = 'XXXXXXXXXXXXXXXXXX'
+ AWSSECRETACCESSKEY = 'YYYYYYYYYYYYYYYYYYYYYYYYYYYY'
+
+ RTurk::logger.level = Logger::DEBUG
+ RTurk.setup(AWSACCESSKEYID, AWSSECRETACCESSKEY, :sandbox => (Rails.env == 'production' ? false : true))
- ./script/generate turkee # Rails 2
- rails g turkee # Rails 3
== Use
@@ -50,8 +56,7 @@ Run the turkee generator from your application directory to copy the needed migr
class SurveysController < ApplicationController
def new
- @assignment_id = params[:assignmentId]
- @disabled = Turkee::TurkeeFormHelper::disable_form_fields?(@assignment_id)
+ @disabled = Turkee::TurkeeFormHelper::disable_form_fields?(params)
# If you wanted to find the associated turkee_task, you could do a find by hitId
# Not necessary in a simple example.
@@ -62,7 +67,8 @@ Run the turkee generator from your application directory to copy the needed migr
end
3) Change your forms to use the form helper.
- <% turkee_form_for(@survey, @assignment_id) do |f| %>
+
+ <% turkee_form_for(@survey, params) do |f| %>
<p><%= f.text_area :value, :disabled => @disabled %></p>
<p><%= f.submit 'Create', :disabled => @disabled %></p>
<% end %>
View
7 Rakefile
@@ -28,11 +28,12 @@ begin
gem.email = "jjones@aantix.com"
gem.homepage = "http://github.com/aantix/turkee"
gem.authors = ["Jim Jones"]
- gem.add_development_dependency "rturk", ">= 2.3.0"
- gem.add_development_dependency "lockfile", ">= 1.4.3"
+ gem.add_dependency(%q<rails>, [">= 3.0.7"])
+ gem.add_dependency(%q<rturk>, [">= 2.3.0"])
+ gem.add_dependency(%q<lockfile>, [">= 1.4.3"])
gem.post_install_message = INSTALL_MESSAGE
gem.require_path = 'lib'
- gem.files = %w(MIT-LICENSE README.textile Rakefile init.rb) + Dir.glob("{lib,spec}/**/*")
+ gem.files = %w(MIT-LICENSE README.textile Gemfile Rakefile init.rb) + Dir.glob("{lib,spec}/**/*")
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
end
View
2  VERSION
@@ -1 +1 @@
-1.0.4
+1.1.0
View
7 lib/generators/turkee/templates/turkee.rb
@@ -1,5 +1,8 @@
+# Go to this page https://aws-portal.amazon.com/gp/aws/developer/account/index.html?action=access-key
+# to retrieve your AWS/Mechanical Turk access keys.
+
AWSACCESSKEYID = 'XXXXXXXXXXXXXXXXXX'
-AWSACCESSKEY = 'YYYYYYYYYYYYYYYYYYYYYYYYYYYY'
+AWSSECRETACCESSKEY = 'YYYYYYYYYYYYYYYYYYYYYYYYYYYY'
RTurk::logger.level = Logger::DEBUG
-RTurk.setup(AWSACCESSKEYID, AWSACCESSKEY, :sandbox => (Rails.env == 'production' ? false : true))
+RTurk.setup(AWSACCESSKEYID, AWSSECRETACCESSKEY, :sandbox => (Rails.env == 'production' ? false : true))
View
4 lib/tasks/turkee.rb
@@ -1,8 +1,8 @@
require 'rake'
require 'turkee'
-include ActionController::PolymorphicRoutes
-include ActionView::Helpers::UrlHelper
+#include ActionController::PolymorphicRoutes
+#include ActionView::Helpers::UrlHelper
# clear && rake turkee:post_hit['Test title','Test desc','Joke',3,0.05,1] --trace
View
57 lib/turkee.rb
@@ -159,9 +159,11 @@ def self.find_model(param_hash)
end
def self.form_url(host, typ)
- @app ||= ActionController::Integration::Session.new
+ @app ||= ActionController::Integration::Session.new(Rails.application)
#@app.send("new_#{typ.to_s.underscore}_url(:host => '#{host}')") # Not sure why app does respond when :host is passed...
- (host + @app.send("new_#{typ.to_s.underscore}_path")) # Workaround for now. :(
+ url = (host + @app.send("new_#{typ.to_s.underscore}_path")) # Workaround for now. :(
+ puts "form_url = #{url}"
+ url
end
end
@@ -169,35 +171,42 @@ def self.form_url(host, typ)
module TurkeeFormHelper
- # Rails 2.3.8 form_for implementation with the exception of the form action url
+ # Rails 3.0.7 form_for implementation with the exception of the form action url
# will always point to the Amazon externalSubmit interface and you must pass in the
# assignment_id parameter.
- def turkee_form_for(record_or_name_or_array, assignment_id, *args, &proc)
+ def turkee_form_for(record_or_name_or_array, params, *args, &proc)
raise ArgumentError, "Missing block" unless block_given?
+ 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)
options = args.extract_options!
case record_or_name_or_array
- when String, Symbol
- object_name = record_or_name_or_array
- when Array
- object = record_or_name_or_array.last
- object_name = ActionController::RecordIdentifier.singular_class_name(object)
- apply_form_for_options!(record_or_name_or_array, options)
- args.unshift object
- else
- object = record_or_name_or_array
- object_name = ActionController::RecordIdentifier.singular_class_name(object)
- apply_form_for_options!([object], options)
- args.unshift object
+ when String, Symbol
+ ActiveSupport::Deprecation.warn("Using form_for(:name, @resource) is deprecated. Please use form_for(@resource, :as => :name) instead.", caller) unless args.empty?
+ object_name = record_or_name_or_array
+ when Array
+ object = record_or_name_or_array.last
+ object_name = options[:as] || ActiveModel::Naming.singular(object)
+ apply_form_for_options!(record_or_name_or_array, options)
+ args.unshift object
+ else
+ object = record_or_name_or_array
+ object_name = options[:as] || ActiveModel::Naming.singular(object)
+ apply_form_for_options!([object], options)
+ args.unshift object
end
- # concat(form_tag(options.delete(:url) || {}, options.delete(:html) || {}))
- concat(form_tag(mturk_url, options.delete(:html) || {}))
- concat("<input type=\"hidden\" id=\"assignmentId\" name=\"assignmentId\" value=\"#{assignment_id}\"/>")
- fields_for(object_name, *(args << options), &proc)
- concat('</form>'.html_safe)
- self
+ (options[:html] ||= {})[:remote] = true if options.delete(:remote)
+
+ output = form_tag(mturk_url, options.delete(:html) || {})
+ params.each do |k,v|
+ unless k =~ /^action$/i || k =~ /^controller$/i
+ output.safe_concat("<input type=\"hidden\" id=\"#{k}\" name=\"#{CGI.escape(k)}\" value=\"#{CGI.escape(v)}\"/>")
+ end
+ end
+ options[:disabled] = true if params[:assignmentId].nil? || Turkee::TurkeeFormHelper::disable_form_fields?(params[:assignmentId])
+ output << fields_for(object_name, *(args << options), &proc)
+ output.safe_concat('</form>')
end
# Returns the external Mechanical Turk url used to post form data based on whether RTurk is cofigured
@@ -207,10 +216,10 @@ def mturk_url
end
# Returns whether the form fields should be disabled or not (based on the assignment_id)
- def self.disable_form_fields?(assignment_id)
+ def self.disable_form_fields?(assignment)
+ assignment_id = assignment.is_a?(Hash) ? assignment[:assignmentId] : assignment
(assignment_id.nil? || assignment_id == 'ASSIGNMENT_ID_NOT_AVAILABLE')
end
-
end
end
View
31 turkee.gemspec
@@ -5,19 +5,20 @@
Gem::Specification.new do |s|
s.name = %q{turkee}
- s.version = "1.0.4"
+ s.version = "1.1.0"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
- s.authors = ["Jeremy Clemenson"]
- s.date = %q{2011-04-03}
+ s.authors = ["Jim Jones"]
+ s.date = %q{2011-05-03}
s.description = %q{Turkee will help you to create your Rails forms, post the HITs, and retrieve the user entered values from Mechanical Turk.}
- s.email = %q{jclemenson@gmail.com}
+ s.email = %q{jjones@aantix.com}
s.extra_rdoc_files = [
"LICENSE",
"README.rdoc"
]
s.files = [
"Rakefile",
+ "lib/generators/turkee/templates/turkee.rb",
"lib/generators/turkee/templates/turkee_imported_assignments.rb.erb",
"lib/generators/turkee/templates/turkee_migration.rb.erb",
"lib/generators/turkee/turkee_generator.rb",
@@ -27,7 +28,7 @@ Gem::Specification.new do |s|
"spec/spec_helper.rb",
"spec/turkee_spec.rb"
]
- s.homepage = %q{http://github.com/jclemenson/turkee}
+ s.homepage = %q{http://github.com/aantix/turkee}
s.post_install_message = %q{
========================================================================
Turkee Installation Complete.
@@ -44,27 +45,15 @@ Gem::Specification.new do |s|
-- Gobble, gobble.
}
s.require_paths = ["lib"]
- s.rubygems_version = %q{1.3.6}
+ s.rubygems_version = %q{1.3.7}
s.summary = %q{Turkee makes dealing with Amazon's Mechnical Turk a breeze.}
s.test_files = [
"spec/spec_helper.rb",
"spec/turkee_spec.rb"
]
- if s.respond_to? :specification_version then
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
- s.specification_version = 3
-
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
- s.add_development_dependency(%q<rturk>, [">= 2.3.0"])
- s.add_development_dependency(%q<lockfile>, [">= 1.4.3"])
- else
- s.add_dependency(%q<rturk>, [">= 2.3.0"])
- s.add_dependency(%q<lockfile>, [">= 1.4.3"])
- end
- else
- s.add_dependency(%q<rturk>, [">= 2.3.0"])
- s.add_dependency(%q<lockfile>, [">= 1.4.3"])
- end
+ s.add_dependency(%q<rails>, ["~> 3.0.7"])
+ s.add_dependency(%q<rturk>, [">= 2.3.0"])
+ s.add_dependency(%q<lockfile>, [">= 1.4.3"])
end
Please sign in to comment.
Something went wrong with that request. Please try again.