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

- (HumanWorker) initialize(options = {})

A new instance of HumanWorker



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/cf/human_worker.rb', line 9

def initialize(options={})
  @skill_badges = []
  @station = options[:station]
  @number  = options[:number].nil? ? 1 : options[:number]
  @reward  = options[:reward]
  @badge = options[:skill_badge].nil? ? nil : options[:skill_badge]
  @stat_badge = options[:stat_badge].nil? ? nil : options[:stat_badge]
  if @station
    if options[:skill_badge].nil? && options[:stat_badge].nil?
      request = 
      {
        :body => 
        {
          :api_key => CF.api_key,
          :worker => {:number => @number, :reward => @reward, :type => "HumanWorker"}
        }
      }
    else
      request = 
      {
        :body => 
        {
          :api_key => CF.api_key,
          :worker => {:number => @number, :reward => @reward, :type => "HumanWorker"},
          :skill_badge => @badge,
          :stat_badge => options[:stat_badge]
        }
      }
    end
    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'] 
    @skill_badges << resp.parsed_response['skill_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

- (Object) badge

Returns the value of attribute badge



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

def badge
  @badge
end

- (Object) errors

Returns the value of attribute errors



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

def errors
  @errors
end

- (Object) id

Returns the value of attribute id



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

def id
  @id
end

- (Object) number

Returns the value of attribute number



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

def number
  @number
end

- (Object) reward

Returns the value of attribute reward



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

def reward
  @reward
end

- (Object) skill_badges

Returns the value of attribute skill_badges



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

def skill_badges
  @skill_badges
end

- (Object) stat_badge

Returns the value of attribute stat_badge



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

def stat_badge
  @stat_badge
end

- (Object) station

Returns the value of attribute station



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

def station
  @station
end