Class: Bob::Employees

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

Constant Summary

Constants inherited from API

API::BASE_URL, API::SANDBOX_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



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

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

.all_anniversaries_this_monthObject



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/bob/api/employees.rb', line 46

def self.all_anniversaries_this_month
  current_month = Date.current.month

  all.select do |employee|
    # Don't process employees that have an internal term date
    internal_term_date = Date.parse(employee.internal.termination_date)
    next if internal_term_date.present?

    parsed_start_date = Date.parse(employee.start_date)
    parsed_start_date.month == current_month
  end
end

.all_leavers(start_date:, end_date:) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/bob/api/employees.rb', line 22

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?

    # Don't process employees that left before the period we are looking into
    internal_term_date = Date.parse(employee.internal.termination_date)
    next if internal_term_date.before?(start_date)

    # Need to fetch lifecycle statuses, as garden leavers have left before the actual internal term date
    lifecycle_statuses = Bob::Employee::LifecycleHistory.all(employee.id)
    garden_leave_status = lifecycle_statuses.find { |status| status.status == 'garden leave' }

    if garden_leave_status
      lifecycle_statuses = Bob::Employee::LifecycleHistory.all(employee.id)
      garden_leave_status = lifecycle_statuses.find { |status| status.status == 'garden leave' }
      termination_date = Date.parse(garden_leave_status.effective_date)
    end

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

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



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

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



69
70
71
72
# File 'lib/bob/api/employees.rb', line 69

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



74
75
76
77
78
# File 'lib/bob/api/employees.rb', line 74

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



64
65
66
67
# File 'lib/bob/api/employees.rb', line 64

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



80
81
82
# File 'lib/bob/api/employees.rb', line 80

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

.update_email(employee_id, email) ⇒ Object



89
90
91
# File 'lib/bob/api/employees.rb', line 89

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



85
86
87
# File 'lib/bob/api/employees.rb', line 85

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