rturk 2.3.3 → 2.3.4

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.
@@ -0,0 +1,3 @@
1
+ 2.3.4
2
+ -----
3
+ * Added bonus_payments to Assignment and HIT for auditing [dbalatero]
data/Rakefile CHANGED
@@ -22,7 +22,7 @@ begin
22
22
  gem.add_dependency('nokogiri', '>= 1.4.1')
23
23
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
24
24
  end
25
-
25
+ Jeweler::GemcutterTasks.new
26
26
  rescue LoadError
27
27
  puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
28
28
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.3.3
1
+ 2.3.4
@@ -8,6 +8,10 @@ module RTurk
8
8
  @id, @source = id, source
9
9
  end
10
10
 
11
+ def bonus_payments
12
+ RTurk::GetBonusPayments(:assignment_id => id).payments
13
+ end
14
+
11
15
  def approve!(feedback = nil)
12
16
  RTurk::ApproveAssignment(:assignment_id => self.id, :feedback => feedback)
13
17
  end
@@ -81,6 +81,10 @@ module RTurk
81
81
  RTurk::ForceExpireHIT(:hit_id => self.id)
82
82
  end
83
83
 
84
+ def bonus_payments
85
+ RTurk::GetBonusPayments(:hit_id => id).payments
86
+ end
87
+
84
88
  def dispose!
85
89
  RTurk::DisposeHIT(:hit_id => self.id)
86
90
  end
@@ -105,8 +109,5 @@ module RTurk
105
109
  self.details.send(method)
106
110
  end
107
111
  end
108
-
109
-
110
112
  end
111
-
112
113
  end
@@ -0,0 +1,26 @@
1
+ module RTurk
2
+ class GetBonusPayments < Operation
3
+ attr_accessor :hit_id, :assignment_id, :page_size,
4
+ :page_number
5
+
6
+ def parse(xml)
7
+ GetBonusPaymentsResponse.new(xml)
8
+ end
9
+
10
+ def to_params
11
+ params = {
12
+ 'PageSize' => (page_size || 100),
13
+ 'PageNumber' => (page_number || 1)
14
+ }
15
+
16
+ params['HITId'] = hit_id if hit_id
17
+ params['AssignmentId'] = assignment_id if assignment_id
18
+
19
+ params
20
+ end
21
+ end
22
+
23
+ def self.GetBonusPayments(*args, &block)
24
+ RTurk::GetBonusPayments.create(*args, &block)
25
+ end
26
+ end
@@ -0,0 +1,16 @@
1
+ module RTurk
2
+ class BonusPaymentParser < RTurk::Parser
3
+ attr_reader :assignment_id, :bonus_amount, :currency_code,
4
+ :reason, :grant_time
5
+
6
+ def initialize(payment_xml)
7
+ @xml_obj = payment_xml
8
+ map_content(@xml_obj,
9
+ :assignment_id => 'AssignmentId',
10
+ :bonus_amount => 'BonusAmount/Amount',
11
+ :currency_code => 'BonusAmount/CurrencyCode',
12
+ :reason => 'Reason',
13
+ :grant_time => 'GrantTime')
14
+ end
15
+ end
16
+ end
@@ -44,7 +44,5 @@ module RTurk
44
44
  :completed_assignments => 'NumberOfAssignmentsCompleted',
45
45
  :auto_approval_delay => 'AutoApprovalDelayInSeconds')
46
46
  end
47
-
48
47
  end
49
-
50
48
  end
@@ -0,0 +1,9 @@
1
+ module RTurk
2
+ class GetBonusPaymentsResponse < Response
3
+ def payments
4
+ @payments ||= @xml.xpath('//BonusPayment').map do |payment_xml|
5
+ BonusPaymentParser.new(payment_xml)
6
+ end
7
+ end
8
+ end
9
+ 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.3.3"
8
+ s.version = "2.3.4"
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-11-17}
12
+ s.date = %q{2010-11-18}
13
13
  s.email = %q{mark@mpercival.com}
