crowdflower 0.4.2 → 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.2
1
+ 0.4.5
data/crowdflower.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{crowdflower}
8
- s.version = "0.4.2"
8
+ s.version = "0.4.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Brian P O'Rourke", "Chris Van Pelt"]
12
- s.date = %q{2010-11-17}
12
+ s.date = %q{2010-12-03}
13
13
  s.description = %q{A toolkit for interacting with CrowdFlower via the REST API.
14
14
 
15
15
  This is alpha software. Have fun!
@@ -32,8 +32,9 @@ module CrowdFlower
32
32
  end
33
33
  end
34
34
 
35
- def self.connect!(key, development = false)
36
- @@domain = development ? "http://api.localhost.com:4000/v1" : "https://api.crowdflower.com/v1"
35
+ def self.connect!(key, development = false, version = 1)
36
+ @@version = version
37
+ @@domain = development ? "http://api.localhost.com:4000/v#{version}" : "https://api.crowdflower.com/v#{version}"
37
38
  @@key = key
38
39
  begin # pass yaml file
39
40
  key = YAML.load_file(key)
@@ -82,14 +82,14 @@ module CrowdFlower
82
82
  Job.get("#{resource_uri}/#{@id}/legend")
83
83
  end
84
84
 
85
- def download_csv(full = true, filename = nil)
86
- filename ||= "#{full ? "f" : "a"}#{@id}.csv"
87
- res = Job.get("#{resource_uri}/#{@id}.csv", {:format => :csv, :query => {:full => full}})
85
+ def download_csv(type = :full, filename = nil)
86
+ filename ||= "#{type.to_s[0].chr}#{@id}.csv"
87
+ res = Job.get("#{resource_uri}/#{@id}.csv", {:format => :csv, :query => {:type => type}})
88
88
  puts "Status... #{res.code.inspect}"
89
89
  if res.code == 202
90
90
  puts "CSV Generating... Trying again in 10 seconds."
91
91
  Kernel.sleep 10
92
- download_csv(full, filename)
92
+ download_csv(type, filename)
93
93
  else
94
94
  puts "CSV written to: #{File.expand_path(filename)}"
95
95
  File.open(filename, "w") {|f| f.puts res.body }
@@ -118,6 +118,14 @@ module CrowdFlower
118
118
  def delete
119
119
  Job.delete("#{resource_uri}/#{@id}.json")
120
120
  end
121
+
122
+ def channels
123
+ Job.get("#{resource_uri}/#{@id}/channels")
124
+ end
125
+
126
+ def enable_channels(channels)
127
+ Job.post("#{resource_uri}/#{@id}/channels", {:body => { :channels => channels } } )
128
+ end
121
129
 
122
130
  private
123
131
  def self.custom_content_type(content_type)
@@ -14,7 +14,8 @@ module CrowdFlower
14
14
 
15
15
  #Pull every judgment
16
16
  def all(page = 1, limit = 100, latest = true)#full = true
17
- Judgment.get(resource_uri, {:query => {:limit => limit, :page => page, :latest => latest}})
17
+ opts = @@version == 2 ? {:unseen => latest} : {:latest => latest}
18
+ Judgment.get(resource_uri, {:query => {:limit => limit, :page => page}.merge(opts)})
18
19
  end
19
20
 
20
21
  def get(id)
@@ -93,20 +93,33 @@ say "Registering a webhook."
93
93
  job.update :webhook_uri => "http://localhost:8080/crowdflower"
94
94
 
95
95
  say "Adding title, instructions, and problem to the job."
96
- job.update({:title => 'testtt', :instructions => 'testttt fdsf sfds fsdfs fesfsdf', :problem => '<cml:text label="Text" class="unmodified"/>' })
96
+ job.update({:title => 'testtt',
97
+ :instructions => 'testttt fdsf sfds fsdfs fesfsdf',
98
+ :cml => '<cml:text label="Text" class="unmodified" validates="required"/>'})
99
+
100
+ say "Checking channels"
101
+ assert !job.channels['available_channels'].empty?
102
+ assert job.channels['enabled_channels'].empty?
103
+ job.enable_channels ['amt']
104
+ assert job.channels['enabled_channels'] == ['amt']
105
+ job.enable_channels ['mob']
106
+ assert job.channels['enabled_channels'].sort == ['amt', 'mob']
107
+ job.enable_channels ['mob']
108
+ assert job.channels['enabled_channels'].sort == ['amt', 'mob']
109
+
97
110
 
98
111
  say "Ordering the job."
99
112
  order = CrowdFlower::Order.new(job)
100
113
  unit_count = 8
101
114
  order.debit(8)
102
- wait_until { job.status["needed_judgments"] == 24}
115
+ wait_until { job.get["state"].casecmp('running') == 0}
103
116
 
104
117
  say "Canceling the unit."
105
118
  unit_id = job.units.all.to_a[0][0]
106
119
  unit = CrowdFlower::Unit.new(job)
107
- assert unit.get(unit_id)['state'] == 'judgable'
120
+ wait_until { unit.get(unit_id)['state'] == 'judgable' }
108
121
  puts unit.cancel(unit_id).inspect
109
- assert unit.get(unit_id)['state'] == 'new'
122
+ assert unit.get(unit_id)['state'] == 'canceled'
110
123
 
111
124
  say "Webhook test needs to be written."
112
125
  #job.test_webhook
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crowdflower
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
4
+ hash: 5
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 2
10
- version: 0.4.2
9
+ - 5
10
+ version: 0.4.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Brian P O'Rourke
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-11-17 00:00:00 -08:00
19
+ date: 2010-12-03 00:00:00 -08:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency