rturk 2.7.0 → 2.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,4 +10,5 @@ hit = RTurk::Hit.create(:title => 'Write a tweet for me') do |hit|
10
10
  hit.question("http://mpercival.com.s3.amazonaws.com/newtweet.html")
11
11
  end
12
12
 
13
+ p hit.hit_id
13
14
  p hit.url
data/lib/rturk.rb CHANGED
@@ -3,7 +3,7 @@ module RTurk
3
3
 
4
4
  SANDBOX = 'https://mechanicalturk.sandbox.amazonaws.com/'
5
5
  PRODUCTION = 'https://mechanicalturk.amazonaws.com/'
6
- API_VERSION = '2008-08-02'
6
+ API_VERSION = '2012-03-25' # '2008-08-02'
7
7
  OLD_API_VERSION = '2006-05-05'
8
8
 
9
9
  class << self
@@ -0,0 +1,18 @@
1
+ module RTurk
2
+ class GetAssignment < Operation
3
+ require_params :assignment_id
4
+ attr_accessor :assignment_id
5
+
6
+ def parse(xml)
7
+ GetAssignmentResponse.new(xml)
8
+ end
9
+
10
+ def to_params
11
+ {'AssignmentId' => assignment_id}
12
+ end
13
+ end
14
+
15
+ def self.GetAssignment(*args, &blk)
16
+ RTurk::GetAssignment.create(*args, &blk)
17
+ end
18
+ end
@@ -0,0 +1,12 @@
1
+ module RTurk
2
+ class GetAssignmentResponse < Response
3
+
4
+ def assignment
5
+ @assignment ||= AssignmentParser.new(@xml.xpath('//Assignment').first)
6
+ end
7
+
8
+ def hit
9
+ @hit ||= HITParser.new(@xml.xpath('//HIT').first)
10
+ end
11
+ end
12
+ end
data/lib/rturk/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RTurk
2
- VERSION = "2.7.0"
2
+ VERSION = "2.8.0"
3
3
  end
