rturk 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -70,7 +70,7 @@ Let's say you have a form at "http://myapp.com/turkers/add_tags" where Turkers c
70
70
  ### Logging
71
71
  Want to see what's going on - enable logging.
72
72
 
73
- RTurk::log.level = Logger::DEBUG
73
+ RTurk::logger.level = Logger::DEBUG
74
74
 
75
75
  ## Nitty Gritty
76
76
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.1
1
+ 2.0.2
data/lib/rturk.rb CHANGED
@@ -16,7 +16,7 @@ module RTurk
16
16
  @host == SANDBOX
17
17
  end
18
18
 
19
- def log
19
+ def logger
20
20
  RTurk::Logger.logger
21
21
  end
22
22
 
@@ -16,7 +16,7 @@ module RTurk
16
16
  @required_params.push(*args)
17
17
  end
18
18
 
19
- def operation(op)
19
+ def set_operation(op)
20
20
  default_params.merge!('Operation' => op)
21
21
  end
22
22
 
@@ -65,7 +65,8 @@ module RTurk
65
65
  validate
66
66
  end
67
67
  check_params
68
- params = self.default_params
68
+ params = {'Operation' => self.class.to_s.gsub('RTurk::', '')}
69
+ params = params.merge(self.default_params)
69
70
  params = to_params.merge(params)
70
71
  response = RTurk.Request(params)
71
72
  parse(response)
@@ -11,7 +11,6 @@
11
11
  module RTurk
12
12
  class ApproveAssignment < Operation
13
13
 
14
- operation 'ApproveAssignment'
15
14
  attr_accessor :assignment_id, :feedback
16
15
  require_params :assignment_id
17
16
 
@@ -0,0 +1,23 @@
1
+ # Operation to block a worker
2
+ #
3
+ # The worker does not see the reason you gave. It's for your records
4
+ # only.
5
+
6
+
7
+ module RTurk
8
+ class BlockWorker < Operation
9
+
10
+ attr_accessor :worker_id, :reason
11
+ require_params :worker_id, :reason
12
+
13
+ def to_params
14
+ {'WorkerId' => self.worker_id,
15
+ 'Reason' => self.reason}
16
+ end
17
+
18
+ end
19
+ def self.BlockWorker(*args)
20
+ RTurk::BlockWorker.create(*args)
21
+ end
22
+
23
+ end
@@ -1,8 +1,6 @@
1
1
  module RTurk
2
2
  class CreateHIT < Operation
3
3
 
4
- operation 'CreateHIT'
5
-
6
4
  attr_accessor :title, :keywords, :description, :reward, :currency, :assignments
7
5
  attr_accessor :lifetime, :duration, :auto_approval, :note, :hit_type_id
8
6
 
@@ -2,7 +2,6 @@
2
2
  module RTurk
3
3
  class DisableHIT < Operation
4
4
 
5
- operation 'DisableHIT'
6
5
  require_params :hit_id
7
6
  attr_accessor :hit_id
8
7
 
@@ -2,7 +2,6 @@
2
2
  module RTurk
3
3
  class DisposeHIT < Operation
4
4
 
5
- operation 'DisposeHIT'
6
5
  require_params :hit_id
7
6
  attr_accessor :hit_id
8
7
 
@@ -1,7 +1,6 @@
1
1
  module RTurk
2
2
  class ForceExpireHIT < Operation
3
3
 
4
- operation 'ForceExpireHIT'
5
4
  require_params :hit_id
6
5
  attr_accessor :hit_id
7
6
 
@@ -1,8 +1,6 @@
1
1
  module RTurk
2
2
  class GetAccountBalance < Operation
3
3
 
4
- operation 'GetAccountBalance'
5
-
6
4
  def parse(xml)
7
5
  RTurk::GetAccountBalanceResponse.new(xml)
8
6
  end
@@ -1,7 +1,6 @@
1
1
  module RTurk
2
2
  class GetAssignmentsForHIT < Operation
3
3
 
4
- operation 'GetAssignmentsForHIT'
5
4
  require_params :hit_id
6
5
 
7
6
  attr_accessor :hit_id, :page_size, :page_number
@@ -1,7 +1,6 @@
1
1
  module RTurk
2
2
  class GetHIT < Operation
