rturk 1.0.5 → 2.0.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.
Files changed (84) hide show
  1. data/.gitmodules +3 -0
  2. data/.yardoc +0 -0
  3. data/README.markdown +49 -29
  4. data/Rakefile +53 -0
  5. data/TODO.markdown +3 -0
  6. data/VERSION +1 -1
  7. data/examples/blank_slate.rb +21 -4
  8. data/examples/create_hit.rb +19 -0
  9. data/examples/newtweet.html +0 -1
  10. data/examples/review_answer.rb +18 -5
  11. data/lib/rturk.rb +33 -6
  12. data/lib/rturk/adapters/answers.rb +38 -0
  13. data/lib/rturk/adapters/assignment.rb +75 -0
  14. data/lib/rturk/adapters/hit.rb +97 -0
  15. data/lib/rturk/builders/qualification_builder.rb +68 -0
  16. data/lib/rturk/builders/qualifications_builder.rb +43 -0
  17. data/lib/rturk/builders/question_builder.rb +51 -0
  18. data/lib/rturk/errors.rb +5 -0
  19. data/lib/rturk/logger.rb +20 -0
  20. data/lib/rturk/macros.rb +35 -0
  21. data/lib/rturk/operation.rb +86 -0
  22. data/lib/rturk/operations/approve_assignment.rb +28 -0
  23. data/lib/rturk/operations/create_hit.rb +77 -0
  24. data/lib/rturk/operations/disable_hit.rb +19 -0
  25. data/lib/rturk/operations/dispose_hit.rb +19 -0
  26. data/lib/rturk/operations/force_expire_hit.rb +18 -0
  27. data/lib/rturk/operations/get_account_balance.rb +15 -0
  28. data/lib/rturk/operations/get_assignments_for_hit.rb +24 -0
  29. data/lib/rturk/operations/get_hit.rb +21 -0
  30. data/lib/rturk/operations/get_reviewable_hits.rb +23 -0
  31. data/lib/rturk/operations/grant_bonus.rb +26 -0
  32. data/lib/rturk/operations/reject_assignment.rb +23 -0
  33. data/lib/rturk/requester.rb +58 -76
  34. data/lib/rturk/response.rb +58 -0
  35. data/lib/rturk/responses/create_hit_response.rb +33 -0
  36. data/lib/rturk/responses/get_account_balance_response.rb +11 -0
  37. data/lib/rturk/responses/get_assignments_for_hit_response.rb +43 -0
  38. data/lib/rturk/responses/get_hit_response.rb +80 -0
  39. data/lib/rturk/responses/get_reviewable_hits_response.rb +33 -0
  40. data/lib/rturk/utilities.rb +19 -1
  41. data/lib/rturk/xml_utilities.rb +23 -0
  42. data/rturk.gemspec +143 -0
  43. data/spec/adapters/answers_spec.rb +27 -0
  44. data/spec/adapters/assignment_spec.rb +0 -0
  45. data/spec/adapters/hit_spec.rb +46 -0
  46. data/spec/builders/qualification_spec.rb +53 -0
  47. data/spec/builders/qualifications_spec.rb +30 -0
  48. data/spec/builders/question_spec.rb +46 -0
  49. data/spec/fake_responses/approve_assignment.xml +5 -0
  50. data/spec/fake_responses/create_hit.xml +12 -0
  51. data/spec/fake_responses/disable_hit.xml +5 -0
  52. data/spec/fake_responses/dispose_hit.xml +5 -0
  53. data/spec/fake_responses/force_expire_hit.xml +5 -0
  54. data/spec/fake_responses/get_account_balance.xml +10 -0
  55. data/spec/fake_responses/get_assignments.xml +35 -0
  56. data/spec/fake_responses/get_hit.xml +41 -0
  57. data/spec/fake_responses/get_reviewable_hits.xml +17 -0
  58. data/spec/fake_responses/grant_bonus.xml +5 -0
  59. data/spec/fake_responses/invalid_credentials.xml +12 -0
  60. data/spec/fake_responses/reject_assignment.xml +5 -0
  61. data/spec/operations/approve_assignment_spec.rb +27 -0
  62. data/spec/operations/create_hit_spec.rb +66 -0
  63. data/spec/operations/disable_hit_spec.rb +26 -0
  64. data/spec/operations/dispose_hit_spec.rb +26 -0
  65. data/spec/operations/force_expire_hit_spec.rb +26 -0
  66. data/spec/operations/get_account_balance_spec.rb +15 -0
  67. data/spec/operations/get_assignments_spec.rb +26 -0
  68. data/spec/operations/get_hit_spec.rb +18 -0
  69. data/spec/operations/get_reviewable_hits_spec.rb +0 -0
  70. data/spec/operations/grant_bonus_spec.rb +32 -0
  71. data/spec/operations/reject_assignment_spec.rb +26 -0
  72. data/spec/requester_spec.rb +7 -18
  73. data/spec/response_spec.rb +48 -0
  74. data/spec/rturk_spec.rb +27 -0
  75. data/spec/spec_helper.rb +28 -3
  76. data/spec/tmp +2 -0
  77. data/spec/xml_parse_spec.rb +32 -0
  78. metadata +94 -34
  79. data/examples/external_page.rb +0 -33
  80. data/lib/rturk/answer.rb +0 -20
  81. data/lib/rturk/custom_operations.rb +0 -80
  82. data/lib/rturk/external_question_builder.rb +0 -22
  83. data/spec/answer_spec.rb +0 -24
  84. data/spec/external_question_spec.rb +0 -27
