Class: Bamboozled::API::Employee

Inherits:
Base
  • Object
show all
Defined in:
lib/bamboozled/api/employee.rb

Instance Attribute Summary

Attributes inherited from Base

#api_key, #subdomain

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Bamboozled::API::Base

Instance Method Details

#add(employee_details) ⇒ Object



104
105
106
107
108
109
# File 'lib/bamboozled/api/employee.rb', line 104

def add(employee_details)
  details = generate_xml(employee_details)
  options = {body: details}

  request(:post, "employees/", options)
end

#add_file(employee_id, file_details) ⇒ Object



122
123
124
# File 'lib/bamboozled/api/employee.rb', line 122

def add_file(employee_id, file_details)
  post_file("employees/#{employee_id}/files", file_details)
end

#add_table_row(employee_id, table_name, table_row_data) ⇒ Object



41
42
43
44
45
# File 'lib/bamboozled/api/employee.rb', line 41

def add_table_row(employee_id, table_name, table_row_data)
  details = generate_xml(table_row_data)
  options = {body: details}
  request(:post, "employees/#{employee_id}/tables/#{table_name}", options)
end

#add_time_off_policies(employee_id, policies) ⇒ Object



78
79
80
81
82
83
84
85
86
87
# File 'lib/bamboozled/api/employee.rb', line 78

def add_time_off_policies(employee_id, policies)
  allowed_keys = %i[timeOffPolicyId accrualStartDate]
  policies = policies.map { |policy| policy.keep_if { |k, _| allowed_keys.include? k } }

  options = {
    body: policies.to_json
  }

  request(:put, "employees/#{employee_id}/time_off/policies", options)
end

#all(fields = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/bamboozled/api/employee.rb', line 5

def all(fields = nil)
  response = request(:get, "employees/directory")

  if fields.nil? || fields == :default
    Array(response['employees'])
  else
    employees = []
    response['employees'].map{|e| e['id']}.each do |id|
      employees << find(id, fields)
    end
    employees
  end
end

#files(employee_id) ⇒ Object



118
119
120
# File 'lib/bamboozled/api/employee.rb', line 118

def files(employee_id)
  request(:get, "employees/#{employee_id}/files/view/")
end

#find(employee_id, fields = nil) ⇒ Object



19
20
21
22
23
# File 'lib/bamboozled/api/employee.rb', line 19

def find(employee_id, fields = nil)
  fields = FieldCollection.wrap(fields).to_csv

  request(:get, "employees/#{employee_id}?fields=#{fields}&onlyCurrent=false")
end

#last_changed(date = "2011-06-05T00:00:00+00:00", type = nil) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/bamboozled/api/employee.rb', line 25

def last_changed(date = "2011-06-05T00:00:00+00:00", type = nil)
  query = Hash.new
  query[:since] = date.respond_to?(:iso8601) ? date.iso8601 : date
  query[:type] = type unless type.nil?

  response = request(:get, "employees/changed", query: query)
  response["employees"]
end

#photo_binary(employee_id) ⇒ Object



89
90
91
# File 'lib/bamboozled/api/employee.rb', line 89

def photo_binary(employee_id)
  request(:get, "employees/#{employee_id}/photo/small")
end

#photo_url(employee) ⇒ Object



93
94
95
96
97
98
99
100
101
102
# File 'lib/bamboozled/api/employee.rb', line 93

def photo_url(employee)
  if (Float(employee) rescue false)
    e = find(employee, ['workEmail', 'homeEmail'])
    employee = e['workEmail'].nil? ? e['homeEmail'] : e['workEmail']
  end

  digest = Digest::MD5.new
  digest.update(employee.strip.downcase)
  "http://#{@subdomain}.bamboohr.com/employees/photos/?h=#{digest}"
end

#table_data(employee_id, table_name) ⇒ Object



53
54
55
# File 'lib/bamboozled/api/employee.rb', line 53

def table_data(employee_id, table_name)
  request(:get, "employees/#{employee_id}/tables/#{table_name}")
end

#time_off_balance_adjustment(employee_id, params) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/bamboozled/api/employee.rb', line 62

def time_off_balance_adjustment(employee_id, params)
  allowed_parameters = %i[date timeOffTypeId amount note]
  params = params.keep_if { |k, _| allowed_parameters.include? k }

  options = {
    body: params.to_json,
    headers: { "Content-Type" => "application/json" }
  }

  request(:put, "employees/#{employee_id}/time_off/balance_adjustment", options)
end

#time_off_estimate(employee_id, end_date) ⇒ Object



57
58
59
60
# File 'lib/bamboozled/api/employee.rb', line 57

def time_off_estimate(employee_id, end_date)
  end_date = end_date.strftime("%F") unless end_date.is_a?(String)
  request(:get, "employees/#{employee_id}/time_off/calculator?end=#{end_date}")
end

#time_off_policies(employee_id) ⇒ Object



74
75
76
# File 'lib/bamboozled/api/employee.rb', line 74

def time_off_policies(employee_id)
  request(:get, "employees/#{employee_id}/time_off/policies", { api_version: 'v1_1' })
end

#update(bamboo_id, employee_details) ⇒ Object



111
112
113
114
115
116
# File 'lib/bamboozled/api/employee.rb', line 111

def update(bamboo_id, employee_details)
  details = generate_xml(employee_details)
  options = { body: details }

  request(:post, "employees/#{bamboo_id}", options)
end

#update_table_row(employee_id, table_name, row_id, table_row_data) ⇒ Object



47
48
49
50
51
# File 'lib/bamboozled/api/employee.rb', line 47

def update_table_row(employee_id, table_name, row_id, table_row_data)
  details = generate_xml(table_row_data)
  options = {body: details}
  request(:post, "employees/#{employee_id}/tables/#{table_name}/#{row_id}", options)
end