rturk 2.1.1 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/rturk/adapters/hit.rb +4 -0
- data/lib/rturk/operations/extend_hit.rb +4 -4
- data/lib/rturk/parsers/assignment_parser.rb +9 -2
- data/lib/rturk/xml_utilities.rb +15 -0
- data/rturk.gemspec +2 -2
- data/spec/adapters/hit_spec.rb +11 -0
- data/spec/operations/extend_hit_spec.rb +2 -2
- data/spec/parsers/answer_parser_spec.rb +11 -2
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.2.0
|
data/lib/rturk/adapters/hit.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
module RTurk
|
2
2
|
class RTurk::ExtendHIT < RTurk::Operation
|
3
3
|
|
4
|
-
attr_accessor :hit_id, :
|
4
|
+
attr_accessor :hit_id, :assignments, :seconds
|
5
5
|
require_params :hit_id
|
6
6
|
|
7
7
|
def to_params
|
8
|
-
if
|
8
|
+
if assignments.nil? && seconds.nil?
|
9
9
|
raise MissingParameters, 'Must add to either the HIT assignment count or expiration time.'
|
10
10
|
end
|
11
11
|
|
12
12
|
{'HITId' => self.hit_id,
|
13
|
-
'MaxAssignmentsIncrement' => self.
|
14
|
-
'ExpirationIncrementInSeconds' => self.
|
13
|
+
'MaxAssignmentsIncrement' => self.assignments,
|
14
|
+
'ExpirationIncrementInSeconds' => self.seconds}
|
15
15
|
end
|
16
16
|
|
17
17
|
end
|
@@ -39,11 +39,18 @@ module RTurk
|
|
39
39
|
:auto_approval_time => 'AutoApprovalTime'
|
40
40
|
)
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
def answers
|
44
44
|
AnswerParser.parse(@xml_obj.xpath('Answer').children)
|
45
45
|
end
|
46
|
+
|
47
|
+
# Normalizes a hash of answers that include nested params
|
48
|
+
# such as the ones you'll find in Rails
|
49
|
+
# Example 'tweet[text]' => 'Tweet!' becomes
|
50
|
+
# {'tweet' => {'text' => 'Tweet!'}}
|
51
|
+
def normalized_answers
|
52
|
+
normalize_nested_params(answers)
|
53
|
+
end
|
46
54
|
|
47
55
|
end
|
48
|
-
|
49
56
|
end
|
data/lib/rturk/xml_utilities.rb
CHANGED
@@ -31,4 +31,19 @@ module RTurk::XMLUtilities
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
+
# Takes a Rails-like nested param hash and normalizes it.
|
35
|
+
def normalize_nested_params(hash)
|
36
|
+
new_hash = {}
|
37
|
+
hash.each do |k,v|
|
38
|
+
inner_hash = new_hash
|
39
|
+
keys = k.split(/[\[\]]/).reject{|s| s.nil? || s.empty? }
|
40
|
+
keys[0...keys.size-1].each do |key|
|
41
|
+
inner_hash[key] ||= {}
|
42
|
+
inner_hash = inner_hash[key]
|
43
|
+
end
|
44
|
+
inner_hash[keys.last] = v
|
45
|
+
end
|
46
|
+
new_hash
|
47
|
+
end
|
48
|
+
|
34
49
|
end
|
data/rturk.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{rturk}
|
8
|
-
s.version = "2.
|
8
|
+
s.version = "2.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Mark Percival"]
|
12
|
-
s.date = %q{2010-06-
|
12
|
+
s.date = %q{2010-06-27}
|
13
13
|
s.email = %q{mark@mpercival.com}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"LICENSE",
|
data/spec/adapters/hit_spec.rb
CHANGED
@@ -9,6 +9,7 @@ describe "HIT adapter" do
|
|
9
9
|
faker('get_hit', :operation => 'GetHIT')
|
10
10
|
faker('get_reviewable_hits', :operation => 'GetReviewableHITs')
|
11
11
|
faker('get_assignments', :operation => 'GetAssignments')
|
12
|
+
faker('extend_hit', :operation => 'ExtendHIT')
|
12
13
|
faker('force_expire_hit', :operation => 'ForceExpireHIT')
|
13
14
|
faker('dispose_hit', :operation => 'DisposeHIT')
|
14
15
|
faker('search_hits', :operation => 'SearchHITs')
|
@@ -34,6 +35,16 @@ describe "HIT adapter" do
|
|
34
35
|
hits.first.assignments.first.answers["tweet"].should eql('This is my tweet!')
|
35
36
|
end
|
36
37
|
|
38
|
+
it "should add time to a hit" do
|
39
|
+
hits = RTurk::Hit.all_reviewable
|
40
|
+
hits.first.extend! :seconds => 3600
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should add assignments a hit" do
|
44
|
+
hits = RTurk::Hit.all_reviewable
|
45
|
+
hits.first.extend! :assignments => 100
|
46
|
+
end
|
47
|
+
|
37
48
|
it "should expire a hit" do
|
38
49
|
hits = RTurk::Hit.all_reviewable
|
39
50
|
hits.first.expire!
|
@@ -15,11 +15,11 @@ describe RTurk::ExtendHIT do
|
|
15
15
|
it "should successfully request the operation" do
|
16
16
|
RTurk::Requester.should_receive(:request).once.with(
|
17
17
|
hash_including('Operation' => 'ExtendHIT'))
|
18
|
-
RTurk::ExtendHIT(:hit_id => "123456789", :
|
18
|
+
RTurk::ExtendHIT(:hit_id => "123456789", :assignments=> 1) rescue RTurk::InvalidRequest
|
19
19
|
end
|
20
20
|
|
21
21
|
it "should parse and return the result" do
|
22
|
-
RTurk::ExtendHIT(:hit_id => "123456789", :
|
22
|
+
RTurk::ExtendHIT(:hit_id => "123456789", :seconds => 3600).should
|
23
23
|
be_a_kind_of RTurk::Response
|
24
24
|
end
|
25
25
|
|
@@ -8,10 +8,14 @@ describe RTurk::AnswerParser do
|
|
8
8
|
<?xml version="1.0" encoding="UTF-8"?>
|
9
9
|
<QuestionFormAnswers xmlns="http://mechanicalturk.amazonaws.com/AWSMechanicalTurkDataSchemas/2005-10-01/QuestionFormAnswers.xsd">
|
10
10
|
<Answer>
|
11
|
-
<QuestionIdentifier>tweet
|
11
|
+
<QuestionIdentifier>tweet[content]</QuestionIdentifier>
|
12
12
|
<FreeText>This is my tweet!</FreeText>
|
13
13
|
</Answer>
|
14
14
|
<Answer>
|
15
|
+
<QuestionIdentifier>tweet[time]</QuestionIdentifier>
|
16
|
+
<FreeText>12345678</FreeText>
|
17
|
+
</Answer>
|
18
|
+
<Answer>
|
15
19
|
<QuestionIdentifier>Submit</QuestionIdentifier>
|
16
20
|
<FreeText>Submit</FreeText>
|
17
21
|
</Answer>
|
@@ -20,8 +24,13 @@ XML
|
|
20
24
|
end
|
21
25
|
|
22
26
|
it "should parse a answer" do
|
23
|
-
RTurk::AnswerParser.parse(@answer).to_hash.should == {"Submit"=>"Submit", "tweet"=>"This is my tweet!"}
|
27
|
+
RTurk::AnswerParser.parse(@answer).to_hash.should == {"Submit"=>"Submit", "tweet[content]"=>"This is my tweet!", "tweet[time]" => "12345678"}
|
24
28
|
end
|
25
29
|
|
30
|
+
it "should parse an answer into a param hash" do
|
31
|
+
hash = RTurk::AnswerParser.parse(@answer).to_hash
|
32
|
+
RTurk::Parser.new.normalize_nested_params(hash).should == {"Submit"=>"Submit", "tweet"=> {"content" => "This is my tweet!", "time" => "12345678"}}
|
33
|
+
end
|
34
|
+
|
26
35
|
|
27
36
|
end
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 2
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 2.
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
version: 2.2.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Mark Percival
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-06-
|
17
|
+
date: 2010-06-27 00:00:00 -07:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|