Class: CF::HumanWorker

Inherits:
Object
  • Object
show all
Extended by:
ActiveSupport::Concern
Includes:
Client
Defined in:
lib/cf/human_worker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ HumanWorker

Initializes a new “worker” object

Usage of HumanWorker.new(hash):

In Block DSL way

line = CF::Line.create("human_worker", "Survey") do |l|
  CF::Station.create({:line => l, :type => "work"}) do |s|
    CF::HumanWorker.new({:station => s, :number => 1, :reward => 10})
  end
end

In Plain Ruby way

line = CF::Line.new("human_worker", "Digitization")
input_format = CF::InputFormat.new({:name => "image_url", :required => true, :valid_type => "url"})
line.input_formats input_format

station = CF::Station.new({:type => "work"})
line.stations station

worker = CF::HumanWorker.new({:number => 2, :reward => 20})
line.stations.first.worker = worker


71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/cf/human_worker.rb', line 71

def initialize(options={})
  @station = options[:station]
  @number  = options[:number].nil? ? 1 : options[:number]
  @reward  = options[:reward]
  @stat_badge = options[:stat_badge]
  @badges = options[:badge]
  if @station
    request =
    {
      :body =>
      {
        :api_key => CF.api_key,
        :worker => {:number => @number, :reward => @reward, :type => "HumanWorker"},
        :badge => options[:badge],
        :stat_badge => options[:stat_badge]
      }
    }
    resp = HTTParty.post("#{CF.api_url}#{CF.api_version}/lines/#{CF.}/#{@station.line['title'].downcase}/stations/#{@station.index}/workers.json",request)

    self.id =  resp.parsed_response['id']
    self.number =  resp.parsed_response['number']
    self.reward =  resp.parsed_response['reward']
    self.stat_badge =  resp.parsed_response['stat_badge']
    self.badges = resp.parsed_response['badges']

    if resp.code != 200
      self.errors = resp.parsed_response['error']['message']
    end
    self.station = options[:station]
    self.station.worker = self
  end
end

Instance Attribute Details

#badgesObject

Badge setting for “worker” object



48
49
50
# File 'lib/cf/human_worker.rb', line 48

def badges
  @badges
end

#errorsObject

Contains Error messages if any for “worker” object



45
46
47
# File 'lib/cf/human_worker.rb', line 45

def errors
  @errors
end

#idObject

ID of “Worker” object



8
9
10
# File 'lib/cf/human_worker.rb', line 8

def id
  @id
end

#numberObject

Number of worker, e.g. :number => 3



11
12
13
# File 'lib/cf/human_worker.rb', line 11

def number
  @number
end

#rewardObject

Reward for worker, e.g. :reward => 10 (reward unit is in cents)



14
15
16
# File 'lib/cf/human_worker.rb', line 14

def reward
  @reward
end

#stat_badgeObject

Stat Badge for “worker” object, e.g. worker = CF::HumanWorker.new(=> 2, :reward => 20, :stat_badge => {:approval_rating => 40, :assignment_duration => 1800, :abandonment_rate => 30})



20
21
22
# File 'lib/cf/human_worker.rb', line 20

def stat_badge
  @stat_badge
end

#stationObject

Station attribute for “worker” object



17
18
19
# File 'lib/cf/human_worker.rb', line 17

def station
  @station
end

Instance Method Details

#to_sObject

:nodoc:



104
105
106
# File 'lib/cf/human_worker.rb', line 104

def to_s # :nodoc:
  "{:id => => #{self.id}, :number => #{self.number}, :reward => #{self.reward}, :stat_badge => #{self.stat_badge}, :errors => #{self.errors},:badges =>#{self.badges}}"
end