rturk 2.0.3 → 2.0.4
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/README.markdown +2 -1
- data/VERSION +1 -1
- data/lib/rturk/adapters/assignment.rb +1 -1
- data/lib/rturk/operation.rb +3 -1
- data/lib/rturk/operations/create_hit.rb +27 -5
- data/lib/rturk/operations/register_hit_type.rb +21 -30
- data/rturk.gemspec +2 -2
- data/spec/operations/disable_hit_spec.rb +1 -1
- data/spec/operations/register_hit_type_spec.rb +0 -2
- metadata +2 -2
data/README.markdown
CHANGED
@@ -25,7 +25,8 @@ Let's say you have a form at "http://myapp.com/turkers/add_tags" where Turkers c
|
|
25
25
|
hit = RTurk::Hit.create(:title => "Add some tags to a photo") do |hit|
|
26
26
|
hit.assignments = 2
|
27
27
|
hit.description = 'blah'
|
28
|
-
hit.question("http://myapp.com/turkers/add_tags"
|
28
|
+
hit.question("http://myapp.com/turkers/add_tags",
|
29
|
+
:frame_height => 1000) # pixels for iframe
|
29
30
|
hit.reward = 0.05
|
30
31
|
hit.qualifications.add :approval_rate, { :gt => 80 }
|
31
32
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.0.
|
1
|
+
2.0.4
|
data/lib/rturk/operation.rb
CHANGED
@@ -73,12 +73,14 @@ module RTurk
|
|
73
73
|
end
|
74
74
|
|
75
75
|
def check_params
|
76
|
+
missing_parameters = []
|
76
77
|
self.class.required_params.each do |param|
|
77
78
|
if self.respond_to?(param)
|
78
|
-
|
79
|
+
missing_parameters << param.to_s if self.send(param).nil?
|
79
80
|
else
|
80
81
|
raise MissingParameters, "The parameter '#{param.to_s}' was required and not available"
|
81
82
|
end
|
83
|
+
raise MissingParameters, "Parameters '#{missing_parameters.join(', ')}' cannot be blank" unless missing_parameters.empty?
|
82
84
|
end
|
83
85
|
end
|
84
86
|
|
@@ -2,27 +2,49 @@ require File.join(File.dirname(__FILE__), 'register_hit_type')
|
|
2
2
|
|
3
3
|
module RTurk
|
4
4
|
class CreateHIT < RegisterHITType
|
5
|
-
attr_accessor :hit_type_id
|
6
|
-
|
5
|
+
attr_accessor :hit_type_id, :assignments, :lifetime, :note
|
6
|
+
|
7
7
|
def parse(response)
|
8
8
|
RTurk::CreateHITResponse.new(response)
|
9
9
|
end
|
10
10
|
|
11
|
+
# Gives us access to a question builder attached to this HIT
|
12
|
+
#
|
13
|
+
# @param [String, Hash] URL Params, if none is passed, simply returns the question
|
14
|
+
# @return [RTurk::Question] The question if instantiated or nil
|
15
|
+
def question(*args)
|
16
|
+
unless args.empty?
|
17
|
+
@question ||= RTurk::Question.new(*args)
|
18
|
+
else
|
19
|
+
@question
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
11
23
|
def to_params
|
12
|
-
super.merge(
|
24
|
+
super.merge(
|
25
|
+
'HITTypeId' => hit_type_id,
|
26
|
+
'MaxAssignments' => (assignments || 1),
|
27
|
+
'Question' => question.to_params,
|
28
|
+
'LifetimeInSeconds' => (lifetime || 3600),
|
29
|
+
'RequesterAnnotation' => note
|
30
|
+
)
|
13
31
|
end
|
14
32
|
|
15
33
|
# More complicated validation run before request
|
16
34
|
#
|
17
35
|
def validate
|
18
36
|
if hit_type_id
|
19
|
-
unless question
|
20
|
-
raise RTurk::MissingParameters, "When you specify a HitTypeID, you must incude a question
|
37
|
+
unless question
|
38
|
+
raise RTurk::MissingParameters, "When you specify a HitTypeID, you must incude a question"
|
21
39
|
end
|
22
40
|
else
|
23
41
|
super # validate as RegisterHitType
|
24
42
|
end
|
25
43
|
end
|
44
|
+
|
45
|
+
def required_fields
|
46
|
+
super << :question
|
47
|
+
end
|
26
48
|
end
|
27
49
|
|
28
50
|
def self.CreateHIT(*args, &blk)
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module RTurk
|
2
2
|
class RegisterHITType < Operation
|
3
3
|
|
4
|
-
attr_accessor :title, :
|
5
|
-
|
4
|
+
attr_accessor :title, :description, :reward, :currency, :duration, :keywords, :auto_approval
|
5
|
+
|
6
6
|
|
7
7
|
# @param [Symbol, Hash] qualification_key opts The unique qualification key
|
8
8
|
# @option opts [Hash] :comparator A comparator and value e.g. :gt => 80
|
@@ -13,18 +13,6 @@ module RTurk
|
|
13
13
|
@qualifications ||= RTurk::Qualifications.new
|
14
14
|
end
|
15
15
|
|
16
|
-
# Gives us access to a question builder attached to this HIT
|
17
|
-
#
|
18
|
-
# @param [String, Hash] URL Params, if none is passed, simply returns the question
|
19
|
-
# @return [RTurk::Question] The question if instantiated or nil
|
20
|
-
def question(*args)
|
21
|
-
unless args.empty?
|
22
|
-
@question ||= RTurk::Question.new(*args)
|
23
|
-
else
|
24
|
-
@question
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
16
|
# Returns parameters specific to this instance
|
29
17
|
#
|
30
18
|
# @return [Hash]
|
@@ -41,27 +29,30 @@ module RTurk
|
|
41
29
|
# More complicated validation run before request
|
42
30
|
#
|
43
31
|
def validate
|
44
|
-
|
45
|
-
|
32
|
+
missing_parameters = []
|
33
|
+
required_fields.each do |param|
|
34
|
+
missing_parameters << param.to_s unless self.send(param)
|
46
35
|
end
|
36
|
+
raise RTurk::MissingParameters, "Parameters: '#{missing_parameters.join(', ')}'" unless missing_parameters.empty?
|
47
37
|
end
|
48
|
-
|
49
|
-
|
50
|
-
|
38
|
+
|
39
|
+
def required_fields
|
40
|
+
[:title, :description, :reward]
|
41
|
+
end
|
42
|
+
|
43
|
+
protected
|
44
|
+
|
51
45
|
def map_params
|
52
|
-
{'Title'=>
|
53
|
-
'
|
54
|
-
'
|
55
|
-
'
|
56
|
-
'Reward.
|
57
|
-
'
|
58
|
-
'
|
59
|
-
'Description' => self.description,
|
60
|
-
'Question' => self.question.to_params,
|
61
|
-
'RequesterAnnotation' => note}
|
46
|
+
{'Title'=>title,
|
47
|
+
'Description' => description,
|
48
|
+
'AssignmentDurationInSeconds' => (duration || 86400),
|
49
|
+
'Reward.Amount' => reward,
|
50
|
+
'Reward.CurrencyCode' => (currency || 'USD'),
|
51
|
+
'Keywords' => keywords,
|
52
|
+
'AutoApprovalDelayInSeconds' => auto_approval}
|
62
53
|
end
|
63
|
-
|
64
54
|
end
|
55
|
+
|
65
56
|
def self.RegisterHITType(*args, &blk)
|
66
57
|
RTurk::RegisterHITType.create(*args, &blk)
|
67
58
|
end
|
data/rturk.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{rturk}
|
8
|
-
s.version = "2.0.
|
8
|
+
s.version = "2.0.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Mark Percival"]
|
12
|
-
s.date = %q{2009-
|
12
|
+
s.date = %q{2009-12-07}
|
13
13
|
s.email = %q{mark@mpercival.com}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"LICENSE",
|
@@ -9,7 +9,7 @@ describe RTurk::DisableHIT do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
it "should ensure required params" do
|
12
|
-
lambda{RTurk::DisableHIT()}.should raise_error
|
12
|
+
lambda{RTurk::DisableHIT()}.should raise_error(RTurk::MissingParameters)
|
13
13
|
end
|
14
14
|
|
15
15
|
it "should successfully request the operation" do
|
@@ -11,9 +11,7 @@ describe RTurk::RegisterHITType do
|
|
11
11
|
|
12
12
|
it "should rerturn a CreateHITResponse after the request" do
|
13
13
|
response = RTurk::RegisterHITType(:title => "Look at some pictures from 4Chan") do |hit|
|
14
|
-
hit.assignments = 5
|
15
14
|
hit.description = "foo"
|
16
|
-
hit.question("http://mpercival.com", :test => 'b')
|
17
15
|
hit.reward = 0.05
|
18
16
|
hit.qualifications.add(:adult, true)
|
19
17
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rturk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Percival
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-12-07 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|