/
create_hit.rb
61 lines (50 loc) · 1.57 KB
/
create_hit.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
module RTurk
class CreateHit < Operation
#
# We perform the magic here to create a HIT with the minimum amount of fuss.
# You should be able to pass in a hash with all the setting(ala YAML) or
# do all the config in a block.
#
attr_accessor :title, :keywords, :description, :reward, :currency, :assignments
attr_accessor :lifetime, :duration, :auto_approval, :note, :qualifications
def initialize(opts = {})
opts.each_pair do |k,v|
if v.is_a? Hash
obj = self.send k.to_sym
v.each_pair do |key,val|
obj.send key.to_sym, val
end
elsif self.respond_to?("#{k.to_sym}=")
self.send "#{k}=".to_sym, v
elsif self.respond_to?(k.to_sym)
self.send k.to_sym, v
end
end
yield(self) if block_given?
end
def qualification
@qualifications ||= RTurk::Qualifications.new
end
def question
@question ||= RTurk::Question.new
end
def to_aws_params
hit_params.merge(qualification.to_aws_params)
end
def response(xml)
RTurk::CreateHitResponse.parse(xml)
end
private
def hit_params
{'Title'=>self.title,
'MaxAssignments' => self.assignments,
'LifetimeInSeconds'=> self.lifetime,
'Reward.Amount' => self.reward,
'Reward.CurrencyCode' => (self.currency || 'USD'),
'Keywords' => self.keywords,
'Description' => self.description,
'RequesterAnnotation' => note}
end
RTurk::Operation.register('create_hit', self)
end
end