3
3
 
4
- operation 'GetHIT'
5
4
  require_params :hit_id
6
5
  attr_accessor :hit_id
7
6
 
@@ -1,7 +1,6 @@
1
1
  module RTurk
2
2
  class GetReviewableHITs < Operation
3
3
 
4
- operation 'GetReviewableHITs'
5
4
  attr_accessor :page_size, :page_number
6
5
 
7
6
  def parse(xml)
@@ -7,7 +7,6 @@ module RTurk
7
7
 
8
8
  class GrantBonus < Operation
9
9
 
10
- operation 'GrantBonus'
11
10
  attr_accessor :assignment_id, :feedback, :worker_id, :amount, :currency
12
11
  require_params :assignment_id, :worker_id, :amount, :feedback
13
12
 
@@ -6,7 +6,6 @@ module RTurk
6
6
 
7
7
  class RejectAssignment < Operation
8
8
 
9
- operation 'RejectAssignment'
10
9
  attr_accessor :assignment_id, :feedback
11
10
  require_params :assignment_id, :feedback
12
11
 
@@ -0,0 +1,23 @@
1
+ # Operation to block a worker
2
+ #
3
+ # The worker does not see the reason you gave. It's for your records
4
+ # only.
5
+
6
+
7
+ module RTurk
8
+ class UnblockWorker < Operation
9
+
10
+ attr_accessor :worker_id, :reason
11
+ require_params :worker_id
12
+
13
+ def to_params
14
+ {'WorkerId' => self.worker_id,
15
+ 'Reason' => self.reason}
16
+ end
17
+
18
+ end
19
+ def self.UnblockWorker(*args)
20
+ RTurk::UnblockWorker.create(*args)
21
+ end
22
+
23
+ end
@@ -30,7 +30,7 @@ module RTurk
30
30
  signature = sign(credentials.secret_key, params['Service'], params['Operation'], params["Timestamp"])
31
31
  params['Signature'] = signature
32
32
  querystring = params.collect { |key, value| [CGI.escape(key.to_s), CGI.escape(value.to_s)].join('=') }.join('&') # order doesn't matter for the actual request
33
- RTurk.log.debug "Sending request:\n\t #{credentials.host}?#{querystring}"
33
+ RTurk.logger.debug "Sending request:\n\t #{credentials.host}?#{querystring}"
34
34
  RestClient.get("#{credentials.host}?#{querystring}")
35
35
  end
36
36
 
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.0.1"
8
+ s.version = "2.0.2"
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{2009-10-26}
12
+ s.date = %q{2009-10-27}
13
13
  s.email = %q{mark@mpercival.com}
