lib/rturk/operations/create_hit.rb in rturk-2.0.2 vs lib/rturk/operations/create_hit.rb in rturk-2.0.3
- old
+ new
@@ -1,75 +1,31 @@
+require File.join(File.dirname(__FILE__), 'register_hit_type')
+
module RTurk
- class CreateHIT < Operation
-
- attr_accessor :title, :keywords, :description, :reward, :currency, :assignments
- attr_accessor :lifetime, :duration, :auto_approval, :note, :hit_type_id
+ class CreateHIT < RegisterHITType
+ attr_accessor :hit_type_id
- # @param [Symbol, Hash] qualification_key opts The unique qualification key
- # @option opts [Hash] :comparator A comparator and value e.g. :gt => 80
- # @option opts [Boolean] :boolean true or false
- # @option opts [Symbol] :exists A comparator without a value
- # @return [RTurk::Qualifications]
- def qualifications
- @qualifications ||= RTurk::Qualifications.new
+ def parse(response)
+ RTurk::CreateHITResponse.new(response)
end
-
- # Gives us access to a question builder attached to this HIT
- #
- # @param [String, Hash] URL Params, if none is passed, simply returns the question
- # @return [RTurk::Question] The question if instantiated or nil
- def question(*args)
- unless args.empty?
- @question ||= RTurk::Question.new(*args)
- else
- @question
- end
- end
-
- # Returns parameters specific to this instance
- #
- # @return [Hash]
- # Any class level default parameters get loaded in at
- # the time of request
+
def to_params
- params = map_params.merge(qualifications.to_params)
+ super.merge('HITTypeId' => hit_type_id)
end
- def parse(response)
- RTurk::CreateHITResponse.new(response)
- end
-
# More complicated validation run before request
#
def validate
if hit_type_id
unless question && lifetime
raise RTurk::MissingParameters, "When you specify a HitTypeID, you must incude a question and lifetime length"
end
else
- unless title && reward && question && description
- raise RTurk::MissingParameters, "You're missing some required parameters"
- end
+ super # validate as RegisterHitType
end
end
-
- private
-
- def map_params
- {'Title'=>self.title,
- 'MaxAssignments' => (self.assignments || 1),
- 'LifetimeInSeconds'=> (self.lifetime || 3600),
- 'AssignmentDurationInSeconds' => (self.duration || 86400),
- 'Reward.Amount' => self.reward,
- 'Reward.CurrencyCode' => (self.currency || 'USD'),
- 'Keywords' => self.keywords,
- 'Description' => self.description,
- 'Question' => self.question.to_params,
- 'RequesterAnnotation' => note}
- end
-
end
+
def self.CreateHIT(*args, &blk)
RTurk::CreateHIT.create(*args, &blk)
end
-
end