kempelen 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/.travis.yml +4 -0
  4. data/CODE_OF_CONDUCT.md +22 -0
  5. data/Gemfile +5 -0
  6. data/Guardfile +42 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +59 -0
  9. data/Rakefile +27 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +7 -0
  12. data/examples/approve_assignment.rb +16 -0
  13. data/examples/create_hit.rb +20 -0
  14. data/examples/force_expire_hit.rb +16 -0
  15. data/examples/get_account_balance.rb +16 -0
  16. data/examples/get_assignments_for_hit.rb +16 -0
  17. data/examples/get_hit.rb +16 -0
  18. data/examples/get_reviewable_hits.rb +16 -0
  19. data/examples/reject_assignment.rb +16 -0
  20. data/examples/set_hit_as_reviewing.rb +16 -0
  21. data/kempelen.gemspec +35 -0
  22. data/lib/kempelen.rb +35 -0
  23. data/lib/kempelen/API/client.rb +45 -0
  24. data/lib/kempelen/API/common/answers.rb +34 -0
  25. data/lib/kempelen/API/common/assignment.rb +37 -0
  26. data/lib/kempelen/API/common/price.rb +26 -0
  27. data/lib/kempelen/API/common/question_form_answers.rb +57 -0
  28. data/lib/kempelen/API/operations/approve_assignment.rb +17 -0
  29. data/lib/kempelen/API/operations/assignment_operation.rb +36 -0
  30. data/lib/kempelen/API/operations/base.rb +71 -0
  31. data/lib/kempelen/API/operations/create_hit.rb +55 -0
  32. data/lib/kempelen/API/operations/force_expire_hit.rb +25 -0
  33. data/lib/kempelen/API/operations/get_account_balance.rb +30 -0
  34. data/lib/kempelen/API/operations/get_assignments_for_hit.rb +42 -0
  35. data/lib/kempelen/API/operations/get_hit.rb +25 -0
  36. data/lib/kempelen/API/operations/get_reviewable_hits.rb +64 -0
  37. data/lib/kempelen/API/operations/hit_operation.rb +23 -0
  38. data/lib/kempelen/API/operations/parameters.rb +40 -0
  39. data/lib/kempelen/API/operations/register_hit_type.rb +47 -0
  40. data/lib/kempelen/API/operations/reject_assignment.rb +17 -0
  41. data/lib/kempelen/API/operations/set_hit_as_reviewing.rb +34 -0
  42. data/lib/kempelen/API/responses/account_balance_response.rb +27 -0
  43. data/lib/kempelen/API/responses/base.rb +32 -0
  44. data/lib/kempelen/API/responses/empty_response.rb +17 -0
  45. data/lib/kempelen/API/responses/error_response.rb +32 -0
  46. data/lib/kempelen/API/responses/get_assignments_response.rb +31 -0
  47. data/lib/kempelen/API/responses/hit_response.rb +66 -0
  48. data/lib/kempelen/API/responses/reviewable_hits_response.rb +38 -0
  49. data/lib/kempelen/version.rb +3 -0
  50. metadata +260 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 57a5100dbaffa8a8c325dc3521423734b2fac35f
