rturk 2.0.5 → 2.1.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/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ gem 'nokogiri'
2
+ gem 'fakeweb'
3
+ gem 'rest-client'
4
+ gem 'rspec'
data/README.markdown CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ## What's it do?!?
4
4
 
5
- RTurk is designed to fire off Mechanical Turk tasks for pages that reside on a external site.
5
+ RTurk is designed to fire off Mechanical Turk tasks for pages that reside on an external site.
6
6
 
7
7
  The pages could be a part of a rails app, or just a simple javascript enabled form.
8
8
 
@@ -11,7 +11,7 @@ You'd be better off with amazon's official library, in all its XML cruftiness.
11
11
 
12
12
  ## Installation
13
13
 
14
- sudo gem install rturk --source http://gemcutter.org
14
+ gem install rturk
15
15
 
16
16
  ## Use
17
17
 
data/Rakefile CHANGED
@@ -18,6 +18,8 @@ begin
18
18
  gem.email = "mark@mpercival.com"
19
19
  gem.homepage = "http://github.com/markpercival/rturk"
20
20
  gem.authors = ["Mark Percival"]
21
+ gem.add_dependency('rest-client', '>= 1.4.0')
22
+ gem.add_dependency('nokogiri', '>= 1.4.1')
21
23
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
22
24
  end
23
25
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.5
1
+ 2.1.0
@@ -19,10 +19,11 @@ module RTurk
19
19
  def url
20
20
  unless querystring.empty?
21
21
  # slam the params onto url, if url already has params, add 'em with a &
22
- @url.index('?') ? "#{@url}&#{querystring}" : "#{@url}?#{querystring}"
22
+ u = @url.index('?') ? "#{@url}&#{querystring}" : "#{@url}?#{querystring}"
23
23
  else
24
- @url
24
+ u = @url
25
25
  end
26
+ CGI.escapeHTML(u) #URL should be XML/HTML escaped
26
27
  end
27
28
 
28
29
  def params
@@ -12,7 +12,7 @@ module RTurk
12
12
  attr_reader :xml, :raw_xml
13
13
 
14
14
  def initialize(response)
15
- @raw_xml = response
15
+ @raw_xml = response.body
16
16
  @xml = Nokogiri::XML(@raw_xml)
17
17
  raise_errors
18
18
  end
@@ -49,7 +49,7 @@ module RTurk
49
49
  :keywords
50
50
 
51
51
  def initialize(response)
52
- @raw_xml = response
52
+ @raw_xml = response.body
53
53
  @xml = Nokogiri::XML(@raw_xml)
54
54
  raise_errors
55
55
  map_content(@xml.xpath('//HIT'),
data/rturk.gemspec CHANGED
@@ -1,15 +1,15 @@
1
1
  # Generated by jeweler
2
- # DO NOT EDIT THIS FILE
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rturk}
8
- s.version = "2.0.5"
8
+ s.version = "2.1.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-01-05}
12
+ s.date = %q{2010-02-28}
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
+ "Gemfile",
22
23
  "LICENSE",
23
24
  "README.markdown",
24
25
  "Rakefile",
@@ -216,7 +217,7 @@ Gem::Specification.new do |s|
216
217
  s.homepage = %q{http://github.com/markpercival/rturk}
217
218
  s.rdoc_options = ["--charset=UTF-8"]
218
219
  s.require_paths = ["lib"]
219
- s.rubygems_version = %q{1.3.5}
220
+ s.rubygems_version = %q{1.3.6}
220
221
  s.summary = %q{Mechanical Turk API Wrapper}
221
222
  s.test_files = [
222
223
  "spec/adapters/assignment_spec.rb",
@@ -259,8 +260,15 @@ Gem::Specification.new do |s|
259
260
  s.specification_version = 3
260
261
 
261
262
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
263
+ s.add_runtime_dependency(%q<rest-client>, [">= 1.4.0"])
264
+ s.add_runtime_dependency(%q<nokogiri>, [">= 1.4.1"])
262
265
  else
266
+ s.add_dependency(%q<rest-client>, [">= 1.4.0"])
267
+ s.add_dependency(%q<nokogiri>, [">= 1.4.1"])
263
268
  end
264
269
  else
270
+ s.add_dependency(%q<rest-client>, [">= 1.4.0"])
271
+ s.add_dependency(%q<nokogiri>, [">= 1.4.1"])
265
272
  end
266
273
  end
274
+
@@ -19,6 +19,12 @@ describe RTurk::Question do
19
19
  question.frame_height.should == 500
20
20
  end
21
21
 
22
+ it "should build a question " do
23
+ question = RTurk::Question.new('http://mpercival.com?myparam=true&anotherparam=12', :frame_height => 500)
24
+ question.url.should == 'http://mpercival.com?myparam=true&amp;anotherparam=12'
25
+ question.frame_height.should == 500
26
+ end
27
+
22
28
  it "should build a question with params" do
23
29
  params = RTurk::Question.new('http://google.com/', :id => 'foo').to_params
24
30
  CGI.unescape(params).should ==
@@ -26,7 +26,8 @@ describe RTurk::NotifyWorkers do
26
26
 
27
27
  it 'should successfully request the operation' do
28
28
  RTurk::Requester.should_receive(:request).once.with(
29
- hash_including('Operation' => 'NotifyWorkers'))
29
+ hash_including('Operation' => 'NotifyWorkers')).and_return(
30
+ fake_response(''))
30
31
 
31
32
  @lambda.call
32
33
  end
@@ -30,7 +30,8 @@ describe RTurk::SendTestEventNotification do
30
30
 
31
31
  it 'should successfully request the operation' do
32
32
  RTurk::Requester.should_receive(:request).once.with(
33
- hash_including('Operation' => 'SendTestEventNotification'))
33
+ hash_including('Operation' => 'SendTestEventNotification')).and_return(
34
+ fake_response(''))
34
35
 
