Skip to content

Commit

Permalink
Add support for the SetHITAsReviewing operation.
Browse files Browse the repository at this point in the history
  • Loading branch information
abscondment committed Jun 1, 2011
1 parent d1d3c42 commit f3ec6a9
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 1 deletion.
7 changes: 7 additions & 0 deletions lib/rturk/adapters/hit.rb
Expand Up @@ -93,6 +93,13 @@ def disable!
RTurk::DisableHIT(:hit_id => self.id)
end

def set_as_reviewing!
RTurk::SetHITAsReviewing(:hit_id => self.id)
end

def set_as_reviewable!
RTurk::SetHITAsReviewing(:hit_id => self.id, :revert => true)
end

def url
if RTurk.sandbox?
Expand Down
18 changes: 18 additions & 0 deletions lib/rturk/operations/set_hit_as_reviewing.rb
@@ -0,0 +1,18 @@
# http://docs.amazonwebservices.com/AWSMturkAPI/2008-08-02/ApiReference_DisposeHITOperation.html
module RTurk
class SetHITAsReviewing < Operation

require_params :hit_id
attr_accessor :hit_id, :revert

def to_params
{'HITId' => self.hit_id, 'Revert' => self.revert}
end

end

def self.SetHITAsReviewing(*args, &blk)
RTurk::SetHITAsReviewing.create(*args, &blk)
end

end
11 changes: 10 additions & 1 deletion spec/adapters/hit_spec.rb
Expand Up @@ -12,6 +12,7 @@
faker('extend_hit', :operation => 'ExtendHIT')
faker('force_expire_hit', :operation => 'ForceExpireHIT')
faker('dispose_hit', :operation => 'DisposeHIT')
faker('set_hit_as_reviewing', :operation => 'SetHITAsReviewing')
faker('search_hits', :operation => 'SearchHITs')
end

Expand Down Expand Up @@ -72,7 +73,15 @@
hits = RTurk::Hit.all_reviewable
hits.first.dispose!
end


it "should set a hit as Reviewing and Reviewable" do
hit = RTurk::Hit.all_reviewable.first
RTurk.should_receive(:SetHITAsReviewing).once.with(:hit_id => hit.id)
hit.set_as_reviewing!
RTurk.should_receive(:SetHITAsReviewing).once.with(:hit_id => hit.id, :revert => true)
hit.set_as_reviewable!
end

it "should return a list of all hits" do
hits = RTurk::Hit.all
hits.size.should eql(2)
Expand Down
5 changes: 5 additions & 0 deletions spec/fake_responses/set_hit_as_reviewing.xml
@@ -0,0 +1,5 @@
<SetHITAsReviewingResult>
<Request>
<IsValid>True</IsValid>
</Request>
</SetHITAsReviewingResult>
29 changes: 29 additions & 0 deletions spec/operations/set_hit_as_reviewing_spec.rb
@@ -0,0 +1,29 @@
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))

describe RTurk::SetHITAsReviewing do

before(:all) do
aws = YAML.load(File.open(File.join(SPEC_ROOT, 'mturk.yml')))
RTurk.setup(aws['AWSAccessKeyId'], aws['AWSAccessKey'], :sandbox => true)
faker('set_hit_as_reviewing', :operation => 'SetHITAsReviewing')
end

it "should ensure required params" do
lambda{RTurk::SetHITAsReviewing()}.should raise_error(RTurk::MissingParameters)
end

it "should successfully request the operation" do
RTurk::Requester.should_receive(:request).twice.with(
hash_including('Operation' => 'SetHITAsReviewing'))
RTurk::SetHITAsReviewing(:hit_id => "123456789") rescue RTurk::InvalidRequest
RTurk::SetHITAsReviewing(:hit_id => "123456789", :revert => true) rescue RTurk::InvalidRequest
end

it "should parse and return the result" do
RTurk::SetHITAsReviewing(:hit_id => "123456789").should
be_a_kind_of RTurk::Response
RTurk::SetHITAsReviewing(:hit_id => "123456789", :revert => true).should
be_a_kind_of RTurk::Response
end

end

0 comments on commit f3ec6a9

Please sign in to comment.