Class: CrowdFlower::Worker

Inherits:
Base
  • Object
show all
Defined in:
lib/crowdflower/worker.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) ⇒ Worker

Returns a new instance of Worker.



5
6
7
8
9
# File 'lib/crowdflower/worker.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/worker.rb', line 3

def job
  @job
end

Instance Method Details

#bonus(worker_id, amount, reason = nil) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/crowdflower/worker.rb', line 15

def bonus( worker_id, amount, reason=nil )
  params = {
    :amount => amount,
    :reason => reason
  }
  connection.post( "#{resource_uri}/#{worker_id}/bonus", :body => params )
end

#deflag(worker_id, reason) ⇒ Object



42
43
44
# File 'lib/crowdflower/worker.rb', line 42

def deflag(worker_id, reason)
  connection.put( "#{resource_uri}/#{worker_id}/deflag", :body => { :reason => reason }, :headers => { "Content-Length" => "0" })
end

#flag(worker_id, reason = nil, persist = false) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/crowdflower/worker.rb', line 34

def flag( worker_id, reason = nil, persist = false )
  params = {
    :reason => reason,
    :persist => persist
  }
  connection.put( "#{resource_uri}/#{worker_id}/flag", :body => params, :headers => { "Content-Length" => "0" })
end

#notify(worker_id, message) ⇒ Object



27
28
29
30
31
32
# File 'lib/crowdflower/worker.rb', line 27

def notify( worker_id, message )
  params = {
    :message => message
  }
  connection.post( "#{resource_uri}/#{worker_id}/notify", :body => params )
end

#reject(worker_id) ⇒ Object



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

def reject( worker_id )
  connection.put( "#{resource_uri}/#{worker_id}/reject", :headers => { "Content-Length" => "0" } )
end

#resource_uriObject



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

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