class FlexitimeClient::CompanyClient

Attributes

company_authorisation[R]
http_client[R]

Public Class Methods

new(company_code:, access_key:) click to toggle source
# File lib/flexitime_client/company_client.rb, line 5
def initialize(company_code:, access_key:)
  @company_authorisation = CompanyAuthorisation.new(
    company_code: company_code,
    access_key: access_key
  )
  @http_client = HttpClient.new(authorisation: company_authorisation)
end

Public Instance Methods

employee_times(employee_key:, from_date:, to_date:) click to toggle source
# File lib/flexitime_client/company_client.rb, line 20
def employee_times(employee_key:, from_date:, to_date:)
  request = ResourceRequest.new(resource: Resources::EmployeeTime, params: {
    employee_key: employee_key ,
    from_date: from_date.strftime("%Y%m%d"),
    to_date: to_date.strftime("%Y%m%d")

  })
  response = http_client.get(resource_request: request)
  attributes = parse_response(response: response) 
  attributes.map { |a| Resources::EmployeeTime.new(attributes: a) }
end
employees() click to toggle source
# File lib/flexitime_client/company_client.rb, line 13
def employees
  request = ResourceRequest.new(resource: Resources::Employee)
  response = http_client.get(resource_request: request)
  attributes = parse_response(response: response) 
  attributes.map { |a| Resources::Employee.new(attributes: a) }
end

Private Instance Methods

parse_response(response:) click to toggle source
# File lib/flexitime_client/company_client.rb, line 36
def parse_response(response:)
  return [] if response.code.to_i == 404
  JSON.parse(response.body)
end