hci 0.0.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/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.rdoc +0 -0
- data/Rakefile +13 -0
- data/hci.gemspec +26 -0
- data/lib/hci/client.rb +34 -0
- data/lib/hci/end_point.rb +34 -0
- data/lib/hci/exceptions.rb +4 -0
- data/lib/hci/frameworks/rails.rb +4 -0
- data/lib/hci/hit.rb +86 -0
- data/lib/hci/hit_request.rb +17 -0
- data/lib/hci/hit_response.rb +17 -0
- data/lib/hci/hit_result.rb +32 -0
- data/lib/hci/version.rb +4 -0
- data/lib/hci.rb +9 -0
- data/spec/.rspec +1 -0
- data/spec/hci_client_spec.rb +16 -0
- data/spec/hci_hit_request_spec.rb +85 -0
- data/spec/hci_hit_response_spec.rb +15 -0
- data/spec/hci_hit_result_spec.rb +40 -0
- data/spec/hci_hit_spec.rb +101 -0
- data/spec/hits/approve_photo.rb +16 -0
- data/spec/spec_helper.rb +20 -0
- metadata +128 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.rdoc
ADDED
File without changes
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
|
6
|
+
task :default => 'spec:unit'
|
7
|
+
|
8
|
+
namespace :spec do
|
9
|
+
desc "Run unit specs"
|
10
|
+
RSpec::Core::RakeTask.new('unit') do |t|
|
11
|
+
t.pattern = 'spec/**/*_spec.rb'
|
12
|
+
end
|
13
|
+
end
|
data/hci.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "hci/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "hci"
|
7
|
+
s.version = Hci::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Sam Oliver"]
|
10
|
+
s.email = ["sam@samoliver.com"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{HCI client}
|
13
|
+
s.description = %q{HCI is a service and simple API for human intelligence tasks}
|
14
|
+
|
15
|
+
s.rubyforge_project = "hci"
|
16
|
+
|
17
|
+
s.add_dependency "rest-client"
|
18
|
+
s.add_dependency "json"
|
19
|
+
s.add_development_dependency "rspec", ">= 1.2.9"
|
20
|
+
s.add_development_dependency "webmock"
|
21
|
+
|
22
|
+
s.files = `git ls-files`.split("\n")
|
23
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
24
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
25
|
+
s.require_paths = ["lib"]
|
26
|
+
end
|
data/lib/hci/client.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
module Hci
|
2
|
+
class Client
|
3
|
+
|
4
|
+
@http_end_point = "http://hci.heroku.com"
|
5
|
+
@load_path = "hits"
|
6
|
+
|
7
|
+
class << self
|
8
|
+
attr_accessor :api_key
|
9
|
+
attr_accessor :load_path
|
10
|
+
attr_accessor :http_end_point
|
11
|
+
attr_accessor :callback_host
|
12
|
+
attr_accessor :callback_path
|
13
|
+
|
14
|
+
def version
|
15
|
+
Hci::VERSION
|
16
|
+
end
|
17
|
+
|
18
|
+
def load!
|
19
|
+
Dir[File.join(load_path, "*.rb")].each do |file|
|
20
|
+
load file
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def callback_url
|
25
|
+
callback_host + '/' + callback_path
|
26
|
+
end
|
27
|
+
|
28
|
+
def callback_path
|
29
|
+
"hci_hit_result"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Hci
|
2
|
+
class EndPoint
|
3
|
+
|
4
|
+
def initialize(app)
|
5
|
+
@app = app
|
6
|
+
end
|
7
|
+
|
8
|
+
def call(env)
|
9
|
+
if env["PATH_INFO"] =~ /^\/#{Client.callback_path}/
|
10
|
+
process_request(env)
|
11
|
+
else
|
12
|
+
@app.call(env)
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def process_request(env)
|
20
|
+
req = Rack::Request.new(env)
|
21
|
+
body = JSON.parse(req.body.read)
|
22
|
+
puts "processing hit callback"
|
23
|
+
puts body.inspect
|
24
|
+
Hci::HitResult.new(body).process!
|
25
|
+
|
26
|
+
[ 200,
|
27
|
+
{ "Content-Type" => "text/html",
|
28
|
+
"Content-Length" => "0" },
|
29
|
+
[""]
|
30
|
+
]
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
data/lib/hci/hit.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
module Hci
|
2
|
+
class Hit
|
3
|
+
|
4
|
+
class << self
|
5
|
+
|
6
|
+
attr_accessor :hits
|
7
|
+
|
8
|
+
def hits
|
9
|
+
@hits ||= {}
|
10
|
+
end
|
11
|
+
|
12
|
+
def define(name, &block)
|
13
|
+
raise ConfigurationError, "Please set your Hci api key with Hci::Client.api_key = 'your-api-key-here'" unless Client.api_key
|
14
|
+
raise ConfigurationError, "Please set your callback URL with Hci::Client.callback_host = 'www.your-domain-name.com'" unless Client.callback_host
|
15
|
+
|
16
|
+
hit = self.new
|
17
|
+
hit.name = name
|
18
|
+
yield hit
|
19
|
+
self.hits[name] = hit
|
20
|
+
end
|
21
|
+
|
22
|
+
def request(name, resource_id)
|
23
|
+
@hits[name].request(resource_id)
|
24
|
+
end
|
25
|
+
|
26
|
+
def find(name)
|
27
|
+
self.hits[name]
|
28
|
+
end
|
29
|
+
|
30
|
+
def clear!
|
31
|
+
@hits = {}
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
attr_accessor :name
|
37
|
+
attr_accessor :directions
|
38
|
+
attr_accessor :image_url
|
39
|
+
attr_accessor :answer_options
|
40
|
+
attr_accessor :answer_type
|
41
|
+
attr_accessor :responses_required
|
42
|
+
attr_accessor :replace # whether hits with the same resource id and name should be overwritten
|
43
|
+
|
44
|
+
def replace
|
45
|
+
@replace ||= false
|
46
|
+
end
|
47
|
+
|
48
|
+
def request(options)
|
49
|
+
hit_request = HitRequest.new(self, options)
|
50
|
+
hit_request.invoke
|
51
|
+
end
|
52
|
+
|
53
|
+
def to_hash
|
54
|
+
{
|
55
|
+
:name=>name,
|
56
|
+
:directions => directions,
|
57
|
+
:image_url => image_url,
|
58
|
+
:answer_options => answer_options,
|
59
|
+
:responses_required => responses_required,
|
60
|
+
:answer_type => answer_type.to_s,
|
61
|
+
:callback_url => Client.callback_url,
|
62
|
+
:replace => replace
|
63
|
+
}
|
64
|
+
end
|
65
|
+
|
66
|
+
# Callbacks
|
67
|
+
|
68
|
+
def on_completion(&block)
|
69
|
+
@on_complete_proc = block
|
70
|
+
end
|
71
|
+
|
72
|
+
def complete!(results)
|
73
|
+
@on_complete_proc.call(results) if @on_complete_proc
|
74
|
+
end
|
75
|
+
|
76
|
+
def on_failure(&block)
|
77
|
+
@on_failure_proc = block
|
78
|
+
end
|
79
|
+
|
80
|
+
def fail!(results)
|
81
|
+
@on_failure_proc.call(results) if @on_failure_proc
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rest_client'
|
2
|
+
require 'json'
|
3
|
+
module Hci
|
4
|
+
class HitRequest
|
5
|
+
|
6
|
+
def initialize(hit, params)
|
7
|
+
@hit = hit
|
8
|
+
@params = params
|
9
|
+
@http_end_point = Client.http_end_point
|
10
|
+
end
|
11
|
+
|
12
|
+
def invoke
|
13
|
+
RestClient.post("#{@http_end_point}/hits", {:hit=>@hit.to_hash.merge(@params).merge(:callback_url=>Client.callback_url), :api_key=>Client.api_key}.to_json, :content_type => :json, :accept => :json)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Hci
|
2
|
+
class HitResponse
|
3
|
+
|
4
|
+
def self.create_collection_from_array(ary)
|
5
|
+
ary.collect {|r| HitResponse.new(r) }
|
6
|
+
end
|
7
|
+
|
8
|
+
attr_accessor :answer, :callback_params, :username
|
9
|
+
|
10
|
+
def initialize(params)
|
11
|
+
@answer = params['answer']
|
12
|
+
@callback_params = params['callback_params']
|
13
|
+
@username = params['username']
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Hci
|
2
|
+
class HitResult
|
3
|
+
|
4
|
+
attr_accessor :callback_params
|
5
|
+
attr_accessor :responses
|
6
|
+
attr_accessor :name
|
7
|
+
attr_accessor :status
|
8
|
+
|
9
|
+
def initialize(params)
|
10
|
+
self.callback_params = params['callback_params']
|
11
|
+
self.responses = HitResponse.create_collection_from_array(params['responses'])
|
12
|
+
self.name = params['name']
|
13
|
+
end
|
14
|
+
|
15
|
+
def answers
|
16
|
+
responses.map(&:answer).flatten
|
17
|
+
end
|
18
|
+
|
19
|
+
def usernames
|
20
|
+
responses.map(&:username).flatten
|
21
|
+
end
|
22
|
+
|
23
|
+
def process!
|
24
|
+
if hit = Hit.find(name)
|
25
|
+
hit.complete!(self)
|
26
|
+
else
|
27
|
+
raise "The hit #{name} could not be found"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
data/lib/hci/version.rb
ADDED
data/lib/hci.rb
ADDED
data/spec/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "Client" do
|
4
|
+
it "should load hits" do
|
5
|
+
Hci::Client.load_path = File.dirname(__FILE__) + '/hits'
|
6
|
+
Hci::Client.load!
|
7
|
+
|
8
|
+
Hci::Hit.find("Approve photo").should_not == nil
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should return the current version number" do
|
12
|
+
Hci::Client.version.should == Hci::VERSION
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "HitRequest" do
|
4
|
+
|
5
|
+
it "should invoke a hit request" do
|
6
|
+
|
7
|
+
hit = Hci::Hit.define "Approve photo" do |h|
|
8
|
+
|
9
|
+
h.directions = "Please classify this photo by choosing the appropriate tickboxes."
|
10
|
+
h.image_url = "http://www.google.com/logo.png"
|
11
|
+
h.answer_type = "tags"
|
12
|
+
h.answer_options = ['Obscenity', 'Nudity', 'Blurry', 'Upside down or sideways', 'Contains more than one person in the foreground', 'Has people in the background', 'Contains children']
|
13
|
+
h.responses_required = 3
|
14
|
+
h.replace = false
|
15
|
+
|
16
|
+
h.on_completion do |result|
|
17
|
+
puts "Complete"
|
18
|
+
end
|
19
|
+
|
20
|
+
h.on_failure do |result|
|
21
|
+
puts "Failed"
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
hit_request = Hci::HitRequest.new(hit, :callback_params=>{:resource_id=>'1234'})
|
27
|
+
|
28
|
+
stub_request(:post, "hci.heroku.com/hits")
|
29
|
+
hit_request.invoke
|
30
|
+
a_request(:post, "http://hci.heroku.com/hits").with(:body=>{'hit'=>
|
31
|
+
{
|
32
|
+
'name'=>"Approve photo",
|
33
|
+
'directions'=>"Please classify this photo by choosing the appropriate tickboxes.",
|
34
|
+
'image_url'=>"http://www.google.com/logo.png",
|
35
|
+
'answer_options'=> ['Obscenity', 'Nudity', 'Blurry', 'Upside down or sideways', 'Contains more than one person in the foreground', 'Has people in the background', 'Contains children'],
|
36
|
+
'responses_required'=>3,
|
37
|
+
'answer_type'=>'tags',
|
38
|
+
'callback_url'=>"#{Hci::Client.callback_host}/hci_hit_result",
|
39
|
+
'callback_params'=>{'resource_id'=>'1234'},
|
40
|
+
'replace'=>false
|
41
|
+
}, :api_key=>'test-api-key'}).should have_been_made.once
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should allow options to be overridden when making the request" do
|
46
|
+
|
47
|
+
hit = Hci::Hit.define "Approve photo" do |h|
|
48
|
+
|
49
|
+
h.directions = "Please classify this photo by choosing the appropriate tickboxes."
|
50
|
+
h.image_url = "http://www.google.com/logo.png"
|
51
|
+
h.answer_type = "tags"
|
52
|
+
h.answer_options = ['Obscenity', 'Nudity', 'Blurry', 'Upside down or sideways', 'Contains more than one person in the foreground', 'Has people in the background', 'Contains children']
|
53
|
+
h.responses_required = 3
|
54
|
+
|
55
|
+
h.on_completion do |result|
|
56
|
+
puts "Complete"
|
57
|
+
end
|
58
|
+
|
59
|
+
h.on_failure do |result|
|
60
|
+
puts "Failed"
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
hit_request = Hci::HitRequest.new(hit, {:callback_params=>{:resource_id=>'1234'}, :image_url=>"http://www.example.com/image.jpg"})
|
66
|
+
|
67
|
+
stub_request(:post, "hci.heroku.com/hits")
|
68
|
+
hit_request.invoke
|
69
|
+
a_request(:post, "http://hci.heroku.com/hits").with(:body=>{'hit'=>
|
70
|
+
{
|
71
|
+
'name'=>"Approve photo",
|
72
|
+
'directions'=>"Please classify this photo by choosing the appropriate tickboxes.",
|
73
|
+
'image_url'=>"http://www.example.com/image.jpg",
|
74
|
+
'answer_options'=> ['Obscenity', 'Nudity', 'Blurry', 'Upside down or sideways', 'Contains more than one person in the foreground', 'Has people in the background', 'Contains children'],
|
75
|
+
'responses_required'=>3,
|
76
|
+
'answer_type'=>'tags',
|
77
|
+
'callback_url'=>"#{Hci::Client.callback_host}/hci_hit_result",
|
78
|
+
'callback_params'=>{'resource_id'=>'1234'},
|
79
|
+
'replace'=>false,
|
80
|
+
}, :api_key=>'test-api-key'}).should have_been_made.once
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "HitResponse" do
|
4
|
+
it "should create responses from an array" do
|
5
|
+
r = Hci::HitResponse.create_collection_from_array([{'answer'=>'answer 1'}, {'answer'=>'answer 2'}])
|
6
|
+
r[0].answer.should == "answer 1"
|
7
|
+
r[1].answer.should == "answer 2"
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should accept and store a username" do
|
11
|
+
r = Hci::HitResponse.create_collection_from_array([{'answer'=>'answer 1', 'username'=>'bilbo'}, {'answer'=>'answer 2', 'username'=>'frodo'}])
|
12
|
+
r[0].username.should == "bilbo"
|
13
|
+
r[1].username.should == "frodo"
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "HitResult" do
|
4
|
+
|
5
|
+
it "should invoke a hits complete callback" do
|
6
|
+
|
7
|
+
resources = {}
|
8
|
+
resources['1'] = OpenStruct.new(:approved=>false)
|
9
|
+
resources['2'] = OpenStruct.new(:approved=>false)
|
10
|
+
resources['3'] = OpenStruct.new(:approved=>false)
|
11
|
+
|
12
|
+
hit = Hci::Hit.define("Approve photo") do |h|
|
13
|
+
|
14
|
+
h.on_completion do |result|
|
15
|
+
if result.responses.first.answer == 'yes'
|
16
|
+
resources[result.callback_params['resource_id']].approved = true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
Hci::HitResult.new({'callback_params'=>{'resource_id' => '2'}, 'responses'=>[{'answer'=>'yes'}], 'name'=>"Approve photo"}).process!
|
23
|
+
|
24
|
+
resources['1'].approved.should == false
|
25
|
+
resources['2'].approved.should == true
|
26
|
+
resources['3'].approved.should == false
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should collect the answers" do
|
31
|
+
r = Hci::HitResult.new({'callback_params'=>{'resource_id' => '2'}, 'responses'=>[{'answer'=>'yes'}, {'answer'=>'no'}, {'answer'=>'yes'}], 'name'=>"Approve photo"})
|
32
|
+
r.answers.should == ['yes', 'no', 'yes']
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should collect the usernames" do
|
36
|
+
r = Hci::HitResult.new({'callback_params'=>{'resource_id' => '2'}, 'responses'=>[{'answer'=>'yes', 'username'=>'bilbo'}, {'answer'=>'no', 'username'=>'frodo'}, {'answer'=>'yes', 'username'=>'sam'}], 'name'=>"Approve photo"})
|
37
|
+
r.usernames.should == ['bilbo', 'frodo', 'sam']
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "Hit" do
|
4
|
+
it "should define a hit" do
|
5
|
+
|
6
|
+
Hci::Hit.define "Approve photo" do |h|
|
7
|
+
|
8
|
+
h.directions = "Please classify this photo by choosing the appropriate tickboxes."
|
9
|
+
h.image_url = "http://www.google.com/logo.png"
|
10
|
+
h.answer_options = ['Obscenity', 'Nudity', 'Blurry', 'Upside down or sideways', 'Contains more than one person in the foreground', 'Has people in the background', 'Contains children']
|
11
|
+
h.responses_required = 3
|
12
|
+
|
13
|
+
h.on_completion do |result|
|
14
|
+
puts "Complete"
|
15
|
+
end
|
16
|
+
|
17
|
+
h.on_failure do |result|
|
18
|
+
puts "Failed"
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
Hci::Hit.hits.first[1].directions.should == "Please classify this photo by choosing the appropriate tickboxes."
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should run a completion callback" do
|
28
|
+
|
29
|
+
object = OpenStruct.new(:test=>nil)
|
30
|
+
|
31
|
+
hit = Hci::Hit.define "Approve photo" do |h|
|
32
|
+
|
33
|
+
h.on_completion do |result|
|
34
|
+
object.test = "Complete"
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
object.test.should == nil
|
40
|
+
hit.complete!({})
|
41
|
+
object.test.should == "Complete"
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should run a failure callback" do
|
45
|
+
|
46
|
+
object = OpenStruct.new(:test=>nil)
|
47
|
+
|
48
|
+
hit = Hci::Hit.define "Approve photo" do |h|
|
49
|
+
|
50
|
+
h.on_failure do |result|
|
51
|
+
object.test = "Failed"
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
object.test.should == nil
|
57
|
+
hit.fail!({})
|
58
|
+
object.test.should == "Failed"
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should not raise an error if there is no callback defined" do
|
62
|
+
lambda {
|
63
|
+
hit = Hci::Hit.define("Approve photo") { }
|
64
|
+
hit.fail!({})
|
65
|
+
}.should_not raise_error
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should request a hit" do
|
69
|
+
|
70
|
+
hit = Hci::Hit.define("Approve photo") { }
|
71
|
+
hit.should_receive(:request).with(:request_id=>'123')
|
72
|
+
Hci::Hit.request("Approve photo", :request_id=>'123')
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should find a hit" do
|
77
|
+
Hci::Hit.define("Approve photo") { }
|
78
|
+
Hci::Hit.define("Check profile text") { }
|
79
|
+
Hci::Hit.define("Check content") { }
|
80
|
+
|
81
|
+
|
82
|
+
Hci::Hit.find("Check profile text").name.should == "Check profile text"
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should raise a ConfigurationError if a callback host is not set" do
|
87
|
+
Hci::Client.callback_host = nil
|
88
|
+
lambda {
|
89
|
+
Hci::Hit.define("Approve photo") { }
|
90
|
+
}.should raise_error Hci::ConfigurationError
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should raise a ConfigurationError if an API key is not set" do
|
94
|
+
Hci::Client.api_key = nil
|
95
|
+
lambda {
|
96
|
+
Hci::Hit.define("Approve photo") { }
|
97
|
+
}.should raise_error Hci::ConfigurationError
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
Hci::Hit.define "Approve photo" do |h|
|
2
|
+
|
3
|
+
h.directions = "Please classify this photo by choosing the appropriate tickboxes."
|
4
|
+
h.image_url = "http://www.google.com/logo.png"
|
5
|
+
h.answer_options = ['Obscenity', 'Nudity', 'Blurry', 'Upside down or sideways', 'Contains more than one person in the foreground', 'Has people in the background', 'Contains children']
|
6
|
+
h.responses_required = 3
|
7
|
+
|
8
|
+
h.on_completion do |result|
|
9
|
+
puts "Complete"
|
10
|
+
end
|
11
|
+
|
12
|
+
h.on_failure do |result|
|
13
|
+
puts "Failed"
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
require 'hci'
|
4
|
+
require 'rspec'
|
5
|
+
require 'rspec/autorun'
|
6
|
+
require 'webmock/rspec'
|
7
|
+
|
8
|
+
RSpec.configure do |config|
|
9
|
+
config.color_enabled = true
|
10
|
+
config.after :each do
|
11
|
+
Hci::Hit.clear!
|
12
|
+
end
|
13
|
+
|
14
|
+
config.before :each do
|
15
|
+
Hci::Client.api_key = "test-api-key"
|
16
|
+
Hci::Client.callback_host = "www.example.com"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hci
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Sam Oliver
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-02-28 00:00:00 +00:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: rest-client
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: "0"
|
25
|
+
type: :runtime
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json
|
29
|
+
prerelease: false
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: "0"
|
36
|
+
type: :runtime
|
37
|
+
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: rspec
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 1.2.9
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id003
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: webmock
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "0"
|
58
|
+
type: :development
|
59
|
+
version_requirements: *id004
|
60
|
+
description: HCI is a service and simple API for human intelligence tasks
|
61
|
+
email:
|
62
|
+
- sam@samoliver.com
|
63
|
+
executables: []
|
64
|
+
|
65
|
+
extensions: []
|
66
|
+
|
67
|
+
extra_rdoc_files: []
|
68
|
+
|
69
|
+
files:
|
70
|
+
- .gitignore
|
71
|
+
- Gemfile
|
72
|
+
- README.rdoc
|
73
|
+
- Rakefile
|
74
|
+
- hci.gemspec
|
75
|
+
- lib/hci.rb
|
76
|
+
- lib/hci/client.rb
|
77
|
+
- lib/hci/end_point.rb
|
78
|
+
- lib/hci/exceptions.rb
|
79
|
+
- lib/hci/frameworks/rails.rb
|
80
|
+
- lib/hci/hit.rb
|
81
|
+
- lib/hci/hit_request.rb
|
82
|
+
- lib/hci/hit_response.rb
|
83
|
+
- lib/hci/hit_result.rb
|
84
|
+
- lib/hci/version.rb
|
85
|
+
- spec/.rspec
|
86
|
+
- spec/hci_client_spec.rb
|
87
|
+
- spec/hci_hit_request_spec.rb
|
88
|
+
- spec/hci_hit_response_spec.rb
|
89
|
+
- spec/hci_hit_result_spec.rb
|
90
|
+
- spec/hci_hit_spec.rb
|
91
|
+
- spec/hits/approve_photo.rb
|
92
|
+
- spec/spec_helper.rb
|
93
|
+
has_rdoc: true
|
94
|
+
homepage: ""
|
95
|
+
licenses: []
|
96
|
+
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options: []
|
99
|
+
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: "0"
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
none: false
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: "0"
|
114
|
+
requirements: []
|
115
|
+
|
116
|
+
rubyforge_project: hci
|
117
|
+
rubygems_version: 1.5.3
|
118
|
+
signing_key:
|
119
|
+
specification_version: 3
|
120
|
+
summary: HCI client
|
121
|
+
test_files:
|
122
|
+
- spec/hci_client_spec.rb
|
123
|
+
- spec/hci_hit_request_spec.rb
|
124
|
+
- spec/hci_hit_response_spec.rb
|
125
|
+
- spec/hci_hit_result_spec.rb
|
126
|
+
- spec/hci_hit_spec.rb
|
127
|
+
- spec/hits/approve_photo.rb
|
128
|
+
- spec/spec_helper.rb
|