rturk 2.0.4 → 2.0.5
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/.gitignore +2 -1
- data/VERSION +1 -1
- data/init.rb +1 -0
- data/lib/rturk.rb +5 -4
- data/lib/rturk/adapters/hit.rb +21 -20
- data/lib/rturk/builders/notification_builder.rb +23 -0
- data/lib/rturk/operation.rb +1 -1
- data/lib/rturk/operations/notify_workers.rb +37 -0
- data/lib/rturk/operations/register_hit_type.rb +17 -12
- data/lib/rturk/operations/send_test_event_notification.rb +17 -0
- data/lib/rturk/operations/set_hit_type_notification.rb +18 -0
- data/lib/rturk/parsers/hit_parser.rb +9 -9
- data/lib/rturk/parsers/responses/get_hit_response.rb +8 -8
- data/lib/rturk/requester.rb +1 -1
- data/rturk.gemspec +16 -2
- data/spec/builders/notification_builder_spec.rb +34 -0
- data/spec/fake_responses/notify_workers.xml +5 -0
- data/spec/operations/notify_workers_spec.rb +61 -0
- data/spec/operations/register_hit_type_spec.rb +11 -7
- data/spec/operations/send_test_event_notification_spec.rb +42 -0
- data/spec/operations/set_hit_type_notification_spec.rb +42 -0
- data/spec/parsers/hit_parser_spec.rb +2 -4
- metadata +16 -2
data/.gitignore
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.0.
|
1
|
+
2.0.5
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'lib', 'rturk')
|
data/lib/rturk.rb
CHANGED
@@ -3,6 +3,9 @@ module RTurk
|
|
3
3
|
|
4
4
|
SANDBOX = 'http://mechanicalturk.sandbox.amazonaws.com/'
|
5
5
|
PRODUCTION = 'http://mechanicalturk.amazonaws.com/'
|
6
|
+
API_VERSION = '2008-08-02'
|
7
|
+
OLD_API_VERSION = '2006-05-05'
|
8
|
+
|
6
9
|
class << self
|
7
10
|
attr_reader :access_key, :secret_key, :host
|
8
11
|
|
@@ -11,17 +14,15 @@ module RTurk
|
|
11
14
|
@secret_key = secret_key
|
12
15
|
@host = opts[:sandbox] ? SANDBOX : PRODUCTION
|
13
16
|
end
|
14
|
-
|
17
|
+
|
15
18
|
def sandbox?
|
16
19
|
@host == SANDBOX
|
17
20
|
end
|
18
|
-
|
21
|
+
|
19
22
|
def logger
|
20
23
|
RTurk::Logger.logger
|
21
24
|
end
|
22
|
-
|
23
25
|
end
|
24
|
-
|
25
26
|
end
|
26
27
|
|
27
28
|
require 'rturk/utilities'
|
data/lib/rturk/adapters/hit.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
module RTurk
|
2
2
|
|
3
3
|
# =The RTurk Hit Adapter
|
4
|
-
#
|
4
|
+
#
|
5
5
|
# Lets us interact with Mechanical Turk without having to know all the operations.
|
6
6
|
#
|
7
7
|
# == Basic usage
|
8
8
|
# @example
|
9
9
|
# require 'rturk'
|
10
|
-
#
|
10
|
+
#
|
11
11
|
# RTurk.setup(YourAWSAccessKeyId, YourAWSAccessKey, :sandbox => true)
|
12
12
|
# hit = RTurk::Hit.create(:title => "Add some tags to a photo") do |hit|
|
13
13
|
# hit.assignments = 2
|
@@ -15,30 +15,29 @@ module RTurk
|
|
15
15
|
# hit.reward = 0.05
|
16
16
|
# hit.qualifications.approval_rate, {:gt => 80}
|
17
17
|
# end
|
18
|
-
#
|
18
|
+
#
|
19
19
|
# hit.url #=> 'http://mturk.amazonaws.com/?group_id=12345678'
|
20
|
-
|
21
|
-
|
20
|
+
|
21
|
+
|
22
22
|
class Hit
|
23
23
|
include RTurk::XMLUtilities
|
24
24
|
|
25
|
-
class << self
|
26
|
-
|
25
|
+
class << self
|
27
26
|
def create(*args, &blk)
|
28
27
|
response = RTurk::CreateHIT(*args, &blk)
|
29
28
|
new(response.hit_id, response)
|
30
29
|
end
|
31
|
-
|
30
|
+
|
32
31
|
def find(id)
|
33
|
-
|
32
|
+
|
34
33
|
end
|
35
|
-
|
34
|
+
|
36
35
|
def all_reviewable
|
37
36
|
RTurk.GetReviewableHITs.hit_ids.inject([]) do |arr, hit_id|
|
38
37
|
arr << new(hit_id); arr
|
39
38
|
end
|
40
39
|
end
|
41
|
-
|
40
|
+
|
42
41
|
def all
|
43
42
|
RTurk.SearchHITs.hits.inject([]) do |arr, hit|
|
44
43
|
arr << new(hit.id, hit); arr;
|
@@ -53,26 +52,28 @@ module RTurk
|
|
53
52
|
@id, @source = id, source
|
54
53
|
end
|
55
54
|
|
55
|
+
# memoing
|
56
56
|
def assignments
|
57
|
-
|
58
|
-
|
59
|
-
|
57
|
+
@assignments ||=
|
58
|
+
RTurk::GetAssignmentsForHIT(:hit_id => self.id).assignments.inject([]) do |arr, assignment|
|
59
|
+
arr << RTurk::Assignment.new(assignment.assignment_id, assignment)
|
60
|
+
end
|
60
61
|
end
|
61
|
-
|
62
|
+
|
62
63
|
def details
|
63
64
|
@details ||= RTurk::GetHIT(:hit_id => self.id)
|
64
65
|
end
|
65
|
-
|
66
|
+
|
66
67
|
def expire!
|
67
68
|
RTurk::ForceExpireHIT(:hit_id => self.id)
|
68
69
|
end
|
69
|
-
|
70
|
+
|
70
71
|
def dispose!
|
71
|
-
RTurk::DisposeHIT(:hit_id => self.id)
|
72
|
+
RTurk::DisposeHIT(:hit_id => self.id)
|
72
73
|
end
|
73
|
-
|
74
|
+
|
74
75
|
def disable!
|
75
|
-
RTurk::DisableHIT(:hit_id => self.id)
|
76
|
+
RTurk::DisableHIT(:hit_id => self.id)
|
76
77
|
end
|
77
78
|
|
78
79
|
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module RTurk
|
2
|
+
Notification = Struct.new(:Destination, :Transport, :Version, :EventType) do
|
3
|
+
extend RTurk::Utilities
|
4
|
+
|
5
|
+
members.each do |member|
|
6
|
+
underscore = underscore(member)
|
7
|
+
alias_method underscore, member
|
8
|
+
alias_method "#{underscore}=", "#{member}="
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_param_hash
|
12
|
+
self.version = RTurk::OLD_API_VERSION # enforce this blindly
|
13
|
+
|
14
|
+
hash = {}
|
15
|
+
missing = []
|
16
|
+
each_pair do |k, v|
|
17
|
+
raise MissingParameters, "Missing parameter for #{k}" if v.nil?
|
18
|
+
hash["Notification.1.#{k}"] = v
|
19
|
+
end
|
20
|
+
hash
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/rturk/operation.rb
CHANGED
@@ -0,0 +1,37 @@
|
|
1
|
+
#########################################################################
|
2
|
+
# Operation to send email to a group of workers. #
|
3
|
+
# #
|
4
|
+
# Caveats: #
|
5
|
+
# - A message can only be send to a maximum of 100 workers at a time. #
|
6
|
+
# - The message length must be 4096 characters or less. #
|
7
|
+
# - The subject length must be 200 characters or less. #
|
8
|
+
#########################################################################
|
9
|
+
|
10
|
+
module RTurk
|
11
|
+
class NotifyWorkers < Operation
|
12
|
+
attr_accessor :worker_ids, :subject, :message_text
|
13
|
+
require_params :worker_ids, :subject, :message_text
|
14
|
+
|
15
|
+
def to_params
|
16
|
+
if worker_ids.length > 100
|
17
|
+
raise ArgumentError, 'Cannot send a message to more than 100 workers at a time.'
|
18
|
+
elsif message_text.length > 4096
|
19
|
+
raise ArgumentError, 'Message cannot be longer than 4096 characters.'
|
20
|
+
elsif subject.length > 200
|
21
|
+
raise ArgumentError, 'Subject cannot be longer than 200 characters.'
|
22
|
+
end
|
23
|
+
|
24
|
+
id_hash = {}
|
25
|
+
worker_ids.each_with_index do |worker_id, index|
|
26
|
+
id_hash["WorkerId.#{index}"] = worker_id
|
27
|
+
end
|
28
|
+
|
29
|
+
{ 'Subject' => self.subject,
|
30
|
+
'MessageText' => self.message_text }.merge(id_hash)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.NotifyWorkers(*args)
|
35
|
+
RTurk::NotifyWorkers.create(*args)
|
36
|
+
end
|
37
|
+
end
|
@@ -35,25 +35,30 @@ module RTurk
|
|
35
35
|
end
|
36
36
|
raise RTurk::MissingParameters, "Parameters: '#{missing_parameters.join(', ')}'" unless missing_parameters.empty?
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
def required_fields
|
40
40
|
[:title, :description, :reward]
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
protected
|
44
|
-
|
45
44
|
def map_params
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
45
|
+
begin
|
46
|
+
keyword_string = keywords.join(', ')
|
47
|
+
rescue NoMethodError
|
48
|
+
keyword_string = keywords.to_s
|
49
|
+
end
|
50
|
+
|
51
|
+
{ 'Title'=>title,
|
52
|
+
'Description' => description,
|
53
|
+
'AssignmentDurationInSeconds' => (duration || 86400),
|
54
|
+
'Reward.Amount' => reward,
|
55
|
+
'Reward.CurrencyCode' => (currency || 'USD'),
|
56
|
+
'Keywords' => keyword_string,
|
57
|
+
'AutoApprovalDelayInSeconds' => auto_approval }
|
53
58
|
end
|
54
59
|
end
|
55
|
-
|
60
|
+
|
56
61
|
def self.RegisterHITType(*args, &blk)
|
57
62
|
RTurk::RegisterHITType.create(*args, &blk)
|
58
63
|
end
|
59
|
-
end
|
64
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module RTurk
|
2
|
+
class SendTestEventNotification < Operation
|
3
|
+
PARAMZ = [:notification, :test_event_type]
|
4
|
+
|
5
|
+
attr_accessor *PARAMZ
|
6
|
+
require_params *PARAMZ
|
7
|
+
|
8
|
+
def to_params
|
9
|
+
{ :TestEventType => self.test_event_type }.
|
10
|
+
merge(self.notification.to_param_hash)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.SendTestEventNotification(*args)
|
15
|
+
RTurk::SendTestEventNotification.create(*args)
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module RTurk
|
2
|
+
class SetHITTypeNotification < Operation
|
3
|
+
PARAMZ = [:hit_type_id, :notification, :active]
|
4
|
+
|
5
|
+
attr_accessor *PARAMZ
|
6
|
+
require_params *PARAMZ
|
7
|
+
|
8
|
+
def to_params
|
9
|
+
{ :HITTypeId => self.hit_type_id,
|
10
|
+
:Active => self.active }.
|
11
|
+
merge(self.notification.to_param_hash)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.SetHITTypeNotification(*args)
|
16
|
+
RTurk::SetHITTypeNotification.create(*args)
|
17
|
+
end
|
18
|
+
end
|
@@ -20,13 +20,13 @@
|
|
20
20
|
# </HIT>
|
21
21
|
|
22
22
|
module RTurk
|
23
|
-
|
23
|
+
|
24
24
|
class HITParser < RTurk::Parser
|
25
|
-
|
26
|
-
attr_reader :id, :type_id, :status, :title, :created_at, :expires_at, :assignments_duration,
|
27
|
-
:reward_amount, :max_assignments, :pending_assignments, :available_assignments,
|
28
|
-
:completed_assignments, :auto_approval_delay
|
29
|
-
|
25
|
+
|
26
|
+
attr_reader :id, :type_id, :status, :title, :created_at, :expires_at, :assignments_duration,
|
27
|
+
:reward_amount, :max_assignments, :pending_assignments, :available_assignments,
|
28
|
+
:completed_assignments, :auto_approval_delay, :keywords
|
29
|
+
|
30
30
|
def initialize(hit_xml)
|
31
31
|
@xml_obj = hit_xml
|
32
32
|
map_content(@xml_obj,
|
@@ -44,7 +44,7 @@ module RTurk
|
|
44
44
|
:completed_assignments => 'NumberOfAssignmentsCompleted',
|
45
45
|
:auto_approval_delay => 'AutoApprovalDelayInSeconds')
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
end
|
49
|
-
|
50
|
-
end
|
49
|
+
|
50
|
+
end
|
@@ -15,7 +15,7 @@
|
|
15
15
|
# <Title>Write a twitter update</Title>
|
16
16
|
# <Description>Simply write a twitter update for me</Description>
|
17
17
|
# <Question><ExternalQuestion xmlns="http://mechanicalturk.amazonaws.com/AWSMechanicalTurkDataSchemas/2006-07-14/ExternalQuestion.xsd">
|
18
|
-
# <ExternalURL>http://s3.amazonaws.com/mpercival.com/newtweet.html?id=foo</ExternalURL>
|
18
|
+
# <ExternalURL>http://s3.amazonaws.com/mpercival.com/newtweet.html?id=foo</ExternalURL>
|
19
19
|
# <FrameHeight>400</FrameHeight>
|
20
20
|
# </ExternalQuestion>
|
21
21
|
# </Question>
|
@@ -43,12 +43,11 @@
|
|
43
43
|
# </GetHITResponse>
|
44
44
|
|
45
45
|
module RTurk
|
46
|
-
|
47
46
|
class GetHITResponse < Response
|
48
|
-
|
49
47
|
attr_reader :hit_id, :type_id, :status, :review_status, :title, :created_at, :expires_at,
|
50
|
-
:assignments_duration, :reward_amount, :max_assignments, :auto_approval_delay
|
51
|
-
|
48
|
+
:assignments_duration, :reward_amount, :max_assignments, :auto_approval_delay,
|
49
|
+
:keywords
|
50
|
+
|
52
51
|
def initialize(response)
|
53
52
|
@raw_xml = response
|
54
53
|
@xml = Nokogiri::XML(@raw_xml)
|
@@ -56,6 +55,7 @@ module RTurk
|
|
56
55
|
map_content(@xml.xpath('//HIT'),
|
57
56
|
:hit_id => 'HITId',
|
58
57
|
:type_id => 'HITTypeId',
|
58
|
+
:keywords => 'Keywords',
|
59
59
|
:status => 'HITStatus',
|
60
60
|
:review_status => 'HITReviewStatus',
|
61
61
|
:title => 'Title',
|
@@ -66,8 +66,8 @@ module RTurk
|
|
66
66
|
:max_assignments => 'MaxAssignments',
|
67
67
|
:auto_approval_delay => 'AutoApprovalDelayInSeconds'
|
68
68
|
)
|
69
|
+
|
70
|
+
@keywords = @keywords.split(', ') if @keywords
|
69
71
|
end
|
70
|
-
|
71
72
|
end
|
72
|
-
|
73
|
-
end
|
73
|
+
end
|
data/lib/rturk/requester.rb
CHANGED
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.
|
8
|
+
s.version = "2.0.5"
|
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{
|
12
|
+
s.date = %q{2010-01-05}
|
13
13
|
s.email = %q{mark@mpercival.com}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"LICENSE",
|
@@ -114,11 +114,13 @@ Gem::Specification.new do |s|
|
|
114
114
|
"examples/mturk.sample.yml",
|
115
115
|
"examples/newtweet.html",
|
116
116
|
"examples/review_answer.rb",
|
117
|
+
"init.rb",
|
117
118
|
"lib/rturk.rb",
|
118
119
|
"lib/rturk/adapter.rb",
|
119
120
|
"lib/rturk/adapters/assignment.rb",
|
120
121
|
"lib/rturk/adapters/hit.rb",
|
121
122
|
"lib/rturk/adapters/worker.rb",
|
123
|
+
"lib/rturk/builders/notification_builder.rb",
|
122
124
|
"lib/rturk/builders/qualification_builder.rb",
|
123
125
|
"lib/rturk/builders/qualifications_builder.rb",
|
124
126
|
"lib/rturk/builders/question_builder.rb",
|
@@ -137,9 +139,12 @@ Gem::Specification.new do |s|
|
|
137
139
|
"lib/rturk/operations/get_hit.rb",
|
138
140
|
"lib/rturk/operations/get_reviewable_hits.rb",
|
139
141
|
"lib/rturk/operations/grant_bonus.rb",
|
142
|
+
"lib/rturk/operations/notify_workers.rb",
|
140
143
|
"lib/rturk/operations/register_hit_type.rb",
|
141
144
|
"lib/rturk/operations/reject_assignment.rb",
|
142
145
|
"lib/rturk/operations/search_hits.rb",
|
146
|
+
"lib/rturk/operations/send_test_event_notification.rb",
|
147
|
+
"lib/rturk/operations/set_hit_type_notification.rb",
|
143
148
|
"lib/rturk/operations/unblock_worker.rb",
|
144
149
|
"lib/rturk/parser.rb",
|
145
150
|
"lib/rturk/parsers/answer_parser.rb",
|
@@ -159,6 +164,7 @@ Gem::Specification.new do |s|
|
|
159
164
|
"rturk.gemspec",
|
160
165
|
"spec/adapters/assignment_spec.rb",
|
161
166
|
"spec/adapters/hit_spec.rb",
|
167
|
+
"spec/builders/notification_builder_spec.rb",
|
162
168
|
"spec/builders/qualification_spec.rb",
|
163
169
|
"spec/builders/qualifications_spec.rb",
|
164
170
|
"spec/builders/question_spec.rb",
|
@@ -175,6 +181,7 @@ Gem::Specification.new do |s|
|
|
175
181
|
"spec/fake_responses/get_reviewable_hits.xml",
|
176
182
|
"spec/fake_responses/grant_bonus.xml",
|
177
183
|
"spec/fake_responses/invalid_credentials.xml",
|
184
|
+
"spec/fake_responses/notify_workers.xml",
|
178
185
|
"spec/fake_responses/register_hit_type.xml",
|
179
186
|
"spec/fake_responses/reject_assignment.xml",
|
180
187
|
"spec/fake_responses/search_hits.xml",
|
@@ -191,8 +198,11 @@ Gem::Specification.new do |s|
|
|
191
198
|
"spec/operations/get_hit_spec.rb",
|
192
199
|
"spec/operations/get_reviewable_hits_spec.rb",
|
193
200
|
"spec/operations/grant_bonus_spec.rb",
|
201
|
+
"spec/operations/notify_workers_spec.rb",
|
194
202
|
"spec/operations/register_hit_type_spec.rb",
|
195
203
|
"spec/operations/reject_assignment_spec.rb",
|
204
|
+
"spec/operations/send_test_event_notification_spec.rb",
|
205
|
+
"spec/operations/set_hit_type_notification_spec.rb",
|
196
206
|
"spec/operations/unblock_worker_spec.rb",
|
197
207
|
"spec/parsers/answer_parser_spec.rb",
|
198
208
|
"spec/parsers/hit_parser_spec.rb",
|
@@ -211,6 +221,7 @@ Gem::Specification.new do |s|
|
|
211
221
|
s.test_files = [
|
212
222
|
"spec/adapters/assignment_spec.rb",
|
213
223
|
"spec/adapters/hit_spec.rb",
|
224
|
+
"spec/builders/notification_builder_spec.rb",
|
214
225
|
"spec/builders/qualification_spec.rb",
|
215
226
|
"spec/builders/qualifications_spec.rb",
|
216
227
|
"spec/builders/question_spec.rb",
|
@@ -225,8 +236,11 @@ Gem::Specification.new do |s|
|
|
225
236
|
"spec/operations/get_hit_spec.rb",
|
226
237
|
"spec/operations/get_reviewable_hits_spec.rb",
|
227
238
|
"spec/operations/grant_bonus_spec.rb",
|
239
|
+
"spec/operations/notify_workers_spec.rb",
|
228
240
|
"spec/operations/register_hit_type_spec.rb",
|
229
241
|
"spec/operations/reject_assignment_spec.rb",
|
242
|
+
"spec/operations/send_test_event_notification_spec.rb",
|
243
|
+
"spec/operations/set_hit_type_notification_spec.rb",
|
230
244
|
"spec/operations/unblock_worker_spec.rb",
|
231
245
|
"spec/parsers/answer_parser_spec.rb",
|
232
246
|
"spec/parsers/hit_parser_spec.rb",
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
2
|
+
|
3
|
+
|
4
|
+
describe RTurk::Notification do
|
5
|
+
before(:each) do
|
6
|
+
@notification = RTurk::Notification.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should not allow extra parameters" do
|
10
|
+
lambda {
|
11
|
+
@notification[:Bananas]
|
12
|
+
}.should raise_error NameError
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "#to_param_hash" do
|
16
|
+
it "should not allow for empty params" do
|
17
|
+
lambda {
|
18
|
+
@notification.to_param_hash
|
19
|
+
}.should raise_error RTurk::MissingParameters
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should return a REST-friendly hash" do
|
23
|
+
@notification.destination = 'foo'
|
24
|
+
@notification.transport = 'bar'
|
25
|
+
@notification.event_type = 'mumble'
|
26
|
+
|
27
|
+
@notification.to_param_hash.should ==
|
28
|
+
{ "Notification.1.Destination" => 'foo',
|
29
|
+
"Notification.1.Transport" => 'bar',
|
30
|
+
"Notification.1.Version" => RTurk::OLD_API_VERSION,
|
31
|
+
"Notification.1.EventType" => 'mumble' }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
2
|
+
|
3
|
+
describe RTurk::NotifyWorkers do
|
4
|
+
before(:each) do
|
5
|
+
@lambda = lambda do
|
6
|
+
begin
|
7
|
+
RTurk::NotifyWorkers(:worker_ids => [*1..100],
|
8
|
+
:subject => 'Return of the Mack',
|
9
|
+
:message_text => 'Mark Morrison, kicking up the jams in 1996')
|
10
|
+
rescue RTurk::InvalidRequest
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
before(:all) do
|
16
|
+
aws = YAML.load(File.open(File.join(SPEC_ROOT, 'mturk.yml')))
|
17
|
+
RTurk.setup(aws['AWSAccessKeyId'], aws['AWSAccessKey'], :sandbox => true)
|
18
|
+
faker('notify_workers', :operation => 'NotifyWorkers')
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should ensure required params' do
|
22
|
+
lambda {
|
23
|
+
RTurk::NotifyWorkers(:subject => 'peruvian mcwallball')
|
24
|
+
}.should raise_error RTurk::MissingParameters
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should successfully request the operation' do
|
28
|
+
RTurk::Requester.should_receive(:request).once.with(
|
29
|
+
hash_including('Operation' => 'NotifyWorkers'))
|
30
|
+
|
31
|
+
@lambda.call
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should parse and return the result' do
|
35
|
+
@lambda.call.should be_a_kind_of RTurk::Response
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should not allow more than 100 worker ids' do
|
39
|
+
lambda {
|
40
|
+
RTurk.NotifyWorkers(:worker_ids => [*1..1000],
|
41
|
+
:subject => 'BOOM',
|
42
|
+
:message_text => 'SHAKA LAKA')
|
43
|
+
}.should raise_error(ArgumentError, 'Cannot send a message to more than 100 workers at a time.')
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should not allow for a message longer than 4096 characters' do
|
47
|
+
lambda {
|
48
|
+
RTurk.NotifyWorkers(:worker_ids => [*1..100],
|
49
|
+
:subject => 'BOOM',
|
50
|
+
:message_text => '!' * 4097)
|
51
|
+
}.should raise_error(ArgumentError, 'Message cannot be longer than 4096 characters.')
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should not allow for a subject longer than 200 characters' do
|
55
|
+
lambda {
|
56
|
+
RTurk.NotifyWorkers(:worker_ids => [*1..100],
|
57
|
+
:subject => '!' * 201,
|
58
|
+
:message_text => 'WINK')
|
59
|
+
}.should raise_error(ArgumentError, 'Subject cannot be longer than 200 characters.')
|
60
|
+
end
|
61
|
+
end
|
@@ -7,16 +7,20 @@ describe RTurk::RegisterHITType do
|
|
7
7
|
RTurk.setup(aws['AWSAccessKeyId'], aws['AWSAccessKey'], :sandbox => true)
|
8
8
|
FakeWeb.clean_registry
|
9
9
|
faker('register_hit_type', :operation => "RegisterHITType")
|
10
|
-
end
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
11
|
+
@lambda = lambda do
|
12
|
+
response = RTurk::RegisterHITType(:title => "Look at some pictures from 4Chan") do |hit|
|
13
|
+
hit.description = "foo"
|
14
|
+
hit.reward = 0.05
|
15
|
+
hit.qualifications.add(:adult, true)
|
16
|
+
end
|
17
17
|
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should return a CreateHITResponse after the request" do
|
22
|
+
response = @lambda.call
|
18
23
|
response.is_a?(RTurk::RegisterHITTypeResponse).should be_true
|
19
24
|
response.type_id.should == 'KZ3GKTRXBWGYX8WXBW60'
|
20
25
|
end
|
21
|
-
|
22
26
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
2
|
+
|
3
|
+
describe RTurk::SendTestEventNotification do
|
4
|
+
before(:each) do
|
5
|
+
@lambda = lambda do
|
6
|
+
n = RTurk::Notification.new
|
7
|
+
n.transport = 'foo'
|
8
|
+
n.destination = 'bar'
|
9
|
+
n.event_type = 'baz'
|
10
|
+
|
11
|
+
begin
|
12
|
+
RTurk::SendTestEventNotification(:test_event_type => 'foo',
|
13
|
+
:notification => n)
|
14
|
+
rescue RTurk::InvalidRequest
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
before(:all) do
|
20
|
+
aws = YAML.load(File.open(File.join(SPEC_ROOT, 'mturk.yml')))
|
21
|
+
RTurk.setup(aws['AWSAccessKeyId'], aws['AWSAccessKey'], :sandbox => true)
|
22
|
+
faker('notify_workers', :operation => 'SendTestEventNotification')
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should ensure required params' do
|
26
|
+
lambda {
|
27
|
+
RTurk::SetHITTypeNotification(:subject => 'peruvian mcwallball')
|
28
|
+
}.should raise_error RTurk::MissingParameters
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should successfully request the operation' do
|
32
|
+
RTurk::Requester.should_receive(:request).once.with(
|
33
|
+
hash_including('Operation' => 'SendTestEventNotification'))
|
34
|
+
|
35
|
+
@lambda.call
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should parse and return the result' do
|
39
|
+
@lambda.call.should be_a_kind_of RTurk::Response
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
2
|
+
|
3
|
+
describe RTurk::SetHITTypeNotification do
|
4
|
+
before(:each) do
|
5
|
+
@lambda = lambda do
|
6
|
+
n = RTurk::Notification.new
|
7
|
+
n.transport = 'foo'
|
8
|
+
n.destination = 'bar'
|
9
|
+
n.event_type = 'baz'
|
10
|
+
|
11
|
+
begin
|
12
|
+
RTurk::SetHITTypeNotification(:hit_type_id => 'foo',
|
13
|
+
:notification => n,
|
14
|
+
:active => true)
|
15
|
+
rescue RTurk::InvalidRequest
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
before(:all) do
|
21
|
+
aws = YAML.load(File.open(File.join(SPEC_ROOT, 'mturk.yml')))
|
22
|
+
RTurk.setup(aws['AWSAccessKeyId'], aws['AWSAccessKey'], :sandbox => true)
|
23
|
+
faker('notify_workers', :operation => 'SetHITTypeNotification')
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should ensure required params' do
|
27
|
+
lambda {
|
28
|
+
RTurk::SetHITTypeNotification(:subject => 'peruvian mcwallball')
|
29
|
+
}.should raise_error RTurk::MissingParameters
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should successfully request the operation' do
|
33
|
+
RTurk::Requester.should_receive(:request).once.with(
|
34
|
+
hash_including('Operation' => 'SetHITTypeNotification'))
|
35
|
+
|
36
|
+
@lambda.call
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should parse and return the result' do
|
40
|
+
@lambda.call.should be_a_kind_of RTurk::Response
|
41
|
+
end
|
42
|
+
end
|
@@ -30,12 +30,10 @@ describe RTurk::HITParser do
|
|
30
30
|
@hit = RTurk::HITParser.new(@hit_xml.children)
|
31
31
|
end
|
32
32
|
|
33
|
-
it "should parse
|
33
|
+
it "should parse an answer" do
|
34
34
|
@hit.id.should eql('ZZRZPTY4ERDZWJ868JCZ')
|
35
35
|
@hit.type_id.should eql('NYVZTQ1QVKJZXCYZCZVZ')
|
36
36
|
@hit.status.should eql('Assignable')
|
37
37
|
@hit.reward_amount.should eql(5.00)
|
38
38
|
end
|
39
|
-
|
40
|
-
|
41
|
-
end
|
39
|
+
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.
|
4
|
+
version: 2.0.5
|
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:
|
12
|
+
date: 2010-01-05 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -121,11 +121,13 @@ files:
|
|
121
121
|
- examples/mturk.sample.yml
|
122
122
|
- examples/newtweet.html
|
123
123
|
- examples/review_answer.rb
|
124
|
+
- init.rb
|
124
125
|
- lib/rturk.rb
|
125
126
|
- lib/rturk/adapter.rb
|
126
127
|
- lib/rturk/adapters/assignment.rb
|
127
128
|
- lib/rturk/adapters/hit.rb
|
128
129
|
- lib/rturk/adapters/worker.rb
|
130
|
+
- lib/rturk/builders/notification_builder.rb
|
129
131
|
- lib/rturk/builders/qualification_builder.rb
|
130
132
|
- lib/rturk/builders/qualifications_builder.rb
|
131
133
|
- lib/rturk/builders/question_builder.rb
|
@@ -144,9 +146,12 @@ files:
|
|
144
146
|
- lib/rturk/operations/get_hit.rb
|
145
147
|
- lib/rturk/operations/get_reviewable_hits.rb
|
146
148
|
- lib/rturk/operations/grant_bonus.rb
|
149
|
+
- lib/rturk/operations/notify_workers.rb
|
147
150
|
- lib/rturk/operations/register_hit_type.rb
|
148
151
|
- lib/rturk/operations/reject_assignment.rb
|
149
152
|
- lib/rturk/operations/search_hits.rb
|
153
|
+
- lib/rturk/operations/send_test_event_notification.rb
|
154
|
+
- lib/rturk/operations/set_hit_type_notification.rb
|
150
155
|
- lib/rturk/operations/unblock_worker.rb
|
151
156
|
- lib/rturk/parser.rb
|
152
157
|
- lib/rturk/parsers/answer_parser.rb
|
@@ -166,6 +171,7 @@ files:
|
|
166
171
|
- rturk.gemspec
|
167
172
|
- spec/adapters/assignment_spec.rb
|
168
173
|
- spec/adapters/hit_spec.rb
|
174
|
+
- spec/builders/notification_builder_spec.rb
|
169
175
|
- spec/builders/qualification_spec.rb
|
170
176
|
- spec/builders/qualifications_spec.rb
|
171
177
|
- spec/builders/question_spec.rb
|
@@ -182,6 +188,7 @@ files:
|
|
182
188
|
- spec/fake_responses/get_reviewable_hits.xml
|
183
189
|
- spec/fake_responses/grant_bonus.xml
|
184
190
|
- spec/fake_responses/invalid_credentials.xml
|
191
|
+
- spec/fake_responses/notify_workers.xml
|
185
192
|
- spec/fake_responses/register_hit_type.xml
|
186
193
|
- spec/fake_responses/reject_assignment.xml
|
187
194
|
- spec/fake_responses/search_hits.xml
|
@@ -198,8 +205,11 @@ files:
|
|
198
205
|
- spec/operations/get_hit_spec.rb
|
199
206
|
- spec/operations/get_reviewable_hits_spec.rb
|
200
207
|
- spec/operations/grant_bonus_spec.rb
|
208
|
+
- spec/operations/notify_workers_spec.rb
|
201
209
|
- spec/operations/register_hit_type_spec.rb
|
202
210
|
- spec/operations/reject_assignment_spec.rb
|
211
|
+
- spec/operations/send_test_event_notification_spec.rb
|
212
|
+
- spec/operations/set_hit_type_notification_spec.rb
|
203
213
|
- spec/operations/unblock_worker_spec.rb
|
204
214
|
- spec/parsers/answer_parser_spec.rb
|
205
215
|
- spec/parsers/hit_parser_spec.rb
|
@@ -240,6 +250,7 @@ summary: Mechanical Turk API Wrapper
|
|
240
250
|
test_files:
|
241
251
|
- spec/adapters/assignment_spec.rb
|
242
252
|
- spec/adapters/hit_spec.rb
|
253
|
+
- spec/builders/notification_builder_spec.rb
|
243
254
|
- spec/builders/qualification_spec.rb
|
244
255
|
- spec/builders/qualifications_spec.rb
|
245
256
|
- spec/builders/question_spec.rb
|
@@ -254,8 +265,11 @@ test_files:
|
|
254
265
|
- spec/operations/get_hit_spec.rb
|
255
266
|
- spec/operations/get_reviewable_hits_spec.rb
|
256
267
|
- spec/operations/grant_bonus_spec.rb
|
268
|
+
- spec/operations/notify_workers_spec.rb
|
257
269
|
- spec/operations/register_hit_type_spec.rb
|
258
270
|
- spec/operations/reject_assignment_spec.rb
|
271
|
+
- spec/operations/send_test_event_notification_spec.rb
|
272
|
+
- spec/operations/set_hit_type_notification_spec.rb
|
259
273
|
- spec/operations/unblock_worker_spec.rb
|
260
274
|
- spec/parsers/answer_parser_spec.rb
|
261
275
|
- spec/parsers/hit_parser_spec.rb
|