4
+ data.tar.gz: e2f33c5193e3a6511b5068b616983a029d7e6eb8
5
+ SHA512:
6
+ metadata.gz: bfb94c173d2e08a31f1abc6a5972f87f1e0e365c53485c1b2987d1ee32d558d3007340d3291e8bfc2a48ff3c442e6b5b03fa77df1d561397662975edfc32aa6f
7
+ data.tar.gz: e3a71009a1ba5f18dde351a6de2ff7cae18534aaa1c0f2b512d2e1d9ac059a5b32b19d5bc6cefdeeef40276f9e390610cd6521cfc4dfd33062505c036427d3be
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ # Local config
2
+ /.bundle/
3
+ /.yardoc
4
+ .ruby-version
5
+
6
+ # Generated
7
+ /Gemfile.lock
8
+ /_yardoc/
9
+ /coverage/
10
+ /doc/
11
+ /pkg/
12
+ /spec/reports/
13
+ /tmp/
14
+
15
+ # Editor files
16
+ .*.swp
17
+ .idea
18
+ *.iml
19
+ .DS_Store
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,22 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality.
6
+
7
+ Examples of unacceptable behavior by participants include:
8
+
9
+ * The use of sexualized language or imagery
10
+ * Personal attacks
11
+ * Trolling or insulting/derogatory comments
12
+ * Public or private harassment
13
+ * Publishing other's private information, such as physical or electronic addresses, without explicit permission
14
+ * Other unethical or unprofessional conduct.
15
+
16
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team.
17
+
18
+ This code of conduct applies both within project spaces and in public spaces when an individual is representing the project or its community.
19
+
20
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
21
+
22
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.2.0, available at [http://contributor-covenant.org/version/1/2/0/](http://contributor-covenant.org/version/1/2/0/)
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+ ruby '2.2.2'
3
+
4
+ # Specify your gem's dependencies in kempelen.gemspec
5
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,42 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ # directories %w(app lib config test spec features) \
6
+ # .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
7
+
8
+ ## Note: if you are using the `directories` clause above and you are not
9
+ ## watching the project directory ('.'), then you will want to move
10
+ ## the Guardfile to a watched dir and symlink it back, e.g.
11
+ #
12
+ # $ mkdir config
13
+ # $ mv Guardfile config/
14
+ # $ ln -s config/Guardfile .
15
+ #
16
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
17
+
18
+ guard :minitest do
19
+ # with Minitest::Unit
20
+ watch(%r{^test/(.*)\/?test_(.*)\.rb$})
21
+ watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
22
+ watch(%r{^test/test_helper\.rb$}) { 'test' }
23
+
24
+ # with Minitest::Spec
25
+ # watch(%r{^spec/(.*)_spec\.rb$})
26
+ # watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
27
+ # watch(%r{^spec/spec_helper\.rb$}) { 'spec' }
28
+
29
+ # Rails 4
30
+ # watch(%r{^app/(.+)\.rb$}) { |m| "test/#{m[1]}_test.rb" }
31
+ # watch(%r{^app/controllers/application_controller\.rb$}) { 'test/controllers' }
32
+ # watch(%r{^app/controllers/(.+)_controller\.rb$}) { |m| "test/integration/#{m[1]}_test.rb" }
33
+ # watch(%r{^app/views/(.+)_mailer/.+}) { |m| "test/mailers/#{m[1]}_mailer_test.rb" }
34
+ # watch(%r{^lib/(.+)\.rb$}) { |m| "test/lib/#{m[1]}_test.rb" }
35
+ # watch(%r{^test/.+_test\.rb$})
36
+ # watch(%r{^test/test_helper\.rb$}) { 'test' }
37
+
38
+ # Rails < 4
39
+ # watch(%r{^app/controllers/(.*)\.rb$}) { |m| "test/functional/#{m[1]}_test.rb" }
40
+ # watch(%r{^app/helpers/(.*)\.rb$}) { |m| "test/helpers/#{m[1]}_test.rb" }
41
+ # watch(%r{^app/models/(.*)\.rb$}) { |m| "test/unit/#{m[1]}_test.rb" }
42
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 ForeFront Labs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # Kempelen
2
+
3
+ [![Circle CI](https://img.shields.io/circleci/project/forefrontlabs/kempelen.svg)](https://circleci.com/gh/forefrontlabs/kempelen/tree/master)
4
+ [![Coverage Status](https://coveralls.io/repos/forefrontlabs/kempelen/badge.svg?branch=master&service=github)](https://coveralls.io/github/forefrontlabs/kempelen?branch=master)
5
+ [![Code Climate](https://codeclimate.com/github/forefrontlabs/kempelen/badges/gpa.svg)](https://codeclimate.com/github/forefrontlabs/kempelen)
6
+ [![Gemnasium](https://img.shields.io/gemnasium/forefrontlabs/kempelen.svg)](https://gemnasium.com/forefrontlabs/kempelen)
7
+
8
+ Kempelen is a modern Mechanical Turk integration gem.
9
+
10
+ Note that note all usage cases are covered by this gem at this time. It is focused on the use cases we needed right now. More cases will be added in the future. If you need something right now, feel free to push us a pull request (see Contributing below).
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ ```ruby
17
+ gem 'kempelen'
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ $ bundle
23
+
24
+ Or install it yourself as:
25
+
26
+ $ gem install kempelen
27
+
28
+ ## Usage
29
+
30
+ In general:
31
+
32
+ * Create a client
33
+ * Create an operation
34
+ * `result = operation.perform_operation`
35
+ * Work with the result
36
+
37
+ See the examples directory for some specific examples of usage.
38
+
39
+ ## Development
40
+
41
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to
42
+ run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
43
+
44
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new
45
+ version, update the version number in `version.rb`, and then run `bundle exec rake release`, which
46
+ will create a git tag for the version, push git commits and tags, and push the `.gem` file
47
+ to [rubygems.org](https://rubygems.org).
48
+
49
+ ## Contributing
50
+
51
+ Bug reports and pull requests are welcome on GitHub at [https://github.com/forefrontlabs/kempelen](https://gemnasium.com/forefrontlabs/kempelen).
52
+
53
+ This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to
54
+ adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
55
+
56
+ ## License
57
+
58
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
59
+
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
11
+
12
+ desc "Open an pry session preloaded with this gem"
13
+ task :console do
14
+ begin
15
+ require 'pry'
16
+ require 'kempelen'
17
+
18
+
19
+ def reload!
20
+ files = $LOADED_FEATURES.select { |feat| feat =~ /\/kempelen\// }
21
+ files.each { |file| load file }
22
+ end
23
+
24
+ ARGV.clear
25
+ Pry.start
26
+ end
27
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "kempelen"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
4
+ require 'kempelen'
5
+ require 'httparty'
6
+
7
+ if ARGV.length < 3
8
+ puts "approve_assignment.rb <ACCESS_KEY> <SECRET_KEY> <HIT_ID>"
9
+ exit
10
+ end
11
+
12
+ @client = Kempelen::API::Client.new(ARGV[0], ARGV[1], :sandbox)
13
+ @operation = Kempelen::API::Operations::ApproveAssignment.new(@client, ARGV[2])
14
+
15
+ get_response = @operation.perform_operation
16
+ puts get_response.inspect
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
4
+ require 'kempelen'
5
+ require 'httparty'
6
+
7
+ if ARGV.length < 4
8
+ puts "create_hit.rb <ACCESS_KEY> <SECRET_KEY> <HIT_TYPE_ID> <LAYOUT_ID>"
9
+ exit
10
+ end
11
+
12
+ @client = Kempelen::API::Client.new(ARGV[0], ARGV[1], :sandbox)
13
+
14
+ @operation = Kempelen::API::Operations::CreateHit.new(@client, ARGV[2], 3600) do |op|
15
+ op.layout_id = ARGV[3]
16
+ op.add_layout_parameter "link", "http://alt-usage-english.org/can_a_cat_man.wav"
17
+ end
18
+
19
+ create_hit_response = @operation.perform_operation
20
+ puts create_hit_response.inspect
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
4
+ require 'kempelen'
5
+ require 'httparty'
6
+
7
+ if ARGV.length < 3
8
+ puts "force_expire_hit.rb <ACCESS_KEY> <SECRET_KEY> <HIT_ID>"
9
+ exit
10
+ end
11
+
12
+ @client = Kempelen::API::Client.new(ARGV[0], ARGV[1], :sandbox)
13
+ @operation = Kempelen::API::Operations::ForceExpireHit.new(@client, ARGV[2])
14
+
15
+ force_expire_hit_response = @operation.perform_operation
16
+ puts force_expire_hit_response.inspect
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
4
+ require 'kempelen'
5
+ require 'httparty'
6
+
7
+ if ARGV.length < 2
8
+ puts "get_account_balance.rb <ACCESS_KEY> <SECRET_KEY>"
9
+ exit
10
+ end
11
+
12
+ @client = Kempelen::API::Client.new(ARGV[0], ARGV[1], :sandbox)
13
+ @operation = Kempelen::API::Operations::GetAccountBalance.new(@client)
14
+
15
+ get_account_balance_response = @operation.perform_operation
16
+ puts get_account_balance_response.inspect
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
4
+ require 'kempelen'
5
+ require 'httparty'
6
+
7
+ if ARGV.length < 3
8
+ puts "get_assignments_for_hit.rb <ACCESS_KEY> <SECRET_KEY> <HIT_ID>"
9
+ exit
10
+ end
11
+
12
+ @client = Kempelen::API::Client.new(ARGV[0], ARGV[1], :sandbox)
13
+ @operation = Kempelen::API::Operations::GetAssignmentsForHit.new(@client, ARGV[2])
14
+
15
+ get_hit_response = @operation.perform_operation
16
+ puts get_hit_response.inspect
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
4
+ require 'kempelen'
5
+ require 'httparty'
6
+
7
+ if ARGV.length < 3
8
+ puts "get_hit.rb <ACCESS_KEY> <SECRET_KEY> <HIT_ID>"
9
+ exit
10
+ end
11
+
12
+ @client = Kempelen::API::Client.new(ARGV[0], ARGV[1], :sandbox)
13
+ @operation = Kempelen::API::Operations::GetHit.new(@client, ARGV[2])
14
+
15
+ get_hit_response = @operation.perform_operation
16
+ puts get_hit_response.inspect
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
4
+ require 'kempelen'
5
+ require 'httparty'
6
+
7
+ if ARGV.length < 3
8
+ puts "get_hit.rb <ACCESS_KEY> <SECRET_KEY> <HIT_TYPE_ID>"
9
+ exit
10
+ end
11
+
12
+ @client = Kempelen::API::Client.new(ARGV[0], ARGV[1], :sandbox)
13
+ @operation = Kempelen::API::Operations::GetReviewableHits.new(@client, ARGV[2])
14
+
15
+ get_reviewable_hits = @operation.perform_operation
16
+ puts get_reviewable_hits.inspect
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
4
+ require 'kempelen'
5
+ require 'httparty'
6
+
7
+ if ARGV.length < 3
8
+ puts "reject_assignment.rb <ACCESS_KEY> <SECRET_KEY> <HIT_ID>"
9
+ exit
10
+ end
11
+
12
+ @client = Kempelen::API::Client.new(ARGV[0], ARGV[1], :sandbox)
13
+ @operation = Kempelen::API::Operations::RejectAssignment.new(@client, ARGV[2])
14
+
15
+ get_response = @operation.perform_operation
16
+ puts get_response.inspect
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
4
+ require 'kempelen'
5
+ require 'httparty'
6
+
7
+ if ARGV.length < 3
8
+ puts "set_hit_as_reviewing.rb <ACCESS_KEY> <SECRET_KEY> <HIT_ID>"
9
+ exit
10
+ end
11
+
12
+ @client = Kempelen::API::Client.new(ARGV[0], ARGV[1], :sandbox)
13
+ @operation = Kempelen::API::Operations::SetHitAsReviewing.new(@client, ARGV[2])
14
+
15
+ set_hit_as_reviewing = @operation.perform_operation
16
+ puts set_hit_as_reviewing.inspect
data/kempelen.gemspec ADDED
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'kempelen/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "kempelen"
8
+ spec.version = Kempelen::VERSION
9
+ spec.authors = ["Brian Nelson"]
10
+ spec.email = ["brian@forefrontlabs.com"]
11
+
12
+ spec.summary = %q{Ruby integration with Amazon's Mechanical Turk}
13
+ spec.description = %q{Modern Ruby integration with Amazon's Mechanical Turk.}
14
+ spec.homepage = "https://github.com/forefrontlabs/kempelen"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "ruby-hmac", "~> 0.4.0"
23
+ spec.add_dependency "nori", "~> 2.6.0"
24
+ spec.add_dependency "httparty", "~> 0.13.6"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.9"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "minitest", "~> 5.8.0"
29
+ spec.add_development_dependency "minitest-reporters", "~> 1.0.20"
30
+ spec.add_development_dependency "pry"
31
+ spec.add_development_dependency "pry-byebug"
32
+ spec.add_development_dependency "guard"
33
+ spec.add_development_dependency "guard-minitest"
34
+ spec.add_development_dependency "coveralls"
35
+ end