Class: Bob::Employees

Inherits:
API
  • Object
show all
Defined in:
lib/bob/api/employees.rb

Constant Summary

Constants inherited from API

API::BASE_URL

Class Method Summary collapse

Methods inherited from API

authorization_header, build_url, content_headers, create_csv, delete, get, post, post_file, post_media, put

Class Method Details

.all(params = { includeHumanReadable: true }) ⇒ Object



16
17
18
19
# File 'lib/bob/api/employees.rb', line 16

def self.all(params = { includeHumanReadable: true })
  response = get('people', params)
  EmployeeParser.new(response).employees
end

.all_leavers(start_date:, end_date:) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/bob/api/employees.rb', line 21

def self.all_leavers(start_date:, end_date:)
  all({ includeHumanReadable: true, showInactive: true }).select do |employee|
    next unless employee.internal.status == 'Inactive' && employee.internal.termination_date.present?

    termination_date = Date.parse(employee.internal.termination_date)
    (start_date..end_date).include?(termination_date)
  end
end

.all_people_managers(params = { includeHumanReadable: true }) ⇒ Object



30
31
32
33
# File 'lib/bob/api/employees.rb', line 30

def self.all_people_managers(params = { includeHumanReadable: true })
  response = get('people', params)
  EmployeeParser.new(response).managers
end

.find(employee_id_or_email, params: { includeHumanReadable: true }) ⇒ Object



40
41
42
43
# File 'lib/bob/api/employees.rb', line 40

def self.find(employee_id_or_email, params: { includeHumanReadable: true })
  response = get("people/#{employee_id_or_email}", params)
  EmployeeParser.new(response).employee
end

.find_by(field:, value:, params: { includeHumanReadable: true }) ⇒ Object



45
46
47
48
49
# File 'lib/bob/api/employees.rb', line 45

def self.find_by(field:, value:, params: { includeHumanReadable: true })
  all(params).find do |employee|
    employee.send(field) == value
  end
end

.starts_on(date = Date.current.to_s, params = { includeHumanReadable: true }) ⇒ Object



35
36
37
38
# File 'lib/bob/api/employees.rb', line 35

def self.starts_on(date = Date.current.to_s, params = { includeHumanReadable: true })
  response = get('people', params)
  EmployeeParser.new(response).starters_on(date)
end

.update(employee_id:, params:) ⇒ Object



51
52
53
# File 'lib/bob/api/employees.rb', line 51

def self.update(employee_id:, params:)
  put("people/#{employee_id}", params)
end

.update_email(employee_id, email) ⇒ Object



60
61
62
# File 'lib/bob/api/employees.rb', line 60

def self.update_email(employee_id, email)
  put("people/#{employee_id}/email", { email: email })
end

.update_start_date(employee_id, start_date) ⇒ Object

start date needs to be in ISO format



56
57
58
# File 'lib/bob/api/employees.rb', line 56

def self.update_start_date(employee_id, start_date)
  post("employees/#{employee_id}", { startDate: start_date })
end