Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added GetQualificationRequests API call

  • Loading branch information...
commit 4eb1a30093271d4c28268bc5ecce3e4a56bcb8ef 1 parent f273199
@hamin hamin authored
View
26 lib/rturk/operations/get_qualification_requests.rb
@@ -0,0 +1,26 @@
+# operation retrieves requests for Qualifications of a particular Qualification type
+
+module RTurk
+ class GetQualificationRequests < Operation
+ attr_accessor :qualification_type_id, :status, :page_size, :page_number
+ require_params :qualification_type_id
+
+ def parse(xml)
+ RTurk::GetQualificationRequestsResponse.new(xml)
+ end
+
+ def to_params
+ params = {
+ 'QualificationTypeId' => qualification_type_id
+ }
+ params['Status'] = status unless status.nil?
+ params['PageSize'] = page_size unless page_size.nil?
+ params['PageNumber'] = page_number unless page_number.nil?
+ params
+ end
+ end
+
+ def self.GetQualificationRequests(*args)
+ RTurk::GetQualificationRequests.create(*args)
+ end
+end
View
19 lib/rturk/parsers/qualification_request_parser.rb
@@ -0,0 +1,19 @@
+# Parses a QualificationRequest object
+
+module RTurk
+ class QualificationRequestParser < RTurk::Parser
+ attr_reader :qualification_request_id, :qualification_type_id, :subject_id,
+ :submit_time, :test, :answer
+
+ def initialize(qualification_request_xml)
+ @xml_obj = qualification_request_xml
+ map_content(@xml_obj,
+ :qualification_request_id => 'QualificationRequestId',
+ :qualification_type_id => 'QualificationTypeId',
+ :subject_id => 'SubjectId',
+ :submit_time => 'SubmitTime',
+ :test => 'Test',
+ :answer => 'Answer')
+ end
+ end
+end
View
26 lib/rturk/parsers/responses/get_qualification_requests_response.rb
@@ -0,0 +1,26 @@
+# Parses the GetQualificationRequests Response
+
+module RTurk
+ class GetQualificationRequestsResponse < Response
+ attr_reader :num_results, :total_num_results, :page_number
+
+ def initialize(response)
+ @raw_xml = response.body
+ @xml = Nokogiri::XML(@raw_xml)
+ raise_errors
+ map_content(@xml.xpath('//GetQualificationRequestsResult'),
+ :num_results => 'NumResults',
+ :total_num_results => 'TotalNumResults',
+ :page_number => 'PageNumber'
+ )
+ end
+
+ def qualification_requests
+ @qualification_requests ||= []
+ @xml.xpath('//QualificationRequest').each do |qualification_request_xml|
+ @qualification_requests << QualificationRequestParser.new(qualification_request_xml)
+ end
+ @qualification_requests
+ end
+ end
+end
View
30 spec/fake_responses/get_qualification_requests.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0"?>
+<GetQualificationRequestsResponse>
+ <OperationRequest>
+ <RequestId>49341251-fcbd-45c3-ab98-8fbe2e4d8060</RequestId>
+ </OperationRequest>
+ <GetQualificationRequestsResult>
+ <Request>
+ <IsValid>True</IsValid>
+ </Request>
+ <NumResults>1</NumResults>
+ <TotalNumResults>1</TotalNumResults>
+ <PageNumber>1</PageNumber>
+ <QualificationRequest>
+ <QualificationRequestId>789RVWYBAZW00EXAMPLE951RVWYBAZW00EXAMPLE</QualificationRequestId>
+ <QualificationTypeId>789RVWYBAZW00EXAMPLE</QualificationTypeId>
+ <SubjectId>AZ3456EXAMPLE</SubjectId>
+ <Test>
+ &lt;QuestionForm&gt;
+ [XML-encoded question data]
+ &lt;/QuestionForm&gt;
+ </Test>
+ <Answer>
+ &lt;QuestionFormAnswers&gt;
+ [XML-encoded answer data]
+ &lt;/QuestionFormAnswers&gt;
+ </Answer>
+ <SubmitTime>2005-12-01T23:59:59Z</SubmitTime>
+ </QualificationRequest>
+ </GetQualificationRequestsResult>
+</GetQualificationRequestsResponse>
View
27 spec/operations/get_qualification_requests_spec.rb
@@ -0,0 +1,27 @@
+require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
+
+describe RTurk::GetQualificationRequests do
+ before(:all) do
+ aws = YAML.load(File.open(File.join(SPEC_ROOT, 'mturk.yml')))
+ RTurk.setup(aws['AWSAccessKeyId'], aws['AWSAccessKey'], :sandbox => true)
+ faker('get_qualification_requests', :operation => 'GetQualificationRequests')
+ end
+
+ it "should ensure required params" do
+ lambda{RTurk::GetQualificationRequests()}.should raise_error RTurk::MissingParameters
+ end
+
+ it "should successfully request the operation" do
+ RTurk::Requester.should_receive(:request).once.with(
+ hash_including('Operation' => 'GetQualificationRequests'))
+ RTurk::GetQualificationRequests(:qualification_type_id => '789RVWYBAZW00EXAMPLE') rescue RTurk::InvalidRequest
+ end
+
+ it "should parse and return the result" do
+ response = RTurk::GetQualificationRequests(:qualification_type_id => '789RVWYBAZW00EXAMPLE')
+ response.num_results.should == 1
+ response.qualification_requests.length.should == 1
+ response.qualification_requests[0].qualification_request_id.should == '789RVWYBAZW00EXAMPLE951RVWYBAZW00EXAMPLE'
+ response.qualification_requests[0].subject_id.should == 'AZ3456EXAMPLE'
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.