bpo-ruby-crowdflower 0.0.0 → 0.0.2
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/Rakefile +6 -0
- data/VERSION +1 -1
- data/lib/ruby-crowdflower.rb +6 -2
- data/lib/ruby-crowdflower/base.rb +27 -0
- data/lib/ruby-crowdflower/job.rb +81 -0
- data/lib/ruby-crowdflower/judgment.rb +21 -0
- data/lib/ruby-crowdflower/order.rb +16 -0
- data/lib/ruby-crowdflower/{httparty.rb → patches/httparty.rb} +7 -13
- data/lib/ruby-crowdflower/unit.rb +32 -0
- data/ruby-crowdflower.gemspec +9 -5
- metadata +9 -6
- data/lib/ruby-crowdflower/crowdflower.rb +0 -132
data/Rakefile
CHANGED
|
@@ -37,6 +37,12 @@ end
|
|
|
37
37
|
|
|
38
38
|
task :default => :spec
|
|
39
39
|
|
|
40
|
+
task :refresh_builder => [:build] do
|
|
41
|
+
cp "pkg/ruby-crowdflower-#{File.read("VERSION").strip}.gem", "../builder/gems/cache/"
|
|
42
|
+
rm_rf "../builder/gems/gems/ruby-crowdflower-#{File.read("VERSION").strip}/"
|
|
43
|
+
`cd ../builder && bin/thor merb:gem:redeploy`
|
|
44
|
+
end
|
|
45
|
+
|
|
40
46
|
require 'rake/rdoctask'
|
|
41
47
|
Rake::RDocTask.new do |rdoc|
|
|
42
48
|
if File.exist?('VERSION.yml')
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.0.
|
|
1
|
+
0.0.2
|
data/lib/ruby-crowdflower.rb
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
require 'httparty'
|
|
2
|
-
require 'ruby-crowdflower/httparty'
|
|
3
|
-
require 'ruby-crowdflower/
|
|
2
|
+
require 'ruby-crowdflower/patches/httparty'
|
|
3
|
+
require 'ruby-crowdflower/base'
|
|
4
|
+
require 'ruby-crowdflower/job'
|
|
5
|
+
require 'ruby-crowdflower/unit'
|
|
6
|
+
require 'ruby-crowdflower/judgment'
|
|
7
|
+
require 'ruby-crowdflower/order'
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module CrowdFlower
|
|
2
|
+
@@key = nil
|
|
3
|
+
@@domain = nil
|
|
4
|
+
|
|
5
|
+
module Defaults
|
|
6
|
+
def self.included(base)
|
|
7
|
+
base.send :include, HTTParty
|
|
8
|
+
base.send :headers, "accept" => "application/json"
|
|
9
|
+
base.send :format, :json
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def self.connect!(key, development = false)
|
|
14
|
+
@@domain = development ? "http://api.localhost:4000/v1" : "https://api.crowdflower.com/v1"
|
|
15
|
+
@@key = key
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def self.with_domain(path)
|
|
19
|
+
raise "Please establish a connection using 'CrowdFlower.connect!'" unless @@domain
|
|
20
|
+
@@domain + path
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def self.key
|
|
24
|
+
raise "Please establish a connection using 'CrowdFlower.connect!'" unless @@key
|
|
25
|
+
{:key => @@key}
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
module CrowdFlower
|
|
2
|
+
class Job
|
|
3
|
+
include Defaults
|
|
4
|
+
attr_reader :id
|
|
5
|
+
|
|
6
|
+
def initialize(job_id)
|
|
7
|
+
@id = job_id
|
|
8
|
+
Job.base_uri CrowdFlower.with_domain("/jobs")
|
|
9
|
+
Job.default_params CrowdFlower.key
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def self.all
|
|
13
|
+
Job.get("/")
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def get(id = nil)
|
|
17
|
+
Job.get("/#{@id || id}")
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
#Copies a job and optionally gold or all units.
|
|
21
|
+
#Parameters
|
|
22
|
+
# opts: Hash
|
|
23
|
+
# gold: when set to true copies gold units
|
|
24
|
+
# all_units: when set to true copies all units
|
|
25
|
+
def copy(opts = {})
|
|
26
|
+
Job.get("/#{@id}/copy", {:query => opts})
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def status
|
|
30
|
+
Job.get("/#{@id}/ping")
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def upload(file, content_type)
|
|
34
|
+
Job.upload(file, content_type, @id)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def legend
|
|
38
|
+
Job.get("/#{@id}/legend")
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def self.upload(file, content_type, job_id = nil)
|
|
42
|
+
job_id = "/#{job_id}" unless job_id.nil?
|
|
43
|
+
Job.post("#{job_id}/upload",
|
|
44
|
+
:body => File.read(file),
|
|
45
|
+
:headers => custom_content_type(content_type))
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def download_csv(full = true, filename = nil)
|
|
49
|
+
filename ||= "#{full ? "f" : "a"}#{@id}.csv"
|
|
50
|
+
res = Job.get("/#{@id}.csv", {:format => :csv, :query => {:full => full}})
|
|
51
|
+
puts "Status... #{res.code.inspect}"
|
|
52
|
+
if res.code == 202
|
|
53
|
+
puts "CSV Generating... Trying again in 10 seconds."
|
|
54
|
+
Kernel.sleep 10
|
|
55
|
+
download_csv
|
|
56
|
+
else
|
|
57
|
+
puts "CSV written to: #{File.expand_path(filename)}"
|
|
58
|
+
File.open(filename, "w") {|f| f.puts res.body }
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def pause
|
|
63
|
+
Job.get("/#{@id}/pause")
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def resume
|
|
67
|
+
Job.get("/#{@id}/resume")
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def cancel
|
|
71
|
+
Job.get("/#{@id}/cancel")
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
private
|
|
75
|
+
|
|
76
|
+
def self.custom_content_type(content_type)
|
|
77
|
+
#To preserve the accept header we are forced to merge the defaults back in...
|
|
78
|
+
Job.default_options[:headers].merge({"content-type" => content_type})
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module CrowdFlower
|
|
2
|
+
class Judgment
|
|
3
|
+
include Defaults
|
|
4
|
+
attr_reader :job
|
|
5
|
+
|
|
6
|
+
def initialize(job)
|
|
7
|
+
@job = job
|
|
8
|
+
Judgment.base_uri CrowdFlower.with_domain("/jobs/#{@job.id}/judgments")
|
|
9
|
+
Judgment.default_params CrowdFlower.key
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
#Pull every judgment
|
|
13
|
+
def all(page = 1, limit = 1000)#full = true
|
|
14
|
+
Judgment.get("", {:query => {:limit => limit, :page => page}})
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def get(id)
|
|
18
|
+
Judgment.get("/#{id}")
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module CrowdFlower
|
|
2
|
+
class Order
|
|
3
|
+
include Defaults
|
|
4
|
+
attr_reader :job
|
|
5
|
+
|
|
6
|
+
def initialize(job)
|
|
7
|
+
@job = job
|
|
8
|
+
Order.base_uri CrowdFlower.with_domain("/jobs/#{@job.id}/orders")
|
|
9
|
+
Order.default_params CrowdFlower.key
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def debit(percentage = 100)
|
|
13
|
+
Order.post("", {:query => {:percentage => percentage}})
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -5,26 +5,20 @@ module HTTParty
|
|
|
5
5
|
when Net::HTTPRedirection
|
|
6
6
|
options[:limit] -= 1
|
|
7
7
|
|
|
8
|
+
self.http_method = Net::HTTP::Get
|
|
8
9
|
self.path = response['location']
|
|
9
|
-
|
|
10
|
+
|
|
11
|
+
#Remove post data
|
|
12
|
+
options[:body] = ""
|
|
13
|
+
options[:headers].delete('content-type')
|
|
10
14
|
@message = parse_response(response.body.to_s) rescue nil
|
|
11
15
|
perform
|
|
12
16
|
else
|
|
13
17
|
parsed_response = parse_response(response.body.to_s)
|
|
14
18
|
Response.new(parsed_response, response.body.to_s, response.code, @message || response.message, response.to_hash)
|
|
15
19
|
end
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
def uri
|
|
19
|
-
# Don't use relative path on redirect
|
|
20
|
-
new_uri = path.relative? && !@redirect ? URI.parse("#{options[:base_uri]}#{path}") : path
|
|
21
|
-
|
|
22
|
-
# avoid double query string on redirects [#12]
|
|
23
|
-
unless @redirect
|
|
24
|
-
new_uri.query = query_string(new_uri)
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
new_uri
|
|
20
|
+
rescue
|
|
21
|
+
puts response.body.to_s
|
|
28
22
|
end
|
|
29
23
|
end
|
|
30
24
|
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
module CrowdFlower
|
|
2
|
+
class Unit
|
|
3
|
+
include Defaults
|
|
4
|
+
attr_reader :job
|
|
5
|
+
|
|
6
|
+
def initialize(job)
|
|
7
|
+
@job = job
|
|
8
|
+
Unit.base_uri CrowdFlower.with_domain("/jobs/#{@job.id}/units")
|
|
9
|
+
Unit.default_params CrowdFlower.key
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def all(page = 1, limit = 1000)
|
|
13
|
+
Unit.get("", {:query => {:limit => limit, :page => page}})
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def get(id)
|
|
17
|
+
Unit.get("/#{id}")
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def create(data, gold = nil)
|
|
21
|
+
Unit.post("", {:query => {:unit => {:data => data.to_json, :golden => gold}}})
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def copy(unit_id, job_id, data = {})
|
|
25
|
+
Unit.get("/#{unit_id}/copy", {:query => {:unit => {:job_id => job_id, :data => data}}})
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def split(on, with = " ")
|
|
29
|
+
Unit.get("/split", {:query => {:on => on, :with => with}})
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
data/ruby-crowdflower.gemspec
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
Gem::Specification.new do |s|
|
|
4
4
|
s.name = %q{ruby-crowdflower}
|
|
5
|
-
s.version = "0.0.
|
|
5
|
+
s.version = "0.0.2"
|
|
6
6
|
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
8
8
|
s.authors = ["Brian P O'Rourke", "Chris Van Pelt"]
|
|
9
|
-
s.date = %q{2009-07
|
|
9
|
+
s.date = %q{2009-08-07}
|
|
10
10
|
s.description = %q{A toolkit for interacting with CrowdFlower via the REST API.
|
|
11
11
|
|
|
12
12
|
This is alpha software in its most nascent stages, and is not
|
|
@@ -26,8 +26,12 @@ yet ready for use with the current version of CrowdFlower.
|
|
|
26
26
|
"Rakefile",
|
|
27
27
|
"VERSION",
|
|
28
28
|
"lib/ruby-crowdflower.rb",
|
|
29
|
-
"lib/ruby-crowdflower/
|
|
30
|
-
"lib/ruby-crowdflower/
|
|
29
|
+
"lib/ruby-crowdflower/base.rb",
|
|
30
|
+
"lib/ruby-crowdflower/job.rb",
|
|
31
|
+
"lib/ruby-crowdflower/judgment.rb",
|
|
32
|
+
"lib/ruby-crowdflower/order.rb",
|
|
33
|
+
"lib/ruby-crowdflower/patches/httparty.rb",
|
|
34
|
+
"lib/ruby-crowdflower/unit.rb",
|
|
31
35
|
"ruby-crowdflower.gemspec",
|
|
32
36
|
"spec/ruby-crowdflower_spec.rb",
|
|
33
37
|
"spec/spec_helper.rb"
|
|
@@ -35,7 +39,7 @@ yet ready for use with the current version of CrowdFlower.
|
|
|
35
39
|
s.homepage = %q{http://github.com/dolores/ruby-crowdflower}
|
|
36
40
|
s.rdoc_options = ["--charset=UTF-8"]
|
|
37
41
|
s.require_paths = ["lib"]
|
|
38
|
-
s.rubygems_version = %q{1.3.
|
|
42
|
+
s.rubygems_version = %q{1.3.4}
|
|
39
43
|
s.summary = %q{a toolkit for the CrowdFlower API}
|
|
40
44
|
s.test_files = [
|
|
41
45
|
"spec/ruby-crowdflower_spec.rb",
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: bpo-ruby-crowdflower
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Brian P O'Rourke
|
|
@@ -10,7 +10,7 @@ autorequire:
|
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
12
|
|
|
13
|
-
date: 2009-07
|
|
13
|
+
date: 2009-08-07 00:00:00 -07:00
|
|
14
14
|
default_executable:
|
|
15
15
|
dependencies:
|
|
16
16
|
- !ruby/object:Gem::Dependency
|
|
@@ -40,14 +40,17 @@ files:
|
|
|
40
40
|
- Rakefile
|
|
41
41
|
- VERSION
|
|
42
42
|
- lib/ruby-crowdflower.rb
|
|
43
|
-
- lib/ruby-crowdflower/
|
|
44
|
-
- lib/ruby-crowdflower/
|
|
43
|
+
- lib/ruby-crowdflower/base.rb
|
|
44
|
+
- lib/ruby-crowdflower/job.rb
|
|
45
|
+
- lib/ruby-crowdflower/judgment.rb
|
|
46
|
+
- lib/ruby-crowdflower/order.rb
|
|
47
|
+
- lib/ruby-crowdflower/patches/httparty.rb
|
|
48
|
+
- lib/ruby-crowdflower/unit.rb
|
|
45
49
|
- ruby-crowdflower.gemspec
|
|
46
50
|
- spec/ruby-crowdflower_spec.rb
|
|
47
51
|
- spec/spec_helper.rb
|
|
48
52
|
has_rdoc: false
|
|
49
53
|
homepage: http://github.com/dolores/ruby-crowdflower
|
|
50
|
-
licenses:
|
|
51
54
|
post_install_message:
|
|
52
55
|
rdoc_options:
|
|
53
56
|
- --charset=UTF-8
|
|
@@ -68,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
68
71
|
requirements: []
|
|
69
72
|
|
|
70
73
|
rubyforge_project:
|
|
71
|
-
rubygems_version: 1.
|
|
74
|
+
rubygems_version: 1.2.0
|
|
72
75
|
signing_key:
|
|
73
76
|
specification_version: 3
|
|
74
77
|
summary: a toolkit for the CrowdFlower API
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
module CrowdFlower
|
|
2
|
-
def self.connect!(key)
|
|
3
|
-
@@conn = Base.new(key)
|
|
4
|
-
end
|
|
5
|
-
|
|
6
|
-
def self.conn
|
|
7
|
-
raise "Please establish a connection using 'CrowdFlower.connect!'" unless @@conn
|
|
8
|
-
@@conn.class
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
class Base
|
|
12
|
-
include HTTParty
|
|
13
|
-
|
|
14
|
-
def initialize(key)
|
|
15
|
-
Base.default_params(:key => key)
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
module Defaults
|
|
20
|
-
def self.included(base)
|
|
21
|
-
base.send :include, HTTParty
|
|
22
|
-
base.send :headers, "HTTP_ACCEPT" => "application/json"
|
|
23
|
-
base.send :format, :json
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
class Job
|
|
28
|
-
include Defaults
|
|
29
|
-
attr_reader :job_id
|
|
30
|
-
|
|
31
|
-
def initialize(job_id)
|
|
32
|
-
@job_id = job_id
|
|
33
|
-
Job.base_uri "https://api.crowdflower.com/v1/jobs"
|
|
34
|
-
Job.default_params(CrowdFlower.conn.default_params)
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def self.all
|
|
38
|
-
Job.get("/")
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def get(id = nil)
|
|
42
|
-
Job.get("/#{@job_id || id}")
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
#Copies a job and optionally gold or all units.
|
|
46
|
-
#Parameters
|
|
47
|
-
# opts: Hash
|
|
48
|
-
# gold: when set to true copies gold units
|
|
49
|
-
# all_units: when set to true copies all units
|
|
50
|
-
def copy(opts = {})
|
|
51
|
-
Job.get("/#{@job_id}/copy", {:query => opts})
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
def status
|
|
55
|
-
Job.get("/#{@job_id}/ping")
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def download_csv(full = true, filename = nil)
|
|
59
|
-
filename ||= "#{full ? "f" : "a"}#{@job_id}.csv"
|
|
60
|
-
res = Job.get("/#{@job_id}.csv", {:format => :csv, :query => {:full => full}})
|
|
61
|
-
puts "Status... #{res.code.inspect}"
|
|
62
|
-
if res.code == 202
|
|
63
|
-
puts "CSV Generating... Trying again in 10 seconds."
|
|
64
|
-
Kernel.sleep 10
|
|
65
|
-
download_csv
|
|
66
|
-
else
|
|
67
|
-
puts "CSV written to: #{File.expand_path(filename)}"
|
|
68
|
-
File.open(filename, "w") {|f| f.puts res.body }
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
def pause
|
|
73
|
-
Job.get("/#{@job_id}/pause")
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
def resume
|
|
77
|
-
Job.get("/#{@job_id}/resume")
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
def cancel
|
|
81
|
-
Job.get("/#{@job_id}/cancel")
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
class Unit
|
|
86
|
-
include Defaults
|
|
87
|
-
|
|
88
|
-
def initialize(job)
|
|
89
|
-
@job = job
|
|
90
|
-
Unit.base_uri "https://api.crowdflower.com/v1/jobs/#{@job.job_id}/units"
|
|
91
|
-
Unit.default_params(CrowdFlower.conn.default_params)
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
def all(page = 1, limit = 1000)
|
|
95
|
-
Unit.get("", {:query => {:limit => limit, :page => page}})
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
def get(id)
|
|
99
|
-
Unit.get("/#{id}")
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
def create(data, gold = nil)
|
|
103
|
-
Unit.post("", {:query => {:unit => {:data => data.to_json, :golden => gold}}})
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
def copy(unit_id, job_id, data = {})
|
|
107
|
-
Unit.get("/#{unit_id}/copy", {:query => {:unit => {:job_id => job_id, :data => data}}})
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
def split(on, with = " ")
|
|
111
|
-
Unit.get("/split", {:query => {:on => on, :with => with}})
|
|
112
|
-
end
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
class Judgment
|
|
116
|
-
include Defaults
|
|
117
|
-
|
|
118
|
-
def initialize(job)
|
|
119
|
-
Judgment.base_uri "https://api.crowdflower.com/v1/jobs/#{@job.job_id}/judgments"
|
|
120
|
-
Judgment.default_params(CrowdFlower.conn.default_params)
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
#Pull every judgment
|
|
124
|
-
def all(page = 1, limit = 1000)#full = true
|
|
125
|
-
Judgment.get("", {:query => {:limit => limit, :page => page}})
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
def get(id)
|
|
129
|
-
Judgment.get("/#{id}")
|
|
130
|
-
end
|
|
131
|
-
end
|
|
132
|
-
end
|