rturk 1.0.5 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitmodules +3 -0
- data/.yardoc +0 -0
- data/README.markdown +49 -29
- data/Rakefile +53 -0
- data/TODO.markdown +3 -0
- data/VERSION +1 -1
- data/examples/blank_slate.rb +21 -4
- data/examples/create_hit.rb +19 -0
- data/examples/newtweet.html +0 -1
- data/examples/review_answer.rb +18 -5
- data/lib/rturk.rb +33 -6
- data/lib/rturk/adapters/answers.rb +38 -0
- data/lib/rturk/adapters/assignment.rb +75 -0
- data/lib/rturk/adapters/hit.rb +97 -0
- data/lib/rturk/builders/qualification_builder.rb +68 -0
- data/lib/rturk/builders/qualifications_builder.rb +43 -0
- data/lib/rturk/builders/question_builder.rb +51 -0
- data/lib/rturk/errors.rb +5 -0
- data/lib/rturk/logger.rb +20 -0
- data/lib/rturk/macros.rb +35 -0
- data/lib/rturk/operation.rb +86 -0
- data/lib/rturk/operations/approve_assignment.rb +28 -0
- data/lib/rturk/operations/create_hit.rb +77 -0
- data/lib/rturk/operations/disable_hit.rb +19 -0
- data/lib/rturk/operations/dispose_hit.rb +19 -0
- data/lib/rturk/operations/force_expire_hit.rb +18 -0
- data/lib/rturk/operations/get_account_balance.rb +15 -0
- data/lib/rturk/operations/get_assignments_for_hit.rb +24 -0
- data/lib/rturk/operations/get_hit.rb +21 -0
- data/lib/rturk/operations/get_reviewable_hits.rb +23 -0
- data/lib/rturk/operations/grant_bonus.rb +26 -0
- data/lib/rturk/operations/reject_assignment.rb +23 -0
- data/lib/rturk/requester.rb +58 -76
- data/lib/rturk/response.rb +58 -0
- data/lib/rturk/responses/create_hit_response.rb +33 -0
- data/lib/rturk/responses/get_account_balance_response.rb +11 -0
- data/lib/rturk/responses/get_assignments_for_hit_response.rb +43 -0
- data/lib/rturk/responses/get_hit_response.rb +80 -0
- data/lib/rturk/responses/get_reviewable_hits_response.rb +33 -0
- data/lib/rturk/utilities.rb +19 -1
- data/lib/rturk/xml_utilities.rb +23 -0
- data/rturk.gemspec +143 -0
- data/spec/adapters/answers_spec.rb +27 -0
- data/spec/adapters/assignment_spec.rb +0 -0
- data/spec/adapters/hit_spec.rb +46 -0
- data/spec/builders/qualification_spec.rb +53 -0
- data/spec/builders/qualifications_spec.rb +30 -0
- data/spec/builders/question_spec.rb +46 -0
- data/spec/fake_responses/approve_assignment.xml +5 -0
- data/spec/fake_responses/create_hit.xml +12 -0
- data/spec/fake_responses/disable_hit.xml +5 -0
- data/spec/fake_responses/dispose_hit.xml +5 -0
- data/spec/fake_responses/force_expire_hit.xml +5 -0
- data/spec/fake_responses/get_account_balance.xml +10 -0
- data/spec/fake_responses/get_assignments.xml +35 -0
- data/spec/fake_responses/get_hit.xml +41 -0
- data/spec/fake_responses/get_reviewable_hits.xml +17 -0
- data/spec/fake_responses/grant_bonus.xml +5 -0
- data/spec/fake_responses/invalid_credentials.xml +12 -0
- data/spec/fake_responses/reject_assignment.xml +5 -0
- data/spec/operations/approve_assignment_spec.rb +27 -0
- data/spec/operations/create_hit_spec.rb +66 -0
- data/spec/operations/disable_hit_spec.rb +26 -0
- data/spec/operations/dispose_hit_spec.rb +26 -0
- data/spec/operations/force_expire_hit_spec.rb +26 -0
- data/spec/operations/get_account_balance_spec.rb +15 -0
- data/spec/operations/get_assignments_spec.rb +26 -0
- data/spec/operations/get_hit_spec.rb +18 -0
- data/spec/operations/get_reviewable_hits_spec.rb +0 -0
- data/spec/operations/grant_bonus_spec.rb +32 -0
- data/spec/operations/reject_assignment_spec.rb +26 -0
- data/spec/requester_spec.rb +7 -18
- data/spec/response_spec.rb +48 -0
- data/spec/rturk_spec.rb +27 -0
- data/spec/spec_helper.rb +28 -3
- data/spec/tmp +2 -0
- data/spec/xml_parse_spec.rb +32 -0
- metadata +94 -34
- data/examples/external_page.rb +0 -33
- data/lib/rturk/answer.rb +0 -20
- data/lib/rturk/custom_operations.rb +0 -80
- data/lib/rturk/external_question_builder.rb +0 -22
- data/spec/answer_spec.rb +0 -24
- data/spec/external_question_spec.rb +0 -27
data/.gitmodules
ADDED
data/.yardoc
ADDED
Binary file
|
data/README.markdown
CHANGED
@@ -11,7 +11,7 @@ You'd be better off with amazon's official library, in all its XML cruftiness.
|
|
11
11
|
|
12
12
|
## Installation
|
13
13
|
|
14
|
-
sudo gem install
|
14
|
+
sudo gem install rturk --source http://gemcutter.org
|
15
15
|
|
16
16
|
## Use
|
17
17
|
|
@@ -21,42 +21,62 @@ Let's say you have a form at "http://myapp.com/turkers/add_tags" where Turkers c
|
|
21
21
|
|
22
22
|
require 'rturk'
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
:QualificationRequirement=>[{
|
32
|
-
# Approval rate of greater than 90%
|
33
|
-
:QualificationTypeId=>"000000000000000000L0",
|
34
|
-
:IntegerValue=>90,
|
35
|
-
:Comparator=>"GreaterThan",
|
36
|
-
:RequiredToPreview=>"false"
|
37
|
-
}]
|
38
|
-
}
|
39
|
-
|
40
|
-
@turk = RTurk::Requester.new(AWSAccessKeyId, AWSAccessKey, :sandbox => true)
|
41
|
-
page = RTurk::ExternalQuestionBuilder.build(
|
42
|
-
"http://myapp.com/turkers/add_tags", :item_id => '1234')
|
24
|
+
RTurk.setup(YourAWSAccessKeyId, YourAWSAccessKey, :sandbox => true)
|
25
|
+
hit = RTurk::Hit.create(:title => "Add some tags to a photo") do |hit|
|
26
|
+
hit.assignments = 2
|
27
|
+
hit.question("http://myapp.com/turkers/add_tags")
|
28
|
+
hit.reward = 0.05
|
29
|
+
hit.qualifications.approval_rate, {:gt => 80}
|
30
|
+
end
|
43
31
|
|
44
|
-
|
45
|
-
|
46
|
-
p @turk.create_hit(props, page)
|
32
|
+
p hit.url #=> 'https://workersandbox.mturk.com:443/mturk/preview?groupId=Q29J3XZQ1ASZH5YNKZDZ'
|
47
33
|
|
48
|
-
### Reviewing HIT's
|
49
|
-
|
50
|
-
|
51
|
-
|
34
|
+
### Reviewing and Approving hits HIT's
|
35
|
+
|
36
|
+
hits = RTurk::Hit.all_reviewable
|
37
|
+
|
38
|
+
puts "#{hits.size} reviewable hits. \n"
|
39
|
+
|
40
|
+
unless hits.empty?
|
41
|
+
puts "Reviewing all assignments"
|
42
|
+
|
43
|
+
hits.each do |hit|
|
44
|
+
hit.assignments.each do |assignment|
|
45
|
+
puts assignment.answers['tags']
|
46
|
+
assignment.approve! if assignment.status == 'Submitted'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
### Wiping all your hits out
|
52
|
+
|
53
|
+
hits = RTurk::Hit.all_reviewable
|
54
|
+
|
55
|
+
puts "#{hits.size} reviewable hits. \n"
|
56
|
+
|
57
|
+
unless hits.empty?
|
58
|
+
puts "Approving all assignments and disposing of each hit!"
|
59
|
+
|
60
|
+
hits.each do |hit|
|
61
|
+
hit.expire!
|
62
|
+
hit.assignments.each do |assignment|
|
63
|
+
assignment.approve!
|
64
|
+
end
|
65
|
+
hit.dispose!
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
### Logging
|
71
|
+
Want to see what's going on - enable logging.
|
52
72
|
|
53
|
-
|
73
|
+
RTurk::Logger.level = Logger::DEBUG
|
54
74
|
|
55
75
|
## Nitty Gritty
|
56
76
|
|
57
77
|
Here's a quick peak at what happens on the Mechanical Turk side.
|
58
78
|
|
59
|
-
A worker takes a look at your hit. The page will contain an iframe with your
|
79
|
+
A worker takes a look at your hit. The page will contain an iframe with your question URL loaded inside of it.
|
60
80
|
|
61
81
|
Amazon will append the AssignmentID parameter to the URL for your own information. In preview mode this will look like
|
62
82
|
http://myapp.com/turkers/add_tags?item_id=1234&AssignmentId=ASSIGNMENT_ID_NOT_AVAILABLE
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'yard'
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'jeweler'
|
7
|
+
Jeweler::Tasks.new do |gem|
|
8
|
+
gem.name = "rturk"
|
9
|
+
gem.summary = %Q{Mechanical Turk API Wrapper}
|
10
|
+
gem.email = "mark@mpercival.com"
|
11
|
+
gem.homepage = "http://github.com/markpercival/rturk"
|
12
|
+
gem.authors = ["Mark Percival"]
|
13
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
14
|
+
end
|
15
|
+
|
16
|
+
rescue LoadError
|
17
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'spec/rake/spectask'
|
21
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
22
|
+
spec.libs << 'lib' << 'spec'
|
23
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
24
|
+
end
|
25
|
+
|
26
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
27
|
+
spec.libs << 'lib' << 'spec'
|
28
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
29
|
+
spec.rcov = true
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
task :default => :spec
|
34
|
+
|
35
|
+
require 'rake/rdoctask'
|
36
|
+
Rake::RDocTask.new do |rdoc|
|
37
|
+
if File.exist?('VERSION.yml')
|
38
|
+
config = YAML.load(File.read('VERSION.yml'))
|
39
|
+
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
40
|
+
else
|
41
|
+
version = ""
|
42
|
+
end
|
43
|
+
|
44
|
+
rdoc.rdoc_dir = 'rdoc'
|
45
|
+
rdoc.title = "rturk-gem #{version}"
|
46
|
+
rdoc.rdoc_files.include('README*')
|
47
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
YARD::Rake::YardocTask.new do |t|
|
52
|
+
t.files = ['lib/**/*.rb', 'lib/**/*.rb']
|
53
|
+
end
|
data/TODO.markdown
ADDED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
2.0.0
|
data/examples/blank_slate.rb
CHANGED
@@ -1,6 +1,23 @@
|
|
1
|
+
$: << File.join(File.dirname(__FILE__), '..', 'lib')
|
2
|
+
require 'rubygems'
|
1
3
|
require '../lib/rturk'
|
2
|
-
root = File.expand_path(File.dirname(__FILE__))
|
3
|
-
aws = YAML.load(File.open(File.join(root, 'mturk.yml')))
|
4
|
-
@turk = RTurk::Requester.new(aws['AWSAccessKeyId'], aws['AWSAccessKey'], :sandbox => true)
|
5
4
|
|
6
|
-
|
5
|
+
aws = YAML.load(File.open(File.join(File.dirname(__FILE__), 'mturk.yml')))
|
6
|
+
RTurk::setup(aws['AWSAccessKeyId'], aws['AWSAccessKey'], :sandbox => true)
|
7
|
+
|
8
|
+
hits = RTurk::Hit.all_reviewable
|
9
|
+
|
10
|
+
puts "#{hits.size} reviewable hits. \n"
|
11
|
+
|
12
|
+
unless hits.empty?
|
13
|
+
puts "Approving all assignments and disposing of each hit!"
|
14
|
+
|
15
|
+
hits.each do |hit|
|
16
|
+
hit.expire!
|
17
|
+
hit.assignments.each do |assignment|
|
18
|
+
assignment.approve!
|
19
|
+
end
|
20
|
+
hit.dispose!
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
$: << File.join(File.dirname(__FILE__), '..', 'lib')
|
2
|
+
require 'rubygems'
|
3
|
+
require '../lib/rturk'
|
4
|
+
|
5
|
+
aws = YAML.load(File.open(File.join(File.dirname(__FILE__), 'mturk.yml')))
|
6
|
+
RTurk::setup(aws['AWSAccessKeyId'], aws['AWSAccessKey'], :sandbox => true)
|
7
|
+
|
8
|
+
root = File.expand_path(File.dirname(__FILE__))
|
9
|
+
aws = YAML.load(File.open(File.join(root, 'mturk.yml')))
|
10
|
+
RTurk::setup(aws['AWSAccessKeyId'], aws['AWSAccessKey'], :sandbox => true)
|
11
|
+
|
12
|
+
hit = RTurk::Hit.create(:title => 'Write a tweet for me') do |hit|
|
13
|
+
hit.description = 'Simply write a witty twitter update for my account'
|
14
|
+
hit.reward = 0.05
|
15
|
+
hit.assignments = 1
|
16
|
+
hit.question("http://mpercival.com.s3.amazonaws.com/newtweet.html")
|
17
|
+
end
|
18
|
+
|
19
|
+
p hit.url
|
data/examples/newtweet.html
CHANGED
@@ -55,7 +55,6 @@
|
|
55
55
|
<li>MUST BE LESS THAN 120 CHARACTERS</li>
|
56
56
|
<li>Could be about an interesting topic or current event</li>
|
57
57
|
<li>Could also make up something about what I'm currently doing</li>
|
58
|
-
<li>Should not be vulgar or crass</li>
|
59
58
|
|
60
59
|
<li>Should fool people into thinking I am clever and witty</li>
|
61
60
|
</ul>
|
data/examples/review_answer.rb
CHANGED
@@ -1,8 +1,21 @@
|
|
1
|
+
$: << File.join(File.dirname(__FILE__), '..', 'lib')
|
2
|
+
require 'rubygems'
|
1
3
|
require '../lib/rturk'
|
2
|
-
root = File.expand_path(File.dirname(__FILE__))
|
3
|
-
aws = YAML.load(File.open(File.join(root, 'mturk.yml')))
|
4
|
-
@turk = RTurk::Requester.new(aws['AWSAccessKeyId'], aws['AWSAccessKey'], :sandbox => true)
|
5
4
|
|
6
|
-
|
5
|
+
aws = YAML.load(File.open(File.join(File.dirname(__FILE__), 'mturk.yml')))
|
6
|
+
RTurk::setup(aws['AWSAccessKeyId'], aws['AWSAccessKey'], :sandbox => true)
|
7
7
|
|
8
|
-
|
8
|
+
hits = RTurk::Hit.all_reviewable
|
9
|
+
|
10
|
+
puts "#{hits.size} reviewable hits. \n"
|
11
|
+
|
12
|
+
unless hits.empty?
|
13
|
+
puts "Reviewing all assignments"
|
14
|
+
|
15
|
+
hits.each do |hit|
|
16
|
+
hit.assignments.each do |assignment|
|
17
|
+
puts assignment.answers['tweet']
|
18
|
+
assignment.approve! if assignment.status == 'Submitted'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/rturk.rb
CHANGED
@@ -1,11 +1,38 @@
|
|
1
1
|
module RTurk
|
2
|
-
|
2
|
+
require 'rturk/logger'
|
3
|
+
|
4
|
+
SANDBOX = 'http://mechanicalturk.sandbox.amazonaws.com/'
|
5
|
+
PRODUCTION = 'http://mechanicalturk.amazonaws.com/'
|
6
|
+
class << self
|
7
|
+
attr_reader :access_key, :secret_key, :host
|
8
|
+
|
9
|
+
def setup(access_key, secret_key, opts ={})
|
10
|
+
@access_key = access_key
|
11
|
+
@secret_key = secret_key
|
12
|
+
@host = opts[:sandbox] ? SANDBOX : PRODUCTION
|
13
|
+
end
|
14
|
+
|
15
|
+
def sandbox?
|
16
|
+
@host == SANDBOX
|
17
|
+
end
|
18
|
+
|
19
|
+
def log
|
20
|
+
RTurk::Logger.logger
|
21
|
+
end
|
3
22
|
|
4
|
-
|
5
|
-
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
6
26
|
|
7
27
|
require 'rturk/utilities'
|
8
|
-
require 'rturk/
|
9
|
-
require 'rturk/answer'
|
10
|
-
require 'rturk/external_question_builder'
|
28
|
+
require 'rturk/xml_utilities'
|
11
29
|
require 'rturk/requester'
|
30
|
+
require 'rturk/response'
|
31
|
+
Dir.glob(File.join(File.dirname(__FILE__), 'rturk', 'responses', '*.rb')).each {|f| require f }
|
32
|
+
require 'rturk/operation'
|
33
|
+
Dir.glob(File.join(File.dirname(__FILE__), 'rturk', 'operations', '*.rb')).each {|f| require f }
|
34
|
+
Dir.glob(File.join(File.dirname(__FILE__), 'rturk', 'builders', '*.rb')).each {|f| require f }
|
35
|
+
Dir.glob(File.join(File.dirname(__FILE__), 'rturk', 'adapters', '*.rb')).each {|f| require f }
|
36
|
+
Dir.glob(File.join(File.dirname(__FILE__), 'rturk', 'parsers', '*.rb')).each {|f| require f }
|
37
|
+
|
38
|
+
require 'rturk/errors'
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
|
3
|
+
module RTurk
|
4
|
+
class Answers
|
5
|
+
|
6
|
+
attr_accessor :answer_hash
|
7
|
+
|
8
|
+
def initialize(xml)
|
9
|
+
answer_xml = Nokogiri::XML(CGI.unescapeHTML(xml))
|
10
|
+
@answer_hash = {}
|
11
|
+
answers = answer_xml.xpath('//xmlns:Answer')
|
12
|
+
answers.each do |answer|
|
13
|
+
key, value = nil, nil
|
14
|
+
answer.children.each do |child|
|
15
|
+
next if child.blank?
|
16
|
+
if child.name == 'QuestionIdentifier'
|
17
|
+
key = child.inner_text
|
18
|
+
else
|
19
|
+
value = child.inner_text
|
20
|
+
end
|
21
|
+
end
|
22
|
+
@answer_hash[key] = value
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
# @param [<String, Symbol>] The string or symbol of the question name
|
28
|
+
# @return [String] The value of the question name
|
29
|
+
def [](key)
|
30
|
+
@answer_hash[key]
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_hash
|
34
|
+
@answer_hash
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'time'
|
2
|
+
|
3
|
+
module RTurk
|
4
|
+
|
5
|
+
# Parses:
|
6
|
+
# <Assignment>
|
7
|
+
# <AssignmentId>GYFTRHZ5J3DZREY48WNZE38ZR9RR1ZPMXGWE7WE0</AssignmentId>
|
8
|
+
# <WorkerId>AD20WXZZP9XXK</WorkerId>
|
9
|
+
# <HITId>GYFTRHZ5J3DZREY48WNZ</HITId>
|
10
|
+
# <AssignmentStatus>Approved</AssignmentStatus>
|
11
|
+
# <AutoApprovalTime>2009-08-12T19:21:54Z</AutoApprovalTime>
|
12
|
+
# <AcceptTime>2009-07-13T19:21:40Z</AcceptTime>
|
13
|
+
# <SubmitTime>2009-07-13T19:21:54Z</SubmitTime>
|
14
|
+
# <ApprovalTime>2009-07-13T19:27:54Z</ApprovalTime>
|
15
|
+
# <Answer>
|
16
|
+
# <?xml version="1.0" encoding="UTF-8"?>
|
17
|
+
# <QuestionFormAnswers xmlns="http://mechanicalturk.amazonaws.com/AWSMechanicalTurkDataSchemas/2005-10-01/QuestionFormAnswers.xsd">
|
18
|
+
# <Answer>
|
19
|
+
# <QuestionIdentifier>Question100</QuestionIdentifier>
|
20
|
+
# <FreeText>Move to X.</FreeText>
|
21
|
+
# </Answer>
|
22
|
+
# </QuestionFormAnswers>
|
23
|
+
# </Answer>
|
24
|
+
# </Assignment>
|
25
|
+
|
26
|
+
class Assignment
|
27
|
+
include RTurk::XmlUtilities
|
28
|
+
|
29
|
+
attr_accessor :worker_id, :id, :status, :submitted_at, :accepted_at, :approved_at
|
30
|
+
attr_reader :answers
|
31
|
+
|
32
|
+
def initialize(xml_object)
|
33
|
+
map_content(xml_object,
|
34
|
+
:id => 'AssignmentId',
|
35
|
+
:worker_id => 'WorkerId',
|
36
|
+
:status => 'AssignmentStatus',
|
37
|
+
:accepted_at => 'AcceptTime',
|
38
|
+
:approved_at => "ApprovalTime",
|
39
|
+
:submitted_at => 'SubmitTime')
|
40
|
+
self.answers = xml_object.xpath('Answer').children.to_s
|
41
|
+
end
|
42
|
+
|
43
|
+
def approved_at=(time)
|
44
|
+
@approved_at = Time.parse(time)
|
45
|
+
end
|
46
|
+
|
47
|
+
def submitted_at=(time)
|
48
|
+
@submitted_at = Time.parse(time)
|
49
|
+
end
|
50
|
+
|
51
|
+
def accepted_at=(time)
|
52
|
+
@accepted_at = Time.parse(time)
|
53
|
+
end
|
54
|
+
|
55
|
+
def approve!(feedback = nil)
|
56
|
+
RTurk::ApproveAssignment(:assignment_id => self.id, :feedback => feedback)
|
57
|
+
end
|
58
|
+
|
59
|
+
def reject!(reason)
|
60
|
+
RTurk::ApproveAssignment(:assignment_id => self.id, :feedback => reason)
|
61
|
+
end
|
62
|
+
|
63
|
+
def bonus!(amount, reason)
|
64
|
+
RTurk::GrantBonus(:amount, :feedback => reason)
|
65
|
+
end
|
66
|
+
|
67
|
+
def answers=(answer_xml)
|
68
|
+
unless answer_xml.empty?
|
69
|
+
@answers = RTurk::Answers.new(answer_xml)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
module RTurk
|
2
|
+
|
3
|
+
# =The RTurk Hit Adapter
|
4
|
+
#
|
5
|
+
# Lets us interact with Mechanical Turk without having to know all the operations.
|
6
|
+
#
|
7
|
+
# == Basic usage
|
8
|
+
# @example
|
9
|
+
# require 'rturk'
|
10
|
+
#
|
11
|
+
# RTurk.setup(YourAWSAccessKeyId, YourAWSAccessKey, :sandbox => true)
|
12
|
+
# hit = RTurk::Hit.create(:title => "Add some tags to a photo") do |hit|
|
13
|
+
# hit.assignments = 2
|
14
|
+
# hit.question("http://myapp.com/turkers/add_tags")
|
15
|
+
# hit.reward = 0.05
|
16
|
+
# hit.qualifications.approval_rate, {:gt => 80}
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# hit.url #=> 'http://mturk.amazonaws.com/?group_id=12345678'
|
20
|
+
|
21
|
+
|
22
|
+
class Hit
|
23
|
+
include RTurk::XmlUtilities
|
24
|
+
|
25
|
+
class << self;
|
26
|
+
|
27
|
+
def create(*args, &blk)
|
28
|
+
response = RTurk::CreateHIT(*args, &blk)
|
29
|
+
response.hit
|
30
|
+
end
|
31
|
+
|
32
|
+
def find(id)
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
def all_reviewable
|
37
|
+
RTurk.GetReviewableHITs.hits
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
attr_accessor :id
|
43
|
+
|
44
|
+
def initialize(id, type = nil)
|
45
|
+
@id, @type = id, type
|
46
|
+
end
|
47
|
+
|
48
|
+
def assignments
|
49
|
+
RTurk::GetAssignmentsForHIT(:hit_id => self.id).assignments
|
50
|
+
end
|
51
|
+
|
52
|
+
def type_id
|
53
|
+
@type_id ||= details.type_id
|
54
|
+
end
|
55
|
+
|
56
|
+
def status
|
57
|
+
@status ||= details.status
|
58
|
+
end
|
59
|
+
|
60
|
+
def expires_at
|
61
|
+
@expires_at ||= details.expires_at
|
62
|
+
end
|
63
|
+
|
64
|
+
def title
|
65
|
+
@title ||= details.title
|
66
|
+
end
|
67
|
+
|
68
|
+
def details
|
69
|
+
@details ||= RTurk::GetHIT(:hit_id => self.id)
|
70
|
+
end
|
71
|
+
|
72
|
+
def expire!
|
73
|
+
RTurk::ForceExpireHIT(:hit_id => self.id)
|
74
|
+
end
|
75
|
+
|
76
|
+
def dispose!
|
77
|
+
RTurk::DisposeHIT(:hit_id => self.id)
|
78
|
+
end
|
79
|
+
|
80
|
+
def disable!
|
81
|
+
RTurk::DisableHIT(:hit_id => self.id)
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
def url
|
86
|
+
if RTurk.sandbox?
|
87
|
+
"http://workersandbox.mturk.com/mturk/preview?groupId=#{self.type_id}" # Sandbox Url
|
88
|
+
else
|
89
|
+
"http://mturk.com/mturk/preview?groupId=#{self.type_id}" # Production Url
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|