rturk 2.1.0 → 2.1.1

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.0
1
+ 2.1.1
@@ -1,5 +1,6 @@
1
1
  module RTurk
2
2
  Notification = Struct.new(:Destination, :Transport, :Version, :EventType) do
3
+ # EventType can be a single string or an array of strings
3
4
  extend RTurk::Utilities
4
5
 
5
6
  members.each do |member|
@@ -15,7 +16,13 @@ module RTurk
15
16
  missing = []
16
17
  each_pair do |k, v|
17
18
  raise MissingParameters, "Missing parameter for #{k}" if v.nil?
18
- hash["Notification.1.#{k}"] = v
19
+ if (k == :EventType) && (v.is_a? Array)
20
+ v.each_index do |i|
21
+ hash["Notification.1.#{k}.#{i+1}"] = v[i]
22
+ end
23
+ else
24
+ hash["Notification.1.#{k}"] = v
25
+ end
19
26
  end
20
27
  hash
21
28
  end
@@ -0,0 +1,23 @@
1
+ module RTurk
2
+ class RTurk::ExtendHIT < RTurk::Operation
3
+
4
+ attr_accessor :hit_id, :max_assignments_increment, :expiration_increment_in_seconds
5
+ require_params :hit_id
6
+
7
+ def to_params
8
+ if max_assignments_increment.nil? && expiration_increment_in_seconds.nil?
9
+ raise MissingParameters, 'Must add to either the HIT assignment count or expiration time.'
10
+ end
11
+
12
+ {'HITId' => self.hit_id,
13
+ 'MaxAssignmentsIncrement' => self.max_assignments_increment,
14
+ 'ExpirationIncrementInSeconds' => self.expiration_increment_in_seconds}
15
+ end
16
+
17
+ end
18
+
19
+ def self.ExtendHIT(*args, &blk)
20
+ RTurk::ExtendHIT.create(*args, &blk)
21
+ end
22
+
23
+ end
@@ -33,18 +33,18 @@ module RTurk
33
33
  RTurk.logger.debug "Sending request:\n\t #{credentials.host}?#{querystring}"
34
34
  RestClient.get("#{credentials.host}?#{querystring}")
35
35
  end
36
-
36
+
37
+ def sign(secret_key, service,method,time)
38
+ msg = "#{service}#{method}#{time}"
39
+ return hmac_sha1(secret_key, msg )
40
+ end
41
+
37
42
  private
38
43
 
39
44
  def credentials
40
45
  RTurk
41
46
  end
42
47
 
43
- def sign(secret_key, service,method,time)
44
- msg = "#{service}#{method}#{time}"
45
- return hmac_sha1(secret_key, msg )
46
- end
47
-
48
48
  def hmac_sha1(key, s)
49
49
  ipad = [].fill(0x36, 0, 64)
50
50
  opad = [].fill(0x5C, 0, 64)
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.0"
8
+ s.version = "2.1.1"
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-02-28}
12
+ s.date = %q{2010-06-26}
13
13
  s.email = %q{mark@mpercival.com}
14
14
  s.extra_rdoc_files = [
15
15
  "LICENSE",
@@ -134,6 +134,7 @@ Gem::Specification.new do |s|
134
134
  "lib/rturk/operations/create_hit.rb",
135
135
  "lib/rturk/operations/disable_hit.rb",
136
136
  "lib/rturk/operations/dispose_hit.rb",
137
+ "lib/rturk/operations/extend_hit.rb",
137
138
  "lib/rturk/operations/force_expire_hit.rb",
138
139
  "lib/rturk/operations/get_account_balance.rb",
139
140
  "lib/rturk/operations/get_assignments_for_hit.rb",
@@ -174,6 +175,7 @@ Gem::Specification.new do |s|
174
175
  "spec/fake_responses/create_hit.xml",
175
176
  "spec/fake_responses/disable_hit.xml",
176
177
  "spec/fake_responses/dispose_hit.xml",
178
+ "spec/fake_responses/extend_hit.xml",
177
179
  "spec/fake_responses/force_expire_hit.xml",
178
180
  "spec/fake_responses/get_account_balance.xml",
179
181
  "spec/fake_responses/get_assignments.xml",
@@ -193,6 +195,7 @@ Gem::Specification.new do |s|
193
195
  "spec/operations/create_hit_spec.rb",
194
196
  "spec/operations/disable_hit_spec.rb",
195
197
  "spec/operations/dispose_hit_spec.rb",
198
+ "spec/operations/extend_hit_spec.rb",
196
199
  "spec/operations/force_expire_hit_spec.rb",
197
200
  "spec/operations/get_account_balance_spec.rb",
198
201
  "spec/operations/get_assignments_spec.rb",
@@ -231,6 +234,7 @@ Gem::Specification.new do |s|
231
234
  "spec/operations/create_hit_spec.rb",
232
235
  "spec/operations/disable_hit_spec.rb",
233
236
  "spec/operations/dispose_hit_spec.rb",
237
+ "spec/operations/extend_hit_spec.rb",
234
238
  "spec/operations/force_expire_hit_spec.rb",
235
239
  "spec/operations/get_account_balance_spec.rb",
236
240
  "spec/operations/get_assignments_spec.rb",
@@ -30,5 +30,17 @@ describe RTurk::Notification do
30
30
  "Notification.1.Version" => RTurk::OLD_API_VERSION,
31
31
  "Notification.1.EventType" => 'mumble' }