35
36
  @lambda.call
36
37
  end
@@ -31,7 +31,8 @@ describe RTurk::SetHITTypeNotification do
31
31
 
32
32
  it 'should successfully request the operation' do
33
33
  RTurk::Requester.should_receive(:request).once.with(
34
- hash_including('Operation' => 'SetHITTypeNotification'))
34
+ hash_including('Operation' => 'SetHITTypeNotification')).and_return(
35
+ fake_response(''))
35
36
 
36
37
  @lambda.call
37
38
  end
@@ -5,18 +5,17 @@ describe RTurk::Response do
5
5
 
6
6
  context "given an invalid response" do
7
7
 
8
- before(:all) do
9
- @invalid_credentials_xml = File.read(File.join(SPEC_ROOT,'fake_responses','invalid_credentials.xml'))
10
-
8
+ before(:each) do
9
+ @bad_credentials_response = fake_response(File.read(File.join(SPEC_ROOT,'fake_responses','invalid_credentials.xml')))
11
10
  end
12
11
 
13
12
  it "should know it failed" do
14
- lambda{RTurk::Response.new(@invalid_credentials_xml)}.should raise_error RTurk::InvalidRequest
13
+ lambda{RTurk::Response.new(@bad_credentials_response)}.should raise_error RTurk::InvalidRequest
15
14
  end
16
15
 
17
16
  it "should know why" do
18
17
  begin
19
- RTurk::Response.new(@invalid_credentials_xml)
18
+ RTurk::Response.new(@bad_credentials_response)
20
19
  rescue RTurk::InvalidRequest => e
21
20
  e.message.should eql("AWS.NotAuthorized: The identity contained in the request is not authorized to use this AWSAccessKeyId")
22
21
  end
@@ -28,7 +27,7 @@ describe RTurk::Response do
28
27
  context "given a valid response" do
29
28
 
30
29
  before(:all) do
31
- @response = RTurk::Response.new(File.read(File.join(SPEC_ROOT,'fake_responses','create_hit.xml')))
30
+ @response = RTurk::Response.new(fake_response(File.read(File.join(SPEC_ROOT,'fake_responses','create_hit.xml'))))
32
31
  end
33
32
 
34
33
  it "should know it succeded" do
data/spec/spec_helper.rb CHANGED
@@ -4,6 +4,7 @@ $: << File.join(File.dirname(__FILE__), '..', 'lib')
4
4
  require 'rubygems'
5
5
  require 'spec'
6
6
  require 'fakeweb'
7
+ require 'yaml'
7
8
  module FakeWeb
8
9
  class Registry
9
10
  # Comment out this override if you're using a quantum computer
@@ -30,6 +31,10 @@ def faker(response_name, opts = {})
30
31
  FakeWeb.register_uri(:get, match, :body => response)
31
32
  end
32
33
 
34
+ def fake_response(xml)
35
+ mock('RestClientFakeResponse', :body => xml)
36
+ end
37
+
33
38
  Spec::Runner.configure do |config|
34
39
 
35
40
  end
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rturk
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.5
4
+ prerelease: false
5
+ segments:
6
+ - 2
7
+ - 1
8
+ - 0
9
+ version: 2.1.0
5
10
  platform: ruby
6
11
  authors:
7
12
  - Mark Percival
@@ -9,10 +14,37 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-01-05 00:00:00 -05:00
17
+ date: 2010-02-28 00:00:00 -05:00
13
18
  default_executable:
14
- dependencies: []
15
-
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rest-client
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 4
30
+ - 0
31
+ version: 1.4.0
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: nokogiri
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 1
43
+ - 4
44
+ - 1
45
+ version: 1.4.1
46
+ type: :runtime
47
+ version_requirements: *id002
16
48
  description:
17
49
  email: mark@mpercival.com
18
50
  executables: []
@@ -26,6 +58,7 @@ files:
26
58
  - .gitignore
27
59
  - .gitmodules
28
60
  - .yardoc
61
+ - Gemfile
29
62
  - LICENSE
30
63
  - README.markdown
31
64
  - Rakefile
@@ -232,18 +265,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
232
265
  requirements:
233
266
  - - ">="
234
267
  - !ruby/object:Gem::Version
268
+ segments:
269
+ - 0
235
270
  version: "0"
236
- version:
237
271
  required_rubygems_version: !ruby/object:Gem::Requirement
238
272
  requirements:
239
273
  - - ">="
240
274
  - !ruby/object:Gem::Version
275
+ segments:
276
+ - 0
241
277
  version: "0"
242
- version:
243
278
  requirements: []
244
279
 
245
280
  rubyforge_project:
246
- rubygems_version: 1.3.5
281
+ rubygems_version: 1.3.6
247
282
  signing_key:
248
283
  specification_version: 3
249
284
  summary: Mechanical Turk API Wrapper