get_humanoid 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 ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ *.swp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in get_humanoid.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Speakertext Inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,57 @@
1
+ == Humanoid REST API Wrapper for Ruby
2
+
3
+ Welcome to Humanoid, the easiest way to get work done without the hassle of hiring and managing a workforce. Design a task, and we’ll send it to our 30,000+ person workforce. Our innovative software ensures that you receive quality results quickly and inexpensively.
4
+
5
+ This Ruby gem wraps our simple REST API to make sending work and receiving results even easier. For further details, you can read our {API documentation}[https://gethumanoid.com/v3/docs/tasks].
6
+
7
+ == Getting Started
8
+
9
+ First, you'll need to initialize an instance of the GetHumanoid class with your configuration details. You can find your public and private key on your {account page}[https://gethumanoid.com/account]. For example:
10
+
11
+ config = {
12
+ 'public_key' => 'foo',
13
+ 'private_key' => 'bar,
14
+ 'callback_url' => 'http://send.me/results,
15
+ }
16
+
17
+ client = GetHumanoid::Client.new(config)
18
+
19
+ That's it! Now you're ready to use Humanoid.
20
+
21
+ If you're using Rails, you'll want to put this in an initializer and store your config in a standard rails config YAML file. An example config/initializers/humanoid.rb might contain:
22
+
23
+ config = YAML.load_file("#{Rails.root}/config/humanoid.yml")[Rails.env]
24
+
25
+ HUMANOID = GetHumanoid::Client.new(config)
26
+
27
+ == Usage
28
+
29
+ After creating a template on https://gethumanoid.com, you'll be able to send work and receive results via our API. To fetch a list of your templates, simply call:
30
+
31
+ client.templates
32
+
33
+ Now you're ready to send data to our workers. Let's assume you want them to tag a set of two images. Your data might look something like this:
34
+
35
+ resources = [
36
+ {
37
+ :identifier => 1,
38
+ :image_url => 'http://images.com/foo',
39
+ },
40
+ {
41
+ :identifier => 2,
42
+ :image_url => 'http://images.com/bar',
43
+ },
44
+ ]
45
+
46
+ To create a task using your template, just call:
47
+
48
+ GetHumanoid::Task.create(
49
+ client,
50
+ template_id,
51
+ resources
52
+ )
53
+
54
+ You can find the template ID on the {templates page}[https://gethumanoid.com/templates]. When your task is complete, Humanoid will POST your results to the callback URL specified in your initial config. You can read further about this process over on our {API documentation}[https://gethumanoid.com/v3/docs/tasks].
55
+
56
+ == Copyright
57
+ Copyright (c) 2012 Speakertext, Inc.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "get_humanoid/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "get_humanoid"
7
+ s.version = GetHumanoid::VERSION
8
+ s.authors = ["Jason Snell"]
9
+ s.email = ["jason@gethumanoid.com"]
10
+ s.homepage = "https://gethumanoid.com"
11
+ s.summary = %q{Official Humanoid Gem}
12
+ s.description = %q{Humanoid is an on-demand human workforce API}
13
+
14
+ s.rubyforge_project = "get_humanoid"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ # s.add_runtime_dependency "rest-client"
24
+
25
+ s.add_runtime_dependency "httparty"
26
+ end
@@ -0,0 +1,5 @@
1
+ require "get_humanoid/version"
2
+ require "get_humanoid/errors"
3
+ require "get_humanoid/client"
4
+ require "get_humanoid/task"
5
+ require "get_humanoid/template"
@@ -0,0 +1,75 @@
1
+ require 'httparty'
2
+
3
+ module GetHumanoid
4
+ class Client
5
+ include HTTParty
6
+
7
+ attr_reader :callback_url
8
+
9
+ format :json
10
+
11
+ class ResponseParser < HTTParty::Parser
12
+ SupportedFormats = {
13
+ 'application/json' => :json,
14
+ 'text/json' => :json,
15
+ 'application/javascript' => :json,
16
+ 'text/javascript' => :json,
17
+ }
18
+
19
+ def parse
20
+ decoded_body = MultiJson.decode(body)
21
+
22
+ # Catch and raise errors as necessary
23
+ if decoded_body.is_a?(Hash) and decoded_body['error']
24
+ raise GetHumanoid::Error, decoded_body
25
+ end
26
+
27
+ return decoded_body
28
+ end
29
+ end
30
+
31
+ parser ResponseParser
32
+
33
+ def initialize(config)
34
+ @public_key = config['public_key']
35
+ @private_key = config['private_key']
36
+ @path = config['path'] || 'https://gethumanoid.com/v3'
37
+ @callback_url = config['callback_url']
38
+
39
+ self.class.basic_auth @public_key, @private_key
40
+ self.class.base_uri @path
41
+ end
42
+
43
+ # Fetch a list of tasks
44
+ def tasks
45
+ return self.class.get('/tasks').parsed_response.map do |task|
46
+ Task.new(
47
+ task['task_id'],
48
+ task['template_id'],
49
+ task['status'],
50
+ task['started_at']
51
+ )
52
+ end
53
+ end
54
+
55
+ # Fetch a single task
56
+ def task(task_id)
57
+ task = self.class.get("/tasks/%s" % task_id).parsed_response
58
+
59
+ return Task.new(
60
+ task['task_id'],
61
+ task['template_id'],
62
+ task['status'],
63
+ task['started_at']
64
+ )
65
+ end
66
+
67
+ # Fetch a list of templates
68
+ def templates
69
+ return self.class.get('/templates').parsed_response.map do |template|
70
+ Template.new(template['template_id'], template['name'])
71
+ end
72
+ end
73
+
74
+ end
75
+ end
@@ -0,0 +1,14 @@
1
+ module GetHumanoid
2
+ class Error < StandardError
3
+ attr_reader :code, :status
4
+
5
+ def initialize(error)
6
+ # Pass the text message through, adding code and status
7
+ @code = error['code']
8
+ @status = error['status']
9
+
10
+ super error['error']
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,33 @@
1
+ module GetHumanoid
2
+ class Task
3
+ attr_accessor :task_id, :template_id, :status, :started_at
4
+
5
+ def initialize(task_id, template_id, status, started_at)
6
+ @task_id = task_id
7
+ @template = template_id
8
+ @status = status
9
+ @started_at = started_at
10
+ end
11
+
12
+ # Send a batch of data to Humanoid. See
13
+ # https://gethumanoid.com/v3/docs/tasks for details.
14
+ def self.create(client, template_id, resources, callback_url = nil, sandbox = false)
15
+ post_data = {
16
+ :template_id => template_id,
17
+ :callback_url => callback_url || client.callback_url,
18
+ :resources => resources,
19
+ :sandbox => sandbox,
20
+ }
21
+
22
+ response = client.class.post('/tasks', :query => post_data).parsed_response
23
+
24
+ return Task.new(
25
+ response['task_id'],
26
+ response['template_id'],
27
+ response['status'],
28
+ response['started_at']
29
+ )
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,15 @@
1
+ module GetHumanoid
2
+ class Template
3
+ attr_accessor :template_id, :name
4
+
5
+ def initialize(template_id, name = nil)
6
+ @template_id = template_id
7
+ @name = name
8
+ end
9
+
10
+ def create_task(client, resources, callback_url = nil, sandbox = false)
11
+ Task.create(client, @template_id, resources, callback_url = nil, sandbox = false)
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module GetHumanoid
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: get_humanoid
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jason Snell
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-14 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: &9824480 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *9824480
25
+ description: Humanoid is an on-demand human workforce API
26
+ email:
27
+ - jason@gethumanoid.com
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - LICENSE
35
+ - README.rdoc
36
+ - Rakefile
37
+ - get_humanoid.gemspec
38
+ - lib/get_humanoid.rb
39
+ - lib/get_humanoid/client.rb
40
+ - lib/get_humanoid/errors.rb
41
+ - lib/get_humanoid/task.rb
42
+ - lib/get_humanoid/template.rb
43
+ - lib/get_humanoid/version.rb
44
+ homepage: https://gethumanoid.com
45
+ licenses: []
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubyforge_project: get_humanoid
64
+ rubygems_version: 1.8.10
65
+ signing_key:
66
+ specification_version: 3
67
+ summary: Official Humanoid Gem
68
+ test_files: []