rturk 2.1.1 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.1.1
1
+ 2.2.0
@@ -64,6 +64,10 @@ module RTurk
64
64
  @details ||= RTurk::GetHIT(:hit_id => self.id)
65
65
  end
66
66
 
67
+ def extend!(options = {})
68
+ RTurk::ExtendHIT(options.merge({:hit_id => self.id}))
69
+ end
70
+
67
71
  def expire!
68
72
  RTurk::ForceExpireHIT(:hit_id => self.id)
69
73
  end
@@ -1,17 +1,17 @@
1
1
  module RTurk
2
2
  class RTurk::ExtendHIT < RTurk::Operation
3
3
 
4
- attr_accessor :hit_id, :max_assignments_increment, :expiration_increment_in_seconds
4
+ attr_accessor :hit_id, :assignments, :seconds
5
5
  require_params :hit_id
6
6
 
7
7
  def to_params
8
- if max_assignments_increment.nil? && expiration_increment_in_seconds.nil?
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.max_assignments_increment,
14
- 'ExpirationIncrementInSeconds' => self.expiration_increment_in_seconds}
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
@@ -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.1.1"
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-26}
12
+ s.date = %q{2010-06-27}
13
13
  s.email = %q{mark@mpercival.com}
14
14
  s.extra_rdoc_files = [
15
15
  "LICENSE",
@@ -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", :max_assignments_increment => 1) rescue RTurk::InvalidRequest
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", :expiration_increment_in_seconds => 3600).should
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
  &lt;?xml version="1.0" encoding="UTF-8"?&gt;
9
9
  &lt;QuestionFormAnswers xmlns="http://mechanicalturk.amazonaws.com/AWSMechanicalTurkDataSchemas/2005-10-01/QuestionFormAnswers.xsd"&gt;
10
10
  &lt;Answer&gt;
11
- &lt;QuestionIdentifier&gt;tweet&lt;/QuestionIdentifier&gt;
11
+ &lt;QuestionIdentifier&gt;tweet&#91;content&#93;&lt;/QuestionIdentifier&gt;
12
12
  &lt;FreeText&gt;This is my tweet!&lt;/FreeText&gt;
13
13
  &lt;/Answer&gt;
14
14
  &lt;Answer&gt;
15
+ &lt;QuestionIdentifier&gt;tweet&#91;time&#93;&lt;/QuestionIdentifier&gt;
16
+ &lt;FreeText&gt;12345678&lt;/FreeText&gt;
17
+ &lt;/Answer&gt;
18
+ &lt;Answer&gt;
15
19
  &lt;QuestionIdentifier&gt;Submit&lt;/QuestionIdentifier&gt;
16
20
  &lt;FreeText&gt;Submit&lt;/FreeText&gt;
17
21
  &lt;/Answer&gt;
@@ -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
- - 1
8
- - 1
9
- version: 2.1.1
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-26 00:00:00 -07:00
17
+ date: 2010-06-27 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency