bpo-ruby-crowdflower 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Dolores Labs
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,21 @@
1
+ = ruby-crowdflower
2
+
3
+ A toolkit for interacting with CrowdFlower via the REST API.
4
+
5
+ This is alpha software in its most nascent stages, and is not
6
+ yet ready for use with the current version of CrowdFlower.
7
+
8
+ == Note on Patches/Pull Requests
9
+
10
+ * Fork the project.
11
+ * Make your feature addition or bug fix.
12
+ * Add tests for it. This is important so I don't break it in a
13
+ future version unintentionally.
14
+ * Commit, do not mess with rakefile, version, or history.
15
+ (if you want to have your own version, that is fine but
16
+ bump version in a commit by itself I can ignore when I pull)
17
+ * Send me a pull request. Bonus points for topic branches.
18
+
19
+ == Copyright
20
+
21
+ Copyright (c) 2009 Dolores Labs. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,54 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "ruby-crowdflower"
8
+ gem.summary = %Q{a toolkit for the CrowdFlower API}
9
+ gem.description = <<-EOF
10
+ A toolkit for interacting with CrowdFlower via the REST API.
11
+
12
+ This is alpha software in its most nascent stages, and is not
13
+ yet ready for use with the current version of CrowdFlower.
14
+
15
+ EOF
16
+ gem.email = "brian@doloreslabs.com"
17
+ gem.homepage = "http://github.com/dolores/ruby-crowdflower"
18
+ gem.authors = ["Brian P O'Rourke", "Chris Van Pelt"]
19
+ gem.add_dependency 'httparty', '>= 0.4.3'
20
+ end
21
+
22
+ rescue LoadError
23
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
24
+ end
25
+
26
+ require 'spec/rake/spectask'
27
+ Spec::Rake::SpecTask.new(:spec) do |spec|
28
+ spec.libs << 'lib' << 'spec'
29
+ spec.spec_files = FileList['spec/**/*_spec.rb']
30
+ end
31
+
32
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
33
+ spec.libs << 'lib' << 'spec'
34
+ spec.pattern = 'spec/**/*_spec.rb'
35
+ spec.rcov = true
36
+ end
37
+
38
+ task :default => :spec
39
+
40
+ require 'rake/rdoctask'
41
+ Rake::RDocTask.new do |rdoc|
42
+ if File.exist?('VERSION.yml')
43
+ config = YAML.load(File.read('VERSION.yml'))
44
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
45
+ else
46
+ version = ""
47
+ end
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "ruby-crowdflower #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
54
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1,132 @@
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
@@ -0,0 +1,30 @@
1
+ module HTTParty
2
+ class Request
3
+ def handle_response(response)
4
+ case response
5
+ when Net::HTTPRedirection
6
+ options[:limit] -= 1
7
+
8
+ self.path = response['location']
9
+ @redirect = true
10
+ @message = parse_response(response.body.to_s) rescue nil
11
+ perform
12
+ else
13
+ parsed_response = parse_response(response.body.to_s)
14
+ Response.new(parsed_response, response.body.to_s, response.code, @message || response.message, response.to_hash)
15
+ end
16
+ end
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
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ require 'httparty'
2
+ require 'ruby-crowdflower/httparty'
3
+ require 'ruby-crowdflower/crowdflower'
@@ -0,0 +1,57 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{ruby-crowdflower}
5
+ s.version = "0.0.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Brian P O'Rourke", "Chris Van Pelt"]
9
+ s.date = %q{2009-07-31}
10
+ s.description = %q{A toolkit for interacting with CrowdFlower via the REST API.
11
+
12
+ This is alpha software in its most nascent stages, and is not
13
+ yet ready for use with the current version of CrowdFlower.
14
+
15
+ }
16
+ s.email = %q{brian@doloreslabs.com}
17
+ s.extra_rdoc_files = [
18
+ "LICENSE",
19
+ "README.rdoc"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ ".gitignore",
24
+ "LICENSE",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "lib/ruby-crowdflower.rb",
29
+ "lib/ruby-crowdflower/crowdflower.rb",
30
+ "lib/ruby-crowdflower/httparty.rb",
31
+ "ruby-crowdflower.gemspec",
32
+ "spec/ruby-crowdflower_spec.rb",
33
+ "spec/spec_helper.rb"
34
+ ]
35
+ s.homepage = %q{http://github.com/dolores/ruby-crowdflower}
36
+ s.rdoc_options = ["--charset=UTF-8"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = %q{1.3.3}
39
+ s.summary = %q{a toolkit for the CrowdFlower API}
40
+ s.test_files = [
41
+ "spec/ruby-crowdflower_spec.rb",
42
+ "spec/spec_helper.rb"
43
+ ]
44
+
45
+ if s.respond_to? :specification_version then
46
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
47
+ s.specification_version = 3
48
+
49
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
50
+ s.add_runtime_dependency(%q<httparty>, [">= 0.4.3"])
51
+ else
52
+ s.add_dependency(%q<httparty>, [">= 0.4.3"])
53
+ end
54
+ else
55
+ s.add_dependency(%q<httparty>, [">= 0.4.3"])
56
+ end
57
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe CrowdFlower do
4
+ it "has examples" do
5
+ pending "they need to be ported to the gem package"
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'rubygems'
4
+ require 'ruby-crowdflower'
5
+ require 'spec'
6
+ require 'spec/autorun'
7
+
8
+ Spec::Runner.configure do |config|
9
+
10
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bpo-ruby-crowdflower
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Brian P O'Rourke
8
+ - Chris Van Pelt
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2009-07-31 00:00:00 -07:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: httparty
18
+ type: :runtime
19
+ version_requirement:
20
+ version_requirements: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: 0.4.3
25
+ version:
26
+ description: A toolkit for interacting with CrowdFlower via the REST API. This is alpha software in its most nascent stages, and is not yet ready for use with the current version of CrowdFlower.
27
+ email: brian@doloreslabs.com
28
+ executables: []
29
+
30
+ extensions: []
31
+
32
+ extra_rdoc_files:
33
+ - LICENSE
34
+ - README.rdoc
35
+ files:
36
+ - .document
37
+ - .gitignore
38
+ - LICENSE
39
+ - README.rdoc
40
+ - Rakefile
41
+ - VERSION
42
+ - lib/ruby-crowdflower.rb
43
+ - lib/ruby-crowdflower/crowdflower.rb
44
+ - lib/ruby-crowdflower/httparty.rb
45
+ - ruby-crowdflower.gemspec
46
+ - spec/ruby-crowdflower_spec.rb
47
+ - spec/spec_helper.rb
48
+ has_rdoc: false
49
+ homepage: http://github.com/dolores/ruby-crowdflower
50
+ licenses:
51
+ post_install_message:
52
+ rdoc_options:
53
+ - --charset=UTF-8
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: "0"
61
+ version:
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ version:
68
+ requirements: []
69
+
70
+ rubyforge_project:
71
+ rubygems_version: 1.3.5
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: a toolkit for the CrowdFlower API
75
+ test_files:
76
+ - spec/ruby-crowdflower_spec.rb
77
+ - spec/spec_helper.rb