14
14
  s.extra_rdoc_files = [
15
15
  "LICENSE",
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
19
19
  ".gitignore",
20
20
  ".gitmodules",
21
21
  ".yardoc",
22
+ "CHANGELOG.markdown",
22
23
  "Gemfile",
23
24
  "LICENSE",
24
25
  "README.markdown",
@@ -141,6 +142,7 @@ Gem::Specification.new do |s|
141
142
  "lib/rturk/operations/force_expire_hit.rb",
142
143
  "lib/rturk/operations/get_account_balance.rb",
143
144
  "lib/rturk/operations/get_assignments_for_hit.rb",
145
+ "lib/rturk/operations/get_bonus_payments.rb",
144
146
  "lib/rturk/operations/get_hit.rb",
145
147
  "lib/rturk/operations/get_qualification_type.rb",
146
148
  "lib/rturk/operations/get_qualifications_for_qualification_type.rb",
@@ -158,12 +160,14 @@ Gem::Specification.new do |s|
158
160
  "lib/rturk/parser.rb",
159
161
  "lib/rturk/parsers/answer_parser.rb",
160
162
  "lib/rturk/parsers/assignment_parser.rb",
163
+ "lib/rturk/parsers/bonus_payment_parser.rb",
161
164
  "lib/rturk/parsers/hit_parser.rb",
162
165
  "lib/rturk/parsers/qualification_parser.rb",
163
166
  "lib/rturk/parsers/response.rb",
164
167
  "lib/rturk/parsers/responses/create_hit_response.rb",
165
168
  "lib/rturk/parsers/responses/get_account_balance_response.rb",
166
169
  "lib/rturk/parsers/responses/get_assignments_for_hit_response.rb",
170
+ "lib/rturk/parsers/responses/get_bonus_payments_response.rb",
167
171
  "lib/rturk/parsers/responses/get_hit_response.rb",
168
172
  "lib/rturk/parsers/responses/get_qualification_type_response.rb",
169
173
  "lib/rturk/parsers/responses/get_qualifications_for_qualification_type_response.rb",
@@ -193,6 +197,7 @@ Gem::Specification.new do |s|
193
197
  "spec/fake_responses/get_account_balance.xml",
194
198
  "spec/fake_responses/get_assignments.xml",
195
199
  "spec/fake_responses/get_assignments_multiple.xml",
200
+ "spec/fake_responses/get_bonus_payments.xml",
196
201
  "spec/fake_responses/get_hit.xml",
197
202
  "spec/fake_responses/get_qualification_type.xml",
198
203
  "spec/fake_responses/get_qualifications_for_qualification_type.xml",
@@ -219,6 +224,7 @@ Gem::Specification.new do |s|
219
224
  "spec/operations/force_expire_hit_spec.rb",
220
225
  "spec/operations/get_account_balance_spec.rb",
221
226
  "spec/operations/get_assignments_spec.rb",
227
+ "spec/operations/get_bonus_payments_spec.rb",
222
228
  "spec/operations/get_hit_spec.rb",
223
229
  "spec/operations/get_qualification_type_spec.rb",
224
230
  "spec/operations/get_qualifications_for_qualification_type_spec.rb",
@@ -265,6 +271,7 @@ Gem::Specification.new do |s|
265
271
  "spec/operations/force_expire_hit_spec.rb",
266
272
  "spec/operations/get_account_balance_spec.rb",
267
273
  "spec/operations/get_assignments_spec.rb",
274
+ "spec/operations/get_bonus_payments_spec.rb",
268
275
  "spec/operations/get_hit_spec.rb",
269
276
  "spec/operations/get_qualification_type_spec.rb",
270
277
  "spec/operations/get_qualifications_for_qualification_type_spec.rb",
@@ -0,0 +1,13 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
2
+
3
+ describe RTurk::Assignment do
4
+ describe "#bonus_payments" do
5
+ it "should call GetBonusPayments with the assignment_id" do
6
+ result = mock('result', :payments => [1, 2, 3])
7
+ hit = RTurk::Assignment.new(123456)
8
+ RTurk.should_receive(:GetBonusPayments).
9
+ with(:assignment_id => 123456).and_return(result)
10
+ hit.bonus_payments.should == result.payments
11
+ end
12
+ end
13
+ end
@@ -18,6 +18,16 @@ describe "HIT adapter" do
18
18
  it "should let us create a hit" do
19
19
  RTurk::Hit.create(:title => 'foo', :description => 'do foo', :question => 'http://mpercival.com', :reward => 0.05)
20
20
  end
21
+
22
+ describe "#bonus_payments" do
23
+ it "should call GetBonusPayments with the hit_id" do
24
+ result = mock('result', :payments => [1, 2, 3])
25
+ hit = RTurk::Hit.new(12345)
26
+ RTurk.should_receive(:GetBonusPayments).
27
+ with(:hit_id => 12345).and_return(result)
28
+ hit.bonus_payments.should == result.payments
29
+ end
30
+ end
21
31
 
22
32
  it "should retrieve all the details of a HIT with find" do
23
33
  proxy_hit = RTurk::Hit.new(12345)
@@ -0,0 +1,2 @@
1
+ <?xml version="1.0"?>
2
+ <GetBonusPaymentsResponse><OperationRequest><RequestId>2851062f-f1a1-46b4-9aa0-268906aef381</RequestId></OperationRequest><GetBonusPaymentsResult><Request><IsValid>True</IsValid></Request><NumResults>3</NumResults><TotalNumResults>3</TotalNumResults><PageNumber>1</PageNumber><BonusPayment><WorkerId>AGDRU4D1VTQLB</WorkerId><BonusAmount><Amount>0.04</Amount><CurrencyCode>USD</CurrencyCode><FormattedPrice>$0.04</FormattedPrice></BonusAmount><AssignmentId>180E4LY5TVT3R8QIIGL8GNEZWCF0UF</AssignmentId><Reason>Congrats! You earned a $0.04 bonus!</Reason><GrantTime>2010-09-17T20:16:40Z</GrantTime></BonusPayment><BonusPayment><WorkerId>A2UMLFMF60AX21</WorkerId><BonusAmount><Amount>0.04</Amount><CurrencyCode>USD</CurrencyCode><FormattedPrice>$0.04</FormattedPrice></BonusAmount><AssignmentId>199HR1YM20ZMAFPXZF8OCEGRF8BHQT</AssignmentId><Reason>Congrats! You earned a $0.04 bonus!</Reason><GrantTime>2010-09-17T20:16:41Z</GrantTime></BonusPayment><BonusPayment><WorkerId>A3FUPDYEZ3Z67F</WorkerId><BonusAmount><Amount>0.04</Amount><CurrencyCode>USD</CurrencyCode><FormattedPrice>$0.04</FormattedPrice></BonusAmount><AssignmentId>10NJ8OOK1GQKTFA5UU0RQDWISW81GL</AssignmentId><Reason>Congrats! You earned a $0.04 bonus!</Reason><GrantTime>2010-09-17T20:16:41Z</GrantTime></BonusPayment></GetBonusPaymentsResult></GetBonusPaymentsResponse>
@@ -1,7 +1,6 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
2
2
 
3
3
  describe RTurk::GetAssignmentsForHIT do
4
-
5
4
  before(:all) do
6
5
  aws = YAML.load(File.open(File.join(SPEC_ROOT, 'mturk.yml')))
7
6
  RTurk.setup(aws['AWSAccessKeyId'], aws['AWSAccessKey'], :sandbox => true)
@@ -18,7 +17,6 @@ describe RTurk::GetAssignmentsForHIT do
18
17
  end
19
18
 
20
19
  context "an HIT with one assignment" do
21
-
22
20
  before(:all) do
23
21
  FakeWeb.clean_registry
24
22
  faker('get_assignments', :operation => 'GetAssignmentsForHIT')
@@ -28,9 +26,8 @@ describe RTurk::GetAssignmentsForHIT do
28
26
  assignments = RTurk::GetAssignmentsForHIT(:hit_id => "abcd").assignments
29
27
  assignments.first.answers['tweet'].should eql("This is my tweet!")
30
28
  end
31
-
32
29
  end
33
-
30
+
34
31
  context "an HIT with multiple assignment" do
35
32
 
36
33
  before(:all) do
@@ -42,7 +39,5 @@ describe RTurk::GetAssignmentsForHIT do
42
39
  assignments = RTurk::GetAssignmentsForHIT(:hit_id => "abcd").assignments
43
40
  assignments.first.answers['tweet'].should eql("This is my tweet!")
44
41
  end
45
-
46
42
  end
47
-
48
43
  end
@@ -0,0 +1,35 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
2
+
3
+ describe RTurk::GetBonusPayments 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
+ context "a HIT with multiple payments" do
10
+ before(:all) do
11
+ FakeWeb.clean_registry
12
+ faker('get_bonus_payments', :operation => 'GetBonusPayments')
13
+
14
+ @response = RTurk::GetBonusPayments(:hit_id => 'fdsa')
15
+ end
16
+
17
+ it "should return 3 payments" do
18
+ @response.payments.should have(3).things
19
+ end
20
+
21
+ it "should parse each payment correctly" do
22
+ payment = @response.payments.first
23
+ payment.bonus_amount.should == 0.04
24
+ payment.currency_code.should == 'USD'
25
+ payment.assignment_id.should == '180E4LY5TVT3R8QIIGL8GNEZWCF0UF'
26
+ payment.reason.should == "Congrats! You earned a $0.04 bonus!"
27
+ payment.grant_time.should < Time.now
28
+ end
29
+
30
+ it "should have unique assignment IDs" do
31
+ ids = @response.payments.collect { |p| p.assignment_id }.uniq
32
+ ids.should have(3).things
33
+ end
34
+ end
35
+ end
data/spec/spec_helper.rb CHANGED
@@ -5,13 +5,13 @@ require 'rubygems'
5
5
  require 'spec'
6
6
  require 'fakeweb'
7
7
  require 'yaml'
8
+
8
9
  module FakeWeb
9
10
  class Registry
10
11
  # Comment out this override if you're using a quantum computer
11
12
  def variations_of_uri_as_strings(uri)
12
13
  [uri.to_s]
13
- end
14
-
14
+ end
15
15
  end
16
16
  end
17
17
 
@@ -37,4 +37,4 @@ end
37
37
 
38
38
  Spec::Runner.configure do |config|
39
39
 
40
- end
40
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rturk
3
3
  version: !ruby/object:Gem::Version
4
- hash: 5
4
+ hash: 11
5
5
  prerelease: false
6
6
  segments:
7
7
  - 2
8
8
  - 3
9
- - 3
10
- version: 2.3.3
9
+ - 4
10
+ version: 2.3.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Mark Percival
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-17 00:00:00 -08:00
18
+ date: 2010-11-18 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -63,6 +63,7 @@ files:
63
63
  - .gitignore
64
64
  - .gitmodules
65
65
  - .yardoc
66
+ - CHANGELOG.markdown
66
67
  - Gemfile
67
68
  - LICENSE
68
69
  - README.markdown
@@ -185,6 +186,7 @@ files:
185
186
  - lib/rturk/operations/force_expire_hit.rb
186
187
  - lib/rturk/operations/get_account_balance.rb
187
188
  - lib/rturk/operations/get_assignments_for_hit.rb
189
+ - lib/rturk/operations/get_bonus_payments.rb
188
190
  - lib/rturk/operations/get_hit.rb
189
191
  - lib/rturk/operations/get_qualification_type.rb
190
192
  - lib/rturk/operations/get_qualifications_for_qualification_type.rb
@@ -202,12 +204,14 @@ files:
202
204
  - lib/rturk/parser.rb
203
205
  - lib/rturk/parsers/answer_parser.rb
204
206
  - lib/rturk/parsers/assignment_parser.rb
207
+ - lib/rturk/parsers/bonus_payment_parser.rb
205
208
  - lib/rturk/parsers/hit_parser.rb
206
209
  - lib/rturk/parsers/qualification_parser.rb
207
210
  - lib/rturk/parsers/response.rb
208
211
  - lib/rturk/parsers/responses/create_hit_response.rb
209
212
  - lib/rturk/parsers/responses/get_account_balance_response.rb
210
213
  - lib/rturk/parsers/responses/get_assignments_for_hit_response.rb
214
+ - lib/rturk/parsers/responses/get_bonus_payments_response.rb
211
215
  - lib/rturk/parsers/responses/get_hit_response.rb
212
216
  - lib/rturk/parsers/responses/get_qualification_type_response.rb
213
217
  - lib/rturk/parsers/responses/get_qualifications_for_qualification_type_response.rb
@@ -237,6 +241,7 @@ files:
237
241
  - spec/fake_responses/get_account_balance.xml
238
242
  - spec/fake_responses/get_assignments.xml
239
243
  - spec/fake_responses/get_assignments_multiple.xml
244
+ - spec/fake_responses/get_bonus_payments.xml
240
245
  - spec/fake_responses/get_hit.xml
241
246
  - spec/fake_responses/get_qualification_type.xml
242
247
  - spec/fake_responses/get_qualifications_for_qualification_type.xml
@@ -263,6 +268,7 @@ files:
263
268
  - spec/operations/force_expire_hit_spec.rb
264
269
  - spec/operations/get_account_balance_spec.rb
265
270
  - spec/operations/get_assignments_spec.rb
271
+ - spec/operations/get_bonus_payments_spec.rb
266
272
  - spec/operations/get_hit_spec.rb
267
273
  - spec/operations/get_qualification_type_spec.rb
268
274
  - spec/operations/get_qualifications_for_qualification_type_spec.rb
@@ -337,6 +343,7 @@ test_files:
337
343
  - spec/operations/force_expire_hit_spec.rb
338
344
  - spec/operations/get_account_balance_spec.rb
339
345
  - spec/operations/get_assignments_spec.rb
346
+ - spec/operations/get_bonus_payments_spec.rb
340
347
  - spec/operations/get_hit_spec.rb
341
348
  - spec/operations/get_qualification_type_spec.rb
342
349
  - spec/operations/get_qualifications_for_qualification_type_spec.rb