Class: CrowdFlower::Unit

Inherits:
Base
  • Object
show all
Defined in:
lib/crowdflower/unit.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#last_response

Instance Method Summary collapse

Methods inherited from Base

connect, #connect, connect!, connect_config!, connect_domain!, connection, #connection, delete, get, post, put, verify_response

Constructor Details

#initialize(job) ⇒ Unit

Returns a new instance of Unit.



5
6
7
8
9
# File 'lib/crowdflower/unit.rb', line 5

def initialize(job)
  super job.connection
  @job = job
  connect
end

Instance Attribute Details

#jobObject (readonly)

Returns the value of attribute job.



3
4
5
# File 'lib/crowdflower/unit.rb', line 3

def job
  @job
end

Instance Method Details

#all(page = 1, limit = 1000) ⇒ Object



15
16
17
# File 'lib/crowdflower/unit.rb', line 15

def all(page = 1, limit = 1000)
  connection.get(resource_uri, {:query => {:limit => limit, :page => page}})
end

#cancel(unit_id) ⇒ Object



51
52
53
# File 'lib/crowdflower/unit.rb', line 51

def cancel(unit_id)
  connection.post("#{resource_uri}/#{unit_id}/cancel.json")
end

#copy(unit_id, job_id, data = {}) ⇒ Object



35
36
37
# File 'lib/crowdflower/unit.rb', line 35

def copy(unit_id, job_id, data = {})
  connection.get("#{resource_uri}/#{unit_id}/copy", {:query => {:unit => {:job_id => job_id, :data => data}}})
end

#create(data, gold = false) ⇒ Object



31
32
33
# File 'lib/crowdflower/unit.rb', line 31

def create(data, gold = false)
  connection.post(resource_uri, {:body => {:unit => {:data => data.to_json, :golden => gold}}})
end

#delete(unit_id) ⇒ Object



55
56
57
# File 'lib/crowdflower/unit.rb', line 55

def delete(unit_id)
  connection.delete("#{resource_uri}/#{unit_id}")
end

#get(id) ⇒ Object



19
20
21
# File 'lib/crowdflower/unit.rb', line 19

def get(id)
  connection.get("#{resource_uri}/#{id}")
end

#judgments(id) ⇒ Object



27
28
29
# File 'lib/crowdflower/unit.rb', line 27

def judgments(id)
  connection.get("#{resource_uri}/#{id}/judgments")
end

#make_gold(unit_id) ⇒ Object



47
48
49
# File 'lib/crowdflower/unit.rb', line 47

def make_gold(unit_id)
  update(unit_id, :golden => "true")
end

#pingObject



23
24
25
# File 'lib/crowdflower/unit.rb', line 23

def ping
  connection.get("#{resource_uri}/ping")
end

#request_more_judgments(unit_id, nb_judgments = 1) ⇒ Object



59
60
61
# File 'lib/crowdflower/unit.rb', line 59

def request_more_judgments(unit_id, nb_judgments = 1)
  connection.post("#{resource_uri}/#{unit_id}/request_more_judgments.json", :body => {:nb_judgments => nb_judgments})
end

#resource_uriObject



11
12
13
# File 'lib/crowdflower/unit.rb', line 11

def resource_uri
  "/jobs/#{@job.id}/units"
end

#split(on, with = " ") ⇒ Object



39
40
41
# File 'lib/crowdflower/unit.rb', line 39

def split(on, with = " ")
  connection.get("#{resource_uri}/split", {:query => {:on => on, :with => with}})
end

#update(unit_id, params) ⇒ Object



43
44
45
# File 'lib/crowdflower/unit.rb', line 43

def update(unit_id, params)
  connection.put("#{resource_uri}/#{unit_id}", {:body => {:unit => params}})
end