@@ -0,0 +1,80 @@
1
+ # Parses the GetHIT Response
2
+ #
3
+ # <?xml version="1.0"?>
4
+ # <GetHITResponse>
5
+ # <OperationRequest>
6
+ # <RequestId>49341251-fcbd-45c3-ab98-8fbe2e4d8060</RequestId>
7
+ # </OperationRequest>
8
+ # <HIT>
9
+ # <Request>
10
+ # <IsValid>True</IsValid>
11
+ # </Request>
12
+ # <HITId>GR4R3HY3YGBZXDCAPJWZ</HITId>
13
+ # <HITTypeId>YGKZ2W5X6YFZ08ZRXXZZ</HITTypeId>
14
+ # <CreationTime>2009-06-25T04:21:17Z</CreationTime>
15
+ # <Title>Write a twitter update</Title>
16
+ # <Description>Simply write a twitter update for me</Description>
17
+ # <Question>&lt;ExternalQuestion xmlns="http://mechanicalturk.amazonaws.com/AWSMechanicalTurkDataSchemas/2006-07-14/ExternalQuestion.xsd"&gt;
18
+ # &lt;ExternalURL&gt;http://s3.amazonaws.com/mpercival.com/newtweet.html?id=foo&lt;/ExternalURL&gt;
19
+ # &lt;FrameHeight&gt;400&lt;/FrameHeight&gt;
20
+ # &lt;/ExternalQuestion&gt;
21
+ # </Question>
22
+ # <Keywords>twitter, blogging, writing, english</Keywords>
23
+ # <HITStatus>Reviewable</HITStatus>
24
+ # <MaxAssignments>1</MaxAssignments>
25
+ # <Reward>
26
+ # <Amount>0.10</Amount>
27
+ # <CurrencyCode>USD</CurrencyCode>
28
+ # <FormattedPrice>$0.10</FormattedPrice>
29
+ # </Reward>
30
+ # <AutoApprovalDelayInSeconds>3600</AutoApprovalDelayInSeconds>
31
+ # <Expiration>2009-06-25T05:21:17Z</Expiration>
32
+ # <AssignmentDurationInSeconds>3600</AssignmentDurationInSeconds>
33
+ # <NumberOfSimilarHITs>0</NumberOfSimilarHITs>
34
+ # <RequesterAnnotation>OptionalNote</RequesterAnnotation>
35
+ # <QualificationRequirement>
36
+ # <QualificationTypeId>000000000000000000L0</QualificationTypeId>
37
+ # <Comparator>GreaterThan</Comparator>
38
+ # <IntegerValue>90</IntegerValue>
39
+ # <RequiredToPreview>0</RequiredToPreview>
40
+ # </QualificationRequirement>
41
+ # <HITReviewStatus>NotReviewed</HITReviewStatus>
42
+ # </HIT>
43
+ # </GetHITResponse>
44
+
45
+ module RTurk
46
+
47
+ class GetHITResponse < Response
48
+
49
+ attr_accessor :id, :type_id, :status, :title, :description, :reward, :assignments
50
+ attr_accessor :similar_hits, :review_status, :expires_at, :auto_approval
51
+
52
+ def initialize(response)
53
+ @raw_xml = response
54
+ @xml = Nokogiri::XML(@raw_xml)
55
+ raise_errors
56
+ map_content(@xml.xpath('//HIT'),
57
+ :id => 'HITId',
58
+ :type_id => 'HITTypeId',
59
+ :status => 'HITStatus',
60
+ :title => "Title",
61
+ :description => 'Description',
62
+ :assignments => 'MaxAssignments',
63
+ :similar_hits => 'NumberOfSimilarHITs',
64
+ :review_status => 'HITReviewStatus',
65
+ :expires_at => 'Expiration',
66
+ :auto_approval => 'AutoApprovalDelayInSeconds'
67
+ )
68
+ end
69
+
70
+ def expires_at=(time)
71
+ @expires_at = Time.parse(time)
72
+ end
73
+
74
+ def auto_approval=(seconds)
75
+ @auto_approval = seconds.to_i
76
+ end
77
+
78
+ end
79
+
80
+ end
@@ -0,0 +1,33 @@
1
+ # <GetReviewableHITsResult>
2
+ # <Request>
3
+ # <IsValid>True</IsValid>
4
+ # </Request>
5
+ # <NumResults>3</NumResults>
6
+ # <TotalNumResults>3</TotalNumResults>
7
+ # <PageNumber>1</PageNumber>
8
+ # <HIT>
9
+ # <HITId>GBHZVQX3EHXZ2AYDY2T0</HITId>
10
+ # </HIT>
11
+ # <HIT>
12
+ # <HITId>GBHZVQX3EHXZ2AYDY2T1</HITId>
13
+ # </HIT>
14
+ # <HIT>
15
+ # <HITId>GBHZVQX3EHXZ2AYDY2T2</HITId>
16
+ # </HIT>
17
+ # </GetReviewableHITsResult>
18
+
19
+ module RTurk
20
+
21
+ class GetReviewableHITsResponse < Response
22
+
23
+ def hits
24
+ @hits ||= []
25
+ @xml.xpath('//HIT').each do |hit_xml|
26
+ @hits << RTurk::Hit.new(hit_xml.inner_text.strip)
27
+ end
28
+ @hits
29
+ end
30
+
31
+ end
32
+
33
+ end
@@ -5,7 +5,7 @@ module RTurk::Utilities
5
5
  phrase.gsub!(/\_/, '')
