Class: VitableConnect::Employees::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/VitableConnect/employees/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ void



9
10
11
# File 'lib/VitableConnect/employees/client.rb', line 9

def initialize(client:)
  @client = client
end

Instance Method Details

#get(request_options: {}, **params) ⇒ VitableConnect::Types::EmployeeResponse

Retrieves detailed information for a specific employee by ID. Returns employee details including personal information, employment status, classification and compensation-type effective dates, compensation type, and payroll deductions from the most recent statement period. Deductions reflect a snapshot of the current period and are replaced when a new statement is generated.

Examples:

client.employees.get(employee_id: "empl_abc123def456")

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

Returns:



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/VitableConnect/employees/client.rb', line 31

def get(request_options: {}, **params)
  params = VitableConnect::Internal::Types::Utils.normalize_keys(params)
  request = VitableConnect::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "v1/employees/#{URI.encode_uri_component(params[:employee_id].to_s)}",
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise VitableConnect::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    VitableConnect::Types::EmployeeResponse.load(response.body)
  else
    error_class = VitableConnect::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#list_enrollments(request_options: {}, **params) ⇒ VitableConnect::Types::EnrollmentListResponse

Retrieves a paginated list of benefit enrollments for an employee.

Examples:

client.employees.list_enrollments(
  employee_id: "empl_abc123def456",
  limit: 20,
  page: 1
)

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

Returns:



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/VitableConnect/employees/client.rb', line 124

def list_enrollments(request_options: {}, **params)
  params = VitableConnect::Internal::Types::Utils.normalize_keys(params)
  query_params = {}
  query_params["limit"] = params[:limit] if params.key?(:limit)
  query_params["page"] = params[:page] if params.key?(:page)

  VitableConnect::Internal::OffsetItemIterator.new(
    initial_page: query_params["page"],
    item_field: :data,
    has_next_field: nil,
    step: false
  ) do |next_page|
    query_params["page"] = next_page
    request = VitableConnect::Internal::JSON::Request.new(
      base_url: request_options[:base_url],
      method: "GET",
      path: "v1/employees/#{URI.encode_uri_component(params[:employee_id].to_s)}/enrollments",
      query: query_params,
      request_options: request_options
    )
    begin
      response = @client.send(request)
    rescue Net::HTTPRequestTimeout
      raise VitableConnect::Errors::TimeoutError
    end
    code = response.code.to_i
    if code.between?(200, 299)
      parsed_response = VitableConnect::Types::EnrollmentListResponse.load(response.body)
      [parsed_response, response]
    else
      error_class = VitableConnect::Errors::ResponseError.subclass_for_code(code)
      raise error_class.new(response.body, code: code)
    end
  end
end

#update(request_options: {}, **params) ⇒ VitableConnect::Types::EmployeeResponse

Updates employee personal, contact, address, and employment fields. This endpoint currently supports email, phone, gender, address, employee_class, start_date, and compensation_type. effective_date is required and applies to employee_class and compensation_type when those fields are included in the request.

Examples:

client.employees.update(
  employee_id: "empl_abc123def456",
  employee_class: "Full Time",
  start_date: "2023-01-15",
  compensation_type: "Salary",
  effective_date: "2023-03-01"
)

Parameters:

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

Returns:



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
# File 'lib/VitableConnect/employees/client.rb', line 76

def update(request_options: {}, **params)
  params = VitableConnect::Internal::Types::Utils.normalize_keys(params)
  request_data = VitableConnect::Employees::Types::PatchedUpdateEmployeeRequest.new(params).to_h
  non_body_param_names = %w[employee_id]
  body = request_data.except(*non_body_param_names)

  request = VitableConnect::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "PATCH",
    path: "v1/employees/#{URI.encode_uri_component(params[:employee_id].to_s)}",
    body: body,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise VitableConnect::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    VitableConnect::Types::EmployeeResponse.load(response.body)
  else
    error_class = VitableConnect::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end