32
32
  end
33
+
34
+ it "should allow multiple event types" do
35
+ @notification.destination = 'foo'
36
+ @notification.transport = 'bar'
37
+ @notification.event_type = ['mumble', 'bumble']
38
+ @notification.to_param_hash.should ==
39
+ { "Notification.1.Destination" => 'foo',
40
+ "Notification.1.Transport" => 'bar',
41
+ "Notification.1.Version" => RTurk::OLD_API_VERSION,
42
+ "Notification.1.EventType.1" => 'mumble',
43
+ "Notification.1.EventType.2" => 'bumble' }
44
+ end
33
45
  end
34
46
  end
@@ -0,0 +1,5 @@
1
+ <ExtendHITResult>
2
+ <Request>
3
+ <IsValid>True</IsValid>
4
+ </Request>
5
+ </ExtendHITResult>
@@ -0,0 +1,26 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
2
+
3
+ describe RTurk::ExtendHIT 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('extend_hit', :operation => 'ExtendHIT')
9
+ end
10
+
11
+ it "should ensure required params" do
12
+ lambda{RTurk::ExtendHIT(:hit_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' => 'ExtendHIT'))
18
+ RTurk::ExtendHIT(:hit_id => "123456789", :max_assignments_increment => 1) rescue RTurk::InvalidRequest
19
+ end
20
+
21
+ it "should parse and return the result" do
22
+ RTurk::ExtendHIT(:hit_id => "123456789", :expiration_increment_in_seconds => 3600).should
23
+ be_a_kind_of RTurk::Response
24
+ end
25
+
26
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 2
7
7
  - 1
8
- - 0
9
- version: 2.1.0
8
+ - 1
9
+ version: 2.1.1
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-02-28 00:00:00 -05:00
17
+ date: 2010-06-26 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -173,6 +173,7 @@ files:
173
173
  - lib/rturk/operations/create_hit.rb
174
174
  - lib/rturk/operations/disable_hit.rb
175
175
  - lib/rturk/operations/dispose_hit.rb
176
+ - lib/rturk/operations/extend_hit.rb
176
177
  - lib/rturk/operations/force_expire_hit.rb
177
178
  - lib/rturk/operations/get_account_balance.rb
178
179
  - lib/rturk/operations/get_assignments_for_hit.rb
@@ -213,6 +214,7 @@ files:
213
214
  - spec/fake_responses/create_hit.xml
214
215
  - spec/fake_responses/disable_hit.xml
215
216
  - spec/fake_responses/dispose_hit.xml
217
+ - spec/fake_responses/extend_hit.xml
216
218
  - spec/fake_responses/force_expire_hit.xml
217
219
  - spec/fake_responses/get_account_balance.xml
218
220
  - spec/fake_responses/get_assignments.xml
@@ -232,6 +234,7 @@ files:
232
234
  - spec/operations/create_hit_spec.rb
233
235
  - spec/operations/disable_hit_spec.rb
234
236
  - spec/operations/dispose_hit_spec.rb
237
+ - spec/operations/extend_hit_spec.rb
235
238
  - spec/operations/force_expire_hit_spec.rb
236
239
  - spec/operations/get_account_balance_spec.rb
237
240
  - spec/operations/get_assignments_spec.rb
@@ -294,6 +297,7 @@ test_files:
294
297
  - spec/operations/create_hit_spec.rb
295
298
  - spec/operations/disable_hit_spec.rb
296
299
  - spec/operations/dispose_hit_spec.rb
300
+ - spec/operations/extend_hit_spec.rb
297
301
  - spec/operations/force_expire_hit_spec.rb
298
302
  - spec/operations/get_account_balance_spec.rb
299
303
  - spec/operations/get_assignments_spec.rb