@@ -0,0 +1,64 @@
1
+ <?xml version="1.0"?>
2
+ <GetAssignmentResult>
3
+ <Request>
4
+ <IsValid>True</IsValid>
5
+ </Request>
6
+ <Assignment>
7
+ <AssignmentId>GYFTRHZ5J3DZREY48WNZE38ZR9RR1ZPMXGWE7WE0</AssignmentId>
8
+ <WorkerId>AD20WXZZP9XXK</WorkerId>
9
+ <HITId>GYFTRHZ5J3DZREY48WNZ</HITId>
10
+ <AssignmentStatus>Approved</AssignmentStatus>
11
+ <AutoApprovalTime>2012-08-12T19:21:54Z</AutoApprovalTime>
12
+ <AcceptTime>2012-07-13T19:21:40Z</AcceptTime>
13
+ <SubmitTime>2012-07-13T19:21:54Z</SubmitTime>
14
+ <ApprovalTime>2012-07-13T19:27:54Z</ApprovalTime>
15
+ <Answer>
16
+ &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
17
+ &lt;QuestionFormAnswers xmlns="http://mechanicalturk.amazonaws.com/AWSMechanicalTurkDataSchemas/2005-10-01/QuestionFormAnswers.xsd"&gt;
18
+ &lt;Answer&gt;
19
+ &lt;QuestionIdentifier&gt;Question100&lt;/QuestionIdentifier&gt;
20
+ &lt;FreeText&gt;Move to X.&lt;/FreeText&gt;
21
+ &lt;/Answer&gt;
22
+ &lt;/QuestionFormAnswers&gt;
23
+ </Answer>
24
+ </Assignment>
25
+ <HIT>
26
+ <HITId>GYFTRHZ5J3DZREY48WNZ</HITId>
27
+ <HITTypeId>NYVZTQ1QVKJZXCYZCZVZ</HITTypeId>
28
+ <CreationTime>2012-07-07T00:56:40Z</CreationTime>
29
+ <Title>Location</Title>
30
+ <Description>Answer this Question</Description>
31
+ <Question>
32
+ <QuestionForm xmlns="http://mechanicalturk.amazonaws.com/AWSMechanicalTurkDataSchemas/2005-10-01/QuestionForm.xsd">
33
+ <Question>
34
+ <QuestionIdentifier>Question100</QuestionIdentifier>
35
+ <DisplayName>My Question</DisplayName>
36
+ <IsRequired>true</IsRequired>
37
+ <QuestionContent>
38
+ <Binary>
39
+ <MimeType>
40
+ <Type>image</Type>
41
+ <SubType>gif</SubType>
42
+ </MimeType>
43
+ <DataURL>http://tictactoe.amazon.com/game/01523/board.gif</DataURL>
44
+ <AltText>The game board, with "X" to move.</AltText>
45
+ </Binary>
46
+ </QuestionContent>
47
+ <AnswerSpecification><FreeTextAnswer/></AnswerSpecification>
48
+ </Question>
49
+ </QuestionForm>
50
+ </Question>
51
+ <HITStatus>Assignable</HITStatus>
52
+ <MaxAssignments>1</MaxAssignments>
53
+ <Reward>
54
+ <Amount>5.00</Amount>
55
+ <CurrencyCode>USD</CurrencyCode>
56
+ <FormattedPrice>$5.00</FormattedPrice>
57
+ </Reward>
58
+ <AutoApprovalDelayInSeconds>2592000</AutoApprovalDelayInSeconds>
59
+ <Expiration>2012-07-14T00:56:40Z</Expiration>
60
+ <AssignmentDurationInSeconds>30</AssignmentDurationInSeconds>
61
+ <NumberOfSimilarHITs>1</NumberOfSimilarHITs>
62
+ <HITReviewStatus>NotReviewed</HITReviewStatus>
63
+ </HIT>
64
+ </GetAssignment>
@@ -0,0 +1,35 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
2
+
3
+ describe RTurk::GetAssignment do
4
+ before(:all) do
5
+ aws = YAML.load(File.open(File.join(SPEC_ROOT, 'mturk.yml')))
6
+ RTurk.setup(aws['AWSAccessKeyId'], aws['AWSAccessKey'], :sandbox => true)
7
+ end
8
+
9
+ it "should ensure required params" do
10
+ lambda{RTurk::GetAssignment()}.should raise_error RTurk::MissingParameters
11
+ end
12
+
13
+ it "should successfully request an assignment" do
14
+ RTurk::Requester.should_receive(:request).once.with(
15
+ hash_including('Operation' => 'GetAssignment'))
16
+ RTurk::GetAssignment(:assignment_id => "abcd") rescue RTurk::InvalidRequest
17
+ end
18
+
19
+ context "an HIT with one assignment" do
20
+ before(:all) do
21
+ WebMock.reset!
22
+ faker('get_assignment', :operation => 'GetAssignment')
23
+ end
24
+
25
+ it "should parse and return and answer" do
26
+ answers = RTurk::GetAssignment(:assignment_id => "abcd").assignment.answers
27
+ answers['Question100'].should eql("Move to X.")
28
+ end
29
+
30
+ it "should parse and return the hit" do
31
+ hit = RTurk::GetAssignment(:assignment_id => "abcd").hit
32
+ hit.title.should eql("Location")
33
+ end
34
+ end
35
+ 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.7.0
4
+ version: 2.8.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -212,6 +212,7 @@ files:
212
212
  - lib/rturk/operations/extend_hit.rb
213
213
  - lib/rturk/operations/force_expire_hit.rb
214
214
  - lib/rturk/operations/get_account_balance.rb
215
+ - lib/rturk/operations/get_assignment.rb
215
216
  - lib/rturk/operations/get_assignments_for_hit.rb
216
217
  - lib/rturk/operations/get_bonus_payments.rb
217
218
  - lib/rturk/operations/get_hit.rb
@@ -244,6 +245,7 @@ files:
244
245
  - lib/rturk/parsers/response.rb
245
246
  - lib/rturk/parsers/responses/create_hit_response.rb
246
247
  - lib/rturk/parsers/responses/get_account_balance_response.rb
248
+ - lib/rturk/parsers/responses/get_assignment_response.rb
247
249
  - lib/rturk/parsers/responses/get_assignments_for_hit_response.rb
248
250
  - lib/rturk/parsers/responses/get_bonus_payments_response.rb
249
251
  - lib/rturk/parsers/responses/get_hit_response.rb
@@ -276,6 +278,7 @@ files:
276
278
  - spec/fake_responses/extend_hit.xml
277
279
  - spec/fake_responses/force_expire_hit.xml
278
280
  - spec/fake_responses/get_account_balance.xml
281
+ - spec/fake_responses/get_assignment.xml
279
282
  - spec/fake_responses/get_assignments.xml
280
283
  - spec/fake_responses/get_assignments_multiple.xml
281
284
  - spec/fake_responses/get_bonus_payments.xml
@@ -309,6 +312,7 @@ files:
309
312
  - spec/operations/extend_hit_spec.rb
310
313
  - spec/operations/force_expire_hit_spec.rb
311
314
  - spec/operations/get_account_balance_spec.rb
315
+ - spec/operations/get_assignment_spec.rb
312
316
  - spec/operations/get_assignments_spec.rb
313
317
  - spec/operations/get_bonus_payments_spec.rb
314
318
  - spec/operations/get_hit_spec.rb