14
14
  s.extra_rdoc_files = [
15
15
  "LICENSE",
@@ -41,6 +41,7 @@ Gem::Specification.new do |s|
41
41
  "lib/rturk/macros.rb",
42
42
  "lib/rturk/operation.rb",
43
43
  "lib/rturk/operations/approve_assignment.rb",
44
+ "lib/rturk/operations/block_worker.rb",
44
45
  "lib/rturk/operations/create_hit.rb",
45
46
  "lib/rturk/operations/disable_hit.rb",
46
47
  "lib/rturk/operations/dispose_hit.rb",
@@ -51,6 +52,7 @@ Gem::Specification.new do |s|
51
52
  "lib/rturk/operations/get_reviewable_hits.rb",
52
53
  "lib/rturk/operations/grant_bonus.rb",
53
54
  "lib/rturk/operations/reject_assignment.rb",
55
+ "lib/rturk/operations/unblock_worker.rb",
54
56
  "lib/rturk/requester.rb",
55
57
  "lib/rturk/response.rb",
56
58
  "lib/rturk/responses/create_hit_response.rb",
@@ -68,6 +70,7 @@ Gem::Specification.new do |s|
68
70
  "spec/builders/qualifications_spec.rb",
69
71
  "spec/builders/question_spec.rb",
70
72
  "spec/fake_responses/approve_assignment.xml",
73
+ "spec/fake_responses/block_worker.xml",
71
74
  "spec/fake_responses/create_hit.xml",
72
75
  "spec/fake_responses/disable_hit.xml",
73
76
  "spec/fake_responses/dispose_hit.xml",
@@ -80,8 +83,10 @@ Gem::Specification.new do |s|
80
83
  "spec/fake_responses/grant_bonus.xml",
81
84
  "spec/fake_responses/invalid_credentials.xml",
82
85
  "spec/fake_responses/reject_assignment.xml",
86
+ "spec/fake_responses/unblock_worker.xml",
83
87
  "spec/mturk.sample.yml",
84
88
  "spec/operations/approve_assignment_spec.rb",
89
+ "spec/operations/block_worker_spec.rb",
85
90
  "spec/operations/create_hit_spec.rb",
86
91
  "spec/operations/disable_hit_spec.rb",
87
92
  "spec/operations/dispose_hit_spec.rb",
@@ -92,6 +97,7 @@ Gem::Specification.new do |s|
92
97
  "spec/operations/get_reviewable_hits_spec.rb",
93
98
  "spec/operations/grant_bonus_spec.rb",
94
99
  "spec/operations/reject_assignment_spec.rb",
100
+ "spec/operations/unblock_worker_spec.rb",
95
101
  "spec/requester_spec.rb",
96
102
  "spec/response_spec.rb",
97
103
  "spec/rturk_spec.rb",
@@ -112,6 +118,7 @@ Gem::Specification.new do |s|
112
118
  "spec/builders/qualifications_spec.rb",
113
119
  "spec/builders/question_spec.rb",
114
120
  "spec/operations/approve_assignment_spec.rb",
121
+ "spec/operations/block_worker_spec.rb",
115
122
  "spec/operations/create_hit_spec.rb",
116
123
  "spec/operations/disable_hit_spec.rb",
117
124
  "spec/operations/dispose_hit_spec.rb",
@@ -122,6 +129,7 @@ Gem::Specification.new do |s|
122
129
  "spec/operations/get_reviewable_hits_spec.rb",
123
130
  "spec/operations/grant_bonus_spec.rb",
124
131
  "spec/operations/reject_assignment_spec.rb",
132
+ "spec/operations/unblock_worker_spec.rb",
125
133
  "spec/requester_spec.rb",
126
134
  "spec/response_spec.rb",
127
135
  "spec/rturk_spec.rb",
@@ -0,0 +1,5 @@
1
+ <BlockWorkerResult>
2
+ <Request>
3
+ <IsValid>True</IsValid>
4
+ </Request>
5
+ </BlockWorkerResult>
@@ -0,0 +1,5 @@
1
+ <UnblockWorkerResult>
2
+ <Request>
3
+ <IsValid>True</IsValid>
4
+ </Request>
5
+ </UnblockWorkerResult>
@@ -0,0 +1,26 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
2
+
3
+ describe RTurk::BlockWorker do
4
+
5
+ before(:all) do
6
+ aws = YAML.load(File.open(File.join(SPEC_ROOT, 'mturk.yml')))
7
+ RTurk.setup(aws['AWSAccessKeyId'], aws['AWSAccessKey'], :sandbox => true)
8
+ faker('block_worker', :operation => 'BlockWorker')
9
+ end
10
+
11
+ it "should ensure required params" do
12
+ lambda{RTurk::BlockWorker(:worker_id => "123456789")}.should raise_error RTurk::MissingParameters
13
+ end
14
+
15
+ it "should successfully request the operation" do
16
+ RTurk::Requester.should_receive(:request).once.with(
17
+ hash_including('Operation' => 'BlockWorker'))
18
+ RTurk::BlockWorker(:worker_id => "123456789", :reason => "Really poor work") rescue RTurk::InvalidRequest
19
+ end
20
+
21
+ it "should parse and return the result" do
22
+ RTurk::BlockWorker(:worker_id => "123456789", :reason => "Really poor work").should
23
+ be_a_kind_of RTurk::Response
24
+ end
25
+
26
+ end
@@ -0,0 +1,26 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
2
+
3
+ describe RTurk::UnblockWorker do
4
+
5
+ before(:all) do
6
+ aws = YAML.load(File.open(File.join(SPEC_ROOT, 'mturk.yml')))
7
+ RTurk.setup(aws['AWSAccessKeyId'], aws['AWSAccessKey'], :sandbox => true)
8
+ faker('unblock_worker', :operation => 'UnblockWorker')
9
+ end
10
+
11
+ it "should ensure required params" do
12
+ lambda{RTurk::UnblockWorker(:reason => 'foo')}.should raise_error RTurk::MissingParameters
13
+ end
14
+
15
+ it "should successfully request the operation" do
16
+ RTurk::Requester.should_receive(:request).once.with(
17
+ hash_including('Operation' => 'UnblockWorker'))
18
+ RTurk::UnblockWorker(:worker_id => "123456789", :reason => "Really poor work") rescue RTurk::InvalidRequest
19
+ end
20
+
21
+ it "should parse and return the result" do
22
+ RTurk::UnblockWorker(:worker_id => "123456789", :reason => "Really poor work").should
23
+ be_a_kind_of RTurk::Response
24
+ end
25
+
26
+ 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.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Percival
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-26 00:00:00 -04:00
12
+ date: 2009-10-27 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -48,6 +48,7 @@ files:
48
48
  - lib/rturk/macros.rb
49
49
  - lib/rturk/operation.rb
50
50
  - lib/rturk/operations/approve_assignment.rb
51
+ - lib/rturk/operations/block_worker.rb
51
52
  - lib/rturk/operations/create_hit.rb
52
53
  - lib/rturk/operations/disable_hit.rb
53
54
  - lib/rturk/operations/dispose_hit.rb
@@ -58,6 +59,7 @@ files:
58
59
  - lib/rturk/operations/get_reviewable_hits.rb
59
60
  - lib/rturk/operations/grant_bonus.rb
60
61
  - lib/rturk/operations/reject_assignment.rb
62
+ - lib/rturk/operations/unblock_worker.rb
61
63
  - lib/rturk/requester.rb
62
64
  - lib/rturk/response.rb
63
65
  - lib/rturk/responses/create_hit_response.rb
@@ -75,6 +77,7 @@ files:
75
77
  - spec/builders/qualifications_spec.rb
76
78
  - spec/builders/question_spec.rb
77
79
  - spec/fake_responses/approve_assignment.xml
80
+ - spec/fake_responses/block_worker.xml
78
81
  - spec/fake_responses/create_hit.xml
79
82
  - spec/fake_responses/disable_hit.xml
80
83
  - spec/fake_responses/dispose_hit.xml
@@ -87,8 +90,10 @@ files:
87
90
  - spec/fake_responses/grant_bonus.xml
88
91
  - spec/fake_responses/invalid_credentials.xml
89
92
  - spec/fake_responses/reject_assignment.xml
93
+ - spec/fake_responses/unblock_worker.xml
90
94
  - spec/mturk.sample.yml
91
95
  - spec/operations/approve_assignment_spec.rb
96
+ - spec/operations/block_worker_spec.rb
92
97
  - spec/operations/create_hit_spec.rb
93
98
  - spec/operations/disable_hit_spec.rb
94
99
  - spec/operations/dispose_hit_spec.rb
@@ -99,6 +104,7 @@ files:
99
104
  - spec/operations/get_reviewable_hits_spec.rb
100
105
  - spec/operations/grant_bonus_spec.rb
101
106
  - spec/operations/reject_assignment_spec.rb
107
+ - spec/operations/unblock_worker_spec.rb
102
108
  - spec/requester_spec.rb
103
109
  - spec/response_spec.rb
104
110
  - spec/rturk_spec.rb
@@ -141,6 +147,7 @@ test_files:
141
147
  - spec/builders/qualifications_spec.rb
142
148
  - spec/builders/question_spec.rb
143
149
  - spec/operations/approve_assignment_spec.rb
150
+ - spec/operations/block_worker_spec.rb
144
151
  - spec/operations/create_hit_spec.rb
145
152
  - spec/operations/disable_hit_spec.rb
146
153
  - spec/operations/dispose_hit_spec.rb
@@ -151,6 +158,7 @@ test_files:
151
158
  - spec/operations/get_reviewable_hits_spec.rb
152
159
  - spec/operations/grant_bonus_spec.rb
153
160
  - spec/operations/reject_assignment_spec.rb
161
+ - spec/operations/unblock_worker_spec.rb
154
162
  - spec/requester_spec.rb
155
163
  - spec/response_spec.rb
156
164
  - spec/rturk_spec.rb