6
6
  return phrase
7
7
  end
8
-
8
+
9
9
  def stringify_keys(ahash)
10
10
  ahash = ahash.inject({}) do |options, (key, value)|
11
11
  options[(key.to_s rescue key) || key] = value
@@ -14,4 +14,22 @@ module RTurk::Utilities
14
14
  ahash
15
15
  end
16
16
 
17
+ def camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true)
18
+ if first_letter_in_uppercase
19
+ lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
20
+ else
21
+ lower_case_and_underscored_word.first + camelize(lower_case_and_underscored_word)[1..-1]
22
+ end
23
+ end
24
+
25
+ def underscore(camel_cased_word)
26
+ camel_cased_word.to_s.gsub(/::/, '/').
27
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
28
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
29
+ tr("-", "_").
30
+ downcase
31
+ end
32
+
17
33
  end
34
+
35
+ # TODO: Build an Nokogiri from_xml parser, should return a hash
@@ -0,0 +1,23 @@
1
+ module RTurk::XmlUtilities
2
+
3
+ def xml_to_hash(noko_xml)
4
+ hash = {}
5
+ noko_xml.children.each do |child|
6
+ next if child.blank?
7
+ if child.text?
8
+ return child.text
9
+ else
10
+ hash[child.name] = xml_to_hash(child)
11
+ end
12
+ end
13
+ hash
14
+ end
15
+
16
+ def map_content(xml_obj, hash)
17
+ hash.each_pair do |k,v|
18
+ self.send("#{k.to_s}=", xml_obj.xpath(v).inner_text)
19
+ end
20
+ end
21
+
22
+
23
+ end
data/rturk.gemspec ADDED
@@ -0,0 +1,143 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{rturk}
8
+ s.version = "2.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Mark Percival"]
12
+ s.date = %q{2009-10-26}
13
+ s.email = %q{mark@mpercival.com}
14
+ s.extra_rdoc_files = [
15
+ "LICENSE",
16
+ "README.markdown"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ ".gitmodules",
21
+ ".yardoc",
22
+ "LICENSE",
23
+ "README.markdown",
24
+ "Rakefile",
25
+ "TODO.markdown",
26
+ "VERSION",
27
+ "examples/blank_slate.rb",
28
+ "examples/create_hit.rb",
29
+ "examples/mturk.sample.yml",
30
+ "examples/newtweet.html",
31
+ "examples/review_answer.rb",
32
+ "lib/rturk.rb",
33
+ "lib/rturk/adapters/answers.rb",
34
+ "lib/rturk/adapters/assignment.rb",
35
+ "lib/rturk/adapters/hit.rb",
36
+ "lib/rturk/builders/qualification_builder.rb",
37
+ "lib/rturk/builders/qualifications_builder.rb",
38
+ "lib/rturk/builders/question_builder.rb",
39
+ "lib/rturk/errors.rb",
40
+ "lib/rturk/logger.rb",
41
+ "lib/rturk/macros.rb",
42
+ "lib/rturk/operation.rb",
43
+ "lib/rturk/operations/approve_assignment.rb",
44
+ "lib/rturk/operations/create_hit.rb",
45
+ "lib/rturk/operations/disable_hit.rb",
46
+ "lib/rturk/operations/dispose_hit.rb",
47
+ "lib/rturk/operations/force_expire_hit.rb",
48
+ "lib/rturk/operations/get_account_balance.rb",
49
+ "lib/rturk/operations/get_assignments_for_hit.rb",
50
+ "lib/rturk/operations/get_hit.rb",
51
+ "lib/rturk/operations/get_reviewable_hits.rb",
52
+ "lib/rturk/operations/grant_bonus.rb",
53
+ "lib/rturk/operations/reject_assignment.rb",
54
+ "lib/rturk/requester.rb",
55
+ "lib/rturk/response.rb",
56
+ "lib/rturk/responses/create_hit_response.rb",
57
+ "lib/rturk/responses/get_account_balance_response.rb",
58
+ "lib/rturk/responses/get_assignments_for_hit_response.rb",
59
+ "lib/rturk/responses/get_hit_response.rb",
60
+ "lib/rturk/responses/get_reviewable_hits_response.rb",
61
+ "lib/rturk/utilities.rb",
62
+ "lib/rturk/xml_utilities.rb",
63
+ "rturk.gemspec",
64
+ "spec/adapters/answers_spec.rb",
65
+ "spec/adapters/assignment_spec.rb",
66
+ "spec/adapters/hit_spec.rb",
67
+ "spec/builders/qualification_spec.rb",
68
+ "spec/builders/qualifications_spec.rb",
69
+ "spec/builders/question_spec.rb",
70
+ "spec/fake_responses/approve_assignment.xml",
71
+ "spec/fake_responses/create_hit.xml",
72
+ "spec/fake_responses/disable_hit.xml",
73
+ "spec/fake_responses/dispose_hit.xml",
74
+ "spec/fake_responses/force_expire_hit.xml",
75
+ "spec/fake_responses/get_account_balance.xml",
76
+ "spec/fake_responses/get_assignments.xml",
77
+ "spec/fake_responses/get_hit.xml",
78
+ "spec/fake_responses/get_reviewable_hits.xml",
79
+ "spec/fake_responses/grant_bonus.xml",
80
+ "spec/fake_responses/invalid_credentials.xml",
81
+ "spec/fake_responses/reject_assignment.xml",
82
+ "spec/mturk.sample.yml",
83
+ "spec/operations/approve_assignment_spec.rb",
84
+ "spec/operations/create_hit_spec.rb",
85
+ "spec/operations/disable_hit_spec.rb",
86
+ "spec/operations/dispose_hit_spec.rb",
87
+ "spec/operations/force_expire_hit_spec.rb",
88
+ "spec/operations/get_account_balance_spec.rb",
89
+ "spec/operations/get_assignments_spec.rb",
90
+ "spec/operations/get_hit_spec.rb",
91
+ "spec/operations/get_reviewable_hits_spec.rb",
92
+ "spec/operations/grant_bonus_spec.rb",
93
+ "spec/operations/reject_assignment_spec.rb",
94
+ "spec/requester_spec.rb",
95
+ "spec/response_spec.rb",
96
+ "spec/rturk_spec.rb",
97
+ "spec/spec_helper.rb",
98
+ "spec/tmp",
99
+ "spec/xml_parse_spec.rb"
100
+ ]
101
+ s.homepage = %q{http://github.com/markpercival/rturk}
102
+ s.rdoc_options = ["--charset=UTF-8"]
103
+ s.require_paths = ["lib"]
104
+ s.rubygems_version = %q{1.3.5}
105
+ s.summary = %q{Mechanical Turk API Wrapper}
106
+ s.test_files = [
107
+ "spec/adapters/answers_spec.rb",
108
+ "spec/adapters/assignment_spec.rb",
109
+ "spec/adapters/hit_spec.rb",
110
+ "spec/builders/qualification_spec.rb",
111
+ "spec/builders/qualifications_spec.rb",
112
+ "spec/builders/question_spec.rb",
113
+ "spec/operations/approve_assignment_spec.rb",
114
+ "spec/operations/create_hit_spec.rb",
115
+ "spec/operations/disable_hit_spec.rb",
116
+ "spec/operations/dispose_hit_spec.rb",
117
+ "spec/operations/force_expire_hit_spec.rb",
118
+ "spec/operations/get_account_balance_spec.rb",
119
+ "spec/operations/get_assignments_spec.rb",
120
+ "spec/operations/get_hit_spec.rb",
121
+ "spec/operations/get_reviewable_hits_spec.rb",
122
+ "spec/operations/grant_bonus_spec.rb",
123
+ "spec/operations/reject_assignment_spec.rb",
124
+ "spec/requester_spec.rb",
125
+ "spec/response_spec.rb",
126
+ "spec/rturk_spec.rb",
127
+ "spec/spec_helper.rb",
128
+ "spec/xml_parse_spec.rb",
129
+ "examples/blank_slate.rb",
130
+ "examples/create_hit.rb",
131
+ "examples/review_answer.rb"
132
+ ]
133
+
134
+ if s.respond_to? :specification_version then
135
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
136
+ s.specification_version = 3
137
+
138
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
139
+ else
140
+ end
141
+ else
142
+ end
143
+ end
@@ -0,0 +1,27 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
2
+
3
+
4
+ describe RTurk::Answers do
5
+
6
+ before(:all) do
7
+ @answer = <<-XML
8
+ &lt;?xml version="1.0" encoding="UTF-8"?&gt;
9
+ &lt;QuestionFormAnswers xmlns="http://mechanicalturk.amazonaws.com/AWSMechanicalTurkDataSchemas/2005-10-01/QuestionFormAnswers.xsd"&gt;
10
+ &lt;Answer&gt;
11
+ &lt;QuestionIdentifier&gt;tweet&lt;/QuestionIdentifier&gt;
12
+ &lt;FreeText&gt;This is my tweet!&lt;/FreeText&gt;
13
+ &lt;/Answer&gt;
14
+ &lt;Answer&gt;
15
+ &lt;QuestionIdentifier&gt;Submit&lt;/QuestionIdentifier&gt;
16
+ &lt;FreeText&gt;Submit&lt;/FreeText&gt;
17
+ &lt;/Answer&gt;
18
+ &lt;/QuestionFormAnswers&gt;
19
+ XML
20
+ end
21
+
22
+ it "should parse a answer" do
23
+ RTurk::Answers.new(@answer).to_hash.should == {"Submit"=>"Submit", "tweet"=>"This is my tweet!"}
24
+ end
25
+
26
+
27
+ end
File without changes
@@ -0,0 +1,46 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
2
+
3
+ describe "HIT adapter" 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('create_hit', :operation => 'CreateHIT')
9
+ faker('get_hit', :operation => 'GetHIT')
10
+ faker('get_reviewable_hits', :operation => 'GetReviewableHITs')
11
+ faker('get_assignments', :operation => 'GetAssignments')
12
+ faker('force_expire_hit', :operation => 'ForceExpireHIT')
13
+ faker('dispose_hit', :operation => 'DisposeHIT')
14
+ end
15
+
16
+ it "should let us create a hit" do
17
+ RTurk::Hit.create(:title => 'foo', :description => 'do foo', :question => 'http://mpercival.com', :reward => 0.05)
18
+ end
19
+
20
+ it "should automagically request additional information on an existing hit" do
21
+ hit = RTurk::Hit.new(12345)
22
+ hit.type_id.should eql("YGKZ2W5X6YFZ08ZRXXZZ")
23
+ hit.url.should eql("http://workersandbox.mturk.com/mturk/preview?groupId=YGKZ2W5X6YFZ08ZRXXZZ")
24
+ end
25
+
26
+ it "should get all reviewable hits" do
27
+ hits = RTurk::Hit.all_reviewable
28
+ hits.size.should eql(3)
29
+ end
30
+
31
+ it "should find assignments for a hit" do
32
+ hits = RTurk::Hit.all_reviewable
33
+ hits.first.assignments.first.answers["tweet"].should eql('This is my tweet!')
34
+ end
35
+
36
+ it "should expire a hit" do
37
+ hits = RTurk::Hit.all_reviewable
38
+ hits.first.expire!
39
+ end
40
+
41
+ it "should dispose of a hit" do
42
+ hits = RTurk::Hit.all_reviewable
43
+ hits.first.dispose!
44
+ end
45
+
46
+ end
@@ -0,0 +1,53 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
2
+
3
+
4
+ describe RTurk::Qualifications do
5
+
6
+ # Possible values coming back
7
+ # {"QualificationTypeId","Comparator", "IntegerValue", "LocaleValue.Country","RequiredToPreview"}
8
+
9
+ before(:each) do
10
+
11
+ end
12
+
13
+ it "should build a qualification for Approval rate" do
14
+ @qualification = RTurk::Qualification.new('000000000000000000L0', :gt => 90)
15
+ @qualification.to_params.should eql({"QualificationTypeId" => '000000000000000000L0',"Comparator" => 'GreaterThan',
16
+ "IntegerValue" => 90, "RequiredToPreview" => "true"})
17
+ end
18
+
19
+ it "should build a qualification for boolean qualification" do
20
+ @qualification = RTurk::Qualification.new('00000000000000000060', true)
21
+ @qualification.to_params.should eql({"QualificationTypeId" => '00000000000000000060',"Comparator" => 'EqualTo',
22
+ "IntegerValue" => 1, "RequiredToPreview" => "true"})
23
+ end
24
+
25
+ it "should build a qualification for country qualification" do
26
+ @qualification = RTurk::Qualification.new('00000000000000000071', :eql => 'PH')
27
+ @qualification.to_params.should eql({"QualificationTypeId" => '00000000000000000071',"Comparator" => 'EqualTo',
28
+ "LocaleValue.Country" => 'PH', "RequiredToPreview" => "true"})
29
+ end
30
+
31
+ context 'passing in symbols representing a TypeID' do
32
+
33
+ it "should build a qualification for Approval rate" do
34
+ @qualification = RTurk::Qualification.new(:approval_rate, :gt => 90)
35
+ @qualification.to_params.should eql({"QualificationTypeId" => '000000000000000000L0',"Comparator" => 'GreaterThan',
36
+ "IntegerValue" => 90, "RequiredToPreview" => "true"})
37
+ end
38
+
39
+ it "should build a qualification for boolean qualification" do
40
+ @qualification = RTurk::Qualification.new(:adult, true)
41
+ @qualification.to_params.should eql({"QualificationTypeId" => '00000000000000000060',"Comparator" => 'EqualTo',
42
+ "IntegerValue" => 1, "RequiredToPreview" => "true"})
43
+ end
44
+
45
+ it "should build a qualification for country qualification" do
46
+ @qualification = RTurk::Qualification.new(:country, :eql => 'PH')
47
+ @qualification.to_params.should eql({"QualificationTypeId" => '00000000000000000071',"Comparator" => 'EqualTo',
48
+ "LocaleValue.Country" => 'PH', "RequiredToPreview" => "true"})
49
+ end
50
+
51
+ end
52
+
53
+ end